-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
// SPDX-FileCopyrightText: 2025 Shota FUJI <pockawoooh@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-only
import "../../../polyfill.ts";
import { createClient } from "@connectrpc/connect";
import { Button, Code, Container, Flex, Spinner, Text } from "@radix-ui/themes";
import { useQuery } from "@tanstack/react-query";
import { type User } from "@yamori/proto/yamori/workspace/v2/user_pb.js";
import { WorkspaceService } from "@yamori/proto/yamori/workspace/v2/workspace_service_pb.js";
import { type FC } from "react";
import * as Empty from "../../../components/Empty.ts";
import { ManagedErrorCallout } from "../../../components/ErrorCallout.ts";
import { useConnectTransport } from "../../../contexts/ConnectTransport.tsx";
import { Select, useURLPatternResult } from "../../../contexts/Router.tsx";
import { IllegalMessageError } from "../../../errors/IllegalMessageError.ts";
import * as edit from "./edit/page.tsx";
import * as list from "../page.tsx";
import { LoggedInLayout } from "../../LoggedInLayout.tsx";
export const Title: FC = () => "カスタムフィールド定義";
export interface PageProps {
loginUser: User;
}
export const Page: FC<PageProps> = ({ loginUser }) => {
const { pathname } = useURLPatternResult();
const defId = pathname.groups.definition;
const transport = useConnectTransport();
const client = createClient(WorkspaceService, transport);
const query = useQuery({
queryKey: [
WorkspaceService.typeName,
WorkspaceService.method.get.name,
import.meta.url,
defId,
],
async queryFn() {
const resp = await client.get({});
if (resp.result.case === "ok") {
return resp.result.value.customAttributeDefinition.find(
(def) => defId === def.id?.value,
);
}
if (typeof resp.result.case === "string") {
throw resp.result.value;
}
throw new IllegalMessageError(resp);
},
});
if (query.isError) {
return (
<LoggedInLayout title={<Title />} user={loginUser}>
<Container p="3" size="2">
<Empty.Root>
<Empty.Title>カスタムフィールド定義の取得に失敗</Empty.Title>
<Empty.Description>
カスタムフィールド定義の取得中にエラーが発生しました。
</Empty.Description>
<ManagedErrorCallout title="取得失敗" error={query.error} />
<Empty.Actions>
<Button size="3" onClick={() => void query.refetch()}>
再取得
</Button>
<Button asChild size="3" variant="outline">
<a href={list.createHref()}>一覧画面へ戻る</a>
</Button>
</Empty.Actions>
</Empty.Root>
</Container>
</LoggedInLayout>
);
}
if (query.isLoading) {
return (
<LoggedInLayout title={<Title />} user={loginUser}>
<Flex position="absolute" inset="0" align="center" justify="center" gap="2">
<Spinner />
<Text size="2" color="gray">
カスタムフィールド定義を読込中...
</Text>
</Flex>
</LoggedInLayout>
);
}
if (!query.data) {
return (
<LoggedInLayout title={<Title />} user={loginUser}>
<Container p="3" size="2">
<Empty.Root>
<Empty.Title>カスタムフィールド定義がありません</Empty.Title>
<Empty.Description>
ID <Code>{defId}</Code> のカスタムフィールド定義は登録されていません。
</Empty.Description>
<Empty.Actions>
<Button asChild size="3">
<a href={list.createHref()}>一覧画面へ戻る</a>
</Button>
</Empty.Actions>
</Empty.Root>
</Container>
</LoggedInLayout>
);
}
const definition = query.data;
return (
<Select
routes={[
{
pattern: edit.pattern,
children: <edit.Page definition={definition} loginUser={loginUser} />,
},
]}
fallback={
<LoggedInLayout title="404" user={loginUser}>
<Empty.Title>ページが見つかりません</Empty.Title>
<Empty.Description>指定された URL にページはありません。</Empty.Description>
<Empty.Actions>
<Button asChild size="3">
<a href={list.createHref()}>一覧へ戻る</a>
</Button>
</Empty.Actions>
</LoggedInLayout>
}
/>
);
};
export const pattern = new URLPattern({
pathname: "/custom-attributes/:definition(cf-[^\\/]+)/:frag*",
});