@scheels-softdev/kendoreact-generics 2.8.13 → 2.9.1

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.
@@ -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 {};
@@ -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, separator: props.separator }), _jsx(Button, { title: "Clear", disabled: !hasValue(props.value), onClick: onClearButtonClick, icon: "filter-clear" })] })));
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
  }
@@ -15,20 +15,15 @@ type GenericDDProps<T> = {
15
15
  onChange: Function;
16
16
  /** The field names used to extract text values for display */
17
17
  textField: keyof T;
18
- /** The separator to use when concatenating multiple text values. (optional)*/
19
- separator?: string;
20
18
  /** Determines whether the dropdown is disabled. (optional)*/
21
19
  idField?: keyof T;
22
- /** The field name used as the identity key (optional)*/
23
- disabled?: boolean;
24
- /** The label displayed for the dropdown (optional)*/
25
- title?: string;
26
20
  /** The Determines whether the clear button is hidden from the dropdown. (optional)*/
27
21
  hideClearButton?: boolean;
28
22
  /** Custom CSS properties for the component. (optional)*/
29
23
  style?: CSSProperties;
30
24
  isLoading?: boolean;
31
25
  suggest?: boolean;
26
+ title?: string;
32
27
  };
33
- export declare function GenericDropdown<T>({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, suggest, }: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
28
+ export declare function GenericDropdown<T>(props: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
34
29
  export {};
@@ -1,69 +1,28 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { ComboBox } from "@progress/kendo-react-dropdowns";
3
- import { filterBy } from "@progress/kendo-data-query";
4
- import { useEffect, useRef, useState } from "react";
5
- import { Guard } from "@scheels-softdev/frontend-utility-functions";
6
- export function GenericDropdown({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, suggest, }) {
7
- //local state
8
- const pageSize = 8;
9
- if (selectedId !== undefined && selectedData !== undefined) {
10
- throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
11
- }
12
- //useState
13
- const [selectedObject, setSelectedObject] = useState(undefined);
3
+ import { useState } from "react";
4
+ const total = 5000;
5
+ const pageSize = 12;
6
+ export function GenericDropdown(props) {
7
+ var _a, _b, _c, _d;
14
8
  const [state, setState] = useState({
9
+ subsetData: props.data.slice(0, pageSize),
15
10
  skip: 0,
16
- total: data.length,
17
- subsetData: data.slice(0, pageSize),
18
11
  });
19
- //trigger functions
20
- useEffect(() => {
21
- var _a, _b;
22
- if (!selectedId && !selectedData)
23
- setSelectedObject(undefined);
24
- else {
25
- setSelectedObject(selectedId
26
- ? (_a = data.find((item) => selectedId === item[idField || "id"])) !== null && _a !== void 0 ? _a : undefined
27
- : (_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 : undefined);
28
- }
29
- }, [selectedId, selectedData, data]);
30
- useEffect(() => {
31
- setState({
32
- skip: 0,
33
- total: data.length,
34
- subsetData: data.slice(0, pageSize),
35
- });
36
- }, [data]);
37
- //external function variables
38
- let filteredData = useRef(data.slice());
39
- //function creation
40
- // function to handle filter changes
41
- const onFilterChange = (event) => {
42
- var _a;
43
- if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
44
- filteredData.current = filterBy(data.slice(), event.filter);
45
- else
46
- filteredData.current = data;
47
- const newData = filteredData.current.slice(0, pageSize);
48
- setState({
49
- subsetData: newData,
50
- skip: 0,
51
- total: filteredData.current.length,
52
- });
53
- };
54
- // function to handle page changes for virtualization
55
12
  const pageChange = (event) => {
56
13
  const skip = event.page.skip;
57
14
  const take = event.page.take;
58
- const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) : data.slice(skip, skip + take);
59
- setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
15
+ const newSubsetData = props.data.slice(skip, skip + take);
16
+ setState({
17
+ subsetData: newSubsetData,
18
+ skip: skip,
19
+ });
60
20
  };
61
- return (_jsx("div", Object.assign({ "data-testid": "dropdown" }, { children: _jsx(ComboBox, { style: style, label: title, disabled: disabled || isLoading, data: state.subsetData, textField: textField.toString(), virtual: {
62
- // enable virtualization for large datasets
63
- total: state.total,
64
- pageSize: pageSize,
65
- skip: state.skip,
66
- }, suggest: suggest, onPageChange: pageChange, filterable: true, onFilterChange: onFilterChange, popupSettings: {
67
- height: "210px",
68
- }, onChange: (e) => onChange(e), onBlur: (e) => e.nativeEvent.preventDefault(), clearButton: !hideClearButton, value: selectedObject !== null && selectedObject !== void 0 ? selectedObject : undefined }) })));
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
+ }, label: (_c = props.title) !== null && _c !== void 0 ? _c : "Select an option", onPageChange: pageChange, popupSettings: {
26
+ height: "250px",
27
+ }, style: Object.assign({ width: "300px" }, props.style), onChange: (event) => props.onChange(event), disabled: props.isLoading, value: (_d = props.selectedData) !== null && _d !== void 0 ? _d : props.data.find((d) => d[props.idField] === props.selectedId) }));
69
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scheels-softdev/kendoreact-generics",
3
- "version": "2.8.13",
3
+ "version": "2.9.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "jest",