Skip to content

Commit 41e020d

Browse files
committed
wip: ダミーデータ生成フォーム
1 parent c9d2214 commit 41e020d

6 files changed

Lines changed: 159 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@codemirror/lang-json": "^6.0.1",
1818
"@emotion/react": "^11.11.1",
1919
"@emotion/styled": "^11.11.0",
20-
"@faker-js/faker": "^8.0.2",
20+
"@faker-js/faker": "^8.3.1",
2121
"@monaco-editor/react": "^4.5.2",
2222
"@rsuite/icons": "yarn ^1.0.3",
2323
"@uiw/codemirror-theme-vscode": "^4.21.21",
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
'use client';
2+
import PlusIcon from '@rsuite/icons/legacy/Plus';
3+
import { Table } from 'antd';
4+
import type { ColumnsType } from 'antd/es/table';
5+
import React, { FC } from 'react';
6+
import { FormProvider, Controller } from 'react-hook-form';
7+
import { Grid, Row, Col, Form, PanelGroup, Panel, IconButton } from 'rsuite';
8+
import { AppLayout } from '@/Layout/App';
9+
import { useDummy, DataType } from '@/app/dummy_generator/useDummy';
10+
import { Input } from '@/components/common/Form/Input';
11+
import { PageTitle } from '@/components/common/PageTitle';
12+
import { PanelHeader } from '@/components/common/PanelHeader';
13+
14+
const columns: ColumnsType<DataType> = [
15+
{
16+
title: 'ID',
17+
key: 'key',
18+
dataIndex: 'key',
19+
},
20+
{
21+
title: 'Content',
22+
key: 'content',
23+
dataIndex: 'content',
24+
},
25+
{
26+
title: 'Action',
27+
key: 'action',
28+
dataIndex: 'action',
29+
},
30+
];
31+
32+
export const DummyGenerator: FC = () => {
33+
const title = 'ダミー情報の生成';
34+
const { methods, fields, onClickAdd } = useDummy();
35+
36+
const source = fields.map((value, index) => {
37+
return {
38+
key: index,
39+
content: <ConfigRow id={value.id} index={index} control={methods.control} />,
40+
action: null,
41+
};
42+
});
43+
44+
// const source: DataType[] = [
45+
// {
46+
// key: 1,
47+
// content: '1',
48+
// action: 'a',
49+
// },
50+
// {
51+
// key: 2,
52+
// content: '2',
53+
// action: 'a',
54+
// }
55+
// ];
56+
57+
return (
58+
<FormProvider {...methods}>
59+
<AppLayout>
60+
<Grid fluid>
61+
<PageTitle title={title} />
62+
<Row gutter={5}>
63+
<Col md={12} xs={24}>
64+
<Form fluid layout="horizontal">
65+
<PanelGroup bordered>
66+
<Panel bordered header={<PanelHeader title="管理" />}>
67+
<IconButton
68+
icon={<PlusIcon />}
69+
placement="right"
70+
size="xs"
71+
onClick={onClickAdd}
72+
>
73+
追加
74+
</IconButton>
75+
</Panel>
76+
<Panel bordered header={<PanelHeader title="設定" />}>
77+
<Table columns={columns} dataSource={source} />
78+
</Panel>
79+
</PanelGroup>
80+
</Form>
81+
</Col>
82+
<Col md={12} xs={24}>
83+
<Panel bordered header={<PanelHeader title="UUID" />}></Panel>
84+
</Col>
85+
</Row>
86+
</Grid>
87+
</AppLayout>
88+
</FormProvider>
89+
);
90+
};
91+
92+
const ConfigRow: FC<{
93+
id: string;
94+
index: number;
95+
control: any;
96+
}> = ({ id, index, control }) => {
97+
return (
98+
<Controller
99+
key={id}
100+
name={`items.${index}.firstName`}
101+
control={control}
102+
render={({ field: { ref, ...field } }) => <Input {...field} />}
103+
/>
104+
);
105+
};

src/app/dummy_generator/facker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { faker } from '@faker-js/faker/locale/ja';

src/app/dummy_generator/page.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, { FC } from 'react';
2+
import { DummyGenerator } from '@/app/dummy_generator/DummyGenerator';
3+
4+
export const metadata = {
5+
title: 'Dev Toolkit - ダミーデータの生成',
6+
};
7+
8+
const DummyGeneratorPage: FC = () => {
9+
return <DummyGenerator />;
10+
};
11+
12+
export default DummyGeneratorPage;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { useCallback } from 'react';
2+
import { useFieldArray } from 'react-hook-form';
3+
import { useCustomForm } from '@/components/common/Form/useCustomForm';
4+
5+
type DummyForm = {
6+
count: number;
7+
format: 'csv' | 'tsv' | 'json';
8+
items: any;
9+
};
10+
11+
export interface DataType {
12+
key: number;
13+
content: any;
14+
action: string;
15+
}
16+
17+
export const useDummy = () => {
18+
const methods = useCustomForm<DummyForm>();
19+
const { control } = methods;
20+
const { fields, append } = useFieldArray({
21+
control,
22+
name: 'items',
23+
});
24+
25+
const onClickAdd = useCallback(() => {
26+
append({ firstName: '' });
27+
}, [append]);
28+
29+
console.log(methods.watch());
30+
31+
return {
32+
methods,
33+
fields,
34+
onClickAdd,
35+
};
36+
};

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,10 @@
642642
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.55.0.tgz#b721d52060f369aa259cf97392403cb9ce892ec6"
643643
integrity sha512-qQfo2mxH5yVom1kacMtZZJFVdW+E70mqHMJvVg6WTLo+VBuQJ4TojZlfWBjK0ve5BdEeNAVxOsl/nvNMpJOaJA==
644644

645-
"@faker-js/faker@^8.0.2":
646-
version "8.0.2"
647-
resolved "https://registry.npmjs.org/@faker-js/faker/-/faker-8.0.2.tgz"
648-
integrity sha512-Uo3pGspElQW91PCvKSIAXoEgAUlRnH29sX2/p89kg7sP1m2PzCufHINd0FhTXQf6DYGiUlVncdSPa2F9wxed2A==
645+
"@faker-js/faker@^8.3.1":
646+
version "8.3.1"
647+
resolved "https://registry.yarnpkg.com/@faker-js/faker/-/faker-8.3.1.tgz#7753df0cb88d7649becf984a96dd1bd0a26f43e3"
648+
integrity sha512-FdgpFxY6V6rLZE9mmIBb9hM0xpfvQOSNOLnzolzKwsE1DH+gC7lEKV1p1IbR0lAYyvYd5a4u3qWJzowUkw1bIw==
649649

650650
"@humanwhocodes/config-array@^0.11.13":
651651
version "0.11.13"

0 commit comments

Comments
 (0)