Skip to content

Commit

Permalink
Merge pull request #60 from solaoi/feature_export-stub-with-json
Browse files Browse the repository at this point in the history
add export button
  • Loading branch information
solaoi authored Jul 20, 2022
2 parents dd9a08b + 293dff4 commit e624a60
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 32 deletions.
31 changes: 30 additions & 1 deletion app/pages/projects/[projectId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
useMutation,
Routes,
usePaginatedQuery,
invoke,
} from "blitz"
import Layout from "app/core/layouts/Layout"
import getProject from "app/projects/queries/getProject"
Expand All @@ -32,8 +33,15 @@ import {
Text,
} from "@chakra-ui/react"
import { HiViewGridAdd, HiOutlineClipboardCopy } from "react-icons/hi"
import { ChevronLeftIcon, ChevronRightIcon, DeleteIcon, EditIcon } from "@chakra-ui/icons"
import {
ChevronLeftIcon,
ChevronRightIcon,
DeleteIcon,
EditIcon,
DownloadIcon,
} from "@chakra-ui/icons"
import { CopyToClipboard } from "react-copy-to-clipboard"
import { saveAs } from "file-saver"

const BreadCrumb = ({ project }) => {
return (
Expand Down Expand Up @@ -148,6 +156,27 @@ export const Project = () => {
<a>EDIT</a>
</Button>
</Link>
<Button
mr="2"
colorScheme="teal"
variant="solid"
_hover={{ bg: "teal.400", borderColor: "teal.400" }}
leftIcon={<DownloadIcon />}
onClick={async () => {
const { stubs } = await invoke(getStubs, { where: { projectId: projectId } })
const stubsForExport = stubs.map(
({ path, method, contentType, statusCode, response, sleep }) => {
return { path, method, contentType, statusCode, response, sleep }
}
)
const blob = new Blob([JSON.stringify(stubsForExport)], {
type: "application/json; charset=utf-8",
})
saveAs(blob, `co-metub_p${project.id}.json`)
}}
>
EXPORT
</Button>
<Button
colorScheme="red"
variant="solid"
Expand Down
22 changes: 21 additions & 1 deletion app/pages/stubs/[stubId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {
Text,
} from "@chakra-ui/react"
import getProject from "app/projects/queries/getProject"
import { DeleteIcon, EditIcon } from "@chakra-ui/icons"
import { DeleteIcon, EditIcon, DownloadIcon } from "@chakra-ui/icons"
import { HiOutlineClipboardCopy } from "react-icons/hi"
import { CopyToClipboard } from "react-copy-to-clipboard"
import formatXml from "xml-formatter"
import { saveAs } from "file-saver"

const BreadCrumb = ({ stub }) => {
const [project] = useQuery(getProject, { id: stub.projectId })
Expand Down Expand Up @@ -93,6 +94,25 @@ export const Stub = () => {
<a>EDIT</a>
</Button>
</Link>
<Button
mr="2"
colorScheme="teal"
variant="solid"
_hover={{ bg: "teal.400", borderColor: "teal.400" }}
leftIcon={<DownloadIcon />}
onClick={async () => {
const { path, method, contentType, statusCode, response, sleep } = stub
const blob = new Blob(
[JSON.stringify({ path, method, contentType, statusCode, response, sleep })],
{
type: "application/json; charset=utf-8",
}
)
saveAs(blob, `co-metub_s${stub.id}.json`)
}}
>
EXPORT
</Button>
<Button
colorScheme="red"
variant="solid"
Expand Down
87 changes: 57 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@prisma/client": "4.0.0",
"better-sqlite3": "7.6.2",
"blitz": "0.45.5",
"file-saver": "2.0.5",
"final-form": "4.20.7",
"framer-motion": "6.5.1",
"react": "18.2.0",
Expand All @@ -46,6 +47,7 @@
},
"devDependencies": {
"@types/react": "18.0.1",
"@types/file-saver": "2.0.5",
"eslint": "8.20.0",
"husky": "8.0.1",
"lint-staged": "13.0.3",
Expand Down

0 comments on commit e624a60

Please sign in to comment.