|
|
@@ -26,165 +26,167 @@ const FormStateTree = () => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-const SetValues = () => {
|
|
|
+function SetValues() {
|
|
|
const formRef = useRef();
|
|
|
+ const formInitValues = {
|
|
|
+ data: [
|
|
|
+ { name: 'Semi D2C', role: 'Engineer' },
|
|
|
+ { name: 'Semi C2D', role: 'Designer' },
|
|
|
+ // { name: 'Semi DSM', role: 'Designer' },
|
|
|
+ ]
|
|
|
+ };
|
|
|
|
|
|
const getFormApi = () => {
|
|
|
const formApi = formRef.current.formApi;
|
|
|
return formApi;
|
|
|
};
|
|
|
|
|
|
- const formInitValues = {
|
|
|
- data: [
|
|
|
- {
|
|
|
- name: '0',
|
|
|
- rules: [
|
|
|
- { desc: '0-0-desc', type: '0-0-type' },
|
|
|
- { desc: '0-1-desc', type: '0-1-type' },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- name: '1',
|
|
|
- rules: [
|
|
|
- { desc: '1-0-desc', type: '1-0-type' }
|
|
|
- ],
|
|
|
- }
|
|
|
- ]
|
|
|
+ const setValuesAsync = () => {
|
|
|
+ const formApi = getFormApi();
|
|
|
+ // setTimeout(() => {
|
|
|
+ formApi.setValues({
|
|
|
+ data: [
|
|
|
+ { name: 'Semi D2C-0', role: 'Engineer-0' },
|
|
|
+ { name: 'Semi C2D-1', role: 'Designer' },
|
|
|
+ ]
|
|
|
+ }, { isOverride: true });
|
|
|
+ // }, 200);
|
|
|
+ };
|
|
|
+
|
|
|
+ const removeHeadAsync = () => {
|
|
|
+ const formApi = getFormApi();
|
|
|
+ // setTimeout(() => {
|
|
|
+ formApi.setValues({ data: [
|
|
|
+ { name: 'Semi C2D', role: 'Designer' },
|
|
|
+ { name: 'Semi DSM', role: 'Designer' },
|
|
|
+ ] }, { isOverride: true });
|
|
|
+ // }, 200);
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ const removeTailAsync = () => {
|
|
|
+ const formApi = getFormApi();
|
|
|
+ // setTimeout(() => {
|
|
|
+ formApi.setValues({ data: [
|
|
|
+ { name: 'Semi D2C', role: 'Engineer' },
|
|
|
+ { name: 'Semi C2D', role: 'Designer' },
|
|
|
+ ] }, { isOverride: true });
|
|
|
+ // }, 200);
|
|
|
+ };
|
|
|
+
|
|
|
+ const removeMiddleAsync = () => {
|
|
|
+ const formApi = getFormApi();
|
|
|
+ // setTimeout(() => {
|
|
|
+ formApi.setValues({ data: [
|
|
|
+ { name: 'Semi D2C', role: 'Engineer' },
|
|
|
+ { name: 'Semi DSM', role: 'Designer' },
|
|
|
+ ] }, { isOverride: true });
|
|
|
+ // }, 200);
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ const removeAllAsync = () => {
|
|
|
+ const formApi = getFormApi();
|
|
|
+ // setTimeout(() => {
|
|
|
+ formApi.setValues({}, { isOverride: true });
|
|
|
+ // }, 200);
|
|
|
+
|
|
|
};
|
|
|
|
|
|
- const setValueChangeOutSide = () => {
|
|
|
+ const addHeadAsync = () => {
|
|
|
const formApi = getFormApi();
|
|
|
- formApi.setValue('data', [
|
|
|
- {
|
|
|
- name: 'new-0',
|
|
|
- rules: [
|
|
|
- { desc: 'new-0-0-desc', type: 'new-0-0-type' },
|
|
|
- { desc: 'new-0-1-desc', type: 'new-0-1-type' },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'new-1',
|
|
|
- rules: [
|
|
|
- { desc: 'new-1-0-desc', type: 'new-1-0-type' },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'new-2',
|
|
|
- rules: [
|
|
|
- { desc: 'new-2-0-desc', type: 'new-2-0-type' },
|
|
|
- { desc: 'new-2-1-desc', type: 'new-2-1-type' },
|
|
|
- { desc: 'new-2-2-desc', type: 'new-2-2-type' },
|
|
|
- ],
|
|
|
- }
|
|
|
- ]);
|
|
|
+ // setTimeout(() => {
|
|
|
+ formApi.setValues({ data: [
|
|
|
+ { name: 'Semi DSM', role: 'Designer' },
|
|
|
+ { name: 'Semi D2C', role: 'Engineer' },
|
|
|
+ { name: 'Semi C2D', role: 'Designer' },
|
|
|
+ ] }, { isOverride: true });
|
|
|
+ // }, 200);
|
|
|
};
|
|
|
|
|
|
- const setValueChangeInside = () => {
|
|
|
+ const addMiddleAsync = () => {
|
|
|
const formApi = getFormApi();
|
|
|
- // formApi.setValue('data[0].rules', [{ desc: 'new-0-0-desc-in', type: 'new-0-0-type-in' }]);
|
|
|
+ // setTimeout(() => {
|
|
|
+ formApi.setValues({ data: [
|
|
|
+ { name: 'Semi D2C', role: 'Engineer' },
|
|
|
+ { name: 'Semi DSM', role: 'Designer' },
|
|
|
+ { name: 'Semi C2D', role: 'Designer' },
|
|
|
+ ] }, { isOverride: true });
|
|
|
+ // }, 200);
|
|
|
};
|
|
|
|
|
|
- const setValueChangeRow = () => {
|
|
|
+ const addTailAsync = () => {
|
|
|
const formApi = getFormApi();
|
|
|
- // formApi.setValue('data[0].rules[0]', { name: 'special-row-name', rules: [{ desc: 'abc', type: 'efg' }] });
|
|
|
+ // setTimeout(() => {
|
|
|
+ formApi.setValues({ data: [
|
|
|
+ { name: 'Semi D2C', role: 'Engineer' },
|
|
|
+ { name: 'Semi C2D', role: 'Designer' },
|
|
|
+ { name: 'Semi DSM', role: 'Designer' },
|
|
|
+ ] }, { isOverride: true });
|
|
|
+ // }, 200);
|
|
|
};
|
|
|
+
|
|
|
|
|
|
return (
|
|
|
- <Form
|
|
|
- ref={formRef}
|
|
|
- initValues={formInitValues}
|
|
|
- labelPosition='inset'
|
|
|
- >
|
|
|
- <ArrayField field='data'>
|
|
|
- {({ add, arrayFields, addWithInitValue }) => (
|
|
|
+ <Form ref={formRef} initValues={formInitValues}>
|
|
|
+ <div>
|
|
|
+ <Space>
|
|
|
+ <Button id='updateAsync' onClick={setValuesAsync}>setValuesAsync</Button>
|
|
|
+ <Button id='addHeadAsync' onClick={addHeadAsync}>addHeadAsync</Button>
|
|
|
+ <Button id='addMiddleAsync' onClick={addMiddleAsync}>addMiddleAsync</Button>
|
|
|
+ <Button id='addTailAsync' onClick={addTailAsync}>addTailAsync</Button>
|
|
|
+ </Space>
|
|
|
+ </div>
|
|
|
+ <div style={{ marginTop: 12, marginBottom: 12 }}>
|
|
|
+ <Space>
|
|
|
+ <Button id='removeHeadAsync' onClick={removeHeadAsync} icon={<IconMinusCircle />} type='danger'>removeHeadAsync</Button>
|
|
|
+ <Button id='removeTailAsync' onClick={removeTailAsync} icon={<IconMinusCircle />} type='danger'>removeTailAsync</Button>
|
|
|
+ <Button id='removeMiddleAsync' onClick={removeMiddleAsync} icon={<IconMinusCircle />} type='danger'>removeMiddleAsync</Button>
|
|
|
+ <Button id='removeAllAsync' onClick={removeAllAsync} icon={<IconMinusCircle />} type='danger'>removeAllAsync</Button>
|
|
|
+ </Space>
|
|
|
+ </div>
|
|
|
+ <ArrayField field="data">
|
|
|
+ {({ add, addWithInitValue, arrayFields }) => (
|
|
|
<React.Fragment>
|
|
|
<Space>
|
|
|
- <Button htmlType='reset' theme='solid' type='secondary' icon={<IconRefresh />}>Reset</Button>
|
|
|
- <Button id='changeOutSide' theme='solid' type='primary' onClick={() => setValueChangeOutSide()}>ChangeOutSide</Button>
|
|
|
- <Button id='changeInside' theme='solid' type='tertiary' onClick={() => setValueChangeInside()}>ChangeInsideSide</Button>
|
|
|
+ <Button id='add' onClick={add} icon={<IconPlusCircle />} type="primary">Add</Button>
|
|
|
+ <Button
|
|
|
+ id='addWithInit'
|
|
|
+ onClick={() => addWithInitValue({ name: `Semi New-${arrayFields.length + 1}`, role: 'Designer' })}
|
|
|
+ icon={<IconPlusCircle />}
|
|
|
+ type="primary">
|
|
|
+ Add with row initValue
|
|
|
+ </Button>
|
|
|
</Space>
|
|
|
{
|
|
|
arrayFields.map(({ field, key, remove }, i) => (
|
|
|
- <div key={key} style={{ width: 1000, display: 'flex', flexWrap: 'wrap' }} id={`data-${i}`} className='line'>
|
|
|
- {key.slice(0, 10)}
|
|
|
+ <div key={key} style={{ display: 'flex', width: 600 }} id={`data-${i}`} className='line'>
|
|
|
<Space>
|
|
|
<Form.Input
|
|
|
- field={`${field}.name`}
|
|
|
- label={`${field}.name`}
|
|
|
- style={{ width: 700 }}
|
|
|
id={`data-${i}-name`}
|
|
|
- >
|
|
|
- </Form.Input>
|
|
|
- <Button
|
|
|
- onClick={() => addWithInitValue({
|
|
|
- name: arrayFields.length,
|
|
|
- rules: [
|
|
|
- { desc: `${arrayFields.length}-0-desc`, type: `${arrayFields.length}-0-type` }
|
|
|
- ]
|
|
|
- })}
|
|
|
- icon={<IconPlusCircle/>}
|
|
|
- id={`data-${i}-add`}
|
|
|
- disabled={i !== arrayFields.length - 1}
|
|
|
+ field={`${field}[name]`}
|
|
|
+ label={`${field}.name`}
|
|
|
+ style={{ width: 200 }}
|
|
|
/>
|
|
|
- <Button
|
|
|
- type='danger'
|
|
|
- onClick={remove}
|
|
|
- id={`data-${i}-remove`}
|
|
|
- icon={<IconMinusCircle />}
|
|
|
+ <Form.Input
|
|
|
+ id={`data-${i}-role`}
|
|
|
+ field={`${field}[role]`}
|
|
|
+ label={`${field}.role`}
|
|
|
+ style={{ width: 200 }}
|
|
|
/>
|
|
|
</Space>
|
|
|
-
|
|
|
- <ArrayField field={`${field}.rules`}>
|
|
|
- {({ add: addNested, arrayFields: nestedArrayFields, addWithInitValue: addNestedWithInitValue }, ) => (
|
|
|
- <React.Fragment>
|
|
|
- {
|
|
|
- nestedArrayFields.map(({ field: f, key: k, remove: r }, n) => (
|
|
|
- <section className='rules' key={k} style={{ display: 'flex', flexWrap: 'wrap', marginLeft: 36 }}>
|
|
|
- <Space>
|
|
|
- {k.slice(0, 10)}
|
|
|
- <Form.Input
|
|
|
- style={{ width: 300, marginRight: 12 }}
|
|
|
- field={`${f}.type`}
|
|
|
- label={`${f}.type`}
|
|
|
- id={`data-${i}-rule-${n}-type`}
|
|
|
- />
|
|
|
- <Form.Input
|
|
|
- style={{ width: 300 }}
|
|
|
- field={`${f}.desc`}
|
|
|
- label={`${f}.desc`}
|
|
|
- id={`data-${i}-rule-${n}-desc`}
|
|
|
- />
|
|
|
- <Button
|
|
|
- onClick={() => addNestedWithInitValue({ type: `${i}-${n+1}-type`, desc: `${i}-${n+1}-desc` })}
|
|
|
- icon={<IconPlusCircle/>}
|
|
|
- id={`data-${i}-rule-${n}-add`}
|
|
|
- disabled={n !== nestedArrayFields.length - 1}
|
|
|
- >
|
|
|
- add new line
|
|
|
- </Button>
|
|
|
- <Button
|
|
|
- type='danger'
|
|
|
- onClick={r}
|
|
|
- id={`data-${i}-rule-${n}-remove`}
|
|
|
- icon={<IconMinusCircle />}
|
|
|
- />
|
|
|
- </Space>
|
|
|
- </section>
|
|
|
- ))
|
|
|
- }
|
|
|
- </React.Fragment>
|
|
|
- )}
|
|
|
- </ArrayField>
|
|
|
+ <Button style={{ margin: "36px 0 0 12px" }} type="danger" icon={<IconMinusCircle/>} onClick={remove}>remove this line</Button>
|
|
|
</div>
|
|
|
))
|
|
|
}
|
|
|
+ <Button htmlType='reset'>Reset</Button>
|
|
|
</React.Fragment>
|
|
|
)}
|
|
|
</ArrayField>
|
|
|
<FormStateTree></FormStateTree>
|
|
|
</Form>
|
|
|
);
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
SetValues.storyName = 'ArrayField-ManualBatchSet Sync';
|
|
|
|