Skip to content

Commit 1c56125

Browse files
authored
Merge pull request #31 from solaoi/feature_add-memo-on-project-andstub
add memo feature
2 parents eb432a0 + a75b5b1 commit 1c56125

File tree

10 files changed

+125
-23
lines changed

10 files changed

+125
-23
lines changed

app/pages/projects/[projectId].tsx

Lines changed: 14 additions & 4 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>{project.updatedAt.toLocaleString()}</Text>
80+
<Text mb="1">{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>{stub.stubs[0].updatedAt.toLocaleString()}</Text>
88+
<Text mb="1">{stub.stubs[0].updatedAt.toLocaleString()}</Text>
8989
</>
9090
)
9191
} else {
9292
return (
9393
<>
9494
<Text mb="1">{project.updatedBy}</Text>
95-
<Text>{project.updatedAt.toLocaleString()}</Text>
95+
<Text mb="1">{project.updatedAt.toLocaleString()}</Text>
9696
</>
9797
)
9898
}
@@ -181,7 +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>updatedAt</Text>
184+
<Text mb="1">updatedAt</Text>
185+
<Text>memo</Text>
185186
</Flex>
186187
</Box>
187188
<Box flex="2">
@@ -190,6 +191,15 @@ export const Project = () => {
190191
<Text mb="1">{project.createdBy}</Text>
191192
<Text mb="1">{project.createdAt.toLocaleString()}</Text>
192193
<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>
193203
</Flex>
194204
</Box>
195205
</Flex>

app/pages/stubs/[stubId].tsx

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,28 @@ export const Stub = () => {
135135
<Text mb="1" h="1.5rem">
136136
statusCode
137137
</Text>
138-
<Text mb="1" h="1.5rem">
139-
sleep
140-
</Text>
141-
<Text mb="1" h="1.5rem">
142-
ntimesError
143-
</Text>
144-
<Text mb="1" h="1.5rem">
145-
ntimesErrorStatusCode
146-
</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
158+
</Text>
159+
)}
147160
<Text>response</Text>
148161
</Flex>
149162
</Box>
@@ -173,16 +186,44 @@ export const Stub = () => {
173186
<Text mb="1" h="1.5rem">
174187
{stub.statusCode}
175188
</Text>
176-
<Text mb="1" h="1.5rem">
177-
{stub.sleep} s
178-
</Text>
179-
<Text mb="1" h="1.5rem">
180-
{stub.ntimesError} times
181-
</Text>
182-
<Text mb="1" h="1.5rem">
183-
{stub.ntimesErrorStatusCode}
184-
</Text>
185-
<Box w="100%" p="2" bgColor="#3c3c3c" color="#fff" borderRadius="lg">
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}
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+
>
186227
<pre style={{ whiteSpace: "pre-wrap" }}>
187228
{(() => {
188229
try {

app/projects/components/ProjectForm.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Form, FormProps } from "app/core/components/Form"
22
import { LabeledTextField } from "app/core/components/LabeledTextField"
3+
import { LabeledTextAreaField } from "app/core/components/LabeledTextAreaField"
34
import { z } from "zod"
45
export { FORM_ERROR } from "app/core/components/Form"
56

@@ -8,6 +9,7 @@ export function ProjectForm<S extends z.ZodType<any, any>>(props: FormProps<S>)
89
<Form<S> {...props}>
910
<LabeledTextField name="name" label="Name" placeholder="Name" />
1011
<LabeledTextField name="basePath" label="BasePath" placeholder="/foo" />
12+
<LabeledTextAreaField name="memo" label="Memo" placeholder="Any additional comments" />
1113
</Form>
1214
)
1315
}

app/projects/mutations/createProject.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const CreateProject = 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().default(""),
1213
})
1314

1415
export default resolver.pipe(resolver.zod(CreateProject), resolver.authorize(), async (input) => {

app/projects/mutations/updateProject.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +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(),
1213
})
1314

1415
export default resolver.pipe(

app/stubs/components/StubForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function StubForm<S extends z.ZodType<any, any>>(props: FormProps<S>) {
4646
/>
4747
<LabeledTextField name="statusCode" label="StatusCode" placeholder="200" />
4848
<LabeledTextAreaField name="response" label="Response" placeholder="Response" />
49+
<LabeledTextAreaField name="memo" label="Memo" placeholder="Any additional comments" />
4950
<Card heading="Optional" bgColor="#E2E8F0">
5051
<LabeledTextField
5152
type="number"

app/stubs/mutations/createStub.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const CreateStub = z.object({
3232
ntimesErrorCounter: z.number().min(0).default(0),
3333
logs: z.string().default(""),
3434
projectId: z.number(),
35+
memo: z.string().default(""),
3536
})
3637

3738
export default resolver.pipe(resolver.zod(CreateStub), resolver.authorize(), async (input) => {

app/stubs/mutations/updateStub.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +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(),
3233
})
3334

3435
export default resolver.pipe(
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-- RedefineTables
2+
PRAGMA foreign_keys=OFF;
3+
CREATE TABLE "new_Project" (
4+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
5+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
6+
"updatedAt" DATETIME NOT NULL,
7+
"name" TEXT NOT NULL,
8+
"basePath" TEXT NOT NULL,
9+
"createdBy" TEXT NOT NULL,
10+
"updatedBy" TEXT NOT NULL,
11+
"memo" TEXT NOT NULL DEFAULT ''
12+
);
13+
INSERT INTO "new_Project" ("basePath", "createdAt", "createdBy", "id", "name", "updatedAt", "updatedBy") SELECT "basePath", "createdAt", "createdBy", "id", "name", "updatedAt", "updatedBy" FROM "Project";
14+
DROP TABLE "Project";
15+
ALTER TABLE "new_Project" RENAME TO "Project";
16+
CREATE UNIQUE INDEX "Project_name_key" ON "Project"("name");
17+
CREATE UNIQUE INDEX "Project_basePath_key" ON "Project"("basePath");
18+
CREATE TABLE "new_Stub" (
19+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
20+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
21+
"updatedAt" DATETIME NOT NULL,
22+
"createdBy" TEXT NOT NULL,
23+
"updatedBy" TEXT NOT NULL,
24+
"path" TEXT NOT NULL,
25+
"method" TEXT NOT NULL,
26+
"contentType" TEXT NOT NULL,
27+
"statusCode" TEXT NOT NULL,
28+
"response" TEXT NOT NULL,
29+
"sleep" INTEGER NOT NULL DEFAULT 0,
30+
"logs" TEXT NOT NULL,
31+
"ntimesError" INTEGER NOT NULL DEFAULT 0,
32+
"ntimesErrorStatusCode" TEXT NOT NULL DEFAULT '500',
33+
"ntimesErrorCounter" INTEGER NOT NULL DEFAULT 0,
34+
"memo" TEXT NOT NULL DEFAULT '',
35+
"projectId" INTEGER NOT NULL,
36+
CONSTRAINT "Stub_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project" ("id") ON DELETE CASCADE ON UPDATE CASCADE
37+
);
38+
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";
39+
DROP TABLE "Stub";
40+
ALTER TABLE "new_Stub" RENAME TO "Stub";
41+
PRAGMA foreign_key_check;
42+
PRAGMA foreign_keys=ON;

db/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ model Project {
7272
basePath String @unique
7373
createdBy String
7474
updatedBy String
75+
memo String @default("")
7576
Stub Stub[]
7677
}
7778

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

0 commit comments

Comments
 (0)