@scheels-softdev/kendoreact-generics 2.4.2 → 2.4.4

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.
@@ -5,7 +5,7 @@ import { CSSProperties } from "react";
5
5
  * @param {object} props - The component props.
6
6
  * @returns {JSX.Element}
7
7
  */
8
- export declare function GenericDropdown<T>({ data, selectedId, selectedData, onChange, textFields, separator, disabled, idField, title, hideClearButton, style, }: {
8
+ type GenericDDProps<T> = {
9
9
  data: T[];
10
10
  /** The ID of the currently selected item. (optional)*/
11
11
  selectedId?: number;
@@ -27,4 +27,7 @@ export declare function GenericDropdown<T>({ data, selectedId, selectedData, onC
27
27
  hideClearButton?: boolean;
28
28
  /** Custom CSS properties for the component. (optional)*/
29
29
  style?: CSSProperties;
30
- }): import("react/jsx-runtime").JSX.Element;
30
+ isLoading?: boolean;
31
+ };
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
+ export {};
@@ -4,27 +4,13 @@ import { filterBy } from "@progress/kendo-data-query";
4
4
  import { useEffect, useRef, useState } from "react";
5
5
  import { getTextValue } from "./Utility";
6
6
  import { Skeleton } from "@progress/kendo-react-indicators";
7
- //TODO add a style property
8
- //TODO add metadata documentation
9
- // component that renders a dropdown with a search filter
10
- /**
11
- * JSX Component for displaying items in a virtualized combobox
12
- * @template T - The type of the data objects in the dropdown.
13
- * @param {object} props - The component props.
14
- * @returns {JSX.Element}
15
- */
16
- export function GenericDropdown({ data, selectedId, selectedData, onChange, textFields, separator, disabled, idField, title, hideClearButton, style, }) {
7
+ export function GenericDropdown({ data, selectedId, selectedData, onChange, textFields, separator, disabled, idField, title, hideClearButton, style, isLoading, }) {
17
8
  if (selectedId !== undefined && selectedData !== undefined) {
18
9
  throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
19
10
  }
20
- useEffect(() => {
21
- console.log(selectedId);
22
- }, [selectedId]);
23
11
  //local state
24
12
  const pageSize = 8;
25
- const [dataList, setDataList] = useState(data.map((x) => {
26
- return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
27
- }));
13
+ const [dataList, setDataList] = useState([]);
28
14
  const [state, setState] = useState({
29
15
  skip: 0,
30
16
  total: dataList.length,
@@ -56,9 +42,14 @@ export function GenericDropdown({ data, selectedId, selectedData, onChange, text
56
42
  };
57
43
  //change event listeners
58
44
  useEffect(() => {
59
- setDataList(data.map((x) => {
60
- return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
61
- }));
45
+ if (data.length) {
46
+ setDataList(data.map((x) => {
47
+ return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
48
+ }));
49
+ setState(Object.assign(Object.assign({}, state), { subsetData: data.map((x) => {
50
+ return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
51
+ }) }));
52
+ }
62
53
  }, [data, textFields, separator]);
63
54
  const findByIndex = (id, idKey) => {
64
55
  console.log(id, data, idField);
@@ -72,13 +63,12 @@ export function GenericDropdown({ data, selectedId, selectedData, onChange, text
72
63
  console.log(returnVal);
73
64
  return returnVal;
74
65
  };
75
- return (_jsx("div", Object.assign({ "data-testid": "dropdown" }, { children: data.length ?
76
- _jsx(ComboBox, { style: style, label: title, disabled: disabled, data: state.subsetData, textField: "textValue", virtual: {
77
- // enable virtualization for large datasets
78
- total: state.total,
79
- pageSize: pageSize,
80
- skip: state.skip,
81
- }, suggest: true, onPageChange: pageChange, filterable: true, onFilterChange: onFilterChange, popupSettings: {
82
- height: "210px",
83
- }, onChange: (e) => onChange(e), onBlur: (e) => e.nativeEvent.preventDefault(), clearButton: !hideClearButton, value: !selectedId && !selectedData ? null : findByIndex(selectedId, idField) || findByValue(selectedData) || null }) : _jsx(Skeleton, { shape: "rectangle", style: style ? style : { height: "40px", width: "100%" } }) })));
66
+ 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: {
67
+ // enable virtualization for large datasets
68
+ total: state.total,
69
+ pageSize: pageSize,
70
+ skip: state.skip,
71
+ }, suggest: true, onPageChange: pageChange, filterable: true, onFilterChange: onFilterChange, popupSettings: {
72
+ height: "210px",
73
+ }, onChange: (e) => onChange(e), onBlur: (e) => e.nativeEvent.preventDefault(), clearButton: !hideClearButton, value: !selectedId && !selectedData ? null : findByIndex(selectedId, idField) || findByValue(selectedData) || null })) : (_jsx(Skeleton, { shape: "rectangle", style: style ? style : { height: "40px", width: "100%" } })) })));
84
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scheels-softdev/kendoreact-generics",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",