@leav/ui 1.9.0-51ddde49 → 1.9.0-5f478d94

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.
Files changed (46) hide show
  1. package/dist/_gqlTypes/index.d.ts +187 -83
  2. package/dist/_gqlTypes/index.js +158 -61
  3. package/dist/_gqlTypes/index.js.map +1 -1
  4. package/dist/components/Explorer/manage-view-settings/filter-items/FilterItems.js +2 -2
  5. package/dist/components/Explorer/manage-view-settings/filter-items/FilterItems.js.map +1 -1
  6. package/dist/components/Explorer/useViewSettingsReducer.js +11 -8
  7. package/dist/components/Explorer/useViewSettingsReducer.js.map +1 -1
  8. package/dist/components/Filters/_queries/treeFiltersDataQuery.d.ts +6 -0
  9. package/dist/components/Filters/_queries/treeFiltersDataQuery.js +54 -0
  10. package/dist/components/Filters/_queries/treeFiltersDataQuery.js.map +1 -0
  11. package/dist/components/Filters/context/useGetTreeFilters.js +5 -5
  12. package/dist/components/Filters/context/useGetTreeFilters.js.map +1 -1
  13. package/dist/components/Filters/filter-items/filter-type/tree/TreeAttributeDropDown.js +1 -2
  14. package/dist/components/Filters/filter-items/filter-type/tree/TreeAttributeDropDown.js.map +1 -1
  15. package/dist/{_queries/trees/getTreeContentQuery.d.ts → components/Filters/filter-items/filter-type/tree/_queries/filterTreeDataQuery.d.ts} +2 -2
  16. package/dist/components/Filters/filter-items/filter-type/tree/_queries/filterTreeDataQuery.js +54 -0
  17. package/dist/components/Filters/filter-items/filter-type/tree/_queries/filterTreeDataQuery.js.map +1 -0
  18. package/dist/components/Filters/filter-items/filter-type/tree/useGetTreeData.js +4 -4
  19. package/dist/components/Filters/filter-items/filter-type/tree/useGetTreeData.js.map +1 -1
  20. package/dist/components/SelectTreeNode/SelectTreeNode.d.ts +0 -2
  21. package/dist/components/SelectTreeNode/SelectTreeNode.js +2 -2
  22. package/dist/components/SelectTreeNode/SelectTreeNode.js.map +1 -1
  23. package/dist/components/SelectTreeNode/SelectTreeNodeContent.d.ts +0 -2
  24. package/dist/components/SelectTreeNode/SelectTreeNodeContent.js +60 -114
  25. package/dist/components/SelectTreeNode/SelectTreeNodeContent.js.map +1 -1
  26. package/dist/components/SelectTreeNode/TreeNodeTitle.d.ts +0 -1
  27. package/dist/components/SelectTreeNode/TreeNodeTitle.js +3 -7
  28. package/dist/components/SelectTreeNode/TreeNodeTitle.js.map +1 -1
  29. package/dist/components/SelectTreeNode/_queries/treeContentDataQuery.d.ts +6 -0
  30. package/dist/components/SelectTreeNode/_queries/treeContentDataQuery.js +56 -0
  31. package/dist/components/SelectTreeNode/_queries/treeContentDataQuery.js.map +1 -0
  32. package/dist/components/SelectTreeNode/_types.d.ts +0 -1
  33. package/dist/components/SelectTreeNode/_types.js.map +1 -1
  34. package/dist/hooks/useGetRecordForm/useGetRecordForm.js +24 -22
  35. package/dist/hooks/useGetRecordForm/useGetRecordForm.js.map +1 -1
  36. package/dist/hooks/useGetRecordValuesQuery/useGetRecordValuesQuery.js +9 -6
  37. package/dist/hooks/useGetRecordValuesQuery/useGetRecordValuesQuery.js.map +1 -1
  38. package/dist/hooks/useIFrameMessenger/schema.d.ts +12 -0
  39. package/dist/hooks/useIFrameMessenger/schema.js +6 -0
  40. package/dist/hooks/useIFrameMessenger/schema.js.map +1 -1
  41. package/dist/hooks/useRecordsConsultationHistory/useRecordsConsultationHistory.d.ts +1 -1
  42. package/dist/hooks/useRecordsConsultationHistory/useRecordsConsultationHistory.js +14 -6
  43. package/dist/hooks/useRecordsConsultationHistory/useRecordsConsultationHistory.js.map +1 -1
  44. package/package.json +7 -7
  45. package/dist/_queries/trees/getTreeContentQuery.js +0 -70
  46. package/dist/_queries/trees/getTreeContentQuery.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"SelectTreeNode.js","sourceRoot":"","sources":["../../../src/components/SelectTreeNode/SelectTreeNode.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,oBA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B,EAAE,EAAC,MAAM,EAAC,CAAC,GAAI,CAAC;IACxE,CAAC;IAED,OAAO,CACH,KAAC,qBAAqB,IAClB,QAAQ,EAAE,EAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,MAAM,EAAC,EAC7F,qCAAqC,EAAE,qCAAqC,EAC5E,+BAA+B,EAAE,+BAA+B,EAChE,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,mBAAmB,EAAE,mBAAmB,EACxC,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,EAC1B,wBAAwB,EAAE,wBAAwB,GACpD,CACL,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {localizedTranslation} from '@leav/utils';\nimport {type FunctionComponent} from 'react';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {\n type ChildrenAsRecordValuePermissionFilterInput,\n type DependentValuesPermissionFilterInput,\n useTreeDataQueryQuery,\n} from '_ui/_gqlTypes';\nimport {ErrorDisplay} from '../..';\nimport useLang from '../../hooks/useLang';\nimport {type ITreeNodeWithRecord} from '../../types/trees';\nimport {SelectTreeNodeContent} from './SelectTreeNodeContent';\nimport {SelectTreeNodeContentSkeleton} from './SelectTreeNodeContentSkeleton';\n\ninterface ISelectTreeNodeProps {\n treeId: string;\n childrenAsRecordValuePermissionFilter?: ChildrenAsRecordValuePermissionFilterInput;\n dependentValuesPermissionFilter?: DependentValuesPermissionFilterInput;\n onSelect: (node: ITreeNodeWithRecord, selected: boolean) => void;\n onCheck?: (selection: ITreeNodeWithRecord[]) => void;\n selectedNodes?: string[];\n disabledNodes?: string[];\n selectableLibraries?: string[]; // all by default\n multiple?: boolean;\n checkStrictly?: boolean;\n checkable?: boolean;\n canSelectRoot?: boolean;\n loadRecursively?: boolean;\n noPagination?: boolean;\n showSelectChildrenButton?: boolean;\n}\n\nexport const SelectTreeNode: FunctionComponent<ISelectTreeNodeProps> = ({\n treeId,\n childrenAsRecordValuePermissionFilter,\n dependentValuesPermissionFilter,\n onSelect,\n onCheck,\n selectedNodes,\n disabledNodes,\n selectableLibraries,\n multiple = false,\n checkStrictly = true,\n checkable = false,\n canSelectRoot = false,\n loadRecursively = true,\n noPagination = false,\n showSelectChildrenButton = false,\n}) => {\n const {lang} = useLang();\n const {t} = useSharedTranslation();\n const {loading, error, data} = useTreeDataQueryQuery({\n variables: {treeId},\n });\n\n if (loading) {\n return <SelectTreeNodeContentSkeleton />;\n }\n\n if (error) {\n return <ErrorDisplay message={error.message} />;\n }\n\n if (!data?.trees.list[0]) {\n return <ErrorDisplay message={t('error.unknown_tree', {treeId})} />;\n }\n\n return (\n <SelectTreeNodeContent\n treeData={{id: treeId, label: localizedTranslation(data.trees.list[0].label, lang) || treeId}}\n childrenAsRecordValuePermissionFilter={childrenAsRecordValuePermissionFilter}\n dependentValuesPermissionFilter={dependentValuesPermissionFilter}\n onCheck={onCheck}\n onSelect={onSelect}\n multiple={multiple}\n checkable={checkable}\n checkStrictly={checkStrictly}\n selectedNodes={selectedNodes}\n disabledNodes={disabledNodes}\n canSelectRoot={canSelectRoot}\n selectableLibraries={selectableLibraries}\n loadRecursively={loadRecursively}\n noPagination={noPagination}\n showSelectChildrenButton={showSelectChildrenButton}\n />\n );\n};\n"]}
