Skip to content

Commit 14b4921

Browse files
authored
Merge pull request #62 from solaoi/feature_change-export-format
change export json format
2 parents e624a60 + b7a8ed0 commit 14b4921

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

app/pages/projects/[projectId].tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,17 @@ export const Project = () => {
166166
const { stubs } = await invoke(getStubs, { where: { projectId: projectId } })
167167
const stubsForExport = stubs.map(
168168
({ path, method, contentType, statusCode, response, sleep }) => {
169-
return { path, method, contentType, statusCode, response, sleep }
169+
return {
170+
path: `/api${project.basePath}${path}`,
171+
method,
172+
contentType,
173+
statusCode,
174+
response,
175+
sleep: sleep * 1000,
176+
}
170177
}
171178
)
172-
const blob = new Blob([JSON.stringify(stubsForExport)], {
179+
const blob = new Blob([JSON.stringify(stubsForExport, null, 2)], {
173180
type: "application/json; charset=utf-8",
174181
})
175182
saveAs(blob, `co-metub_p${project.id}.json`)

app/pages/stubs/[stubId].tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import { CopyToClipboard } from "react-copy-to-clipboard"
2121
import formatXml from "xml-formatter"
2222
import { saveAs } from "file-saver"
2323

24-
const BreadCrumb = ({ stub }) => {
25-
const [project] = useQuery(getProject, { id: stub.projectId })
26-
24+
const BreadCrumb = ({ stub, project }) => {
2725
return (
2826
<Suspense fallback={<></>}>
2927
<Breadcrumb m="2" color="#666">
@@ -46,8 +44,7 @@ const BreadCrumb = ({ stub }) => {
4644
</Suspense>
4745
)
4846
}
49-
const CopyUrlButton = ({ stub }) => {
50-
const [project] = useQuery(getProject, { id: stub.projectId })
47+
const CopyUrlButton = ({ stub, project }) => {
5148
return (
5249
<Suspense fallback={<></>}>
5350
<CopyToClipboard
@@ -72,17 +69,18 @@ export const Stub = () => {
7269
const stubId = useParam("stubId", "number")
7370
const [deleteStubMutation] = useMutation(deleteStub)
7471
const [stub] = useQuery(getStub, { id: stubId })
72+
const [project] = useQuery(getProject, { id: stub.projectId })
7573

7674
return (
7775
<Box>
78-
<BreadCrumb stub={stub} />
76+
<BreadCrumb stub={stub} project={project} />
7977
<Flex align="center" justify="center" m={5}>
8078
<Box w="80%">
8179
<Heading size="lg" as="h1">
8280
Stub
8381
</Heading>
8482
<Flex justify="flex-end">
85-
<CopyUrlButton stub={stub} />
83+
<CopyUrlButton stub={stub} project={project} />
8684
<Link href={Routes.EditStubPage({ stubId: stub.id })}>
8785
<Button
8886
mr="2"
@@ -103,7 +101,20 @@ export const Stub = () => {
103101
onClick={async () => {
104102
const { path, method, contentType, statusCode, response, sleep } = stub
105103
const blob = new Blob(
106-
[JSON.stringify({ path, method, contentType, statusCode, response, sleep })],
104+
[
105+
JSON.stringify(
106+
{
107+
path: `/api${project.basePath}${path}`,
108+
method,
109+
contentType,
110+
statusCode,
111+
response,
112+
sleep: sleep * 1000,
113+
},
114+
null,
115+
2
116+
),
117+
],
107118
{
108119
type: "application/json; charset=utf-8",
109120
}

0 commit comments

Comments
 (0)