@scheels-softdev/kendoreact-generics 2.8.12 → 2.9.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 +0 -2
- package/FilterCellDropdown.js +1 -1
- package/GenericDropdown.d.ts +3 -18
- package/GenericDropdown.js +18 -69
- package/package.json +1 -1
package/FilterCellDropdown.d.ts
CHANGED
@@ -4,8 +4,6 @@ interface DropdownFilterCellProps<T> extends GridFilterCellProps {
|
|
4
4
|
data: T[];
|
5
5
|
/** The field names used to extract text values for display */
|
6
6
|
textField: keyof T;
|
7
|
-
/** The separator to use when concatenating multiple text values */
|
8
|
-
separator?: string;
|
9
7
|
}
|
10
8
|
export declare function FilterCellDropdown<T>(props: DropdownFilterCellProps<T>): import("react/jsx-runtime").JSX.Element;
|
11
9
|
export {};
|
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, textField: props.textField
|
31
|
+
return (_jsxs("div", Object.assign({ className: "k-filtercell", "data-testid": "dropdownFilter" }, { children: [_jsx(GenericDropdown, { data: props.data, onChange: onChange, selectedId: props.value, textField: props.textField }), _jsx(Button, { title: "Clear", disabled: !hasValue(props.value), onClick: onClearButtonClick, icon: "filter-clear" })] })));
|
32
32
|
}
|
package/GenericDropdown.d.ts
CHANGED
@@ -1,14 +1,4 @@
|
|
1
1
|
import { CSSProperties } from "react";
|
2
|
-
import { ComboBoxChangeEvent } from "@progress/kendo-react-dropdowns";
|
3
|
-
/**
|
4
|
-
* Handles the change event of a dropdown.
|
5
|
-
*
|
6
|
-
* @param {ComboBoxChangeEvent} e - The change event object.
|
7
|
-
* @param {(value: T) => void} setFunction - The function to set the value.
|
8
|
-
* @param {T} nullEventValue - The value to set when the event value is null.
|
9
|
-
* @param {string} valueKey - The key to access the value in the event object.
|
10
|
-
*/
|
11
|
-
export declare function handleDropdownChange<T>(e: ComboBoxChangeEvent, setFunction: (value: T) => void, nullEventValue: T, valueKey?: string): void;
|
12
2
|
/**
|
13
3
|
* JSX Component for displaying items in a virtualized combobox
|
14
4
|
* @template T - The type of the data objects in the dropdown.
|
@@ -22,23 +12,18 @@ type GenericDDProps<T> = {
|
|
22
12
|
/** The currently selected data object. (optional)*/
|
23
13
|
selectedData?: T;
|
24
14
|
/** Callback function triggered when the selected value changes*/
|
25
|
-
onChange:
|
15
|
+
onChange: Function;
|
26
16
|
/** The field names used to extract text values for display */
|
27
17
|
textField: keyof T;
|
28
|
-
/** The separator to use when concatenating multiple text values. (optional)*/
|
29
|
-
separator?: string;
|
30
18
|
/** Determines whether the dropdown is disabled. (optional)*/
|
31
19
|
idField?: keyof T;
|
32
|
-
/** The field name used as the identity key (optional)*/
|
33
|
-
disabled?: boolean;
|
34
|
-
/** The label displayed for the dropdown (optional)*/
|
35
|
-
title?: string;
|
36
20
|
/** The Determines whether the clear button is hidden from the dropdown. (optional)*/
|
37
21
|
hideClearButton?: boolean;
|
38
22
|
/** Custom CSS properties for the component. (optional)*/
|
39
23
|
style?: CSSProperties;
|
40
24
|
isLoading?: boolean;
|
41
25
|
suggest?: boolean;
|
26
|
+
title?: string;
|
42
27
|
};
|
43
|
-
export declare function GenericDropdown<T>(
|
28
|
+
export declare function GenericDropdown<T>(props: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
|
44
29
|
export {};
|
package/GenericDropdown.js
CHANGED
@@ -1,79 +1,28 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { ComboBox } from "@progress/kendo-react-dropdowns";
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
*
|
9
|
-
* @param {ComboBoxChangeEvent} e - The change event object.
|
10
|
-
* @param {(value: T) => void} setFunction - The function to set the value.
|
11
|
-
* @param {T} nullEventValue - The value to set when the event value is null.
|
12
|
-
* @param {string} valueKey - The key to access the value in the event object.
|
13
|
-
*/
|
14
|
-
export function handleDropdownChange(e, setFunction, nullEventValue, valueKey) {
|
15
|
-
Guard.Catch.NullEmptyOrWhitespace(e.target.value)
|
16
|
-
? setFunction(nullEventValue)
|
17
|
-
: setFunction(Guard.Catch.NullEmptyOrWhitespace(valueKey) ? e.target.value : e.target.value[valueKey !== null && valueKey !== void 0 ? valueKey : ""]);
|
18
|
-
}
|
19
|
-
export function GenericDropdown({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, suggest, }) {
|
20
|
-
//local state
|
21
|
-
const pageSize = 8;
|
22
|
-
if (selectedId !== undefined && selectedData !== undefined) {
|
23
|
-
throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
|
24
|
-
}
|
25
|
-
//useState
|
26
|
-
const [selectedObject, setSelectedObject] = useState(null);
|
3
|
+
import { useState } from "react";
|
4
|
+
const total = 5000;
|
5
|
+
const pageSize = 12;
|
6
|
+
export function GenericDropdown(props) {
|
7
|
+
var _a, _b, _c;
|
27
8
|
const [state, setState] = useState({
|
9
|
+
subsetData: props.data.slice(0, pageSize),
|
28
10
|
skip: 0,
|
29
|
-
total: data.length,
|
30
|
-
subsetData: data.slice(0, pageSize),
|
31
11
|
});
|
32
|
-
//trigger functions
|
33
|
-
useEffect(() => {
|
34
|
-
var _a, _b;
|
35
|
-
console.log(selectedData, selectedId);
|
36
|
-
setSelectedObject(selectedId
|
37
|
-
? (_a = data.find((item) => selectedId === item[idField || "id"])) !== null && _a !== void 0 ? _a : null
|
38
|
-
: (_b = data.find((x) => Guard.Ensure.EqualObjects(Object.assign(Object.assign({}, x), selectedData), Object.assign({}, (x !== null && x !== void 0 ? x : {}))))) !== null && _b !== void 0 ? _b : null);
|
39
|
-
}, [selectedId, selectedData, data]);
|
40
|
-
useEffect(() => {
|
41
|
-
setState({
|
42
|
-
skip: 0,
|
43
|
-
total: data.length,
|
44
|
-
subsetData: data.slice(0, pageSize),
|
45
|
-
});
|
46
|
-
}, [data]);
|
47
|
-
//external function variables
|
48
|
-
let filteredData = useRef(data.slice());
|
49
|
-
//function creation
|
50
|
-
// function to handle filter changes
|
51
|
-
const onFilterChange = (event) => {
|
52
|
-
var _a;
|
53
|
-
if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
|
54
|
-
filteredData.current = filterBy(data.slice(), event.filter);
|
55
|
-
else
|
56
|
-
filteredData.current = data;
|
57
|
-
const newData = filteredData.current.slice(0, pageSize);
|
58
|
-
setState({
|
59
|
-
subsetData: newData,
|
60
|
-
skip: 0,
|
61
|
-
total: filteredData.current.length,
|
62
|
-
});
|
63
|
-
};
|
64
|
-
// function to handle page changes for virtualization
|
65
12
|
const pageChange = (event) => {
|
66
13
|
const skip = event.page.skip;
|
67
14
|
const take = event.page.take;
|
68
|
-
const newSubsetData =
|
69
|
-
setState(
|
15
|
+
const newSubsetData = props.data.slice(skip, skip + take);
|
16
|
+
setState({
|
17
|
+
subsetData: newSubsetData,
|
18
|
+
skip: skip,
|
19
|
+
});
|
70
20
|
};
|
71
|
-
return (_jsx(
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
}, onChange: (e) => handleDropdownChange(e, () => onChange(e.value), {}, idField === null || idField === void 0 ? void 0 : idField.toString()), onBlur: (e) => e.nativeEvent.preventDefault(), clearButton: !hideClearButton, value: selectedObject }) })));
|
21
|
+
return (_jsx(ComboBox, { data: state.subsetData, dataItemKey: (_b = (_a = props.idField) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : undefined, textField: props.textField.toString(), virtual: {
|
22
|
+
total: total,
|
23
|
+
pageSize: pageSize,
|
24
|
+
skip: state.skip,
|
25
|
+
}, onPageChange: pageChange, popupSettings: {
|
26
|
+
height: "250px",
|
27
|
+
}, placeholder: props.title, style: { width: "300px" }, onChange: (event) => props.onChange(event), disabled: props.isLoading, value: (_c = props.selectedData) !== null && _c !== void 0 ? _c : props.data.find((d) => d[props.idField] === props.selectedId) }));
|
79
28
|
}
|