1
+ {"version":3,"file":"SelectTreeNode.js","sourceRoot":"","sources":["../../../src/components/SelectTreeNode/SelectTreeNode.tsx"],"names":[],"mappings":";AA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C,CAAC,oBAAoB,EAAE,EAAC,MAAM,EAAC,CAAC,GAAI,CAAC;IACxE,CAAC;IAED,OAAO,CACH,KAAC,qBAAqB,IAClB,QAAQ,EAAE,EAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,MAAM,EAAC,EAC7F,qCAAqC,EAAE,qCAAqC,EAC5E,+BAA+B,EAAE,+BAA+B,EAChE,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,mBAAmB,EAAE,mBAAmB,EACxC,wBAAwB,EAAE,wBAAwB,GACpD,CACL,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {localizedTranslation} from '@leav/utils';\nimport {type FunctionComponent} from 'react';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport {\n type ChildrenAsRecordValuePermissionFilterInput,\n type DependentValuesPermissionFilterInput,\n useTreeDataQueryQuery,\n} from '_ui/_gqlTypes';\nimport {ErrorDisplay} from '../..';\nimport useLang from '../../hooks/useLang';\nimport {type ITreeNodeWithRecord} from '../../types/trees';\nimport {SelectTreeNodeContent} from './SelectTreeNodeContent';\nimport {SelectTreeNodeContentSkeleton} from './SelectTreeNodeContentSkeleton';\n\ninterface ISelectTreeNodeProps {\n treeId: string;\n childrenAsRecordValuePermissionFilter?: ChildrenAsRecordValuePermissionFilterInput;\n dependentValuesPermissionFilter?: DependentValuesPermissionFilterInput;\n onSelect: (node: ITreeNodeWithRecord, selected: boolean) => void;\n onCheck?: (selection: ITreeNodeWithRecord[]) => void;\n selectedNodes?: string[];\n disabledNodes?: string[];\n selectableLibraries?: string[]; // all by default\n multiple?: boolean;\n checkStrictly?: boolean;\n checkable?: boolean;\n canSelectRoot?: boolean;\n showSelectChildrenButton?: boolean;\n}\n\nexport const SelectTreeNode: FunctionComponent<ISelectTreeNodeProps> = ({\n treeId,\n childrenAsRecordValuePermissionFilter,\n dependentValuesPermissionFilter,\n onSelect,\n onCheck,\n selectedNodes,\n disabledNodes,\n selectableLibraries,\n multiple = false,\n checkStrictly = true,\n checkable = false,\n canSelectRoot = false,\n showSelectChildrenButton = false,\n}) => {\n const {lang} = useLang();\n const {t} = useSharedTranslation();\n const {loading, error, data} = useTreeDataQueryQuery({\n variables: {treeId},\n });\n\n if (loading) {\n return <SelectTreeNodeContentSkeleton />;\n }\n\n if (error) {\n return <ErrorDisplay message={error.message} />;\n }\n\n if (!data?.trees.list[0]) {\n return <ErrorDisplay message={t('error.unknown_tree', {treeId})} />;\n }\n\n return (\n <SelectTreeNodeContent\n treeData={{id: treeId, label: localizedTranslation(data.trees.list[0].label, lang) || treeId}}\n childrenAsRecordValuePermissionFilter={childrenAsRecordValuePermissionFilter}\n dependentValuesPermissionFilter={dependentValuesPermissionFilter}\n onCheck={onCheck}\n onSelect={onSelect}\n multiple={multiple}\n checkable={checkable}\n checkStrictly={checkStrictly}\n selectedNodes={selectedNodes}\n disabledNodes={disabledNodes}\n canSelectRoot={canSelectRoot}\n selectableLibraries={selectableLibraries}\n showSelectChildrenButton={showSelectChildrenButton}\n />\n );\n};\n"]}
@@ -17,8 +17,6 @@ interface ISelectTreeNodeContentProps {
17
17
  checkStrictly?: boolean;
18
18
  canSelectRoot?: boolean;
19
19
  selectableLibraries?: string[];
20
- loadRecursively?: boolean;
21
- noPagination?: boolean;
22
20
  showSelectChildrenButton?: boolean;
23
21
  }
24
22
  export declare const SelectTreeNodeContent: FunctionComponent<ISelectTreeNodeContentProps>;
@@ -5,13 +5,34 @@ import { jsx as _jsx } from "react/jsx-runtime";
5
5
  import { useEffect, useState } from 'react';
6
6
  import { KitTree } from 'aristid-ds';
7
7
  import { Spin } from 'antd';
8
- import { useTreeNodeChildrenLazyQuery, } from '../../_gqlTypes';
9
- import { defaultPaginationPageSize, ErrorDisplay } from '../../index';
8
+ import { ErrorDisplay } from '../../index';
10
9
  import { TreeNodeTitle } from './TreeNodeTitle';
11
10
  import { _isObjectSelection } from './_types';
