@scheels-softdev/kendoreact-generics 4.0.16 → 4.0.17

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.
@@ -1,17 +1,19 @@
1
1
  import { ComboBoxProps } from "@progress/kendo-react-dropdowns";
2
- interface BaseProps<T> extends ComboBoxProps {
2
+ interface BaseProps<T> extends Omit<ComboBoxProps, "textField"> {
3
3
  data: T[];
4
4
  pageSize?: number;
5
5
  onClear?: () => void;
6
- textField: Extract<keyof T, string>;
6
+ textField: keyof T & string;
7
7
  }
8
8
  interface SelectedDataProps<T> {
9
9
  selectedData?: T;
10
10
  }
11
11
  interface SelectedIdProps<T> {
12
- selectedId?: number;
12
+ selectedId?: number | string;
13
13
  idField: keyof T;
14
14
  }
15
15
  type GenericDropdownProps<T> = BaseProps<T> & (SelectedDataProps<T> | SelectedIdProps<T>);
16
- export declare function GenericDropdown<T>({ data, onClear, ...props }: GenericDropdownProps<T>): import("react/jsx-runtime").JSX.Element;
16
+ export declare function GenericDropdown<T extends {
17
+ [K in keyof T]: string | number;
18
+ }>({ data, textField, pageSize, ...props }: GenericDropdownProps<T>): import("react/jsx-runtime").JSX.Element;
17
19
  export default GenericDropdown;
@@ -10,44 +10,35 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import React, { useMemo } from "react";
13
+ import { useState, useMemo, useCallback } from "react";
14
14
  import { ComboBox } from "@progress/kendo-react-dropdowns";
15
15
  export function GenericDropdown(_a) {
16
- var { data, onClear } = _a, props = __rest(_a, ["data", "onClear"]);
16
+ var { data, textField, pageSize = 6 } = _a, props = __rest(_a, ["data", "textField", "pageSize"]);
17
+ const [state, setState] = useState({
18
+ subsetData: data.slice(0, pageSize),
19
+ skip: 0,
20
+ });
17
21
  const selectedItem = useMemo(() => {
18
22
  var _a;
19
- if ("selectedData" in props) {
23
+ if ("selectedData" in props && props.selectedData !== undefined) {
20
24
  return props.selectedData;
21
25
  }
22
- else if ("selectedId" in props && "idField" in props) {
23
- return (_a = data.find((item) => item[props.idField] === props.selectedId)) !== null && _a !== void 0 ? _a : null;
26
+ else if ("selectedId" in props && "idField" in props && props.selectedId !== undefined) {
27
+ return (_a = data.find((item) => item[props.idField] === String(props.selectedId))) !== null && _a !== void 0 ? _a : null;
24
28
  }
25
29
  return null;
26
30
  }, [props, data]);
27
- const [state, setState] = React.useState({
28
- skip: 0,
29
- total: data.length,
30
- subsetData: data.slice(0, 11),
31
- });
32
- const onFilterChange = (event) => {
33
- const filteredData = data.filter((x) => x[props.textField].includes(event.filter.value));
34
- const newData = filteredData.slice(0, 11);
31
+ const pageChange = useCallback((event) => {
32
+ const { skip, take } = event.page;
35
33
  setState({
36
- subsetData: newData,
37
- skip: 0,
38
- total: filteredData.length,
34
+ subsetData: data.slice(skip, skip + take),
35
+ skip,
39
36
  });
40
- };
41
- const pageChange = (event) => {
42
- const skip = event.page.skip;
43
- const take = event.page.take;
44
- const newSubsetData = state.subsetData.slice(skip, skip + take);
45
- setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
46
- };
47
- return (_jsx(ComboBox, Object.assign({ data: state.subsetData, value: selectedItem, virtual: {
48
- total: state.total,
49
- pageSize: 100,
37
+ }, [data]);
38
+ return (_jsx(ComboBox, Object.assign({ data: state.subsetData, value: selectedItem, textField: textField, virtual: {
39
+ pageSize: pageSize,
50
40
  skip: state.skip,
51
- }, onPageChange: pageChange, onFilterChange: onFilterChange, dataItemKey: "idField" in props ? props.idField : undefined }, props)));
41
+ total: data.length,
42
+ }, onPageChange: pageChange }, props)));
52
43
  }
53
44
  export default GenericDropdown;
package/_index.test.js CHANGED
@@ -10,7 +10,7 @@ describe("GenericDropdown", () => {
10
10
  // Set initial selectedData to the second item in the data array
11
11
  let selectedData = data[1];
12
12
  // Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
13
- let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => { }, textField: "name", selectedData: selectedData }));
13
+ let result = render(_jsx(GenericDropdown, { data: data, onChange: () => { }, textField: "name", selectedData: selectedData }));
14
14
  // Get the input element by its role of "combobox"
15
15
  const input = result.getByRole("combobox");
16
16
  expect(input.getAttribute("value")).toBe("Option 2");
@@ -33,7 +33,7 @@ describe("GenericDropdown", () => {
33
33
  // Set initial selectedData to the second item in the data array
34
34
  let selectedId = 2;
35
35
  // Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
36
- let result = render(_jsx(GenericDropdown, { data: data, onChange: () => { }, textField: "name", selectedId: selectedId, idField: "id" }));
36
+ let result = render(_jsx(GenericDropdown, { data: data, onChange: () => { }, textField: "name", selectedId: selectedId }));
37
37
  // Get the input element by its role of "combobox"
38
38
  const input = result.getByRole("combobox");
39
39
  expect(input.getAttribute("value")).toBe("Option 2");
@@ -72,7 +72,7 @@ describe("GenericDropdown", () => {
72
72
  // Set initial selectedData to the second item in the data array
73
73
  let selectedId = 1;
74
74
  // Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
75
- let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedId = (e === null || e === void 0 ? void 0 : e.value.id) || null), textField: "name", selectedId: selectedId, idField: "id" }));
75
+ let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => { var _a; return (selectedId = ((_a = e.value) === null || _a === void 0 ? void 0 : _a.id) || null); }, textField: "name", selectedId: selectedId, idField: "id" }));
76
76
  // Get the input element by its role of "combobox"
