react-core-ts 1.3.19 → 1.3.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"convertFlatArraytoTreeStructure.js","sourceRoot":"","sources":["../../src/utilities/convertFlatArraytoTreeStructure.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS,CAAC,IAAW,EAAE,OAAe,EAAE,WAAmB;IACzE,IAAM,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAE1B,uBAAuB;IACvB,IAAI,CAAC,OAAO,CAAC,UAAC,IAAI;QAChB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,2BAA2B;IAC3B,IAAM,IAAI,GAAU,EAAE,CAAC;IAEvB,IAAI,CAAC,OAAO,CAAC,UAAC,IAAI;QAChB,IAAI,IAAI,CAAC,WAAW,CAAC,EAAE;YACrB,8CAA8C;YAC9C,IAAM,QAAM,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;YAC9C,IAAI,QAAM,EAAE;gBACV,QAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC5B;SACF;aAAM;YACL,qCAAqC;YACrC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACjB;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC;AA1BD,8BA0BC"}
1
+ {"version":3,"file":"convertFlatArraytoTreeStructure.js","sourceRoot":"","sources":["../../src/utilities/convertFlatArraytoTreeStructure.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,SAAgB,SAAS,CAAC,IAAW,EAAE,OAAe,EAAE,WAAmB;IACzE,IAAM,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAE1B,uBAAuB;IACvB,IAAI,CAAC,OAAO,CAAC,UAAC,IAAI;QAChB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,2BAA2B;IAC3B,IAAM,IAAI,GAAU,EAAE,CAAC;IAEvB,IAAI,CAAC,OAAO,CAAC,UAAC,IAAI;QAChB,IAAI,IAAI,CAAC,WAAW,CAAC,EAAE;YACrB,8CAA8C;YAC9C,IAAM,QAAM,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;YAC9C,IAAI,QAAM,EAAE;gBACV,QAAM,CAAC,QAAQ,CAAC,IAAI,uBAAM,IAAI,KAAE,OAAO,EAAE,KAAK,IAAG,CAAC;aACnD;SACF;aAAM;YACL,qCAAqC;YACrC,IAAI,CAAC,IAAI,uBAAM,IAAI,KAAE,OAAO,EAAE,KAAK,IAAG,CAAC;SACxC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC;AA1BD,8BA0BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-core-ts",
3
- "version": "1.3.19",
3
+ "version": "1.3.21",
4
4
  "description": "React Components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -74,6 +74,7 @@ const AutoCompleteWithTreeStructure = forwardRef<
74
74
  const [inputValue, setInputValue] = useState<string>(value);
75
75
  const [searchValue, setSearchValue] = useState<string>('');
76
76
  const [nextPage, setNextPage] = useState<number | undefined>(1);
77
+ const [updateKey, setUpdateKey] = useState<number>(0);
77
78
  const [dropOpen, setDropOpen] = useState<boolean>(false);
78
79
  const [selectedItems, setSelectedItems] = useState<ValueProps[]>([]);
79
80
  // API call for suggestions through a custom hook
@@ -215,7 +216,10 @@ const AutoCompleteWithTreeStructure = forwardRef<
215
216
  errors && errors?.message ? 'textfield-error' : 'tree-textfield'
216
217
  } ${expandable ? 'expandable' : ''}`;
217
218
  }, [errors, name]);
219
+
218
220
  const handleRemoveSelectedItem = (index: number) => {
221
+ setDropDownData(clearAllNodes(dropDownData));
222
+ setUpdateKey(updateKey + 1);
219
223
  setSelectedItems((prev) => {
220
224
  return prev.filter((_, i) => i !== index);
221
225
  });
@@ -305,6 +309,13 @@ const AutoCompleteWithTreeStructure = forwardRef<
305
309
  setDropDownData(newTreeData);
306
310
  };
307
311
 
312
+ const clearAllNodes = (nodes: any[]): any[] => {
313
+ return nodes.map((node) => ({
314
+ ...node,
315
+ checked: false,
316
+ children: node.children ? clearAllNodes(node.children) : undefined,
317
+ }));
318
+ };
308
319
  // Function to handle checkbox change (single or multi-select)
309
320
  const updateNode = (id: string, checked: boolean) => {
310
321
  let newTreeData;
@@ -343,7 +354,6 @@ const AutoCompleteWithTreeStructure = forwardRef<
343
354
  updateAllNodes(node, id, checked)
344
355
  );
345
356
  }
346
- setDropDownData(newTreeData);
347
357
  };
348
358
  const getCheckedNodes = (node: any, checkedNodes: any[]) => {
349
359
  if (node.checked) {
@@ -396,7 +406,7 @@ const AutoCompleteWithTreeStructure = forwardRef<
396
406
  return (
397
407
  <div className="qbs-tree-list-container-child">
398
408
  <TreeNode
399
- key={node[descId]}
409
+ key={`${node[descId]}${updateKey}`}
400
410
  node={node}
401
411
  // handleMultiSelect={handleMultiSelect}
402
412
  selected={selected}
@@ -586,7 +596,7 @@ const AutoCompleteWithTreeStructure = forwardRef<
586
596
  {dropDownData?.length > 0 ? (
587
597
  dropDownData.map((suggestion: any, idx: number) => (
588
598
  <TreeNode
589
- key={suggestion[descId]}
599
+ key={`${suggestion[descId]}${updateKey}`}
590
600
  node={suggestion}
591
601
  isSelected={isSelected}
592
602
  // handleMultiSelect={handleMultiSelect}
@@ -15,11 +15,11 @@ export function buildTree(data: any[], idField: string, parentField: string) {
15
15
  // Find the parent and add the node as a child
16
16
  const parent = nodeMap.get(node[parentField]);
17
17
  if (parent) {
18
- parent.children.push(node);
18
+ parent.children.push({ ...node, checked: false });
19
19
  }
20
20
  } else {
21
21
  // No parentId means it's a root node
22
- tree.push(node);
22
+ tree.push({ ...node, checked: false });
23
23
  }
24
24
  });
25
25