12
- import { useSharedTranslation } from '../../hooks/useSharedTranslation';
13
- export const SelectTreeNodeContent = ({ treeData: tree, childrenAsRecordValuePermissionFilter, dependentValuesPermissionFilter, onSelect, onCheck, selectedNodes = [], disabledNodes = [], multiple = false, checkable = false, checkStrictly = true, canSelectRoot = false, selectableLibraries, loadRecursively = true, noPagination = false, showSelectChildrenButton = false, }) => {
14
- const { t } = useSharedTranslation();
11
+ import { useLazyQuery } from '@apollo/client';
12
+ import { treeContentDataQuery } from './_queries/treeContentDataQuery';
13
+ const _toTreeMapElement = (node, parents, disabledNodes) => {
14
+ const children = (node.children ?? []).map(child => _toTreeMapElement(child, [...parents, node.id], disabledNodes));
15
+ return {
16
+ record: node.record,
17
+ title: node.record.whoAmI.label || node.record.whoAmI.id,
18
+ id: node.id,
19
+ key: node.id,
20
+ isLeaf: !node.childrenCount,
21
+ children,
22
+ parents,
23
+ disabled: disabledNodes.includes(node.id),
24
+ };
25
+ };
26
+ const _buildTreeMap = (root) => {
27
+ const map = {};
28
+ const visit = (node) => {
29
+ map[node.id] = node;
30
+ node.children.forEach(visit);
31
+ };
32
+ visit(root);
33
+ return map;
34
+ };
35
+ export const SelectTreeNodeContent = ({ treeData: tree, childrenAsRecordValuePermissionFilter, dependentValuesPermissionFilter, onSelect, onCheck, selectedNodes = [], disabledNodes = [], multiple = false, checkable = false, checkStrictly = true, canSelectRoot = false, selectableLibraries, showSelectChildrenButton = false, }) => {
15
36
  const rootNode = {
16
37
  title: tree.label,
17
38
  record: null,
@@ -19,123 +40,47 @@ export const SelectTreeNodeContent = ({ treeData: tree, childrenAsRecordValuePer
19
40
  key: tree.id,
20
41
  isLeaf: false,
21
42
  parents: [],
22
- paginationOffset: 0,
23
43
  children: [],
24
44
  };
25
- // As we'll fetch children when a node is expanded, we store the whole tree content in a hash map
26
- // to make update easier and more efficient
27
- const [treeMap, setTreeMap] = useState({
28
- [tree.id]: rootNode,
45
+ const [treeMap, setTreeMap] = useState({ [tree.id]: rootNode });
46
+ const [isLoading, setIsLoading] = useState(true);
47
+ const [error, setError] = useState(null);
48
+ const [loadTreeContent] = useLazyQuery(treeContentDataQuery(), {
49
+ fetchPolicy: dependentValuesPermissionFilter ? 'no-cache' : undefined,
29
50
  });
30
- const [fetchError, setFetchError] = useState();
31
- const [loadTreeContent, { error, called }] = useTreeNodeChildrenLazyQuery();
32
- const _fetchTreeContent = async (parentNodeKey, offset = 0, currentTreeMap = { ...treeMap }) => {
33
- try {
34
- const { data: { treeNodeChildren }, } = await loadTreeContent({
35
- // If dependentValuesPermissionFilter is set, we need to bypass the cache to get up-to-date data,
36
- // because tree content depends on record values that may have changed
37
- fetchPolicy: dependentValuesPermissionFilter ? 'no-cache' : undefined,
38
- variables: {
39
- treeId: tree.id,
40
- node: parentNodeKey && parentNodeKey !== tree.id ? parentNodeKey : null,
41
- pagination: noPagination
42
- ? undefined
43
- : {
44
- limit: defaultPaginationPageSize,
45
- offset,
46
- },
47
- childrenAsRecordValuePermissionFilter,
48
- dependentValuesPermissionFilter,
49
- },
50
- });
51
- const parentMapKey = parentNodeKey ?? tree.id;
52
- const totalCount = treeNodeChildren.totalCount;
53
- const parentElement = currentTreeMap[parentMapKey];
54
- const showMoreKey = '__showMore' + parentMapKey + offset;
55
- const parentPath = parentElement?.parents ?? [];
56
- const currentParents = [...parentPath, parentMapKey];
57
- const formattedNodes = treeNodeChildren.list.map(e => ({
58
- record: e.record,
59
- title: e.record.whoAmI.label || e.record.whoAmI.id,
60
- id: e.id,
61
- key: e.id,
62
- isLeaf: !e.childrenCount,
63
- children: [],
64
- parents: currentParents,
65
- paginationOffset: 0,
66
- disabled: disabledNodes.includes(e.id),
67
- }));
68
- const existingKeys = new Set(parentElement.children.map(child => child.key));
69
- const newNodes = formattedNodes.filter(node => !existingKeys.has(node.key));
70
- parentElement.children = [
71
- ...parentElement.children.filter(child => !child.key.startsWith(`__showMore${parentMapKey}`)),
72
- ...newNodes,
73
- ];
74
- for (const node of formattedNodes) {
75
- currentTreeMap[node.key] = node;
76
- parentElement.paginationOffset = offset;
77
- }
78
- if (!noPagination && totalCount > parentElement.paginationOffset + defaultPaginationPageSize) {
79
- const showMoreElement = {
80
- isShowMore: true,
81
- record: null,
82
- title: t('tree-node-selection.show_more'),
83
- id: parentMapKey,
84
- key: showMoreKey,
85
- isLeaf: false,
86
- children: [],
87
- paginationOffset: 0,
51
+ useEffect(() => {
52
+ const fetchTreeContent = async () => {
53
+ setIsLoading(true);
54
+ setError(null);
55
+ try {
56
+ const { data } = await loadTreeContent({
57
+ variables: {
58
+ treeId: tree.id,
59
+ childrenAsRecordValuePermissionFilter,
60
+ dependentValuesPermissionFilter,
61
+ },
62
+ });
63
+ const content = data?.treeContent ?? [];
64
+ const newRoot = {
65
+ ...rootNode,
66
+ children: content.map(node => _toTreeMapElement(node, [tree.id], disabledNodes)),
88
67
  };
89
- parentElement.children.push(showMoreElement);
68
+ setTreeMap(_buildTreeMap(newRoot));
90
69
  }
91
- const newOffset = offset + defaultPaginationPageSize;
92
- if (treeNodeChildren.totalCount > newOffset) {
93
- await _fetchTreeContent(parentNodeKey, newOffset, currentTreeMap);
70
+ catch (err) {
71
+ setError(err instanceof Error ? err : new Error('Failed to load tree'));
94
72
  }
95
- if (loadRecursively) {
96
- for (const node of formattedNodes) {
97
- if (!node.isLeaf) {
98
- await _fetchTreeContent(node.key, 0, currentTreeMap);
99
- }
100
- }
73
+ finally {
74
+ setIsLoading(false);
101
75
  }
102
- setTreeMap(currentTreeMap);
103
- setFetchError(undefined);
104
- }
105
- catch (err) {
106
- setFetchError(err.message);
107
- }
108
- };
109
- useEffect(() => {
110
- _fetchTreeContent(undefined, 0);
111
- }, []);
112
- /**
113
- * In strict mode, loadData handler is called twice
114
- * https://github.com/ant-design/ant-design/issues/54497
115
- */
116
- const _handleLoadData = async (nodeData) => {
117
- const { id, isShowMore } = nodeData;
118
- // Handle offset if we get here through the "show more" element
119
- const currentNodeOffset = treeMap[id]?.paginationOffset ?? 0;
120
- const paginationOffset = isShowMore
121
- ? (treeMap[id]?.paginationOffset ?? 0) + defaultPaginationPageSize
122
- : currentNodeOffset;
123
- if (id === tree.id && !isShowMore) {
124
- // Root has already been loaded
125
- return;
126
- }
127
- await _fetchTreeContent(id, paginationOffset);
128
- };
76
+ };
77
+ fetchTreeContent();
78
+ }, [tree.id, childrenAsRecordValuePermissionFilter, dependentValuesPermissionFilter]);
129
79
  const _handleSelect = (_, e) => {
130
80
  // Prevent selecting when clicking on select all children button
131
81
  if (e.nativeEvent.target instanceof HTMLButtonElement) {
132
82
  return;
133
83
  }
134
- // If user clicked on the text "show more", we load more children instead of selecting the node
135
- if ('isShowMore' in e.node && e.node.isShowMore) {
136
- _handleLoadData(e.node);
137
- return;
138
- }
139
84
  const node = treeMap[e.node.key];
140
85
  const isRoot = node.id === tree.id;
141
86
  if ((!canSelectRoot && isRoot) ||
@@ -174,12 +119,13 @@ export const SelectTreeNodeContent = ({ treeData: tree, childrenAsRecordValuePer
174
119
  const nodes = checkedKeys.map(key => treeMap[key]);
175
120
  onCheck(nodes);
176
121
  };
177
- if (!called) {
122
+ if (isLoading) {
178
123
  return _jsx(Spin, {});
179
124
  }
180
- if (error || fetchError) {
181
- return _jsx(ErrorDisplay, { message: error?.message ?? fetchError });
125
+ if (error) {
126
+ return _jsx(ErrorDisplay, { message: error.message });
182
127
  }
183
- return (_jsx(KitTree, { checkStrictly: checkStrictly, treeData: [treeMap[rootNode.key]], loadData: loadRecursively ? undefined : _handleLoadData, multiple: multiple, checkable: checkable, defaultExpandedKeys: selectedNodes.length > 0 ? [...selectedNodes, tree.id] : [tree.id], selectedKeys: selectedNodes, checkedKeys: selectedNodes, titleRender: node => (_jsx(TreeNodeTitle, { checkable: checkable, disabledNodes: disabledNodes, loadRecursively: loadRecursively, node: node, onSelect: onSelect, selectedNodes: selectedNodes, showSelectChildrenButton: showSelectChildrenButton })), onSelect: _handleSelect, onCheck: _handleCheck }));
128
+ const defaultExpandedKeys = selectedNodes.length && !showSelectChildrenButton ? [...selectedNodes, tree.id] : [tree.id];
129
+ return (_jsx(KitTree, { checkStrictly: checkStrictly, treeData: [treeMap[rootNode.key]], multiple: multiple, checkable: checkable, defaultExpandedKeys: defaultExpandedKeys, selectedKeys: selectedNodes, checkedKeys: selectedNodes, titleRender: node => (_jsx(TreeNodeTitle, { checkable: checkable, disabledNodes: disabledNodes, node: node, onSelect: onSelect, selectedNodes: selectedNodes, showSelectChildrenButton: showSelectChildrenButton })), onSelect: _handleSelect, onCheck: _handleCheck }));
184
130
  };
185
131
  //# sourceMappingURL=SelectTreeNodeContent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SelectTreeNodeContent.js","sourceRoot":"","sources":["../../../src/components/SelectTreeNode/SelectTreeNodeContent.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAA8C,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AACvF,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAG1B,OAAO,EAGH,4BAA4B,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,yBAAyB,EAAE,YAAY,EAAC,MAAM,aAAa,CAAC;AACpE,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,kBAAkB,EAAsC,MAAM,UAAU,CAAC;AACjF,OAAO,EAAC,oBAAoB,EAAC,M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G,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QAEnD,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC;IAEF,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO,KAAC,IAAI,KAAG,CAAC;IACpB,CAAC;IAED,IAAI,KAAK,IAAI,UAAU,EAAE,CAAC;QACtB,OAAO,KAAC,YAAY,IAAC,OAAO,EAAE,KAAK,EAAE,OAAO,IAAI,UAAU,GAAI,CAAC;IACnE,CAAC;IAED,OAAO,CACH,KAAC,OAAO,IACJ,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EACjC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,EACvD,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,mBAAmB,EAAE,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EACvF,YAAY,EAAE,aAAa,EAC3B,WAAW,EAAE,aAAa,EAC1B,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,CACjB,KAAC,aAAa,IACV,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,IAAuB,EAC7B,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,aAAa,EAC5B,wBAAwB,EAAE,wBAAwB,GACpD,CACL,EACD,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,YAAY,GACvB,CACL,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type ComponentProps, type FunctionComponent, useEffect, useState} from 'react';\nimport {KitTree} from 'aristid-ds';\nimport {Spin} from 'antd';\nimport {type EventDataNode} from 'antd/lib/tree';\nimport {type ITreeNodeWithRecord} from '_ui/types';\nimport {\n type ChildrenAsRecordValuePermissionFilterInput,\n type DependentValuesPermissionFilterInput,\n useTreeNodeChildrenLazyQuery,\n} from '_ui/_gqlTypes';\nimport {defaultPaginationPageSize, ErrorDisplay} from '../../index';\nimport {TreeNodeTitle} from './TreeNodeTitle';\nimport {_isObjectSelection, type ITreeMap, type ITreeMapElement} from './_types';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\n\ninterface ISelectTreeNodeContentProps {\n treeData: {id: string; label: string};\n childrenAsRecordValuePermissionFilter?: ChildrenAsRecordValuePermissionFilterInput;\n dependentValuesPermissionFilter?: DependentValuesPermissionFilterInput;\n selectedNodes?: string[];\n disabledNodes?: string[];\n onSelect: (node: ITreeNodeWithRecord, selected: boolean) => void;\n onCheck?: (selection: ITreeNodeWithRecord[]) => void;\n multiple?: boolean;\n checkable?: boolean;\n checkStrictly?: boolean;\n canSelectRoot?: boolean;\n selectableLibraries?: string[]; // all by default\n loadRecursively?: boolean;\n noPagination?: boolean;\n showSelectChildrenButton?: boolean;\n}\n\nexport const SelectTreeNodeContent: FunctionComponent<ISelectTreeNodeContentProps> = ({\n treeData: tree,\n childrenAsRecordValuePermissionFilter,\n dependentValuesPermissionFilter,\n onSelect,\n onCheck,\n selectedNodes = [],\n disabledNodes = [],\n multiple = false,\n checkable = false,\n checkStrictly = true,\n canSelectRoot = false,\n selectableLibraries,\n loadRecursively = true,\n noPagination = false,\n showSelectChildrenButton = false,\n}) => {\n const {t} = useSharedTranslation();\n\n const rootNode: ITreeMapElement = {\n title: tree.label,\n record: null,\n id: tree.id,\n key: tree.id,\n isLeaf: false,\n parents: [],\n paginationOffset: 0,\n children: [],\n };\n\n // As we'll fetch children when a node is expanded, we store the whole tree content in a hash map\n // to make update easier and more efficient\n const [treeMap, setTreeMap] = useState<ITreeMap>({\n [tree.id]: rootNode,\n });\n\n const [fetchError, setFetchError] = useState<string | undefined>();\n const [loadTreeContent, {error, called}] = useTreeNodeChildrenLazyQuery();\n\n const _fetchTreeContent = async (parentNodeKey?: string, offset = 0, currentTreeMap = {...treeMap}) => {\n try {\n const {\n data: {treeNodeChildren},\n } = await loadTreeContent({\n // If dependentValuesPermissionFilter is set, we need to bypass the cache to get up-to-date data,\n // because tree content depends on record values that may have changed\n fetchPolicy: dependentValuesPermissionFilter ? 'no-cache' : undefined,\n variables: {\n treeId: tree.id,\n node: parentNodeKey && parentNodeKey !== tree.id ? parentNodeKey : null,\n pagination: noPagination\n ? undefined\n : {\n limit: defaultPaginationPageSize,\n offset,\n },\n childrenAsRecordValuePermissionFilter,\n dependentValuesPermissionFilter,\n },\n });\n\n const parentMapKey = parentNodeKey ?? tree.id;\n const totalCount = treeNodeChildren.totalCount;\n const parentElement = currentTreeMap[parentMapKey];\n const showMoreKey = '__showMore' + parentMapKey + offset;\n\n const parentPath = parentElement?.parents ?? [];\n const currentParents = [...parentPath, parentMapKey];\n\n const formattedNodes = treeNodeChildren.list.map(e => ({\n record: e.record,\n title: e.record.whoAmI.label || e.record.whoAmI.id,\n id: e.id,\n key: e.id,\n isLeaf: !e.childrenCount,\n children: [],\n parents: currentParents,\n paginationOffset: 0,\n disabled: disabledNodes.includes(e.id),\n }));\n\n const existingKeys = new Set(parentElement.children.map(child => child.key));\n const newNodes = formattedNodes.filter(node => !existingKeys.has(node.key));\n parentElement.children = [\n ...parentElement.children.filter(child => !child.key.startsWith(`__showMore${parentMapKey}`)),\n ...newNodes,\n ];\n\n for (const node of formattedNodes) {\n currentTreeMap[node.key] = node as ITreeMapElement;\n parentElement.paginationOffset = offset;\n }\n\n if (!noPagination && totalCount > parentElement.paginationOffset + defaultPaginationPageSize) {\n const showMoreElement: ITreeMapElement = {\n isShowMore: true,\n record: null,\n title: t('tree-node-selection.show_more'),\n id: parentMapKey,\n key: showMoreKey,\n isLeaf: false,\n children: [],\n paginationOffset: 0,\n };\n parentElement.children.push(showMoreElement);\n }\n\n const newOffset = offset + defaultPaginationPageSize;\n if (treeNodeChildren.totalCount > newOffset) {\n await _fetchTreeContent(parentNodeKey, newOffset, currentTreeMap);\n }\n\n if (loadRecursively) {\n for (const node of formattedNodes) {\n if (!node.isLeaf) {\n await _fetchTreeContent(node.key, 0, currentTreeMap);\n }\n }\n }\n\n setTreeMap(currentTreeMap);\n setFetchError(undefined);\n } catch (err) {\n setFetchError((err as Error).message);\n }\n };\n\n useEffect(() => {\n _fetchTreeContent(undefined, 0);\n }, []);\n\n /**\n * In strict mode, loadData handler is called twice\n * https://github.com/ant-design/ant-design/issues/54497\n */\n const _handleLoadData: ComponentProps<typeof KitTree>['loadData'] = async nodeData => {\n const {id, isShowMore} = nodeData as EventDataNode<ITreeMapElement>;\n\n // Handle offset if we get here through the \"show more\" element\n const currentNodeOffset = treeMap[id]?.paginationOffset ?? 0;\n const paginationOffset = isShowMore\n ? (treeMap[id]?.paginationOffset ?? 0) + defaultPaginationPageSize\n : currentNodeOffset;\n\n if (id === tree.id && !isShowMore) {\n // Root has already been loaded\n return;\n }\n\n await _fetchTreeContent(id, paginationOffset);\n };\n\n const _handleSelect: ComponentProps<typeof KitTree>['onSelect'] = (_, e) => {\n // Prevent selecting when clicking on select all children button\n if (e.nativeEvent.target instanceof HTMLButtonElement) {\n return;\n }\n // If user clicked on the text \"show more\", we load more children instead of selecting the node\n if ('isShowMore' in e.node && e.node.isShowMore) {\n _handleLoadData(e.node);\n return;\n }\n\n const node = treeMap[e.node.key];\n const isRoot = node.id === tree.id;\n\n if (\n (!canSelectRoot && isRoot) ||\n (!isRoot && selectableLibraries && !selectableLibraries.includes(node.record.whoAmI.library.id))\n ) {\n return;\n }\n\n const getAllDescendants = (nodeId: string): string[] =>\n treeMap[nodeId].children.reduce<string[]>(\n (acc, child) => [...acc, child.id, ...getAllDescendants(child.id)],\n [],\n );\n\n if (node) {\n if (checkable) {\n const isDeselecting = selectedNodes.includes(node.id);\n\n if (isDeselecting && isRoot) {\n _handleCheck([], null);\n } else if (isDeselecting) {\n const nodeToDeselect = [node.id, ...node.parents, ...getAllDescendants(node.id)];\n const selectionToKeep = selectedNodes.filter(\n selectedNode => !nodeToDeselect.includes(selectedNode),\n );\n\n _handleCheck(selectionToKeep, null);\n } else if (isRoot) {\n _handleCheck([...getAllDescendants(tree.id), tree.id], null);\n } else {\n _handleCheck([...selectedNodes, node.id], null);\n }\n } else {\n onSelect(node, e.selected);\n }\n }\n };\n\n const _handleCheck: ComponentProps<typeof KitTree>['onCheck'] = selection => {\n if (!canSelectRoot && Array.isArray(selection) && selection.includes(tree.id)) {\n return;\n }\n\n const checkedKeys = _isObjectSelection(selection) ? selection.checked : selection;\n const nodes = checkedKeys.map(key => treeMap[key]);\n\n onCheck(nodes);\n };\n\n if (!called) {\n return <Spin />;\n }\n\n if (error || fetchError) {\n return <ErrorDisplay message={error?.message ?? fetchError} />;\n }\n\n return (\n <KitTree\n checkStrictly={checkStrictly}\n treeData={[treeMap[rootNode.key]]}\n loadData={loadRecursively ? undefined : _handleLoadData}\n multiple={multiple}\n checkable={checkable}\n defaultExpandedKeys={selectedNodes.length > 0 ? [...selectedNodes, tree.id] : [tree.id]}\n selectedKeys={selectedNodes}\n checkedKeys={selectedNodes}\n titleRender={node => (\n <TreeNodeTitle\n checkable={checkable}\n disabledNodes={disabledNodes}\n loadRecursively={loadRecursively}\n node={node as ITreeMapElement}\n onSelect={onSelect}\n selectedNodes={selectedNodes}\n showSelectChildrenButton={showSelectChildrenButton}\n />\n )}\n onSelect={_handleSelect}\n onCheck={_handleCheck}\n />\n );\n};\n"]}
1
+ {"version":3,"file":"SelectTreeNodeContent.js","sourceRoot":"","sources":["../../../src/components/SelectTreeNode/SelectTreeNodeContent.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAA8C,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AAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEhG,OAAO,CACH,KAAC,OAAO,IACJ,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EACjC,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,mBAAmB,EAAE,mBAAmB,EACxC,YAAY,EAAE,aAAa,EAC3B,WAAW,EAAE,aAAa,EAC1B,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,CACjB,KAAC,aAAa,IACV,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,IAAuB,EAC7B,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,aAAa,EAC5B,wBAAwB,EAAE,wBAAwB,GACpD,CACL,EACD,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,YAAY,GACvB,CACL,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type ComponentProps, type FunctionComponent, useEffect, useState} from 'react';\nimport {KitTree} from 'aristid-ds';\nimport {Spin} from 'antd';\nimport {type ITreeNodeWithRecord} from '_ui/types';\nimport {\n type ChildrenAsRecordValuePermissionFilterInput,\n type DependentValuesPermissionFilterInput,\n type TreeContentDataQueryQuery,\n} from '_ui/_gqlTypes';\nimport {ErrorDisplay} from '../../index';\nimport {TreeNodeTitle} from './TreeNodeTitle';\nimport {_isObjectSelection, type ITreeMap, type ITreeMapElement} from './_types';\nimport {useLazyQuery} from '@apollo/client';\nimport {treeContentDataQuery} from './_queries/treeContentDataQuery';\n\ninterface ISelectTreeNodeContentProps {\n treeData: {id: string; label: string};\n childrenAsRecordValuePermissionFilter?: ChildrenAsRecordValuePermissionFilterInput;\n dependentValuesPermissionFilter?: DependentValuesPermissionFilterInput;\n selectedNodes?: string[];\n disabledNodes?: string[];\n onSelect: (node: ITreeNodeWithRecord, selected: boolean) => void;\n onCheck?: (selection: ITreeNodeWithRecord[]) => void;\n multiple?: boolean;\n checkable?: boolean;\n checkStrictly?: boolean;\n canSelectRoot?: boolean;\n selectableLibraries?: string[]; // all by default\n showSelectChildrenButton?: boolean;\n}\n\ntype TreeContentNode = TreeContentDataQueryQuery['treeContent'][number] & {\n children?: Array<TreeContentDataQueryQuery['treeContent'][number]>;\n};\n\nconst _toTreeMapElement = (node: TreeContentNode, parents: string[], disabledNodes: string[]): ITreeMapElement => {\n const children = (node.children ?? []).map(child =>\n _toTreeMapElement(child as TreeContentNode, [...parents, node.id], disabledNodes),\n );\n\n return {\n record: node.record,\n title: node.record.whoAmI.label || node.record.whoAmI.id,\n id: node.id,\n key: node.id,\n isLeaf: !node.childrenCount,\n children,\n parents,\n disabled: disabledNodes.includes(node.id),\n };\n};\n\nconst _buildTreeMap = (root: ITreeMapElement): ITreeMap => {\n const map: ITreeMap = {};\n\n const visit = (node: ITreeMapElement) => {\n map[node.id] = node;\n node.children.forEach(visit);\n };\n\n visit(root);\n\n return map;\n};\n\nexport const SelectTreeNodeContent: FunctionComponent<ISelectTreeNodeContentProps> = ({\n treeData: tree,\n childrenAsRecordValuePermissionFilter,\n dependentValuesPermissionFilter,\n onSelect,\n onCheck,\n selectedNodes = [],\n disabledNodes = [],\n multiple = false,\n checkable = false,\n checkStrictly = true,\n canSelectRoot = false,\n selectableLibraries,\n showSelectChildrenButton = false,\n}) => {\n const rootNode: ITreeMapElement = {\n title: tree.label,\n record: null,\n id: tree.id,\n key: tree.id,\n isLeaf: false,\n parents: [],\n children: [],\n };\n\n const [treeMap, setTreeMap] = useState<ITreeMap>({[tree.id]: rootNode});\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const [loadTreeContent] = useLazyQuery(treeContentDataQuery(), {\n fetchPolicy: dependentValuesPermissionFilter ? 'no-cache' : undefined,\n });\n\n useEffect(() => {\n const fetchTreeContent = async () => {\n setIsLoading(true);\n setError(null);\n try {\n const {data} = await loadTreeContent({\n variables: {\n treeId: tree.id,\n childrenAsRecordValuePermissionFilter,\n dependentValuesPermissionFilter,\n },\n });\n\n const content = data?.treeContent ?? [];\n\n const newRoot: ITreeMapElement = {\n ...rootNode,\n children: content.map(node => _toTreeMapElement(node as TreeContentNode, [tree.id], disabledNodes)),\n };\n\n setTreeMap(_buildTreeMap(newRoot));\n } catch (err) {\n setError(err instanceof Error ? err : new Error('Failed to load tree'));\n } finally {\n setIsLoading(false);\n }\n };\n\n fetchTreeContent();\n }, [tree.id, childrenAsRecordValuePermissionFilter, dependentValuesPermissionFilter]);\n\n const _handleSelect: ComponentProps<typeof KitTree>['onSelect'] = (_, e) => {\n // Prevent selecting when clicking on select all children button\n if (e.nativeEvent.target instanceof HTMLButtonElement) {\n return;\n }\n const node = treeMap[e.node.key];\n const isRoot = node.id === tree.id;\n\n if (\n (!canSelectRoot && isRoot) ||\n (!isRoot && selectableLibraries && !selectableLibraries.includes(node.record.whoAmI.library.id))\n ) {\n return;\n }\n\n const getAllDescendants = (nodeId: string): string[] =>\n treeMap[nodeId].children.reduce<string[]>(\n (acc, child) => [...acc, child.id, ...getAllDescendants(child.id)],\n [],\n );\n\n if (node) {\n if (checkable) {\n const isDeselecting = selectedNodes.includes(node.id);\n\n if (isDeselecting && isRoot) {\n _handleCheck([], null);\n } else if (isDeselecting) {\n const nodeToDeselect = [node.id, ...node.parents, ...getAllDescendants(node.id)];\n const selectionToKeep = selectedNodes.filter(\n selectedNode => !nodeToDeselect.includes(selectedNode),\n );\n\n _handleCheck(selectionToKeep, null);\n } else if (isRoot) {\n _handleCheck([...getAllDescendants(tree.id), tree.id], null);\n } else {\n _handleCheck([...selectedNodes, node.id], null);\n }\n } else {\n onSelect(node, e.selected);\n }\n }\n };\n\n const _handleCheck: ComponentProps<typeof KitTree>['onCheck'] = selection => {\n if (!canSelectRoot && Array.isArray(selection) && selection.includes(tree.id)) {\n return;\n }\n\n const checkedKeys = _isObjectSelection(selection) ? selection.checked : selection;\n const nodes = checkedKeys.map(key => treeMap[key]);\n\n onCheck(nodes);\n };\n\n if (isLoading) {\n return <Spin />;\n }\n\n if (error) {\n return <ErrorDisplay message={error.message} />;\n }\n\n const defaultExpandedKeys =\n selectedNodes.length && !showSelectChildrenButton ? [...selectedNodes, tree.id] : [tree.id];\n\n return (\n <KitTree\n checkStrictly={checkStrictly}\n treeData={[treeMap[rootNode.key]]}\n multiple={multiple}\n checkable={checkable}\n defaultExpandedKeys={defaultExpandedKeys}\n selectedKeys={selectedNodes}\n checkedKeys={selectedNodes}\n titleRender={node => (\n <TreeNodeTitle\n checkable={checkable}\n disabledNodes={disabledNodes}\n node={node as ITreeMapElement}\n onSelect={onSelect}\n selectedNodes={selectedNodes}\n showSelectChildrenButton={showSelectChildrenButton}\n />\n )}\n onSelect={_handleSelect}\n onCheck={_handleCheck}\n />\n );\n};\n"]}
@@ -4,7 +4,6 @@ import { type ITreeNodeWithRecord } from '../../types';
4
4
  interface ITreeNodeTitleProps {
5
5
  checkable: boolean;
6
6
  disabledNodes: string[];
7
- loadRecursively: boolean;
8
7
  node: ITreeMapElement;
9
8
  onSelect: (node: ITreeNodeWithRecord, selected: boolean) => void;
10
9
  selectedNodes: string[];
@@ -18,7 +18,7 @@ const TreeNodeLineSection = styled.div `
18
18
  align-items: center;
19
19
  gap: calc(var(--general-spacing-xs) * 1px);
20
20
  `;
21
- export const TreeNodeTitle = ({ checkable, disabledNodes, loadRecursively, node, onSelect, selectedNodes, showSelectChildrenButton, }) => {
21
+ export const TreeNodeTitle = ({ checkable, disabledNodes, node, onSelect, selectedNodes, showSelectChildrenButton, }) => {
22
22
  const { t } = useSharedTranslation();
23
23
  const [hover, setHover] = useState(false);
24
24
  const isSelected = selectedNodes.includes(node.id) && !node.isShowMore;
@@ -35,13 +35,9 @@ export const TreeNodeTitle = ({ checkable, disabledNodes, loadRecursively, node,
35
35
  onSelect(child, buttonInSelectMode);
36
36
  });
37
37
  };
38
- return (_jsxs(TreeNodeLine, { onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), children: [_jsxs(TreeNodeLineSection, { children: [_jsx(KitTypography.Text, { size: "fontSize5", disabled: isDisabled, children: node.title }), _jsx(SelectedChildrenCount, { node: node, selectedNodes: selectedNodes, loadRecursively: loadRecursively })] }), _jsxs(TreeNodeLineSection, { children: [showSelectChildrenButton && node.children.length > 0 && hover && (_jsx(KitButton, { size: "s", onClick: e => handleChildrenSelection(e), children: t(`tree-node-selection.${buttonInSelectMode ? 'select_children' : 'unselect_children'}`) })), !checkable && isSelected && (_jsx(FontAwesomeIcon, { icon: faCheck, color: isDisabled ? 'var(--general-utilities-text-disabled)' : 'var(--general-utilities-text-blue)' }))] })] }));
38
+ return (_jsxs(TreeNodeLine, { onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), children: [_jsxs(TreeNodeLineSection, { children: [_jsx(KitTypography.Text, { size: "fontSize5", disabled: isDisabled, children: node.title }), _jsx(SelectedChildrenCount, { node: node, selectedNodes: selectedNodes })] }), _jsxs(TreeNodeLineSection, { children: [showSelectChildrenButton && node.children.length > 0 && hover && (_jsx(KitButton, { size: "s", onClick: e => handleChildrenSelection(e), children: t(`tree-node-selection.${buttonInSelectMode ? 'select_children' : 'unselect_children'}`) })), !checkable && isSelected && (_jsx(FontAwesomeIcon, { icon: faCheck, color: isDisabled ? 'var(--general-utilities-text-disabled)' : 'var(--general-utilities-text-blue)' }))] })] }));
39
39
  };
40
- const SelectedChildrenCount = ({ node, selectedNodes, loadRecursively }) => {
41
- // it can work only if all children are loaded
42
- if (!loadRecursively) {
43
- return null;
44
- }
40
+ const SelectedChildrenCount = ({ node, selectedNodes }) => {
45
41
  const selectedChildrenCount = countSelectedNodes(node, selectedNodes);
46
42
  return selectedChildrenCount > 0 ? (_jsx(KitTag, { children: _jsx(KitIdCard, { description: selectedChildrenCount }) })) : null;
47
43
  };
@@ -1 +1 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IACZ,IAAI,EAAE,OAAO,EACb,KAAK,EACD,UAAU,CAAC,CAAC,CAAC,wCAAwC,CAAC,CAAC,CAAC,oCAAoC,GAElG,CACL,IACiB,IACX,CAClB,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAItB,CAAC,EAAC,IAAI,EAAE,aAAa,EAAE,eAAe,EAAC,EAAE,EAAE;IAC5C,8CAA8C;IAC9C,IAAI,CAAC,eAAe,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,qBAAqB,GAAG,kBAAkB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAEtE,OAAO,qBAAqB,GAAG,CAAC,CAAC,CAAC,CAAC,CAC/B,KAAC,MAAM,cACH,KAAC,SAAS,IAAC,WAAW,EAAE,qBAAqB,GAAI,GAC5C,CACZ,CAAC,CAAC,CAAC,IAAI,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,IAAqB,EAAE,aAAuB,EAAU,EAAE,CAClF,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;IACnC,IAAI,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACxD,KAAK,IAAI,CAAC,CAAC;IACf,CAAC;IACD,KAAK,IAAI,kBAAkB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC;AACjB,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {useState, type FunctionComponent} from 'react';\nimport {type ITreeMapElement} from './_types';\nimport {KitButton, KitIdCard, KitTag, KitTypography} from 'aristid-ds';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faCheck} from '@fortawesome/free-solid-svg-icons';\nimport {type ITreeNodeWithRecord} from '_ui/types';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport styled from 'styled-components';\n\nconst TreeNodeLine = styled.div`\n display: flex;\n align-items: center;\n justify-content: space-between;\n`;\nconst TreeNodeLineSection = styled.div`\n display: flex;\n align-items: center;\n gap: calc(var(--general-spacing-xs) * 1px);\n`;\ninterface ITreeNodeTitleProps {\n checkable: boolean;\n disabledNodes: string[];\n loadRecursively: boolean;\n node: ITreeMapElement;\n onSelect: (node: ITreeNodeWithRecord, selected: boolean) => void;\n selectedNodes: string[];\n showSelectChildrenButton: boolean;\n}\n\nexport const TreeNodeTitle: FunctionComponent<ITreeNodeTitleProps> = ({\n checkable,\n disabledNodes,\n loadRecursively,\n node,\n onSelect,\n selectedNodes,\n showSelectChildrenButton,\n}) => {\n const {t} = useSharedTranslation();\n\n const [hover, setHover] = useState(false);\n\n const isSelected = selectedNodes.includes(node.id) && !node.isShowMore;\n const isDisabled = disabledNodes.includes(node.id);\n\n const buttonInSelectMode = node.children\n .filter(child => !child.isShowMore && !disabledNodes.includes(child.id))\n .every(child => !selectedNodes.includes(child.id));\n\n const handleChildrenSelection = (event: React.MouseEvent) => {\n event.stopPropagation();\n node.children.forEach(child => {\n if (node.disabled || child.isShowMore) {\n return;\n }\n onSelect(child, buttonInSelectMode);\n });\n };\n\n return (\n <TreeNodeLine onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}>\n <TreeNodeLineSection>\n <KitTypography.Text size=\"fontSize5\" disabled={isDisabled}>\n {node.title}\n </KitTypography.Text>\n <SelectedChildrenCount node={node} selectedNodes={selectedNodes} loadRecursively={loadRecursively} />\n </TreeNodeLineSection>\n <TreeNodeLineSection>\n {showSelectChildrenButton && node.children.length > 0 && hover && (\n <KitButton size=\"s\" onClick={e => handleChildrenSelection(e)}>\n {t(`tree-node-selection.${buttonInSelectMode ? 'select_children' : 'unselect_children'}`)}\n </KitButton>\n )}\n {!checkable && isSelected && (\n <FontAwesomeIcon\n icon={faCheck}\n color={\n isDisabled ? 'var(--general-utilities-text-disabled)' : 'var(--general-utilities-text-blue)'\n }\n />\n )}\n </TreeNodeLineSection>\n </TreeNodeLine>\n );\n};\n\nconst SelectedChildrenCount: FunctionComponent<{\n node: ITreeMapElement;\n selectedNodes: string[];\n loadRecursively: boolean;\n}> = ({node, selectedNodes, loadRecursively}) => {\n // it can work only if all children are loaded\n if (!loadRecursively) {\n return null;\n }\n\n const selectedChildrenCount = countSelectedNodes(node, selectedNodes);\n\n return selectedChildrenCount > 0 ? (\n <KitTag>\n <KitIdCard description={selectedChildrenCount} />\n </KitTag>\n ) : null;\n};\n\nconst countSelectedNodes = (node: ITreeMapElement, selectedNodes: string[]): number =>\n node.children?.reduce((count, child) => {\n if (selectedNodes.includes(child.id) && !child.isShowMore) {\n count += 1;\n }\n count += countSelectedNodes(child, selectedNodes);\n return count;\n }, 0) ?? 0;\n"]}
1
+ {"version":3,"file":"TreeNodeTitle.js","sourceRoot":"","sources":["../../../src/components/SelectTreeNode/TreeNodeTitle.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,QAAQ,EAAyB,MAAM,OAAO,CAAC;AAEvD,OAAO,EAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACvE,OAAO,EAAC,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAC,OAAO,EAAC,MAAM,mCAAmC,CAAC;AAE1D,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAA;;;;CAI9B,CAAC;AACF,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;CAIrC,CAAC;AA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C,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACxD,KAAK,IAAI,CAAC,CAAC;IACf,CAAC;IACD,KAAK,IAAI,kBAAkB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC;AACjB,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {useState, type FunctionComponent} from 'react';\nimport {type ITreeMapElement} from './_types';\nimport {KitButton, KitIdCard, KitTag, KitTypography} from 'aristid-ds';\nimport {FontAwesomeIcon} from '@fortawesome/react-fontawesome';\nimport {faCheck} from '@fortawesome/free-solid-svg-icons';\nimport {type ITreeNodeWithRecord} from '_ui/types';\nimport {useSharedTranslation} from '_ui/hooks/useSharedTranslation';\nimport styled from 'styled-components';\n\nconst TreeNodeLine = styled.div`\n display: flex;\n align-items: center;\n justify-content: space-between;\n`;\nconst TreeNodeLineSection = styled.div`\n display: flex;\n align-items: center;\n gap: calc(var(--general-spacing-xs) * 1px);\n`;\ninterface ITreeNodeTitleProps {\n checkable: boolean;\n disabledNodes: string[];\n node: ITreeMapElement;\n onSelect: (node: ITreeNodeWithRecord, selected: boolean) => void;\n selectedNodes: string[];\n showSelectChildrenButton: boolean;\n}\n\nexport const TreeNodeTitle: FunctionComponent<ITreeNodeTitleProps> = ({\n checkable,\n disabledNodes,\n node,\n onSelect,\n selectedNodes,\n showSelectChildrenButton,\n}) => {\n const {t} = useSharedTranslation();\n\n const [hover, setHover] = useState(false);\n\n const isSelected = selectedNodes.includes(node.id) && !node.isShowMore;\n const isDisabled = disabledNodes.includes(node.id);\n\n const buttonInSelectMode = node.children\n .filter(child => !child.isShowMore && !disabledNodes.includes(child.id))\n .every(child => !selectedNodes.includes(child.id));\n\n const handleChildrenSelection = (event: React.MouseEvent) => {\n event.stopPropagation();\n node.children.forEach(child => {\n if (node.disabled || child.isShowMore) {\n return;\n }\n onSelect(child, buttonInSelectMode);\n });\n };\n\n return (\n <TreeNodeLine onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}>\n <TreeNodeLineSection>\n <KitTypography.Text size=\"fontSize5\" disabled={isDisabled}>\n {node.title}\n </KitTypography.Text>\n <SelectedChildrenCount node={node} selectedNodes={selectedNodes} />\n </TreeNodeLineSection>\n <TreeNodeLineSection>\n {showSelectChildrenButton && node.children.length > 0 && hover && (\n <KitButton size=\"s\" onClick={e => handleChildrenSelection(e)}>\n {t(`tree-node-selection.${buttonInSelectMode ? 'select_children' : 'unselect_children'}`)}\n </KitButton>\n )}\n {!checkable && isSelected && (\n <FontAwesomeIcon\n icon={faCheck}\n color={\n isDisabled ? 'var(--general-utilities-text-disabled)' : 'var(--general-utilities-text-blue)'\n }\n />\n )}\n </TreeNodeLineSection>\n </TreeNodeLine>\n );\n};\n\nconst SelectedChildrenCount: FunctionComponent<{\n node: ITreeMapElement;\n selectedNodes: string[];\n}> = ({node, selectedNodes}) => {\n const selectedChildrenCount = countSelectedNodes(node, selectedNodes);\n\n return selectedChildrenCount > 0 ? (\n <KitTag>\n <KitIdCard description={selectedChildrenCount} />\n </KitTag>\n ) : null;\n};\n\nconst countSelectedNodes = (node: ITreeMapElement, selectedNodes: string[]): number =>\n node.children?.reduce((count, child) => {\n if (selectedNodes.includes(child.id) && !child.isShowMore) {\n count += 1;\n }\n count += countSelectedNodes(child, selectedNodes);\n return count;\n }, 0) ?? 0;\n"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generates recursive GraphQL for tree node children.
3
+ * Used to fetch nested children up to the specified depth.
4
+ */
5
+ export declare const treeContentTreeNodeChildren: (depth?: number) => string;
6
+ export declare const treeContentDataQuery: (depthTreeNodes?: number) => import("@apollo/client").DocumentNode;
@@ -0,0 +1,56 @@
1
+ // Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
2
+ // This file is released under LGPL V3
3
+ // License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
4
+ import { gql } from '@apollo/client';
5
+ const DEFAULT_DEPTH_TREE_NODES = 10;
6
+ /**
7
+ * Generates recursive GraphQL for tree node children.
8
+ * Used to fetch nested children up to the specified depth.
9
+ */
10
+ export const treeContentTreeNodeChildren = (depth = 0) => `
11
+ children {
12
+ id
13
+ childrenCount
14
+ record {
15
+ id
16
+ whoAmI {
17
+ id
18
+ label
19
+ library {
20
+ id
21
+ }
22
+ }
23
+ }
24
+ ${depth > 0 ? treeContentTreeNodeChildren(depth - 1) : ''}
25
+ }
26
+ `;
27
+ export const treeContentDataQuery = (depthTreeNodes = DEFAULT_DEPTH_TREE_NODES) => gql `
28
+ query TreeContentDataQuery(
29
+ $treeId: ID!
30
+ $startAt: ID
31
+ $childrenAsRecordValuePermissionFilter: ChildrenAsRecordValuePermissionFilterInput
32
+ $dependentValuesPermissionFilter: DependentValuesPermissionFilterInput
33
+ ) {
34
+ treeContent(
35
+ treeId: $treeId
36
+ startAt: $startAt
37
+ childrenAsRecordValuePermissionFilter: $childrenAsRecordValuePermissionFilter
38
+ dependentValuesPermissionFilter: $dependentValuesPermissionFilter
39
+ ) {
40
+ id
41
+ childrenCount
42
+ record {
43
+ id
44
+ whoAmI {
45
+ id
46
+ label
47
+ library {
48
+ id
49
+ }
50
+ }
51
+ }
52
+ ${treeContentTreeNodeChildren(depthTreeNodes - 1)}
53
+ }
54
+ }
55
+ `;
56
+ //# sourceMappingURL=treeContentDataQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeContentDataQuery.js","sourceRoot":"","sources":["../../../../src/components/SelectTreeNode/_queries/treeContentDataQuery.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,GAAG,EAAC,MAAM,gBAAgB,CAAC;AAEnC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC;;;;;;;;;;;;;;UAchD,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,2BAA2B,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;;CAEhE,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,cAAc,GAAG,wBAAwB,EAAE,EAAE,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;cAyBxE,2BAA2B,CAAC,cAAc,GAAG,CAAC,CAAC;;;CAG5D,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {gql} from '@apollo/client';\n\nconst DEFAULT_DEPTH_TREE_NODES = 10;\n\n/**\n * Generates recursive GraphQL for tree node children.\n * Used to fetch nested children up to the specified depth.\n */\nexport const treeContentTreeNodeChildren = (depth = 0) => `\n children {\n id\n childrenCount\n record {\n id\n whoAmI {\n id\n label\n library {\n id\n }\n }\n }\n ${depth > 0 ? treeContentTreeNodeChildren(depth - 1) : ''}\n }\n`;\n\nexport const treeContentDataQuery = (depthTreeNodes = DEFAULT_DEPTH_TREE_NODES) => gql`\n query TreeContentDataQuery(\n $treeId: ID!\n $startAt: ID\n $childrenAsRecordValuePermissionFilter: ChildrenAsRecordValuePermissionFilterInput\n $dependentValuesPermissionFilter: DependentValuesPermissionFilterInput\n ) {\n treeContent(\n treeId: $treeId\n startAt: $startAt\n childrenAsRecordValuePermissionFilter: $childrenAsRecordValuePermissionFilter\n dependentValuesPermissionFilter: $dependentValuesPermissionFilter\n ) {\n id\n childrenCount\n record {\n id\n whoAmI {\n id\n label\n library {\n id\n }\n }\n }\n ${treeContentTreeNodeChildren(depthTreeNodes - 1)}\n }\n }\n`;\n"]}
@@ -3,7 +3,6 @@ import { type KitTree } from 'aristid-ds';
3
3
  import { type ITreeNodeWithRecord } from '../../types';
4
4
  export interface ITreeMapElement extends ITreeNodeWithRecord {
5
5
  isLeaf?: boolean;
6
- paginationOffset: number;
7
6
  children: ITreeMapElement[];
8
7
  parents?: string[];
9
8
  isShowMore?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"_types.js","sourceRoot":"","sources":["../../../src/components/SelectTreeNode/_types.ts"],"names":[],"mappings":"AAuBA,gEAAgE;AAChE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,SAA4B,EAAkD,EAAE,CAC/G,SAAS,IAAI,SAAS,IAAI,aAAa,IAAI,SAAS,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type ComponentProps, type Key} from 'react';\nimport {type KitTree} from 'aristid-ds';\nimport {type ITreeNodeWithRecord} from '_ui/types';\n\nexport interface ITreeMapElement extends ITreeNodeWithRecord {\n isLeaf?: boolean;\n paginationOffset: number;\n children: ITreeMapElement[];\n parents?: string[];\n isShowMore?: boolean;\n selectable?: boolean;\n disabled?: boolean;\n}\n\nexport interface ITreeMap {\n [nodeId: string]: ITreeMapElement;\n}\n\ntype OnCheckFirstParam = Parameters<ComponentProps<typeof KitTree>['onCheck']>[0];\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const _isObjectSelection = (selection: OnCheckFirstParam): selection is Exclude<OnCheckFirstParam, Key[]> =>\n 'checked' in selection && 'halfChecked' in selection;\n"]}
1
+ {"version":3,"file":"_types.js","sourceRoot":"","sources":["../../../src/components/SelectTreeNode/_types.ts"],"names":[],"mappings":"AAsBA,gEAAgE;AAChE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,SAA4B,EAAkD,EAAE,CAC/G,SAAS,IAAI,SAAS,IAAI,aAAa,IAAI,SAAS,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type ComponentProps, type Key} from 'react';\nimport {type KitTree} from 'aristid-ds';\nimport {type ITreeNodeWithRecord} from '_ui/types';\n\nexport interface ITreeMapElement extends ITreeNodeWithRecord {\n isLeaf?: boolean;\n children: ITreeMapElement[];\n parents?: string[];\n isShowMore?: boolean;\n selectable?: boolean;\n disabled?: boolean;\n}\n\nexport interface ITreeMap {\n [nodeId: string]: ITreeMapElement;\n}\n\ntype OnCheckFirstParam = Parameters<ComponentProps<typeof KitTree>['onCheck']>[0];\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const _isObjectSelection = (selection: OnCheckFirstParam): selection is Exclude<OnCheckFirstParam, Key[]> =>\n 'checked' in selection && 'halfChecked' in selection;\n"]}
@@ -1,5 +1,5 @@
1
1
  import { objectToNameValueArray } from '@leav/utils';
2
- import { useState } from 'react';
2
+ import { useEffect, useState } from 'react';
3
3
  import { useRecordFormQuery, } from '../../_gqlTypes';
4
4
  import { arrayValueVersionToObject } from '../../_utils';
5
5
  const useGetRecordForm = ({ libraryId, recordId, formId, version, }) => {
@@ -12,7 +12,7 @@ const useGetRecordForm = ({ libraryId, recordId, formId, version, }) => {
12
12
  treeNodeId: value.id,
13
13
  }))
14
14
  : null;
15
- const { loading, error, refetch } = useRecordFormQuery({
15
+ const { loading, error, data, refetch } = useRecordFormQuery({
16
16
  fetchPolicy: 'no-cache',
17
17
  notifyOnNetworkStatusChange: true,
18
18
  variables: {
@@ -21,28 +21,30 @@ const useGetRecordForm = ({ libraryId, recordId, formId, version, }) => {
21
21
  formId,
22
22
  version: requestVersion,
23
23
  },
24
- onCompleted: data => {
25
- // Transform result to format values version to a more convenient object
26
- const recordFormFormatted = {
27
- ...data.recordForm,
28
- elements: data.recordForm.elements.map((element) => ({
29
- ...element,
30
- values: (element?.values ?? []).map(value => ({
31
- ...value,
32
- version: arrayValueVersionToObject(value.version ?? []),
33
- metadata: (value.metadata ?? []).map(metadata => ({
34
- ...metadata,
35
- value: {
36
- ...metadata.value,
37
- version: arrayValueVersionToObject(metadata.value?.version ?? []),
38
- },
39
- })),
24
+ });
25
+ useEffect(() => {
26
+ if (!data?.recordForm) {
27
+ return;
28
+ }
29
+ const recordFormFormatted = {
30
+ ...data.recordForm,
31
+ elements: data.recordForm.elements.map((element) => ({
32
+ ...element,
33
+ values: (element?.values ?? []).map(value => ({
34
+ ...value,
35
+ version: arrayValueVersionToObject(value.version ?? []),
36
+ metadata: (value.metadata ?? []).map(metadata => ({
37
+ ...metadata,
38
+ value: {
39
+ ...metadata.value,
40
+ version: arrayValueVersionToObject(metadata.value?.version ?? []),
41
+ },
40
42
  })),
41
43
  })),
42
- };
43
- setRecordForm(recordFormFormatted);
44
- },
45
- });
44
+ })),
45
+ };
46
+ setRecordForm(recordFormFormatted);
47
+ }, [data]);
46
48
  const refetchRecordForm = () => refetch({
47
49
  libraryId,
48
50
  recordId,
@@ -1 +1 @@
1
- {"version":3,"file":"useGetRecordForm.js","sourceRoot":"","sources":["../../../src/hooks/useGetRecordForm/useGetRecordForm.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,sBAAsB,EAAgB,MAAM,aAAa,CAAC;AAClE,OAAO,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAC;AAE/B,OAAO,EAIH,kBAAkB,GAIrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,yBAAyB,EAAC,MAAM,YAAY,CAAC;AAkErD,MAAM,gBAAgB,GAAG,CAAC,EACtB,SAAS,EACT,QAAQ,EACR,MAAM,EACN,OAAO,GAMV,EAAyB,EAAE;IACxB,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAqB,IAAI,CAAC,CAAC;IAEvE,MAAM,cAAc,GAAG,OAAO;QAC1B,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC;a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;aACJ,CAAC;YAEF,aAAa,CAAC,mBAAmB,CAAC,CAAC;QACvC,CAAC;KACJ,CAAC,CAAC;IAEH,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAC3B,OAAO,CAAC;QACJ,SAAS;QACT,QAAQ;QACR,MAAM;QACN,OAAO,EAAE,cAAc;KAC1B,CAAC,CAAC;IAEP,kHAAkH;IAClH,2BAA2B;IAC3B,OAAO,EAAC,OAAO,EAAE,OAAO,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,iBAAiB,EAAC,CAAC;AACxG,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type ApolloError} from '@apollo/client';\nimport {objectToNameValueArray, type Override} from '@leav/utils';\nimport {useState} from 'react';\nimport {type IValueVersion} from '_ui/types/values';\nimport {\n type RecordFormElementFragment,\n type RecordFormQuery,\n type RecordFormQueryResult,\n useRecordFormQuery,\n type ValueDetailsLinkValueFragment,\n type ValueDetailsTreeValueFragment,\n type ValueDetailsValueFragment,\n} from '_ui/_gqlTypes';\nimport {arrayValueVersionToObject} from '_ui/_utils';\n\nexport type RecordFormElementsValueStandardValue = Override<\n ValueDetailsValueFragment,\n {\n version?: IValueVersion;\n metadata?: Array<{\n name: string;\n value: Override<ValueDetailsValueFragment['metadata'][number]['value'], {version?: IValueVersion}>;\n }>;\n attribute?: ValueDetailsValueFragment['attribute'];\n }\n>;\n\nexport type RecordFormElementsValueLinkValue = Override<\n ValueDetailsLinkValueFragment,\n {\n version?: IValueVersion;\n metadata?: Array<{\n name: string;\n value: Override<ValueDetailsLinkValueFragment['metadata'][number]['value'], {version?: IValueVersion}>;\n }>;\n attribute?: ValueDetailsValueFragment['attribute'];\n }\n>;\n\nexport type RecordFormElementsValueTreeValue = Override<\n ValueDetailsTreeValueFragment,\n {\n version?: IValueVersion;\n metadata?: Array<{\n name: string;\n value: Override<ValueDetailsTreeValueFragment['metadata'][number]['value'], {version?: IValueVersion}>;\n }>;\n attribute?: ValueDetailsValueFragment['attribute'];\n }\n>;\n\nexport type RecordFormElementsValue =\n | RecordFormElementsValueStandardValue\n | RecordFormElementsValueLinkValue\n | RecordFormElementsValueTreeValue;\n\nexport type RecordFormElement = Override<\n RecordFormElementFragment,\n {\n values: RecordFormElementsValue[];\n }\n>;\n\nexport type IRecordForm = Override<\n RecordFormQuery['recordForm'],\n {\n elements: RecordFormElement[];\n }\n>;\n\nexport type RecordFormElementAttribute = RecordFormElement['attribute'];\n\nexport interface IUseGetRecordFormHook {\n loading: boolean;\n error: ApolloError;\n recordForm: IRecordForm | null;\n refetch: RecordFormQueryResult['refetch'];\n}\n\nconst useGetRecordForm = ({\n libraryId,\n recordId,\n formId,\n version,\n}: {\n libraryId: string;\n recordId: string;\n formId: string;\n version: IValueVersion;\n}): IUseGetRecordFormHook => {\n const [recordForm, setRecordForm] = useState<IRecordForm | null>(null);\n\n const requestVersion = version\n ? objectToNameValueArray(version)\n .filter(arrayVersion => !!arrayVersion.value)\n .map(({name, value}) => ({\n treeId: name,\n treeNodeId: value.id,\n }))\n : null;\n\n const {loading, error, refetch} = useRecordFormQuery({\n fetchPolicy: 'no-cache',\n notifyOnNetworkStatusChange: true,\n variables: {\n libraryId,\n recordId,\n formId,\n version: requestVersion,\n },\n onCompleted: data => {\n // Transform result to format values version to a more convenient object\n const recordFormFormatted: IRecordForm = {\n ...data.recordForm,\n elements: data.recordForm.elements.map(\n (element): RecordFormElement => ({\n ...element,\n values: (element?.values ?? []).map(value => ({\n ...value,\n version: arrayValueVersionToObject(value.version ?? []),\n metadata: (value.metadata ?? []).map(metadata => ({\n ...metadata,\n value: {\n ...metadata.value,\n version: arrayValueVersionToObject(metadata.value?.version ?? []),\n },\n })),\n })),\n }),\n ),\n };\n\n setRecordForm(recordFormFormatted);\n },\n });\n\n const refetchRecordForm = () =>\n refetch({\n libraryId,\n recordId,\n formId,\n version: requestVersion,\n });\n\n // To avoid a moment where loading is done and record form is not available yet, we force loading to be true until\n // record form is available\n return {loading: loading || (!recordForm && !error), error, recordForm, refetch: refetchRecordForm};\n};\n\nexport default useGetRecordForm;\n"]}
1
+ {"version":3,"file":"useGetRecordForm.js","sourceRoot":"","sources":["../../../src/hooks/useGetRecordForm/useGetRecordForm.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,sBAAsB,EAAgB,MAAM,aAAa,CAAC;AAClE,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAE1C,OAAO,EAIH,kBAAkB,GAIrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,yBAAyB,EAAC,MAAM,YAAY,CAAC;AAkErD,MAAM,gBAAgB,GAAG,CAAC,EACtB,SAAS,EACT,QAAQ,EACR,MAAM,EACN,OAAO,GAMV,EAAyB,EAAE;IACxB,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAqB,IAAI,CAAC,CAAC;IAEvE,MAAM,cAAc,GAAG,OAAO;QAC1B,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC;aAC1B,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC;aAC5C,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,EAAE,EAAE,CAAC,CAAC;YACrB,MAAM,EAAE,IAAI;YACZ,UAAU,EAAE,KAAK,CAAC,EAAE;SACvB,CAAC,CAAC;QACT,CAAC,CAAC,IAAI,CAAC;IAEX,MAAM,EAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAC,GAAG,kBAAkB,CAAC;QACvD,WAAW,EAAE,UAAU;QACvB,2BAA2B,EAAE,IAAI;QACjC,SAAS,EAAE;YACP,SAAS;YACT,QAAQ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E,UAAU,EAAE,OAAO,EAAE,iBAAiB,EAAC,CAAC;AACxG,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type ApolloError} from '@apollo/client';\nimport {objectToNameValueArray, type Override} from '@leav/utils';\nimport {useEffect, useState} from 'react';\nimport {type IValueVersion} from '_ui/types/values';\nimport {\n type RecordFormElementFragment,\n type RecordFormQuery,\n type RecordFormQueryResult,\n useRecordFormQuery,\n type ValueDetailsLinkValueFragment,\n type ValueDetailsTreeValueFragment,\n type ValueDetailsValueFragment,\n} from '_ui/_gqlTypes';\nimport {arrayValueVersionToObject} from '_ui/_utils';\n\nexport type RecordFormElementsValueStandardValue = Override<\n ValueDetailsValueFragment,\n {\n version?: IValueVersion;\n metadata?: Array<{\n name: string;\n value: Override<ValueDetailsValueFragment['metadata'][number]['value'], {version?: IValueVersion}>;\n }>;\n attribute?: ValueDetailsValueFragment['attribute'];\n }\n>;\n\nexport type RecordFormElementsValueLinkValue = Override<\n ValueDetailsLinkValueFragment,\n {\n version?: IValueVersion;\n metadata?: Array<{\n name: string;\n value: Override<ValueDetailsLinkValueFragment['metadata'][number]['value'], {version?: IValueVersion}>;\n }>;\n attribute?: ValueDetailsValueFragment['attribute'];\n }\n>;\n\nexport type RecordFormElementsValueTreeValue = Override<\n ValueDetailsTreeValueFragment,\n {\n version?: IValueVersion;\n metadata?: Array<{\n name: string;\n value: Override<ValueDetailsTreeValueFragment['metadata'][number]['value'], {version?: IValueVersion}>;\n }>;\n attribute?: ValueDetailsValueFragment['attribute'];\n }\n>;\n\nexport type RecordFormElementsValue =\n | RecordFormElementsValueStandardValue\n | RecordFormElementsValueLinkValue\n | RecordFormElementsValueTreeValue;\n\nexport type RecordFormElement = Override<\n RecordFormElementFragment,\n {\n values: RecordFormElementsValue[];\n }\n>;\n\nexport type IRecordForm = Override<\n RecordFormQuery['recordForm'],\n {\n elements: RecordFormElement[];\n }\n>;\n\nexport type RecordFormElementAttribute = RecordFormElement['attribute'];\n\nexport interface IUseGetRecordFormHook {\n loading: boolean;\n error: ApolloError;\n recordForm: IRecordForm | null;\n refetch: RecordFormQueryResult['refetch'];\n}\n\nconst useGetRecordForm = ({\n libraryId,\n recordId,\n formId,\n version,\n}: {\n libraryId: string;\n recordId: string;\n formId: string;\n version: IValueVersion;\n}): IUseGetRecordFormHook => {\n const [recordForm, setRecordForm] = useState<IRecordForm | null>(null);\n\n const requestVersion = version\n ? objectToNameValueArray(version)\n .filter(arrayVersion => !!arrayVersion.value)\n .map(({name, value}) => ({\n treeId: name,\n treeNodeId: value.id,\n }))\n : null;\n\n const {loading, error, data, refetch} = useRecordFormQuery({\n fetchPolicy: 'no-cache',\n notifyOnNetworkStatusChange: true,\n variables: {\n libraryId,\n recordId,\n formId,\n version: requestVersion,\n },\n });\n\n useEffect(() => {\n if (!data?.recordForm) {\n return;\n }\n\n const recordFormFormatted: IRecordForm = {\n ...data.recordForm,\n elements: data.recordForm.elements.map(\n (element): RecordFormElement => ({\n ...element,\n values: (element?.values ?? []).map(value => ({\n ...value,\n version: arrayValueVersionToObject(value.version ?? []),\n metadata: (value.metadata ?? []).map(metadata => ({\n ...metadata,\n value: {\n ...metadata.value,\n version: arrayValueVersionToObject(metadata.value?.version ?? []),\n },\n })),\n })),\n }),\n ),\n };\n\n setRecordForm(recordFormFormatted);\n }, [data]);\n\n const refetchRecordForm = () =>\n refetch({\n libraryId,\n recordId,\n formId,\n version: requestVersion,\n });\n\n // To avoid a moment where loading is done and record form is not available yet, we force loading to be true until\n // record form is available\n return {loading: loading || (!recordForm && !error), error, recordForm, refetch: refetchRecordForm};\n};\n\nexport default useGetRecordForm;\n"]}