77
77
  // Simulate a change event on the input element by setting its target value to "O"
78
78
  let input = result.getByRole("combobox");
package/index.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- export { CommandCellCheckBox } from "./commandCell/CommandCellCheckbox";
2
- export { CommandCellDate } from "./commandCell/CommandCellDate";
3
- export { CommandCellPrice } from "./commandCell/CommandCellPrice";
4
- export { CommandCellSwitch } from "./commandCell/CommandCellSwitch";
5
1
  export { ToolbarButton } from "./Toolbar";
6
2
  export { GenericDropdown } from "./GenericDropdown";
7
3
  export { GridChangeEvent, CommonProps } from "./PropTypes";
package/index.js CHANGED
@@ -1,7 +1,3 @@
1
- export { CommandCellCheckBox } from "./commandCell/CommandCellCheckbox";
2
- export { CommandCellDate } from "./commandCell/CommandCellDate";
3
- export { CommandCellPrice } from "./commandCell/CommandCellPrice";
4
- export { CommandCellSwitch } from "./commandCell/CommandCellSwitch";
5
1
  export { ToolbarButton } from "./Toolbar";
6
2
  export { GenericDropdown } from "./GenericDropdown";
7
3
  export { MultiSelectDropdown } from "./MultiSelectDropdown";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scheels-softdev/kendoreact-generics",
3
- "version": "4.0.16",
3
+ "version": "4.0.17",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -15,7 +15,6 @@
15
15
  "dependencies": {
16
16
  "@progress/kendo-data-query": "latest",
17
17
  "@progress/kendo-react-dateinputs": "latest",
18
- "@progress/kendo-react-dropdowns": "latest",
19
18
  "@progress/kendo-react-indicators": "^5.14.1",
20
19
  "@progress/kendo-react-inputs": "latest",
21
20
  "@scheels-softdev/frontend-utility-functions": "^1.3.7",
@@ -35,7 +34,7 @@
35
34
  },
