Skip to content

Commit b9ed2af

Browse files
authored
Merge pull request #35 from solaoi/feature_add-xml-pretty-print
add xml pretty print and some fix
2 parents 83a4b74 + 278fb1d commit b9ed2af

File tree

6 files changed

+189
-142
lines changed

6 files changed

+189
-142
lines changed

app/pages/projects/[projectId].tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,22 @@ const UpdatedInfo = ({ stub, project }) => {
7777
return (
7878
<>
7979
<Text mb="1">{project.updatedBy}</Text>
80-
<Text mb="1">{project.updatedAt.toLocaleString()}</Text>
80+
<Text mb={project.memo !== "" ? 1 : 0}>{project.updatedAt.toLocaleString()}</Text>
8181
</>
8282
)
8383
}
8484
if (stub.stubs[0].updatedAt > project.updatedAt) {
8585
return (
8686
<>
8787
<Text mb="1">{stub.stubs[0].updatedBy}</Text>
88-
<Text mb="1">{stub.stubs[0].updatedAt.toLocaleString()}</Text>
88+
<Text mb={project.memo !== "" ? 1 : 0}>{stub.stubs[0].updatedAt.toLocaleString()}</Text>
8989
</>
9090
)
9191
} else {
9292
return (
9393
<>
9494
<Text mb="1">{project.updatedBy}</Text>
95-
<Text mb="1">{project.updatedAt.toLocaleString()}</Text>
95+
<Text mb={project.memo !== "" ? 1 : 0}>{project.updatedAt.toLocaleString()}</Text>
9696
</>
9797
)
9898
}
@@ -181,8 +181,8 @@ export const Project = () => {
181181
<Text mb="1">createdBy</Text>
182182
<Text mb="1">createdAt</Text>
183183
<Text mb="1">updatedBy</Text>
184-
<Text mb="1">updatedAt</Text>
185-
<Text>memo</Text>
184+
<Text mb={project.memo !== "" ? 1 : 0}>updatedAt</Text>
185+
{project.memo !== "" && <Text>memo</Text>}
186186
</Flex>
187187
</Box>
188188
<Box flex="2">
@@ -191,15 +191,17 @@ export const Project = () => {
191191
<Text mb="1">{project.createdBy}</Text>
192192
<Text mb="1">{project.createdAt.toLocaleString()}</Text>
193193
<UpdatedInfo stub={latestStub} project={project} />
194-
<Text
195-
maxH="150"
196-
overflowY="auto"
197-
style={{ whiteSpace: "pre-wrap", wordWrap: "break-word" }}
198-
borderRadius="lg"
199-
borderWidth="1px"
200-
>
201-
{project.memo}
202-
</Text>
194+
{project.memo !== "" && (
195+
<Text
196+
maxH="150"
197+
overflowY="auto"
198+
style={{ whiteSpace: "pre-wrap", wordWrap: "break-word" }}
199+
borderRadius="lg"
200+
borderWidth="1px"
201+
>
202+
{project.memo}
203+
</Text>
204+
)}
203205
</Flex>
204206
</Box>
205207
</Flex>

app/pages/stubs/[stubId].tsx

Lines changed: 137 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import getProject from "app/projects/queries/getProject"
1818
import { DeleteIcon, EditIcon } from "@chakra-ui/icons"
1919
import { HiOutlineClipboardCopy } from "react-icons/hi"
2020
import { CopyToClipboard } from "react-copy-to-clipboard"
21+
import formatXml from "xml-formatter"
2122

2223
const BreadCrumb = ({ stub }) => {
2324
const [project] = useQuery(getProject, { id: stub.projectId })
@@ -107,137 +108,144 @@ export const Stub = () => {
107108
DELETE
108109
</Button>
109110
</Flex>
110-
<Box fontSize="md" mr="1" ml="1" mt="1" mb="5" p="1" borderWidth="1px" borderRadius="lg">
111-
<Flex justify="space-between">
112-
<Box flex="1">
113-
<Flex direction="column" fontWeight="bold" color="#666">
114-
<Text mb="1" h="1.5rem">
115-
path
116-
</Text>
117-
<Text mb="1" h="1.5rem">
118-
createdBy
119-
</Text>
120-
<Text mb="1" h="1.5rem">
121-
createdAt
122-
</Text>
123-
<Text mb="1" h="1.5rem">
124-
updatedBy
125-
</Text>
126-
<Text mb="1" h="1.5rem">
127-
updatedAt
128-
</Text>
129-
<Text mb="1" h="1.5rem">
130-
method
131-
</Text>
132-
<Text mb="1" h="1.5rem">
133-
contentType
134-
</Text>
135-
<Text mb="1" h="1.5rem">
136-
statusCode
137-
</Text>
138-
{stub.sleep !== 0 && (
139-
<>
140-
<Text mb="1" h="1.5rem">
141-
sleep
142-
</Text>
143-
</>
144-
)}
145-
{stub.ntimesError !== 0 && (
146-
<>
147-
<Text mb="1" h="1.5rem">
148-
ntimesError
149-
</Text>
150-
<Text mb="1" h="1.5rem">
151-
ntimesErrorStatusCode
152-
</Text>
153-
</>
154-
)}
155-
{stub.memo !== "" && (
156-
<Text mb="1" h="100">
157-
memo
111+
<Flex fontSize="md" mr="1" ml="1" mt="1" mb="5" p="1" borderWidth="1px" borderRadius="lg">
112+
<Box w="33%">
113+
<Flex direction="column" fontWeight="bold" color="#666">
114+
<Text mb="1" h="1.5rem">
115+
path
116+
</Text>
117+
<Text mb="1" h="1.5rem">
118+
createdBy
119+
</Text>
120+
<Text mb="1" h="1.5rem">
121+
createdAt
122+
</Text>
123+
<Text mb="1" h="1.5rem">
124+
updatedBy
125+
</Text>
126+
<Text mb="1" h="1.5rem">
127+
updatedAt
128+
</Text>
129+
<Text mb="1" h="1.5rem">
130+
method
131+
</Text>
132+
<Text mb="1" h="1.5rem">
133+
contentType
134+
</Text>
135+
<Text mb="1" h="1.5rem">
136+
statusCode
137+
</Text>
138+
{stub.sleep !== 0 && (
139+
<>
140+
<Text mb="1" h="1.5rem">
141+
sleep
158142
</Text>
159-
)}
160-
<Text>response</Text>
161-
</Flex>
162-
</Box>
163-
<Box flex="2">
164-
<Flex direction="column">
165-
<Text mb="1" h="1.5rem">
166-
{stub.path}
167-
</Text>
168-
<Text mb="1" h="1.5rem">
169-
{stub.createdBy}
170-
</Text>
171-
<Text mb="1" h="1.5rem">
172-
{stub.createdAt.toLocaleString()}
173-
</Text>
174-
<Text mb="1" h="1.5rem">
175-
{stub.updatedBy}
176-
</Text>
177-
<Text mb="1" h="1.5rem">
178-
{stub.updatedAt.toLocaleString()}
179-
</Text>
180-
<Text mb="1" h="1.5rem">
181-
{stub.method}
182-
</Text>
183-
<Text mb="1" h="1.5rem">
184-
{stub.contentType}
185-
</Text>
186-
<Text mb="1" h="1.5rem">
187-
{stub.statusCode}
143+
</>
144+
)}
145+
{stub.ntimesError !== 0 && (
146+
<>
147+
<Text mb="1" h="1.5rem">
148+
ntimesError
149+
</Text>
150+
<Text mb="1" h="1.5rem">
151+
ntimesErrorStatusCode
152+
</Text>
153+
</>
154+
)}
155+
{stub.memo !== "" && (
156+
<Text mb="1" h="100">
157+
memo
188158
</Text>
189-
{stub.sleep !== 0 && (
190-
<>
191-
<Text mb="1" h="1.5rem">
192-
{stub.sleep} s
193-
</Text>
194-
</>
195-
)}
196-
{stub.ntimesError !== 0 && (
197-
<>
198-
<Text mb="1" h="1.5rem">
199-
{stub.ntimesError} times
200-
</Text>
201-
<Text mb="1" h="1.5rem">
202-
{stub.ntimesErrorStatusCode}
203-
</Text>
204-
</>
205-
)}
206-
{stub.memo !== "" && (
207-
<Text
208-
h="100"
209-
overflowY="auto"
210-
mb="1"
211-
style={{ whiteSpace: "pre-wrap", wordWrap: "break-word" }}
212-
borderRadius="lg"
213-
borderWidth="1px"
214-
>
215-
{stub.memo}
159+
)}
160+
<Text>response</Text>
161+
</Flex>
162+
</Box>
163+
<Box w="66%">
164+
<Flex direction="column">
165+
<Text mb="1" h="1.5rem">
166+
{stub.path}
167+
</Text>
168+
<Text mb="1" h="1.5rem">
169+
{stub.createdBy}
170+
</Text>
171+
<Text mb="1" h="1.5rem">
172+
{stub.createdAt.toLocaleString()}
173+
</Text>
174+
<Text mb="1" h="1.5rem">
175+
{stub.updatedBy}
176+
</Text>
177+
<Text mb="1" h="1.5rem">
178+
{stub.updatedAt.toLocaleString()}
179+
</Text>
180+
<Text mb="1" h="1.5rem">
181+
{stub.method}
182+
</Text>
183+
<Text mb="1" h="1.5rem">
184+
{stub.contentType}
185+
</Text>
186+
<Text mb="1" h="1.5rem">
187+
{stub.statusCode}
188+
</Text>
189+
{stub.sleep !== 0 && (
190+
<>
191+
<Text mb="1" h="1.5rem">
192+
{stub.sleep} s
216193
</Text>
217-
)}
218-
<Box
219-
w="100%"
220-
p="2"
221-
bgColor="#3c3c3c"
222-
color="#fff"
223-
borderRadius="lg"
224-
maxH="300"
194+
</>
195+
)}
196+
{stub.ntimesError !== 0 && (
197+
<>
198+
<Text mb="1" h="1.5rem">
199+
{stub.ntimesError} times
200+
</Text>
201+
<Text mb="1" h="1.5rem">
202+
{stub.ntimesErrorStatusCode}
203+
</Text>
204+
</>
205+
)}
206+
{stub.memo !== "" && (
207+
<Text
208+
h="100"
225209
overflowY="auto"
210+
mb="1"
211+
style={{ whiteSpace: "pre-wrap", wordWrap: "break-word" }}
212+
borderRadius="lg"
213+
borderWidth="1px"
226214
>
227-
<pre style={{ whiteSpace: "pre-wrap" }}>
228-
{(() => {
229-
try {
215+
{stub.memo}
216+
</Text>
217+
)}
218+
<Box
219+
w="100%"
220+
p="2"
221+
bgColor="#3c3c3c"
222+
color="#fff"
223+
borderRadius="lg"
224+
maxH="300"
225+
overflowY="auto"
226+
>
227+
<pre style={{ whiteSpace: "pre-wrap" }}>
228+
{(() => {
229+
try {
230+
if (
231+
stub.contentType === "application/json" ||
232+
stub.contentType === "text/json"
233+
) {
230234
return JSON.stringify(JSON.parse(stub.response), null, 2)
231-
} catch {
235+
} else if (stub.contentType === "application/xml") {
236+
return formatXml(stub.response, { lineSeparator: "\n" })
237+
} else {
232238
return stub.response
233239
}
234-
})()}
235-
</pre>
236-
</Box>
237-
</Flex>
238-
</Box>
239-
</Flex>
240-
</Box>
240+
} catch {
241+
return stub.response
242+
}
243+
})()}
244+
</pre>
245+
</Box>
246+
</Flex>
247+
</Box>
248+
</Flex>
241249
<Heading size="md" as="h3" mb="1">
242250
Recent Requests
243251
</Heading>
@@ -255,9 +263,12 @@ export const Stub = () => {
255263
.split("\t")
256264
.filter((s) => s !== "")
257265
.map((l, i) => (
258-
<pre style={{ whiteSpace: "pre-wrap" }} key={"log_" + i}>
259-
{i !== 0 ? `\n${l}` : l}
260-
</pre>
266+
<>
267+
<pre style={{ whiteSpace: "pre-wrap" }} key={"log_" + i}>
268+
{i !== 0 ? `\n${l}` : l}
269+
</pre>
270+
<hr />
271+
</>
261272
))
262273
: "Never been requested..."}
263274
</Box>

app/projects/mutations/updateProject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const UpdateProject = z.object({
99
basePath: z
1010
.string()
1111
.regex(/^\/[^\/]+$/, { message: "The only slash allowed is at the beginning of a basePath" }),
12-
memo: z.string(),
12+
memo: z.string().default(""),
1313
})
1414

1515
export default resolver.pipe(

app/stubs/mutations/updateStub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const UpdateStub = z.object({
2929
ntimesErrorStatusCode: z
3030
.string()
3131
.regex(/^\d{3}$/, { message: "The ntimes error status code must be a three-digit number." }),
32-
memo: z.string(),
32+
memo: z.string().default(""),
3333
})
3434

3535
export default resolver.pipe(

0 commit comments

Comments
 (0)