11'use client' ;
2+ import { DeleteOutlined } from '@ant-design/icons' ;
23import PlusIcon from '@rsuite/icons/legacy/Plus' ;
3- import { Table , Form } from 'antd' ;
4+ import { Table , Form , Popconfirm , Button } from 'antd' ;
45import type { DefaultOptionType } from 'antd/es/select' ;
56import type { ColumnsType } from 'antd/es/table' ;
67import React , { FC } from 'react' ;
78import { FormProvider , Controller } from 'react-hook-form' ;
9+ import type { Control , UseFormWatch } from 'react-hook-form/dist/types/form' ;
810import { Grid , Row , Col , PanelGroup , Panel , IconButton } from 'rsuite' ;
911import { AppLayout } from '@/Layout/App' ;
1012import { dataTypeOptions } from '@/app/dummy_generator/facker' ;
1113import type { DataType } from '@/app/dummy_generator/facker' ;
1214import { NameOptions } from '@/app/dummy_generator/options/NameOptions' ;
13- import { useDummy , RecordType } from '@/app/dummy_generator/useDummy' ;
15+ import { useDummy , RecordType , DummyForm } from '@/app/dummy_generator/useDummy' ;
1416import { FormRow } from '@/components/common/Form/FormRow' ;
1517import { Select } from '@/components/common/Form/Select' ;
18+ import { TextArea } from '@/components/common/Form/TextArea' ;
1619import { PageTitle } from '@/components/common/PageTitle' ;
1720import { PanelHeader } from '@/components/common/PanelHeader' ;
18-
19- const columns : ColumnsType < RecordType > = [
20- {
21- title : 'ID' ,
22- key : 'key' ,
23- dataIndex : 'key' ,
24- width : '5%' ,
25- } ,
26- {
27- title : 'Content' ,
28- key : 'content' ,
29- dataIndex : 'content' ,
30- } ,
31- {
32- title : '削除' ,
33- key : 'action' ,
34- dataIndex : 'action' ,
35- width : '15%' ,
36- } ,
37- ] ;
21+ import { AddressOptions } from '@/app/dummy_generator/options/AddressOptions' ;
3822
3923export const DummyGenerator : FC = ( ) => {
4024 const title = 'ダミー情報の生成' ;
41- const { methods, fields, onClickAdd } = useDummy ( ) ;
25+ const { methods, fields, output , onClickAdd, onClickDelete } = useDummy ( ) ;
4226 const { watch, control } = methods ;
4327
4428 const source = fields . map ( ( value , index ) => {
@@ -49,6 +33,28 @@ export const DummyGenerator: FC = () => {
4933 } ;
5034 } ) ;
5135
36+ const columns : ColumnsType < RecordType > = [
37+ {
38+ title : 'ID' ,
39+ key : 'key' ,
40+ dataIndex : 'key' ,
41+ width : '5%' ,
42+ } ,
43+ {
44+ title : 'データ' ,
45+ key : 'content' ,
46+ dataIndex : 'content' ,
47+ } ,
48+ {
49+ key : 'action' ,
50+ dataIndex : 'action' ,
51+ width : '5%' ,
52+ render : ( _ , record : RecordType ) => (
53+ < DeleteAction key = { record . key } onClick = { onClickDelete ( record . key ) } />
54+ ) ,
55+ } ,
56+ ] ;
57+
5258 return (
5359 < FormProvider { ...methods } >
5460 < AppLayout >
@@ -75,7 +81,9 @@ export const DummyGenerator: FC = () => {
7581 </ Form >
7682 </ Col >
7783 < Col md = { 12 } xs = { 24 } >
78- < Panel bordered header = { < PanelHeader title = "UUID" /> } > </ Panel >
84+ < Panel bordered header = { < PanelHeader title = "UUID" /> } >
85+ < TextArea value = { output } readOnly rows = { 20 } />
86+ </ Panel >
7987 </ Col >
8088 </ Row >
8189 </ Grid >
@@ -87,8 +95,8 @@ export const DummyGenerator: FC = () => {
8795const ConfigRow : FC < {
8896 id : string ;
8997 index : number ;
90- control : any ;
91- watch : any ;
98+ control : Control < DummyForm > ;
99+ watch : UseFormWatch < DummyForm > ;
92100} > = ( { id, index, control, watch } ) => {
93101 return (
94102 < FormRow label = "形式" >
@@ -101,27 +109,46 @@ const ConfigRow: FC<{
101109 style = { { width : 250 } }
102110 options = { dataTypeOptions as unknown as DefaultOptionType [ ] }
103111 defaultValue = { undefined }
112+ listHeight = { 512 }
113+ listItemHeight = { 12 }
104114 showSearch
105115 { ...field }
106116 />
107117 ) }
108118 />
109- < Options dataType = { watch ( `items.${ index } .dataType` ) } index = { index } control = { control } />
119+ < Options
120+ dataType = { watch ( `items.${ index } .dataType` ) }
121+ id = { id }
122+ index = { index }
123+ control = { control }
124+ />
110125 </ FormRow >
111126 ) ;
112127} ;
113128
114- const Options : FC < { dataType : DataType ; index : number ; control : any } > = ( {
115- dataType,
116- index,
117- control,
118- } ) => {
129+ const Options : FC < {
130+ dataType : DataType ;
131+ id : string ;
132+ index : number ;
133+ control : Control < DummyForm > ;
134+ } > = ( { dataType, id : id , index, control } ) => {
119135 switch ( dataType ) {
120136 case 'name' : {
121- return < NameOptions /> ;
137+ return < NameOptions id = { id } index = { index } control = { control } /> ;
138+ }
139+ case 'address' : {
140+ return < AddressOptions id = { id } index = { index } control = { control } /> ;
122141 }
123142 default : {
124143 return null ;
125144 }
126145 }
127146} ;
147+
148+ const DeleteAction : FC < { key : number ; onClick : any } > = ( { key, onClick } ) => {
149+ return (
150+ < Popconfirm title = "本当に削除していいですか?" onConfirm = { onClick } >
151+ < Button icon = { < DeleteOutlined /> } danger />
152+ </ Popconfirm >
153+ ) ;
154+ } ;
0 commit comments