Changes
4 changed files (+75/-18)
-
-
@@ -11,6 +11,52 @@ mock,type MockOptions, } from "../../../../../.storybook/decorators/withMockedBackend.tsx"; export interface GetOptions extends MockOptions { workspace?: MessageInitShape<typeof WorkspaceSchema>; error?: Exclude< MessageInitShape<typeof WorkspaceService.method.get.output>["result"], { case: "ok" | undefined } >; failureRate?: number; } export function Get({ workspace = { id: { value: "ws-foo" }, displayName: "株式会社あああ", }, error = { case: "systemError", value: { code: "MOCK_ERR", message: "This is sample error message.", }, }, failureRate = 0, ...options }: GetOptions = {}) { return mock( WorkspaceService.method.get, () => { if (Math.random() < failureRate) { return { result: error, }; } return { result: { case: "ok" as const, value: workspace, }, }; }, options, ); } export interface ListOptions extends MockOptions { workspaces?: MessageInitShape<typeof WorkspaceSchema>[];
-
-
-
@@ -24,7 +24,7 @@ component: Page,parameters: { layout: "fullscreen", }, decorators: [withMockedBackend([workspaceService.List()])], decorators: [withMockedBackend([workspaceService.Get()])], } satisfies Meta<typeof Page>; type Story = StoryObj<typeof Page>;
-
@@ -37,10 +37,16 @@ export const Loading: Story = {decorators: [ withRoute(), withInmemoryRouter({ initialURL: "/ws-foo/invalid" }), withMockedBackend([workspaceService.List({ delayMs: 5_000 })]), withMockedBackend([workspaceService.Get({ delayMs: 5_000 })]), ], }; export const NonexistentWorkspace: Story = { decorators: [withRoute(), withInmemoryRouter({ initialURL: "/ws-000/invalid" })], decorators: [ withRoute(), withInmemoryRouter({ initialURL: "/ws-000/invalid" }), withMockedBackend([ workspaceService.Get({ failureRate: 1, error: { case: "notFound", value: {} } }), ]), ], };
-
-
-
@@ -3,8 +3,9 @@ // SPDX-License-Identifier: AGPL-3.0-onlyimport "../../polyfill.ts"; import { ListRequestSchema } from "@yamori/proto/yamori/workspace/v1/list_request_pb.js"; import { ListResponseSchema } from "@yamori/proto/yamori/workspace/v1/list_response_pb.js"; import { GetRequestSchema } from "@yamori/proto/yamori/workspace/v1/get_request_pb.js"; import { GetResponseSchema } from "@yamori/proto/yamori/workspace/v1/get_response_pb.js"; import { WorkspaceSchema } from "@yamori/proto/yamori/workspace/v1/workspace_pb.js"; import { type FC } from "react"; import { Select, useURLPatternResult } from "../../contexts/Router.tsx";
-
@@ -18,16 +19,24 @@export const Page: FC = () => { const { pathname } = useURLPatternResult(); // TODO: 単体取得に切り替える const list = useMethodQuery({ const query = useMethodQuery({ service: "yamori.workspace.v1.WorkspaceService", method: "List", method: "Get", request: { schema: ListRequestSchema, data: {}, schema: GetRequestSchema, data: { workspaceId: { value: pathname.groups.workspace! }, readMask: { fields: [ WorkspaceSchema.field.id.number, WorkspaceSchema.field.displayName.number, WorkspaceSchema.field.workerAddKey.number, ], }, }, }, response: { schema: ListResponseSchema, schema: GetResponseSchema, }, mapResponse(resp) { switch (resp.result.case) {
-
@@ -41,16 +50,11 @@ }}, }); if (!list.data) { if (!query.data) { return "読込中"; } const workspace = list.data.workspaces.find( (workspace) => workspace.id?.value === pathname.groups.workspace!, ); if (!workspace) { return "合致するワークスペースなし"; } const workspace = query.data; return ( <Select
-
-
-
@@ -19,6 +19,7 @@ layout: "fullscreen",}, decorators: [ withMockedBackend([ workspaceService.Get(), workspaceService.List(), workspaceService.Create(), workerService.List(),
-