36
35
  "devDependencies": {
37
36
  "@progress/kendo-react-dateinputs": "latest",
38
- "@progress/kendo-react-dropdowns": "latest",
37
+ "@progress/kendo-react-dropdowns": "^7.4.0",
39
38
  "@progress/kendo-react-inputs": "latest",
40
39
  "@types/moment": "^2.13.0",
41
40
  "@types/react": "^18.0.28",
@@ -1,10 +0,0 @@
1
- export declare function CommandCellCheckBox({ checked, onCheck, onUncheck, disabled, }: {
2
- /** Boolean value indicating whether the checkbox is checked (`true`) or unchecked (`false`). */
3
- checked: boolean;
4
- /** Callback function to be called when the checkbox is checked. */
5
- onCheck: () => void;
6
- /** Callback function to be called when the checkbox is unchecked. */
7
- onUncheck: () => void;
8
- /** Boolean value indicating whether the checkbox is disabled. */
9
- disabled?: boolean;
10
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,13 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Checkbox } from "@progress/kendo-react-inputs";
3
- export function CommandCellCheckBox({ checked, onCheck, onUncheck, disabled, }) {
4
- const functionToRun = () => {
5
- if (checked) {
6
- onUncheck();
7
- }
8
- else {
9
- onCheck();
10
- }
11
- };
12
- return (_jsx("td", Object.assign({ className: "justify-content-center", "data-testid": "checkbox" }, { children: _jsx(Checkbox, { checked: checked, onChange: functionToRun, disabled: disabled }) })));
13
- }
@@ -1,9 +0,0 @@
1
- import { CommonProps, GridChangeEvent } from "../PropTypes";
2
- export declare function CommandCellDate<T extends CommonProps>({ dataItem, onChange, field, }: {
3
- /** The data item for the cell. */
4
- dataItem: T;
5
- /** Callback function to be called when the value changes. */
6
- onChange: (e: GridChangeEvent) => void;
7
- /** The field of the data item to display in the cell. this field must be formattable into a date. */
8
- field: keyof T;
9
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,12 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { DatePicker } from "@progress/kendo-react-dateinputs";
3
- import moment from "moment";
4
- export function CommandCellDate({ dataItem, onChange, field, }) {
5
- let valString = "" + dataItem[field];
6
- let date = moment(valString).format("MM/DD/YY");
7
- return (_jsx("td", Object.assign({ "data-testid": "date" }, { children: valString === undefined || dataItem.isEditing ? (_jsx(DatePicker, { value: new Date(moment(valString).format("MMMM, DD YYYY")), onChange: (e) => onChange({
8
- field: field.toString(),
9
- value: moment(e.value),
10
- dataItem: dataItem,
11
- }) })) : (date) })));
12
- }
@@ -1,3 +0,0 @@
1
- export declare function CommandCellPrice({ cost }: {
2
- cost: number;
3
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- export function CommandCellPrice({ cost }) {
3
- let formattedCost = new Intl.NumberFormat("en", {
4
- style: "currency",
5
- currency: "USD",
6
- minimumSignificantDigits: 2,
7
- maximumFractionDigits: 3,
8
- }).format(cost);
9
- return _jsx("td", Object.assign({ "data-testid": "price" }, { children: formattedCost }));
10
- }
@@ -1,12 +0,0 @@
1
- export declare function CommandCellSwitch<T extends {
2
- isEditing: boolean;
3
- [key: string]: any;
4
- }>({ props, changeFunction, }: {
5
- /** The GridCellProps object containing cell-related properties. */
6
- props: {
7
- dataItem: T;
8
- field?: keyof T;
9
- };
10
- /** The function to call when the switch value changes. */
11
- changeFunction: Function;
12
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Switch } from "@progress/kendo-react-inputs";
3
- export function CommandCellSwitch({ props, changeFunction, }) {
4
- return (_jsx("td", Object.assign({ "data-testid": "switch" }, { children: props.dataItem.isEditing ? (_jsx(Switch, { onChange: () => changeFunction(), checked: props.dataItem[props.field] })) : (props.dataItem[props.field].toString()) })));
5
- }