@leav/ui 1.9.0-51ddde49 → 1.9.0-59aae7a0
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.
- package/dist/_gqlTypes/index.d.ts +187 -83
- package/dist/_gqlTypes/index.js +158 -61
- package/dist/_gqlTypes/index.js.map +1 -1
- package/dist/components/Filters/_queries/treeFiltersDataQuery.d.ts +6 -0
- package/dist/components/Filters/_queries/treeFiltersDataQuery.js +54 -0
- package/dist/components/Filters/_queries/treeFiltersDataQuery.js.map +1 -0
- package/dist/components/Filters/context/useGetTreeFilters.js +5 -5
- package/dist/components/Filters/context/useGetTreeFilters.js.map +1 -1
- package/dist/{_queries/trees/getTreeContentQuery.d.ts → components/Filters/filter-items/filter-type/tree/_queries/filterTreeDataQuery.d.ts} +2 -2
- package/dist/components/Filters/filter-items/filter-type/tree/_queries/filterTreeDataQuery.js +54 -0
- package/dist/components/Filters/filter-items/filter-type/tree/_queries/filterTreeDataQuery.js.map +1 -0
- package/dist/components/Filters/filter-items/filter-type/tree/useGetTreeData.js +4 -4
- package/dist/components/Filters/filter-items/filter-type/tree/useGetTreeData.js.map +1 -1
- package/dist/components/SelectTreeNode/SelectTreeNode.d.ts +0 -2
- package/dist/components/SelectTreeNode/SelectTreeNode.js +2 -2
- package/dist/components/SelectTreeNode/SelectTreeNode.js.map +1 -1
- package/dist/components/SelectTreeNode/SelectTreeNodeContent.d.ts +0 -2
- package/dist/components/SelectTreeNode/SelectTreeNodeContent.js +59 -115
- package/dist/components/SelectTreeNode/SelectTreeNodeContent.js.map +1 -1
- package/dist/components/SelectTreeNode/TreeNodeTitle.d.ts +0 -1
- package/dist/components/SelectTreeNode/TreeNodeTitle.js +3 -7
- package/dist/components/SelectTreeNode/TreeNodeTitle.js.map +1 -1
- package/dist/components/SelectTreeNode/_queries/treeContentDataQuery.d.ts +6 -0
- package/dist/components/SelectTreeNode/_queries/treeContentDataQuery.js +56 -0
- package/dist/components/SelectTreeNode/_queries/treeContentDataQuery.js.map +1 -0
- package/dist/components/SelectTreeNode/_types.d.ts +0 -1
- package/dist/components/SelectTreeNode/_types.js.map +1 -1
- package/package.json +1 -1
- package/dist/_queries/trees/getTreeContentQuery.js +0 -70
- package/dist/_queries/trees/getTreeContentQuery.js.map +0 -1
|
@@ -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 treeFiltersTreeNodeChildren: (depth?: number) => string;
|
|
6
|
+
export declare const treeFiltersDataQuery: (depthTreeNodes?: number) => import("@apollo/client").DocumentNode;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 treeFiltersTreeNodeChildren = (depth = 0) => `
|
|
11
|
+
children {
|
|
12
|
+
id
|
|
13
|
+
record {
|
|
14
|
+
id
|
|
15
|
+
whoAmI {
|
|
16
|
+
id
|
|
17
|
+
label
|
|
18
|
+
library {
|
|
19
|
+
id
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
accessRecordByDefaultPermission
|
|
24
|
+
${depth > 0 ? treeFiltersTreeNodeChildren(depth - 1) : ''}
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
export const treeFiltersDataQuery = (depthTreeNodes = DEFAULT_DEPTH_TREE_NODES) => gql `
|
|
28
|
+
query TreeFiltersDataQuery(
|
|
29
|
+
$treeId: ID!
|
|
30
|
+
$startAt: ID
|
|
31
|
+
$accessRecordByDefaultPermission: AccessRecordByDefaultPermissionInput
|
|
32
|
+
) {
|
|
33
|
+
treeContent(
|
|
34
|
+
treeId: $treeId
|
|
35
|
+
startAt: $startAt
|
|
36
|
+
accessRecordByDefaultPermission: $accessRecordByDefaultPermission
|
|
37
|
+
) {
|
|
38
|
+
id
|
|
39
|
+
record {
|
|
40
|
+
id
|
|
41
|
+
whoAmI {
|
|
42
|
+
id
|
|
43
|
+
label
|
|
44
|
+
library {
|
|
45
|
+
id
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
${treeFiltersTreeNodeChildren(depthTreeNodes - 1)}
|
|
50
|
+
accessRecordByDefaultPermission
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
//# sourceMappingURL=treeFiltersDataQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"treeFiltersDataQuery.js","sourceRoot":"","sources":["../../../../src/components/Filters/_queries/treeFiltersDataQuery.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;;;;;;;;;;;;;;;;;;;;;;cAsBxE,2BAA2B,CAAC,cAAc,GAAG,CAAC,CAAC;;;;CAI5D,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 treeFiltersTreeNodeChildren = (depth = 0) => `\n children {\n id\n record {\n id\n whoAmI {\n id\n label\n library {\n id\n }\n }\n }\n accessRecordByDefaultPermission\n ${depth > 0 ? treeFiltersTreeNodeChildren(depth - 1) : ''}\n }\n`;\n\nexport const treeFiltersDataQuery = (depthTreeNodes = DEFAULT_DEPTH_TREE_NODES) => gql`\n query TreeFiltersDataQuery(\n $treeId: ID!\n $startAt: ID\n $accessRecordByDefaultPermission: AccessRecordByDefaultPermissionInput\n ) {\n treeContent(\n treeId: $treeId\n startAt: $startAt\n accessRecordByDefaultPermission: $accessRecordByDefaultPermission\n ) {\n id\n record {\n id\n whoAmI {\n id\n label\n library {\n id\n }\n }\n }\n ${treeFiltersTreeNodeChildren(depthTreeNodes - 1)}\n accessRecordByDefaultPermission\n }\n }\n`;\n"]}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// This file is released under LGPL V3
|
|
3
3
|
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
|
|
4
4
|
import { useLazyQuery } from '@apollo/client';
|
|
5
|
-
import { useGetLibraryByIdQuery
|
|
6
|
-
import { getTreeContentQuery } from '../../../_queries/trees/getTreeContentQuery';
|
|
5
|
+
import { useGetLibraryByIdQuery } from '../../../_gqlTypes';
|
|
7
6
|
import { useEffect, useState } from 'react';
|
|
7
|
+
import { treeFiltersDataQuery } from '../_queries/treeFiltersDataQuery';
|
|
8
8
|
const _flattenNodes = (nodes) => nodes.flatMap(node => [
|
|
9
9
|
...(node.accessRecordByDefaultPermission
|
|
10
10
|
? [
|
|
@@ -21,7 +21,7 @@ const _flattenNodes = (nodes) => nodes.flatMap(node => [
|
|
|
21
21
|
export const useGetTreeFilters = ({ libraryId, skip }) => {
|
|
22
22
|
const [treeFilters, setTreeFilters] = useState({});
|
|
23
23
|
const [treeFiltersLoading, setTreeFiltersLoading] = useState(true);
|
|
24
|
-
const [
|
|
24
|
+
const [loadTreeFilters] = useLazyQuery(treeFiltersDataQuery());
|
|
25
25
|
const { data: libraryData, loading: libraryLoading } = useGetLibraryByIdQuery({
|
|
26
26
|
variables: {
|
|
27
27
|
id: libraryId,
|
|
@@ -38,7 +38,7 @@ export const useGetTreeFilters = ({ libraryId, skip }) => {
|
|
|
38
38
|
treeId: libraryData?.libraries.list[0]?.attributes.find(tree => tree.id === attribute.id)?.linked_tree?.id,
|
|
39
39
|
})) || [];
|
|
40
40
|
const treeResponse = await Promise.all(treeAttributesWithExtendedPermissions.map(async (attribute) => {
|
|
41
|
-
const { data } = await
|
|
41
|
+
const { data } = await loadTreeFilters({
|
|
42
42
|
variables: {
|
|
43
43
|
treeId: attribute.treeId,
|
|
44
44
|
accessRecordByDefaultPermission: {
|
|
@@ -63,7 +63,7 @@ export const useGetTreeFilters = ({ libraryId, skip }) => {
|
|
|
63
63
|
setTreeFiltersLoading(false);
|
|
64
64
|
};
|
|
65
65
|
fetchTreeFilters();
|
|
66
|
-
}, [skip, libraryId, libraryLoading, libraryData,
|
|
66
|
+
}, [skip, libraryId, libraryLoading, libraryData, loadTreeFilters]);
|
|
67
67
|
return {
|
|
68
68
|
data: treeFilters,
|
|
69
69
|
loading: treeFiltersLoading,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetTreeFilters.js","sourceRoot":"","sources":["../../../../src/components/Filters/context/useGetTreeFilters.tsx"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"useGetTreeFilters.js","s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YAEF,MAAM,gBAAgB,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;gBACvD,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC5B,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;gBAC3C,CAAC;gBACD,OAAO,GAAG,CAAC;YACf,CAAC,EAAE,EAAE,CAAC,CAAC;YAEP,cAAc,CAAC,gBAAgB,CAAC,CAAC;YACjC,qBAAqB,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,CAAC;QAEF,gBAAgB,EAAE,CAAC;IACvB,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC;IAEpE,OAAO;QACH,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,kBAAkB;KAC9B,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 {useLazyQuery} from '@apollo/client';\nimport {type TreeAttributeDetailsFragment, useGetLibraryByIdQuery, type TreeFiltersDataQueryQuery} from '_ui/_gqlTypes';\nimport {useEffect, useState} from 'react';\nimport {treeFiltersDataQuery} from '../_queries/treeFiltersDataQuery';\n\ninterface ITreeNode {\n nodeId: string;\n libraryId: string;\n value: string;\n label: string;\n}\n\nexport interface ITreeFilters {\n [x: string]: ITreeNode[];\n}\n\nconst _flattenNodes = (\n nodes: Array<\n TreeFiltersDataQueryQuery['treeContent'][number] & {\n children?: Array<TreeFiltersDataQueryQuery['treeContent'][number]>;\n }\n >,\n): ITreeNode[] =>\n nodes.flatMap(node => [\n ...(node.accessRecordByDefaultPermission\n ? [\n {\n nodeId: node.id,\n libraryId: node.record.whoAmI.library.id,\n value: node.record.id,\n label: node.record.whoAmI.label,\n },\n ]\n : []),\n ..._flattenNodes(node.children ?? []),\n ]);\n\nexport const useGetTreeFilters = ({libraryId, skip}: {libraryId: string; skip: boolean}) => {\n const [treeFilters, setTreeFilters] = useState<ITreeFilters>({});\n const [treeFiltersLoading, setTreeFiltersLoading] = useState(true);\n const [loadTreeFilters] = useLazyQuery(treeFiltersDataQuery());\n\n const {data: libraryData, loading: libraryLoading} = useGetLibraryByIdQuery({\n variables: {\n id: libraryId,\n },\n skip: skip || !libraryId,\n });\n\n useEffect(() => {\n if (skip || !libraryId || libraryLoading || !libraryData) {\n return;\n }\n\n const fetchTreeFilters = async () => {\n const treeAttributesWithExtendedPermissions: Array<{attributeId: string; treeId: string}> =\n libraryData?.libraries.list[0]?.permissions_conf?.permissionTreeAttributes.map(attribute => ({\n attributeId: attribute.id,\n treeId: (\n libraryData?.libraries.list[0]?.attributes.find(\n tree => tree.id === attribute.id,\n ) as TreeAttributeDetailsFragment\n )?.linked_tree?.id,\n })) || [];\n\n const treeResponse = await Promise.all(\n treeAttributesWithExtendedPermissions.map(async attribute => {\n const {data} = await loadTreeFilters({\n variables: {\n treeId: attribute.treeId,\n accessRecordByDefaultPermission: {\n attributeId: attribute.attributeId,\n libraryId,\n },\n },\n });\n\n const flatNodes = _flattenNodes(data?.treeContent ?? []);\n\n return {\n attributeId: attribute.attributeId,\n recordIds: flatNodes,\n };\n }),\n );\n\n const attributeRecords = treeResponse.reduce((acc, item) => {\n if (item.recordIds.length > 0) {\n acc[item.attributeId] = item.recordIds;\n }\n return acc;\n }, {});\n\n setTreeFilters(attributeRecords);\n setTreeFiltersLoading(false);\n };\n\n fetchTreeFilters();\n }, [skip, libraryId, libraryLoading, libraryData, loadTreeFilters]);\n\n return {\n data: treeFilters,\n loading: treeFiltersLoading,\n };\n};\n"]}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Generates recursive GraphQL for tree node children.
|
|
3
3
|
* Used to fetch nested children up to the specified depth.
|
|
4
4
|
*/
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
5
|
+
export declare const filterTreeNodeChildren: (depth?: number) => string;
|
|
6
|
+
export declare const filterTreeDataQuery: (depthTreeNodes?: number) => import("@apollo/client").DocumentNode;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 filterTreeNodeChildren = (depth = 0) => `
|
|
11
|
+
children {
|
|
12
|
+
id
|
|
13
|
+
record {
|
|
14
|
+
id
|
|
15
|
+
whoAmI {
|
|
16
|
+
id
|
|
17
|
+
label
|
|
18
|
+
library {
|
|
19
|
+
id
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
${depth > 0 ? filterTreeNodeChildren(depth - 1) : ''}
|
|
24
|
+
accessRecordByDefaultPermission
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
export const filterTreeDataQuery = (depthTreeNodes = DEFAULT_DEPTH_TREE_NODES) => gql `
|
|
28
|
+
query FilterTreeDataQuery(
|
|
29
|
+
$treeId: ID!
|
|
30
|
+
$startAt: ID
|
|
31
|
+
$accessRecordByDefaultPermission: AccessRecordByDefaultPermissionInput
|
|
32
|
+
) {
|
|
33
|
+
treeContent(
|
|
34
|
+
treeId: $treeId
|
|
35
|
+
startAt: $startAt
|
|
36
|
+
accessRecordByDefaultPermission: $accessRecordByDefaultPermission
|
|
37
|
+
) {
|
|
38
|
+
id
|
|
39
|
+
record {
|
|
40
|
+
id
|
|
41
|
+
whoAmI {
|
|
42
|
+
id
|
|
43
|
+
label
|
|
44
|
+
library {
|
|
45
|
+
id
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
${filterTreeNodeChildren(depthTreeNodes - 1)}
|
|
50
|
+
accessRecordByDefaultPermission
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
//# sourceMappingURL=filterTreeDataQuery.js.map
|
package/dist/components/Filters/filter-items/filter-type/tree/_queries/filterTreeDataQuery.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterTreeDataQuery.js","sourceRoot":"","sources":["../../../../../../../src/components/Filters/filter-items/filter-type/tree/_queries/filterTreeDataQuery.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,sBAAsB,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC;;;;;;;;;;;;;UAa3C,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;;;CAG3D,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,cAAc,GAAG,wBAAwB,EAAE,EAAE,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;cAsBvE,sBAAsB,CAAC,cAAc,GAAG,CAAC,CAAC;;;;CAIvD,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 filterTreeNodeChildren = (depth = 0) => `\n children {\n id\n record {\n id\n whoAmI {\n id\n label\n library {\n id\n }\n }\n }\n ${depth > 0 ? filterTreeNodeChildren(depth - 1) : ''}\n accessRecordByDefaultPermission\n }\n`;\n\nexport const filterTreeDataQuery = (depthTreeNodes = DEFAULT_DEPTH_TREE_NODES) => gql`\n query FilterTreeDataQuery(\n $treeId: ID!\n $startAt: ID\n $accessRecordByDefaultPermission: AccessRecordByDefaultPermissionInput\n ) {\n treeContent(\n treeId: $treeId\n startAt: $startAt\n accessRecordByDefaultPermission: $accessRecordByDefaultPermission\n ) {\n id\n record {\n id\n whoAmI {\n id\n label\n library {\n id\n }\n }\n }\n ${filterTreeNodeChildren(depthTreeNodes - 1)}\n accessRecordByDefaultPermission\n }\n }\n`;\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
|
|
2
2
|
// This file is released under LGPL V3
|
|
3
3
|
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
|
|
4
|
-
import { useLazyQuery } from '@apollo/client';
|
|
5
4
|
import { useEffect, useState } from 'react';
|
|
6
|
-
import {
|
|
5
|
+
import { filterTreeDataQuery } from './_queries/filterTreeDataQuery';
|
|
6
|
+
import { useLazyQuery } from '@apollo/client';
|
|
7
7
|
const _toTreeNode = (node) => ({
|
|
8
8
|
title: node.record.whoAmI.label ?? node.record.whoAmI.id,
|
|
9
9
|
id: node.id,
|
|
@@ -14,7 +14,7 @@ const _toTreeNode = (node) => ({
|
|
|
14
14
|
recordId: node.record.id,
|
|
15
15
|
});
|
|
16
16
|
export const useGetTreeData = ({ treeId, attributeId, libraryId }) => {
|
|
17
|
-
const [
|
|
17
|
+
const [loadFilterTreeData] = useLazyQuery(filterTreeDataQuery());
|
|
18
18
|
const [treeData, setTreeData] = useState([]);
|
|
19
19
|
const [isLoading, setIsLoading] = useState(true);
|
|
20
20
|
const [error, setError] = useState(null);
|
|
@@ -28,7 +28,7 @@ export const useGetTreeData = ({ treeId, attributeId, libraryId }) => {
|
|
|
28
28
|
setIsLoading(true);
|
|
29
29
|
setError(null);
|
|
30
30
|
try {
|
|
31
|
-
const { data } = await
|
|
31
|
+
const { data } = await loadFilterTreeData({
|
|
32
32
|
variables: {
|
|
33
33
|
treeId,
|
|
34
34
|
accessRecordByDefaultPermission: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetTreeData.js","sourceRoot":"","sources":["../../../../../../src/components/Filters/filter-items/filter-type/tree/useGetTreeData.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"useGetTreeData.js","sourceRoot":"","sources":["../../../../../../src/components/Filters/filter-items/filter-type/tree/useGetTreeData.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAkB5C,MAAM,WAAW,GAAG,CAChB,IAEC,EACQ,EAAE,CAAC,CAAC;IACb,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;IACxD,EAAE,EAAE,IAAI,CAAC,EAAE;IACX,GAAG,EAAE,IAAI,CAAC,EAAE;IACZ,QAAQ,EAAE,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC;IAChD,+BAA+B,EAAE,IAAI,CAAC,+BAA+B,IAAI,SAAS;IAClF,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,E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CAAC,qBAAqB,CAAC,CAAC,CAAC;YAC5E,CAAC;oBAAS,CAAC;gBACP,YAAY,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;QACL,CAAC,CAAC;QAEF,QAAQ,EAAE,CAAC;IACf,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC;IAErC,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAC,CAAC;AACxC,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 {useEffect, useState} from 'react';\nimport {type FilterTreeDataQueryQuery} from '_ui/_gqlTypes';\nimport {filterTreeDataQuery} from './_queries/filterTreeDataQuery';\nimport {useLazyQuery} from '@apollo/client';\n\nexport interface ITreeNode {\n title: string;\n id: string;\n key: string;\n children: ITreeNode[];\n accessRecordByDefaultPermission?: boolean;\n libraryId: string;\n recordId: string;\n}\n\ninterface IUseGetTreeDataProps {\n treeId: string;\n attributeId: string;\n libraryId: string;\n}\n\nconst _toTreeNode = (\n node: FilterTreeDataQueryQuery['treeContent'][number] & {\n children?: Array<FilterTreeDataQueryQuery['treeContent'][number]>;\n },\n): ITreeNode => ({\n title: node.record.whoAmI.label ?? node.record.whoAmI.id,\n id: node.id,\n key: node.id,\n children: (node.children ?? []).map(_toTreeNode),\n accessRecordByDefaultPermission: node.accessRecordByDefaultPermission ?? undefined,\n libraryId: node.record.whoAmI.library.id,\n recordId: node.record.id,\n});\n\nexport const useGetTreeData = ({treeId, attributeId, libraryId}: IUseGetTreeDataProps) => {\n const [loadFilterTreeData] = useLazyQuery(filterTreeDataQuery());\n\n const [treeData, setTreeData] = useState<ITreeNode[]>([]);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n if (!treeId) {\n setTreeData([]);\n setIsLoading(false);\n return;\n }\n\n const loadTree = async () => {\n setIsLoading(true);\n setError(null);\n try {\n const {data} = await loadFilterTreeData({\n variables: {\n treeId,\n accessRecordByDefaultPermission: {\n attributeId,\n libraryId,\n },\n },\n });\n\n setTreeData((data?.treeContent ?? []).map(node => _toTreeNode(node)));\n } catch (err) {\n setError(err instanceof Error ? err : new Error('Failed to load tree'));\n } finally {\n setIsLoading(false);\n }\n };\n\n loadTree();\n }, [treeId, attributeId, libraryId]);\n\n return {treeData, isLoading, error};\n};\n"]}
|
|
@@ -14,8 +14,6 @@ interface ISelectTreeNodeProps {
|
|
|
14
14
|
checkStrictly?: boolean;
|
|
15
15
|
checkable?: boolean;
|
|
16
16
|
canSelectRoot?: boolean;
|
|
17
|
-
loadRecursively?: boolean;
|
|
18
|
-
noPagination?: boolean;
|
|
19
17
|
showSelectChildrenButton?: boolean;
|
|
20
18
|
}
|
|
21
19
|
export declare const SelectTreeNode: FunctionComponent<ISelectTreeNodeProps>;
|
|
@@ -9,7 +9,7 @@ import { ErrorDisplay } from '../..';
|
|
|
9
9
|
import useLang from '../../hooks/useLang';
|
|
10
10
|
import { SelectTreeNodeContent } from './SelectTreeNodeContent';
|
|
11
11
|
import { SelectTreeNodeContentSkeleton } from './SelectTreeNodeContentSkeleton';
|
|
12
|
-
export const SelectTreeNode = ({ treeId, childrenAsRecordValuePermissionFilter, dependentValuesPermissionFilter, onSelect, onCheck, selectedNodes, disabledNodes, selectableLibraries, multiple = false, checkStrictly = true, checkable = false, canSelectRoot = false,
|
|
12
|
+
export const SelectTreeNode = ({ treeId, childrenAsRecordValuePermissionFilter, dependentValuesPermissionFilter, onSelect, onCheck, selectedNodes, disabledNodes, selectableLibraries, multiple = false, checkStrictly = true, checkable = false, canSelectRoot = false, showSelectChildrenButton = false, }) => {
|
|
13
13
|
const { lang } = useLang();
|
|
14
14
|
const { t } = useSharedTranslation();
|
|
15
15
|
const { loading, error, data } = useTreeDataQueryQuery({
|
|
@@ -24,6 +24,6 @@ export const SelectTreeNode = ({ treeId, childrenAsRecordValuePermissionFilter,
|
|
|
24
24
|
if (!data?.trees.list[0]) {
|
|
25
25
|
return _jsx(ErrorDisplay, { message: t('error.unknown_tree', { treeId }) });
|
|
26
26
|
}
|
|
27
|
-
return (_jsx(SelectTreeNodeContent, { treeData: { id: treeId, label: localizedTranslation(data.trees.list[0].label, lang) || treeId }, childrenAsRecordValuePermissionFilter: childrenAsRecordValuePermissionFilter, dependentValuesPermissionFilter: dependentValuesPermissionFilter, onCheck: onCheck, onSelect: onSelect, multiple: multiple, checkable: checkable, checkStrictly: checkStrictly, selectedNodes: selectedNodes, disabledNodes: disabledNodes, canSelectRoot: canSelectRoot, selectableLibraries: selectableLibraries,
|
|
27
|
+
return (_jsx(SelectTreeNodeContent, { treeData: { id: treeId, label: localizedTranslation(data.trees.list[0].label, lang) || treeId }, childrenAsRecordValuePermissionFilter: childrenAsRecordValuePermissionFilter, dependentValuesPermissionFilter: dependentValuesPermissionFilter, onCheck: onCheck, onSelect: onSelect, multiple: multiple, checkable: checkable, checkStrictly: checkStrictly, selectedNodes: selectedNodes, disabledNodes: disabledNodes, canSelectRoot: canSelectRoot, selectableLibraries: selectableLibraries, showSelectChildrenButton: showSelectChildrenButton }));
|
|
28
28
|
};
|
|
29
29
|
//# sourceMappingURL=SelectTreeNode.js.map
|
|
@@ -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,oBAAoB,EAAC,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAGH,qBAAqB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,YAAY,EAAC,MAAM,OAAO,CAAC;AACnC,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAE1C,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;QACR,OAAO,KAAC,YAAY,IAAC,OAAO,EAAE,KAAK,CAAC,OAAO,GAAI,CAAC;IACpD,CAAC;IAED,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,OAAO,KAAC,YAAY,IAAC,OAAO,EAAE,CAAC,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 {
|
|
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 {
|
|
13
|
-
|
|
14
|
-
|
|
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,46 @@ 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
|
-
|
|
26
|
-
|
|
27
|
-
const [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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,
|
|
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
|
+
useEffect(() => {
|
|
50
|
+
const fetchTreeContent = async () => {
|
|
51
|
+
setIsLoading(true);
|
|
52
|
+
setError(null);
|
|
53
|
+
try {
|
|
54
|
+
const { data } = await loadTreeContent({
|
|
55
|
+
fetchPolicy: dependentValuesPermissionFilter ? 'no-cache' : undefined,
|
|
56
|
+
variables: {
|
|
57
|
+
treeId: tree.id,
|
|
58
|
+
childrenAsRecordValuePermissionFilter,
|
|
59
|
+
dependentValuesPermissionFilter,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const content = data?.treeContent ?? [];
|
|
63
|
+
const newRoot = {
|
|
64
|
+
...rootNode,
|
|
65
|
+
children: content.map(node => _toTreeMapElement(node, [tree.id], disabledNodes)),
|
|
88
66
|
};
|
|
89
|
-
|
|
67
|
+
setTreeMap(_buildTreeMap(newRoot));
|
|
90
68
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
await _fetchTreeContent(parentNodeKey, newOffset, currentTreeMap);
|
|
69
|
+
catch (err) {
|
|
70
|
+
setError(err instanceof Error ? err : new Error('Failed to load tree'));
|
|
94
71
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (!node.isLeaf) {
|
|
98
|
-
await _fetchTreeContent(node.key, 0, currentTreeMap);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
72
|
+
finally {
|
|
73
|
+
setIsLoading(false);
|
|
101
74
|
}
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
};
|
|
75
|
+
};
|
|
76
|
+
fetchTreeContent();
|
|
77
|
+
}, [tree.id, childrenAsRecordValuePermissionFilter, dependentValuesPermissionFilter]);
|
|
129
78
|
const _handleSelect = (_, e) => {
|
|
130
79
|
// Prevent selecting when clicking on select all children button
|
|
131
80
|
if (e.nativeEvent.target instanceof HTMLButtonElement) {
|
|
132
81
|
return;
|
|
133
82
|
}
|
|
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
83
|
const node = treeMap[e.node.key];
|
|
140
84
|
const isRoot = node.id === tree.id;
|
|
141
85
|
if ((!canSelectRoot && isRoot) ||
|
|
@@ -174,12 +118,12 @@ export const SelectTreeNodeContent = ({ treeData: tree, childrenAsRecordValuePer
|
|
|
174
118
|
const nodes = checkedKeys.map(key => treeMap[key]);
|
|
175
119
|
onCheck(nodes);
|
|
176
120
|
};
|
|
177
|
-
if (
|
|
121
|
+
if (isLoading) {
|
|
178
122
|
return _jsx(Spin, {});
|
|
179
123
|
}
|
|
180
|
-
if (error
|
|
181
|
-
return _jsx(ErrorDisplay, { message: error
|
|
124
|
+
if (error) {
|
|
125
|
+
return _jsx(ErrorDisplay, { message: error.message });
|
|
182
126
|
}
|
|
183
|
-
return (_jsx(KitTree, { checkStrictly: checkStrictly, treeData: [treeMap[rootNode.key]],
|
|
127
|
+
return (_jsx(KitTree, { checkStrictly: checkStrictly, treeData: [treeMap[rootNode.key]], 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, node: node, onSelect: onSelect, selectedNodes: selectedNodes, showSelectChildrenButton: showSelectChildrenButton })), onSelect: _handleSelect, onCheck: _handleCheck }));
|
|
184
128
|
};
|
|
185
129
|
//# sourceMappingURL=SelectTreeNodeContent.js.map
|