@topconsultnpm/sdkui-react-beta 6.7.85 → 6.7.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export interface ITMTreeDataSource {
|
|
3
|
-
id: number;
|
|
4
|
-
label: string;
|
|
5
|
-
value: string;
|
|
6
|
-
categoryId?: number;
|
|
7
|
-
expanded?: boolean;
|
|
8
|
-
}
|
|
9
2
|
interface TMTreeDropDownProps {
|
|
10
|
-
dataSource: Array<
|
|
3
|
+
dataSource: Array<{
|
|
4
|
+
id: number;
|
|
5
|
+
label: string;
|
|
6
|
+
value: string;
|
|
7
|
+
categoryId?: number;
|
|
8
|
+
expanded?: boolean;
|
|
9
|
+
}>;
|
|
11
10
|
values: Array<number>;
|
|
12
11
|
setValues: React.Dispatch<React.SetStateAction<Array<number>>>;
|
|
13
12
|
isValidKey?: (key: number) => boolean;
|
|
@@ -4,16 +4,22 @@ import DropDownBox from 'devextreme-react/drop-down-box';
|
|
|
4
4
|
import TreeView from 'devextreme-react/tree-view';
|
|
5
5
|
import { TMTooltip } from '@topconsultnpm/sdkui-react-beta/lib';
|
|
6
6
|
import { SDKUI_Localizator } from '../../helper';
|
|
7
|
-
// The
|
|
7
|
+
// The TMTreeDropDown functional component
|
|
8
8
|
const TMTreeDropDown = (props) => {
|
|
9
9
|
// Destructure props for easy access
|
|
10
10
|
const { dataSource, values, setValues, isValidKey, elementStyle } = props;
|
|
11
11
|
// Reference to the TreeView component for programmatic control
|
|
12
12
|
const treeViewRef = useRef(null);
|
|
13
13
|
// Helper function to get a comma-separated string of labels for the selected IDs
|
|
14
|
-
const getLabelsByIds = (ids) => {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const getLabelsByIds = (ids, outputFormat) => {
|
|
15
|
+
if (ids.length === 0)
|
|
16
|
+
return _jsx("p", { children: SDKUI_Localizator.SelectDesiredFilters });
|
|
17
|
+
const filteredLabels = dataSource.filter(item => ids.includes(item.id));
|
|
18
|
+
if (outputFormat === 'text') {
|
|
19
|
+
const labels = filteredLabels.map(item => item.label).join(', ');
|
|
20
|
+
return _jsx("p", { children: labels });
|
|
21
|
+
}
|
|
22
|
+
return (_jsx("div", { style: { textAlign: 'left' }, children: filteredLabels.map(item => (_jsx("p", { children: item.label }, item.id))) }));
|
|
17
23
|
};
|
|
18
24
|
// Synchronizes the selection in the TreeView when the dropdown value changes
|
|
19
25
|
const syncTreeViewSelection = useCallback((e) => {
|
|
@@ -43,6 +49,6 @@ const TMTreeDropDown = (props) => {
|
|
|
43
49
|
filteredKeys = selectedKeys.filter(isValidKey); // If a validation function is provided, filter the selected keys
|
|
44
50
|
setValues(filteredKeys);
|
|
45
51
|
}, []);
|
|
46
|
-
return _jsx(TMTooltip, { content: getLabelsByIds(values), children: _jsx(DropDownBox, { width: "100%", style: elementStyle, valueExpr: "id", displayExpr: "label", value: values, dataSource: dataSource, placeholder: SDKUI_Localizator.SelectDesiredFilters, onContentReady: syncTreeViewSelection, focusStateEnabled: true, contentRender: () => _jsx(TreeView, { ref: treeViewRef, keyExpr: "id", dataSource: dataSource, selectByClick: true, selectNodesRecursive: true, selectionMode: "multiple", displayExpr: "label", parentIdExpr: "categoryId", dataStructure: "plain", showCheckBoxesMode: "normal", onContentReady: syncTreeViewSelection, onItemSelectionChanged: (e) => treeViewItemSelectionChanged(e) }) }) });
|
|
52
|
+
return _jsx(TMTooltip, { content: getLabelsByIds(values, 'formatted'), children: _jsx(DropDownBox, { width: "100%", style: elementStyle, valueExpr: "id", displayExpr: "label", value: values, dataSource: dataSource, placeholder: SDKUI_Localizator.SelectDesiredFilters, onContentReady: syncTreeViewSelection, focusStateEnabled: true, contentRender: () => _jsx(TreeView, { ref: treeViewRef, keyExpr: "id", dataSource: dataSource, selectByClick: true, selectNodesRecursive: true, selectionMode: "multiple", displayExpr: "label", parentIdExpr: "categoryId", dataStructure: "plain", showCheckBoxesMode: "normal", onContentReady: syncTreeViewSelection, onItemSelectionChanged: (e) => treeViewItemSelectionChanged(e) }) }) });
|
|
47
53
|
};
|
|
48
54
|
export default TMTreeDropDown;
|