Skip to content

Commit

Permalink
Merge pull request #35 from solaoi/feature_add-xml-pretty-print
Browse files Browse the repository at this point in the history
add xml pretty print and some fix
  • Loading branch information
solaoi authored Mar 18, 2022
2 parents 83a4b74 + 278fb1d commit b9ed2af
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 142 deletions.
30 changes: 16 additions & 14 deletions app/pages/projects/[projectId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ const UpdatedInfo = ({ stub, project }) => {
return (
<>
<Text mb="1">{project.updatedBy}</Text>
<Text mb="1">{project.updatedAt.toLocaleString()}</Text>
<Text mb={project.memo !== "" ? 1 : 0}>{project.updatedAt.toLocaleString()}</Text>
</>
)
}
if (stub.stubs[0].updatedAt > project.updatedAt) {
return (
<>
<Text mb="1">{stub.stubs[0].updatedBy}</Text>
<Text mb="1">{stub.stubs[0].updatedAt.toLocaleString()}</Text>
<Text mb={project.memo !== "" ? 1 : 0}>{stub.stubs[0].updatedAt.toLocaleString()}</Text>
</>
)
} else {
return (
<>
<Text mb="1">{project.updatedBy}</Text>
<Text mb="1">{project.updatedAt.toLocaleString()}</Text>
<Text mb={project.memo !== "" ? 1 : 0}>{project.updatedAt.toLocaleString()}</Text>
</>
)
}
Expand Down Expand Up @@ -181,8 +181,8 @@ export const Project = () => {
<Text mb="1">createdBy</Text>
<Text mb="1">createdAt</Text>
<Text mb="1">updatedBy</Text>
<Text mb="1">updatedAt</Text>
<Text>memo</Text>
<Text mb={project.memo !== "" ? 1 : 0}>updatedAt</Text>
{project.memo !== "" && <Text>memo</Text>}
</Flex>
</Box>
<Box flex="2">
Expand All @@ -191,15 +191,17 @@ export const Project = () => {
<Text mb="1">{project.createdBy}</Text>
<Text mb="1">{project.createdAt.toLocaleString()}</Text>
<UpdatedInfo stub={latestStub} project={project} />
<Text
maxH="150"
overflowY="auto"
style={{ whiteSpace: "pre-wrap", wordWrap: "break-word" }}
borderRadius="lg"
borderWidth="1px"
>
{project.memo}
</Text>
{project.memo !== "" && (
<Text
maxH="150"
overflowY="auto"
style={{ whiteSpace: "pre-wrap", wordWrap: "break-word" }}
borderRadius="lg"
borderWidth="1px"
>
{project.memo}
</Text>
)}
</Flex>
</Box>
</Flex>
Expand Down
263 changes: 137 additions & 126 deletions app/pages/stubs/[stubId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import getProject from "app/projects/queries/getProject"
import { DeleteIcon, EditIcon } from "@chakra-ui/icons"
import { HiOutlineClipboardCopy } from "react-icons/hi"
import { CopyToClipboard } from "react-copy-to-clipboard"
import formatXml from "xml-formatter"

const BreadCrumb = ({ stub }) => {
const [project] = useQuery(getProject, { id: stub.projectId })
Expand Down Expand Up @@ -107,137 +108,144 @@ export const Stub = () => {
DELETE
</Button>
</Flex>
<Box fontSize="md" mr="1" ml="1" mt="1" mb="5" p="1" borderWidth="1px" borderRadius="lg">
<Flex justify="space-between">
<Box flex="1">
<Flex direction="column" fontWeight="bold" color="#666">
<Text mb="1" h="1.5rem">
path
</Text>
<Text mb="1" h="1.5rem">
createdBy
</Text>
<Text mb="1" h="1.5rem">
createdAt
</Text>
<Text mb="1" h="1.5rem">
updatedBy
</Text>
<Text mb="1" h="1.5rem">
updatedAt
</Text>
<Text mb="1" h="1.5rem">
method
</Text>
<Text mb="1" h="1.5rem">
contentType
</Text>
<Text mb="1" h="1.5rem">
statusCode
</Text>
{stub.sleep !== 0 && (
<>
<Text mb="1" h="1.5rem">
sleep
</Text>
</>
)}
{stub.ntimesError !== 0 && (
<>
<Text mb="1" h="1.5rem">
ntimesError
</Text>
<Text mb="1" h="1.5rem">
ntimesErrorStatusCode
</Text>
</>
)}
{stub.memo !== "" && (
<Text mb="1" h="100">
memo
<Flex fontSize="md" mr="1" ml="1" mt="1" mb="5" p="1" borderWidth="1px" borderRadius="lg">
<Box w="33%">
<Flex direction="column" fontWeight="bold" color="#666">
<Text mb="1" h="1.5rem">
path
</Text>
<Text mb="1" h="1.5rem">
createdBy
</Text>
<Text mb="1" h="1.5rem">
createdAt
</Text>
<Text mb="1" h="1.5rem">
updatedBy
</Text>
<Text mb="1" h="1.5rem">
updatedAt
</Text>
<Text mb="1" h="1.5rem">
method
</Text>
<Text mb="1" h="1.5rem">
contentType
</Text>
<Text mb="1" h="1.5rem">
statusCode
</Text>
{stub.sleep !== 0 && (
<>
<Text mb="1" h="1.5rem">
sleep
</Text>
)}
<Text>response</Text>
</Flex>
</Box>
<Box flex="2">
<Flex direction="column">
<Text mb="1" h="1.5rem">
{stub.path}
</Text>
<Text mb="1" h="1.5rem">
{stub.createdBy}
</Text>
<Text mb="1" h="1.5rem">
{stub.createdAt.toLocaleString()}
</Text>
<Text mb="1" h="1.5rem">
{stub.updatedBy}
</Text>
<Text mb="1" h="1.5rem">
{stub.updatedAt.toLocaleString()}
</Text>
<Text mb="1" h="1.5rem">
{stub.method}
</Text>
<Text mb="1" h="1.5rem">
{stub.contentType}
</Text>
<Text mb="1" h="1.5rem">
{stub.statusCode}
</>
)}
{stub.ntimesError !== 0 && (
<>
<Text mb="1" h="1.5rem">
ntimesError
</Text>
<Text mb="1" h="1.5rem">
ntimesErrorStatusCode
</Text>
</>
)}
{stub.memo !== "" && (
<Text mb="1" h="100">
memo
</Text>
{stub.sleep !== 0 && (
<>
<Text mb="1" h="1.5rem">
{stub.sleep} s
</Text>
</>
)}
{stub.ntimesError !== 0 && (
<>
<Text mb="1" h="1.5rem">
{stub.ntimesError} times
</Text>
<Text mb="1" h="1.5rem">
{stub.ntimesErrorStatusCode}
</Text>
</>
)}
{stub.memo !== "" && (
<Text
h="100"
overflowY="auto"
mb="1"
style={{ whiteSpace: "pre-wrap", wordWrap: "break-word" }}
borderRadius="lg"
borderWidth="1px"
>
{stub.memo}
)}
<Text>response</Text>
</Flex>
</Box>
<Box w="66%">
<Flex direction="column">
<Text mb="1" h="1.5rem">
{stub.path}
</Text>
<Text mb="1" h="1.5rem">
{stub.createdBy}
</Text>
<Text mb="1" h="1.5rem">
{stub.createdAt.toLocaleString()}
</Text>
<Text mb="1" h="1.5rem">
{stub.updatedBy}
</Text>
<Text mb="1" h="1.5rem">
{stub.updatedAt.toLocaleString()}
</Text>
<Text mb="1" h="1.5rem">
{stub.method}
</Text>
<Text mb="1" h="1.5rem">
{stub.contentType}
</Text>
<Text mb="1" h="1.5rem">
{stub.statusCode}
</Text>
{stub.sleep !== 0 && (
<>
<Text mb="1" h="1.5rem">
{stub.sleep} s
</Text>
)}
<Box
w="100%"
p="2"
bgColor="#3c3c3c"
color="#fff"
borderRadius="lg"
maxH="300"
</>
)}
{stub.ntimesError !== 0 && (
<>
<Text mb="1" h="1.5rem">
{stub.ntimesError} times
</Text>
<Text mb="1" h="1.5rem">
{stub.ntimesErrorStatusCode}
</Text>
</>
)}
{stub.memo !== "" && (
<Text
h="100"
overflowY="auto"
mb="1"
style={{ whiteSpace: "pre-wrap", wordWrap: "break-word" }}
borderRadius="lg"
borderWidth="1px"
>
<pre style={{ whiteSpace: "pre-wrap" }}>
{(() => {
try {
{stub.memo}
</Text>
)}
<Box
w="100%"
p="2"
bgColor="#3c3c3c"
color="#fff"
borderRadius="lg"
maxH="300"
overflowY="auto"
>
<pre style={{ whiteSpace: "pre-wrap" }}>
{(() => {
try {
if (
stub.contentType === "application/json" ||
stub.contentType === "text/json"
) {
return JSON.stringify(JSON.parse(stub.response), null, 2)
} catch {
} else if (stub.contentType === "application/xml") {
return formatXml(stub.response, { lineSeparator: "\n" })
} else {
return stub.response
}
})()}
</pre>
</Box>
</Flex>
</Box>
</Flex>
</Box>
} catch {
return stub.response
}
})()}
</pre>
</Box>
</Flex>
</Box>
</Flex>
<Heading size="md" as="h3" mb="1">
Recent Requests
</Heading>
Expand All @@ -255,9 +263,12 @@ export const Stub = () => {
.split("\t")
.filter((s) => s !== "")
.map((l, i) => (
<pre style={{ whiteSpace: "pre-wrap" }} key={"log_" + i}>
{i !== 0 ? `\n${l}` : l}
</pre>
<>
<pre style={{ whiteSpace: "pre-wrap" }} key={"log_" + i}>
{i !== 0 ? `\n${l}` : l}
</pre>
<hr />
</>
))
: "Never been requested..."}
</Box>
Expand Down
2 changes: 1 addition & 1 deletion app/projects/mutations/updateProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const UpdateProject = z.object({
basePath: z
.string()
.regex(/^\/[^\/]+$/, { message: "The only slash allowed is at the beginning of a basePath" }),
memo: z.string(),
memo: z.string().default(""),
})

export default resolver.pipe(
Expand Down
2 changes: 1 addition & 1 deletion app/stubs/mutations/updateStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const UpdateStub = z.object({
ntimesErrorStatusCode: z
.string()
.regex(/^\d{3}$/, { message: "The ntimes error status code must be a three-digit number." }),
memo: z.string(),
memo: z.string().default(""),
})

export default resolver.pipe(
Expand Down
Loading

0 comments on commit b9ed2af

Please sign in to comment.