Skip to content

Commit

Permalink
Merge pull request #31 from solaoi/feature_add-memo-on-project-andstub
Browse files Browse the repository at this point in the history
add memo feature
  • Loading branch information
solaoi authored Feb 27, 2022
2 parents eb432a0 + a75b5b1 commit 1c56125
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 23 deletions.
18 changes: 14 additions & 4 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>{project.updatedAt.toLocaleString()}</Text>
<Text mb="1">{project.updatedAt.toLocaleString()}</Text>
</>
)
}
if (stub.stubs[0].updatedAt > project.updatedAt) {
return (
<>
<Text mb="1">{stub.stubs[0].updatedBy}</Text>
<Text>{stub.stubs[0].updatedAt.toLocaleString()}</Text>
<Text mb="1">{stub.stubs[0].updatedAt.toLocaleString()}</Text>
</>
)
} else {
return (
<>
<Text mb="1">{project.updatedBy}</Text>
<Text>{project.updatedAt.toLocaleString()}</Text>
<Text mb="1">{project.updatedAt.toLocaleString()}</Text>
</>
)
}
Expand Down Expand Up @@ -181,7 +181,8 @@ export const Project = () => {
<Text mb="1">createdBy</Text>
<Text mb="1">createdAt</Text>
<Text mb="1">updatedBy</Text>
<Text>updatedAt</Text>
<Text mb="1">updatedAt</Text>
<Text>memo</Text>
</Flex>
</Box>
<Box flex="2">
Expand All @@ -190,6 +191,15 @@ 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>
</Flex>
</Box>
</Flex>
Expand Down
79 changes: 60 additions & 19 deletions app/pages/stubs/[stubId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,28 @@ export const Stub = () => {
<Text mb="1" h="1.5rem">
statusCode
</Text>
<Text mb="1" h="1.5rem">
sleep
</Text>
<Text mb="1" h="1.5rem">
ntimesError
</Text>
<Text mb="1" h="1.5rem">
ntimesErrorStatusCode
</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
</Text>
)}
<Text>response</Text>
</Flex>
</Box>
Expand Down Expand Up @@ -173,16 +186,44 @@ export const Stub = () => {
<Text mb="1" h="1.5rem">
{stub.statusCode}
</Text>
<Text mb="1" h="1.5rem">
{stub.sleep} s
</Text>
<Text mb="1" h="1.5rem">
{stub.ntimesError} times
</Text>
<Text mb="1" h="1.5rem">
{stub.ntimesErrorStatusCode}
</Text>
<Box w="100%" p="2" bgColor="#3c3c3c" color="#fff" borderRadius="lg">
{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>
)}
<Box
w="100%"
p="2"
bgColor="#3c3c3c"
color="#fff"
borderRadius="lg"
maxH="300"
overflowY="auto"
>
<pre style={{ whiteSpace: "pre-wrap" }}>
{(() => {
try {
Expand Down
2 changes: 2 additions & 0 deletions app/projects/components/ProjectForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Form, FormProps } from "app/core/components/Form"
import { LabeledTextField } from "app/core/components/LabeledTextField"
import { LabeledTextAreaField } from "app/core/components/LabeledTextAreaField"
import { z } from "zod"
export { FORM_ERROR } from "app/core/components/Form"

Expand All @@ -8,6 +9,7 @@ export function ProjectForm<S extends z.ZodType<any, any>>(props: FormProps<S>)
<Form<S> {...props}>
<LabeledTextField name="name" label="Name" placeholder="Name" />
<LabeledTextField name="basePath" label="BasePath" placeholder="/foo" />
<LabeledTextAreaField name="memo" label="Memo" placeholder="Any additional comments" />
</Form>
)
}
1 change: 1 addition & 0 deletions app/projects/mutations/createProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const CreateProject = z.object({
basePath: z
.string()
.regex(/^\/[^\/]+$/, { message: "The only slash allowed is at the beginning of a basePath" }),
memo: z.string().default(""),
})

export default resolver.pipe(resolver.zod(CreateProject), resolver.authorize(), async (input) => {
Expand Down
1 change: 1 addition & 0 deletions app/projects/mutations/updateProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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(),
})

export default resolver.pipe(
Expand Down
1 change: 1 addition & 0 deletions app/stubs/components/StubForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function StubForm<S extends z.ZodType<any, any>>(props: FormProps<S>) {
/>
<LabeledTextField name="statusCode" label="StatusCode" placeholder="200" />
<LabeledTextAreaField name="response" label="Response" placeholder="Response" />
<LabeledTextAreaField name="memo" label="Memo" placeholder="Any additional comments" />
<Card heading="Optional" bgColor="#E2E8F0">
<LabeledTextField
type="number"
Expand Down
1 change: 1 addition & 0 deletions app/stubs/mutations/createStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const CreateStub = z.object({
ntimesErrorCounter: z.number().min(0).default(0),
logs: z.string().default(""),
projectId: z.number(),
memo: z.string().default(""),
})

export default resolver.pipe(resolver.zod(CreateStub), resolver.authorize(), async (input) => {
Expand Down
1 change: 1 addition & 0 deletions app/stubs/mutations/updateStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +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(),
})

export default resolver.pipe(
Expand Down
42 changes: 42 additions & 0 deletions db/migrations/20220227143200_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Project" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"name" TEXT NOT NULL,
"basePath" TEXT NOT NULL,
"createdBy" TEXT NOT NULL,
"updatedBy" TEXT NOT NULL,
"memo" TEXT NOT NULL DEFAULT ''
);
INSERT INTO "new_Project" ("basePath", "createdAt", "createdBy", "id", "name", "updatedAt", "updatedBy") SELECT "basePath", "createdAt", "createdBy", "id", "name", "updatedAt", "updatedBy" FROM "Project";
DROP TABLE "Project";
ALTER TABLE "new_Project" RENAME TO "Project";
CREATE UNIQUE INDEX "Project_name_key" ON "Project"("name");
CREATE UNIQUE INDEX "Project_basePath_key" ON "Project"("basePath");
CREATE TABLE "new_Stub" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"createdBy" TEXT NOT NULL,
"updatedBy" TEXT NOT NULL,
"path" TEXT NOT NULL,
"method" TEXT NOT NULL,
"contentType" TEXT NOT NULL,
"statusCode" TEXT NOT NULL,
"response" TEXT NOT NULL,
"sleep" INTEGER NOT NULL DEFAULT 0,
"logs" TEXT NOT NULL,
"ntimesError" INTEGER NOT NULL DEFAULT 0,
"ntimesErrorStatusCode" TEXT NOT NULL DEFAULT '500',
"ntimesErrorCounter" INTEGER NOT NULL DEFAULT 0,
"memo" TEXT NOT NULL DEFAULT '',
"projectId" INTEGER NOT NULL,
CONSTRAINT "Stub_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_Stub" ("contentType", "createdAt", "createdBy", "id", "logs", "method", "ntimesError", "ntimesErrorCounter", "ntimesErrorStatusCode", "path", "projectId", "response", "sleep", "statusCode", "updatedAt", "updatedBy") SELECT "contentType", "createdAt", "createdBy", "id", "logs", "method", "ntimesError", "ntimesErrorCounter", "ntimesErrorStatusCode", "path", "projectId", "response", "sleep", "statusCode", "updatedAt", "updatedBy" FROM "Stub";
DROP TABLE "Stub";
ALTER TABLE "new_Stub" RENAME TO "Stub";
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
2 changes: 2 additions & 0 deletions db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ model Project {
basePath String @unique
createdBy String
updatedBy String
memo String @default("")
Stub Stub[]
}

Expand All @@ -91,6 +92,7 @@ model Stub {
ntimesError Int @default(0)
ntimesErrorStatusCode String @default("500")
ntimesErrorCounter Int @default(0)
memo String @default("")
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
projectId Int
}

0 comments on commit 1c56125

Please sign in to comment.