lu-lowcode-package-form 0.10.51 → 0.10.52

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lu-lowcode-package-form",
3
- "version": "0.10.51",
3
+ "version": "0.10.52",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^4.8.1",
6
6
  "@dnd-kit/core": "^6.1.0",
@@ -6,7 +6,7 @@ import { BaseWrapper } from "../base"
6
6
  import { debounce, isEqual } from 'lodash';
7
7
 
8
8
 
9
- const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsValue, value, type, defaultValue, onChange, option_label, option_value, option_search, options, request, requestParams, callError, subRequest, sub_option_label = "label", mode = "single", sub_option_value = "id", rightIconRender, rightIcon, rightIconClick,recordFieldsChange, ...props }, ref) => {
9
+ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsValue, shouldUpdateKey,value, type, defaultValue, onChange, option_label, option_value, option_search, options, request, requestParams, callError, subRequest, sub_option_label = "label", mode = "single", sub_option_value = "id", rightIconRender, rightIcon, rightIconClick,recordFieldsChange, ...props }, ref) => {
10
10
  const [nOptions, setNOptions] = React.useState([])
11
11
  const [fetching, setFetching] = useState(false);
12
12
  useEffect(() => {
@@ -32,9 +32,10 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
32
32
  // }, [requestParams, fieldsValue])
33
33
 
34
34
  useEffect(() => {
35
- console.log("SearchSelect useEffect fieldsValue", fieldsValue)
35
+ console.log("SearchSelect useEffect shouldUpdateKey", shouldUpdateKey)
36
+ console.log("SearchSelect useEffect requestParams", requestParams)
36
37
  initData(requestParams)
37
- }, [fieldsValue])
38
+ }, [shouldUpdateKey,requestParams])
38
39
 
39
40
  // useEffect(() => {
40
41
  // console.log("SearchSelect useEffect requestParams", requestParams)
@@ -136,7 +136,6 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
136
136
  }
137
137
  if (result) {
138
138
  newidRefs.current[childIndex] = nanoid();
139
- console.log(`[${child.props.label}]newid`, newidRefs.current[childIndex]);
140
139
  }
141
140
  return result;
142
141
  }}
@@ -152,11 +151,13 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
152
151
  rules={rules}
153
152
  >
154
153
  {React.cloneElement(child, {
155
- key: `row_${field.key}_child_${childIndex}_${newidRefs.current[childIndex]}`,
154
+ // key: `row_${field.key}_child_${childIndex}_${newidRefs.current[childIndex]}`,
155
+ key: `row_${field.key}_child_${childIndex}`,
156
156
  subTable: true,
157
157
  subTableIndex: index,
158
158
  subTableHead: index === 0,
159
159
  form,
160
+ shouldUpdateKey: newidRefs.current[childIndex],
160
161
  fieldName: [fieldName, field.name, col_id],
161
162
  fieldsValue: fieldsValue,
162
163
  initializeFormRender,
@@ -68,9 +68,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
68
68
  initializeDependencyMap();
69
69
  setFormContent(renderChildren());
70
70
  }, 300),
71
- [children, cols]
71
+ [children, cols]
72
72
  );
73
-
73
+
74
74
 
75
75
  useEffect(() => {
76
76
  throttledInitializeFormRender();
@@ -284,7 +284,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
284
284
  }
285
285
 
286
286
  setTimeout(() => {
287
- recordFieldsChange(changedFields,true)
287
+ recordFieldsChange(changedFields, true)
288
288
  // console.log("idGroups", idGroups)
289
289
  if (idGroups.length > 0) idGroups.forEach(ids => { if (Array.isArray(ids) && ids.length > 0) handleTableAddRow(ids) })
290
290
  }, 0)
@@ -483,6 +483,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
483
483
  })
484
484
  }, 0);
485
485
  }
486
+
487
+ const shouldUpdateKey = React.useRef({})
486
488
  const renderChildren = () => {
487
489
  const childrenArray = React.Children.toArray(children);
488
490
  const groupedChildren = batchElements(
@@ -492,7 +494,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
492
494
  }),
493
495
  cols
494
496
  );
495
-
497
+
498
+
499
+
496
500
 
