@scheels-softdev/kendoreact-generics 2.5.6 → 2.6.0
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/FilterCellDropdown.d.ts +1 -1
- package/FilterCellDropdown.js +1 -1
- package/GenericDropdown.d.ts +2 -2
- package/GenericDropdown.js +31 -11
- package/MultiSelectDropdown.d.ts +4 -2
- package/MultiSelectDropdown.js +18 -8
- package/commandCell/CommandCellDDWithoutId.d.ts +1 -1
- package/commandCell/CommandCellDDWithoutId.js +2 -3
- package/commandCell/CommandCellDropdown.d.ts +1 -1
- package/commandCell/CommandCellDropdown.js +4 -3
- package/package.json +1 -1
package/FilterCellDropdown.d.ts
CHANGED
@@ -3,7 +3,7 @@ interface DropdownFilterCellProps<T> extends GridFilterCellProps {
|
|
3
3
|
/** The data to populate the dropdown options */
|
4
4
|
data: T[];
|
5
5
|
/** The field names used to extract text values for display */
|
6
|
-
|
6
|
+
textFields: (keyof T)[];
|
7
7
|
/** The separator to use when concatenating multiple text values */
|
8
8
|
separator?: string;
|
9
9
|
}
|
package/FilterCellDropdown.js
CHANGED
@@ -28,5 +28,5 @@ export function FilterCellDropdown(props) {
|
|
28
28
|
});
|
29
29
|
};
|
30
30
|
// Render a div containing a GenericDropdownWithSearch component and a Clear button
|
31
|
-
return (_jsxs("div", Object.assign({ className: "k-filtercell", "data-testid": "dropdownFilter" }, { children: [_jsx(GenericDropdown, { data: props.data, onChange: onChange, selectedId: props.value,
|
31
|
+
return (_jsxs("div", Object.assign({ className: "k-filtercell", "data-testid": "dropdownFilter" }, { children: [_jsx(GenericDropdown, { data: props.data, onChange: onChange, selectedId: props.value, textFields: [...props.textFields], separator: props.separator }), _jsx(Button, { title: "Clear", disabled: !hasValue(props.value), onClick: onClearButtonClick, icon: "filter-clear" })] })));
|
32
32
|
}
|
package/GenericDropdown.d.ts
CHANGED
@@ -14,7 +14,7 @@ type GenericDDProps<T> = {
|
|
14
14
|
/** Callback function triggered when the selected value changes*/
|
15
15
|
onChange: Function;
|
16
16
|
/** The field names used to extract text values for display */
|
17
|
-
|
17
|
+
textFields: (keyof T)[];
|
18
18
|
/** The separator to use when concatenating multiple text values. (optional)*/
|
19
19
|
separator?: string;
|
20
20
|
/** Determines whether the dropdown is disabled. (optional)*/
|
@@ -29,5 +29,5 @@ type GenericDDProps<T> = {
|
|
29
29
|
style?: CSSProperties;
|
30
30
|
isLoading?: boolean;
|
31
31
|
};
|
32
|
-
export declare function GenericDropdown<T>({ data, selectedId, selectedData, onChange,
|
32
|
+
export declare function GenericDropdown<T>({ data, selectedId, selectedData, onChange, textFields, separator, disabled, idField, title, hideClearButton, style, isLoading, }: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
|
33
33
|
export {};
|
package/GenericDropdown.js
CHANGED
@@ -1,29 +1,31 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { ComboBox } from "@progress/kendo-react-dropdowns";
|
3
3
|
import { filterBy } from "@progress/kendo-data-query";
|
4
|
-
import { useRef, useState } from "react";
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
5
|
+
import { getTextValue } from "./Utility";
|
5
6
|
import { Skeleton } from "@progress/kendo-react-indicators";
|
6
|
-
export function GenericDropdown({ data, selectedId, selectedData, onChange,
|
7
|
+
export function GenericDropdown({ data, selectedId, selectedData, onChange, textFields, separator, disabled, idField, title, hideClearButton, style, isLoading, }) {
|
7
8
|
if (selectedId !== undefined && selectedData !== undefined) {
|
8
9
|
throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
|
9
10
|
}
|
10
11
|
//local state
|
11
12
|
const pageSize = 8;
|
13
|
+
const [dataList, setDataList] = useState([]);
|
12
14
|
const [state, setState] = useState({
|
13
15
|
skip: 0,
|
14
|
-
total:
|
15
|
-
subsetData:
|
16
|
+
total: dataList.length,
|
17
|
+
subsetData: dataList.slice(0, pageSize),
|
16
18
|
});
|
17
19
|
//external function variables
|
18
|
-
let filteredData = useRef(
|
20
|
+
let filteredData = useRef(dataList.slice());
|
19
21
|
//function creation
|
20
22
|
// function to handle filter changes
|
21
23
|
const onFilterChange = (event) => {
|
22
24
|
var _a;
|
23
25
|
if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
|
24
|
-
filteredData.current = filterBy(
|
26
|
+
filteredData.current = filterBy(dataList.slice(), event.filter);
|
25
27
|
else
|
26
|
-
filteredData.current =
|
28
|
+
filteredData.current = dataList;
|
27
29
|
const newData = filteredData.current.slice(0, pageSize);
|
28
30
|
setState({
|
29
31
|
subsetData: newData,
|
@@ -36,18 +38,36 @@ export function GenericDropdown({ data, selectedId, selectedData, onChange, text
|
|
36
38
|
console.log("page change data: ", event.page, filteredData.current);
|
37
39
|
const skip = event.page.skip;
|
38
40
|
const take = event.page.take;
|
39
|
-
const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) :
|
41
|
+
const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) : dataList.slice(skip, skip + take);
|
40
42
|
setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
|
41
43
|
};
|
44
|
+
//change event listeners
|
45
|
+
useEffect(() => {
|
46
|
+
dataList;
|
47
|
+
});
|
48
|
+
useEffect(() => {
|
49
|
+
if (data.length) {
|
50
|
+
setDataList(data.map((x) => {
|
51
|
+
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
52
|
+
}));
|
53
|
+
setState(Object.assign(Object.assign({}, state), { total: data.length, subsetData: data.map((x) => {
|
54
|
+
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
55
|
+
}) }));
|
56
|
+
}
|
57
|
+
}, [data, textFields, separator]);
|
42
58
|
const findByIndex = (id, idKey) => {
|
43
|
-
|
59
|
+
console.log(id, data, idField);
|
60
|
+
const item = dataList.find((item) => id === item[idKey || "id"]);
|
61
|
+
console.log(item);
|
44
62
|
return item;
|
45
63
|
};
|
46
64
|
const findByValue = (item) => {
|
47
|
-
|
65
|
+
console.log(item, data);
|
66
|
+
const returnVal = dataList.find((x) => JSON.stringify(Object.assign(Object.assign({}, x), selectedData)) === JSON.stringify(Object.assign({}, x)));
|
67
|
+
console.log(returnVal);
|
48
68
|
return returnVal;
|
49
69
|
};
|
50
|
-
return (_jsx("div", Object.assign({ "data-testid": "dropdown" }, { children:
|
70
|
+
return (_jsx("div", Object.assign({ "data-testid": "dropdown" }, { children: dataList.length && !isLoading ? (_jsx(ComboBox, { style: style, label: title, disabled: disabled, data: state.subsetData, textField: "textValue", virtual: {
|
51
71
|
// enable virtualization for large datasets
|
52
72
|
total: state.total,
|
53
73
|
pageSize: pageSize,
|
package/MultiSelectDropdown.d.ts
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
export declare function MultiSelectDropdown<T>({ data, selectedData,
|
1
|
+
export declare function MultiSelectDropdown<T>({ data, selectedData, textFields, selectEvent, title, separator, limit, }: {
|
2
2
|
/** The data array for the dropdown options. */
|
3
3
|
data: T[];
|
4
4
|
/** The array of selected data items. */
|
5
5
|
selectedData: T[];
|
6
6
|
/** The field names to use for text values in the dropdown. */
|
7
|
-
|
7
|
+
textFields: (keyof T)[];
|
8
8
|
/** The function to call when an item is selected or deselected. */
|
9
9
|
selectEvent: Function;
|
10
10
|
/** The optional title of the dropdown. */
|
11
11
|
title?: string;
|
12
|
+
/** The optional separator to use for concatenating text values. */
|
13
|
+
separator?: string;
|
12
14
|
/** The optional limit of the maximum number of selected items. */
|
13
15
|
limit?: number;
|
14
16
|
}): import("react/jsx-runtime").JSX.Element;
|
package/MultiSelectDropdown.js
CHANGED
@@ -1,25 +1,29 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { useRef, useState } from "react";
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
3
3
|
import { filterBy } from "@progress/kendo-data-query";
|
4
4
|
import { MultiSelect } from "@progress/kendo-react-dropdowns";
|
5
|
-
|
5
|
+
import { getTextValue } from "./Utility";
|
6
|
+
export function MultiSelectDropdown({ data, selectedData, textFields, selectEvent, title, separator, limit, }) {
|
6
7
|
//local state
|
7
8
|
const pageSize = 8;
|
9
|
+
const [dataList, setDataList] = useState(data.map((x) => {
|
10
|
+
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
11
|
+
}));
|
8
12
|
const [state, setState] = useState({
|
9
13
|
skip: 0,
|
10
|
-
total:
|
11
|
-
subsetData:
|
14
|
+
total: dataList.length,
|
15
|
+
subsetData: dataList.slice(0, pageSize),
|
12
16
|
});
|
13
17
|
//external function variables
|
14
|
-
const filteredData = useRef(
|
18
|
+
const filteredData = useRef(dataList.slice());
|
15
19
|
//function creation
|
16
20
|
// function to handle filter changes
|
17
21
|
const onFilterChange = (event) => {
|
18
22
|
var _a;
|
19
23
|
if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
|
20
|
-
filteredData.current = filterBy(
|
24
|
+
filteredData.current = filterBy(dataList.slice(), event.filter);
|
21
25
|
else
|
22
|
-
filteredData.current =
|
26
|
+
filteredData.current = dataList;
|
23
27
|
const newData = filteredData.current.slice(0, pageSize);
|
24
28
|
setState({
|
25
29
|
subsetData: newData,
|
@@ -34,7 +38,13 @@ export function MultiSelectDropdown({ data, selectedData, textField, selectEvent
|
|
34
38
|
const newSubsetData = filteredData.current.slice(skip, skip + take);
|
35
39
|
setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
|
36
40
|
};
|
37
|
-
|
41
|
+
//change event listeners
|
42
|
+
useEffect(() => {
|
43
|
+
setDataList(data.map((x) => {
|
44
|
+
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
45
|
+
}));
|
46
|
+
}, [data, textFields, separator]);
|
47
|
+
return (_jsx("div", Object.assign({ "data-testid": "multiselect", style: { width: "100%" } }, { children: _jsx(MultiSelect, { label: title, data: state.subsetData, textField: "textValue", style: { width: "100%" }, virtual: {
|
38
48
|
total: state.total,
|
39
49
|
pageSize: pageSize,
|
40
50
|
skip: state.skip,
|
@@ -5,7 +5,7 @@ export declare function CommandCellDDWithoutId<T>(props: {
|
|
5
5
|
/** The currently selected data item. */
|
6
6
|
selectedData: T;
|
7
7
|
/** The field names to use for text values in the dropdown. */
|
8
|
-
|
8
|
+
textFields: (keyof T)[];
|
9
9
|
/** Callback function to be called when the selected value changes. */
|
10
10
|
onChange: (e: ComboBoxChangeEvent) => void;
|
11
11
|
/** Optional separator to use for concatenating text values. */
|
@@ -1,9 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { GenericDropdown } from "../GenericDropdown";
|
3
3
|
export function CommandCellDDWithoutId(props) {
|
4
4
|
// Function implementation...
|
5
|
-
return (_jsx("td", { children: props.checkEditField && !props.isEditing ? (
|
6
|
-
) : (
|
5
|
+
return (_jsx("td", { children: props.checkEditField && !props.isEditing ? (props.textFields.map((x) => props.data.find((y) => y === props.selectedData)[x]).join(props.separator || " ")) : (
|
7
6
|
// If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
|
8
7
|
_jsx(GenericDropdown, Object.assign({}, props))) }));
|
9
8
|
}
|
@@ -5,7 +5,7 @@ export declare function CommandCellDropdown<T>(props: {
|
|
5
5
|
/** The ID of the currently selected item. */
|
6
6
|
selectedId: number;
|
7
7
|
/** The field names to use for text values in the dropdown. */
|
8
|
-
|
8
|
+
textFields: (keyof T)[];
|
9
9
|
/** Callback function to be called when the selected value changes. */
|
10
10
|
onChange: (e: ComboBoxChangeEvent) => void;
|
11
11
|
/** Optional separator to use for concatenating text values. */
|
@@ -1,10 +1,11 @@
|
|
1
|
-
import {
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { GenericDropdown } from "../GenericDropdown";
|
3
3
|
// This exports a function component called "CommandCellDropdown"
|
4
4
|
// It takes in various props that are used to render a dropdown in a table cell
|
5
5
|
export function CommandCellDropdown(props) {
|
6
|
-
return (_jsx("td", { children: props.checkEditField && !props.isEditing && props.data.length ? (
|
7
|
-
|
6
|
+
return (_jsx("td", { children: props.checkEditField && !props.isEditing && props.data.length ? (props.textFields
|
7
|
+
.map((x) => props.data.find((y) => y[props.idField ? props.idField : "id"] === props.selectedId)[x])
|
8
|
+
.join(props.separator || " ")) : (
|
8
9
|
// If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
|
9
10
|
_jsx(GenericDropdown, Object.assign({}, props))) }));
|
10
11
|
}
|