@scheels-softdev/kendoreact-generics 2.5.4 → 2.5.5

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.
@@ -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
- textFields: (keyof T)[];
6
+ textField: keyof T;
7
7
  /** The separator to use when concatenating multiple text values */
8
8
  separator?: string;
9
9
  }
@@ -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, textFields: [...props.textFields], 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, separator: props.separator }), _jsx(Button, { title: "Clear", disabled: !hasValue(props.value), onClick: onClearButtonClick, icon: "filter-clear" })] })));
32
32
  }
@@ -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
- textFields: (keyof T)[];
17
+ textField: 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, textFields, separator, disabled, idField, title, hideClearButton, style, isLoading, }: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
32
+ export declare function GenericDropdown<T>({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, }: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
33
33
  export {};
@@ -1,31 +1,29 @@
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 { useEffect, useRef, useState } from "react";
5
- import { getTextValue } from "./Utility";
4
+ import { useRef, useState } from "react";
6
5
  import { Skeleton } from "@progress/kendo-react-indicators";
7
- export function GenericDropdown({ data, selectedId, selectedData, onChange, textFields, separator, disabled, idField, title, hideClearButton, style, isLoading, }) {
6
+ export function GenericDropdown({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, }) {
8
7
  if (selectedId !== undefined && selectedData !== undefined) {
9
8
  throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
10
9
  }
11
10
  //local state
12
11
  const pageSize = 8;
13
- const [dataList, setDataList] = useState([]);
14
12
  const [state, setState] = useState({
15
13
  skip: 0,
16
- total: dataList.length,
17
- subsetData: dataList.slice(0, pageSize),
14
+ total: data.length,
15
+ subsetData: data.slice(0, pageSize),
18
16
  });
19
17
  //external function variables
20
- let filteredData = useRef(dataList.slice());
18
+ let filteredData = useRef(data.slice());
21
19
  //function creation
22
20
  // function to handle filter changes
23
21
  const onFilterChange = (event) => {
24
22
  var _a;
25
23
  if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
26
- filteredData.current = filterBy(dataList.slice(), event.filter);
24
+ filteredData.current = filterBy(data.slice(), event.filter);
27
25
  else
28
- filteredData.current = dataList;
26
+ filteredData.current = data;
29
27
  const newData = filteredData.current.slice(0, pageSize);
30
28
  setState({
31
29
  subsetData: newData,
@@ -38,29 +36,18 @@ export function GenericDropdown({ data, selectedId, selectedData, onChange, text
38
36
  console.log("page change data: ", event.page, filteredData.current);
39
37
  const skip = event.page.skip;
40
38
  const take = event.page.take;
41
- const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) : dataList.slice(skip, skip + take);
39
+ const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) : data.slice(skip, skip + take);
42
40
  setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
43
41
  };
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
- }
54
- }, [data, textFields, separator]);
55
42
  const findByIndex = (id, idKey) => {
56
- const item = dataList.find((item) => id === item[idKey || "id"]);
43
+ const item = data.find((item) => id === item[idKey || "id"]);
57
44
  return item;
58
45
  };
59
46
  const findByValue = (item) => {
60
- const returnVal = dataList.find((x) => JSON.stringify(Object.assign(Object.assign({}, x), selectedData)) === JSON.stringify(Object.assign({}, x)));
47
+ const returnVal = data.find((x) => JSON.stringify(Object.assign(Object.assign({}, x), selectedData)) === JSON.stringify(Object.assign({}, x)));
61
48
  return returnVal;
62
49
  };
63
- 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: {
50
+ return (_jsx("div", Object.assign({ "data-testid": "dropdown" }, { children: data.length && !isLoading ? (_jsx(ComboBox, { style: style, label: title, disabled: disabled, data: state.subsetData, textField: textField.toString(), virtual: {
64
51
  // enable virtualization for large datasets
65
52
  total: state.total,
66
53
  pageSize: pageSize,
@@ -1,16 +1,14 @@
1
- export declare function MultiSelectDropdown<T>({ data, selectedData, textFields, selectEvent, title, separator, limit, }: {
1
+ export declare function MultiSelectDropdown<T>({ data, selectedData, textField, selectEvent, title, 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
- textFields: (keyof T)[];
7
+ textField: 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;
14
12
  /** The optional limit of the maximum number of selected items. */
15
13
  limit?: number;
16
14
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,29 +1,25 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useRef, useState } from "react";
2
+ import { useRef, useState } from "react";
3
3
  import { filterBy } from "@progress/kendo-data-query";
4
4
  import { MultiSelect } from "@progress/kendo-react-dropdowns";
5
- import { getTextValue } from "./Utility";
6
- export function MultiSelectDropdown({ data, selectedData, textFields, selectEvent, title, separator, limit, }) {
5
+ export function MultiSelectDropdown({ data, selectedData, textField, selectEvent, title, limit, }) {
7
6
  //local state
8
7
  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
- }));
12
8
  const [state, setState] = useState({
13
9
  skip: 0,
14
- total: dataList.length,
15
- subsetData: dataList.slice(0, pageSize),
10
+ total: data.length,
11
+ subsetData: data.slice(0, pageSize),
16
12
  });
17
13
  //external function variables
18
- const filteredData = useRef(dataList.slice());
14
+ const filteredData = useRef(data.slice());
19
15
  //function creation
20
16
  // function to handle filter changes
21
17
  const onFilterChange = (event) => {
22
18
  var _a;
23
19
  if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
24
- filteredData.current = filterBy(dataList.slice(), event.filter);
20
+ filteredData.current = filterBy(data.slice(), event.filter);
25
21
  else
26
- filteredData.current = dataList;
22
+ filteredData.current = data;
27
23
  const newData = filteredData.current.slice(0, pageSize);
28
24
  setState({
29
25
  subsetData: newData,
@@ -38,13 +34,7 @@ export function MultiSelectDropdown({ data, selectedData, textFields, selectEven
38
34
  const newSubsetData = filteredData.current.slice(skip, skip + take);
39
35
  setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
40
36
  };
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: {
37
+ return (_jsx("div", Object.assign({ "data-testid": "multiselect", style: { width: "100%" } }, { children: _jsx(MultiSelect, { label: title, data: state.subsetData, textField: textField.toString(), style: { width: "100%" }, virtual: {
48
38
  total: state.total,
49
39
  pageSize: pageSize,
50
40
  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
- textFields: (keyof T)[];
8
+ textField: 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,8 +1,9 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, 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 ? (props.textFields.map((x) => props.data.find((y) => y === props.selectedData)[x]).join(props.separator || " ")) : (
5
+ return (_jsx("td", { children: props.checkEditField && !props.isEditing ? (_jsx(_Fragment, {}) //TODO remove this from Marketing display
6
+ ) : (
6
7
  // If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
7
8
  _jsx(GenericDropdown, Object.assign({}, props))) }));
8
9
  }
@@ -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
- textFields: (keyof T)[];
8
+ textField: 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,11 +1,10 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, 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 ? (props.textFields
7
- .map((x) => props.data.find((y) => y[props.idField ? props.idField : "id"] === props.selectedId)[x])
8
- .join(props.separator || " ")) : (
6
+ return (_jsx("td", { children: props.checkEditField && !props.isEditing && props.data.length ? (_jsx(_Fragment, {}) //TODO remove this from Marketing display
7
+ ) : (
9
8
  // If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
10
9
  _jsx(GenericDropdown, Object.assign({}, props))) }));
11
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scheels-softdev/kendoreact-generics",
3
- "version": "2.5.4",
3
+ "version": "2.5.5",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",