497
501
  return groupedChildren.map((group, index) => (
498
502
  <Row key={`row-${index}`} gutter={[24, 24]}>
@@ -500,6 +504,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
500
504
  const { componentId, __id, _componentName, ...props } = child.props;
501
505
  const componentName = child.type?.displayName || _componentName;
502
506
  const identifier = componentId || __id;
507
+ if (!(identifier in shouldUpdateKey.current)) {
508
+ shouldUpdateKey.current[identifier] = nanoid()
509
+ }
503
510
  const isLayoutComponent = componentName && componentName.startsWith('Layout.');
504
511
  const isTable = componentName && componentName == 'Field.Table';
505
512
  const hidden = props.calcHidden && mode != "desgin";
@@ -518,10 +525,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
518
525
  const onCustomChange = (value) => {
519
526
  form.setFieldValue(identifier, value)
520
527
  }
521
-
528
+
522
529
  let childComponent
523
- if (isTable || isLayoutComponent){
524
- childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode , recordFieldsChange })
530
+ if (isTable || isLayoutComponent) {
531
+ childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode, recordFieldsChange })
525
532
  }
526
533
  else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
527
534
  childComponent = <Form.Item
@@ -545,18 +552,18 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
545
552
  }
546
553
  }
547
554
  }
548
- console.log(" ")
549
- console.log("curValues",curValues)
550
- console.log("prevValues",prevValues)
551
- console.log("result",result)
552
- console.log("props.label",props.label)
553
- console.log(" ")
555
+ if (result) {
556
+ shouldUpdateKey.current[identifier] = nanoid()
557
+ }
554
558
  return result;
555
559
  }}
556
560
  >
557
561
  {({ getFieldsValue }) => {
558
562
  const fieldsValue = getFieldsValue();
559
- let element = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender ,recordFieldsChange})
563
+ let element = React.cloneElement(child, {
564
+ onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender, recordFieldsChange,
565
+ shouldUpdateKey: newidRefs.current[childIndex],
566
+ })
560
567
  return componentName === "show.WithTable" ? <>{element}</> : <Form.Item
561
568
  style={{ marginBottom: 0 }}
562
569
  label=""
@@ -575,7 +582,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
575
582
  name={identifier}
576
583
  rules={rules}
577
584
  >
578
- {React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender,recordFieldsChange })}
585
+ {React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender, recordFieldsChange })}
579
586
  </Form.Item>
580
587
  }
581
588
  return (
@@ -1,4 +1,5 @@
1
1
  import React, { useMemo } from 'react';
2
+ import { nanoid } from 'nanoid';
2
3
  import { Form, Row, Col } from 'antd';
3
4
 
4
5
  const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form, initializeFormRender,recordFieldsChange, mode }) => {
@@ -12,6 +13,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
12
13
  const colSpans = useMemo(() => getColSpan(layout), [layout]);
13
14
 
14
15
 
16
+ const shouldUpdateKey = React.useRef({})
15
17
  const formItems = useMemo(() => {
16
18
  return React.Children.toArray(children).map((child, index) => {
17
19
  const props = child.props;
@@ -22,7 +24,9 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
22
24
  // let childComponent = child;
23
25
  // if (componentName == 'Field.Table')
24
26
  // childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow })
25
-
27
+ if (!(identifier in shouldUpdateKey.current)) {
28
+ shouldUpdateKey.current[identifier] = nanoid()
29
+ }
26
30
  const hidden = props?.calcHidden && mode != "desgin";
27
31
  const rules = []
28
32
  if (props?.isRequired)
@@ -63,12 +67,15 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
63
67
  }
64
68
  }
65
69
  }
70
+ if (result) {
71
+ shouldUpdateKey.current[identifier] = nanoid()
72
+ }
66
73
  return result;
67
74
  }}
68
75
  >
69
76
  {({ getFieldsValue }) => {
70
77
  const fieldsValue = getFieldsValue();
71
- let element = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender,recordFieldsChange })
78
+ let element = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender,recordFieldsChange, shouldUpdateKey: shouldUpdateKey.current[identifier] })
72
79
  return componentName === "Show.WithTable" ? <>{element}</> : <Form.Item
73
80
  style={{ marginBottom: 0 }}
74
81
  label=""