@scheels-softdev/kendoreact-generics 2.9.8 → 3.0.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.
@@ -1,29 +1,14 @@
1
- import { CSSProperties } from "react";
2
- /**
3
- * JSX Component for displaying items in a virtualized combobox
4
- * @template T - The type of the data objects in the dropdown.
5
- * @param {object} props - The component props.
6
- * @returns {JSX.Element}
7
- */
1
+ import React from "react";
8
2
  type GenericDDProps<T> = {
9
3
  data: T[];
10
- /** The ID of the currently selected item. (optional)*/
11
- selectedId?: number;
12
- /** The currently selected data object. (optional)*/
4
+ selectedId?: string | number;
13
5
  selectedData?: T;
14
- /** Callback function triggered when the selected value changes*/
15
- onChange: Function;
16
- /** The field names used to extract text values for display */
6
+ onChange: (selectedItem: T | null) => void;
17
7
  textField: keyof T;
18
- /** Determines whether the dropdown is disabled. (optional)*/
19
8
  idField?: keyof T;
20
- /** The Determines whether the clear button is hidden from the dropdown. (optional)*/
21
- hideClearButton?: boolean;
22
- /** Custom CSS properties for the component. (optional)*/
23
- style?: CSSProperties;
9
+ style?: React.CSSProperties;
24
10
  isLoading?: boolean;
25
- suggest?: boolean;
26
11
  title?: string;
27
12
  };
28
- export declare function GenericDropdown<T>(props: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
13
+ export declare function GenericDropdown<T extends Record<string, any>>({ data, selectedId, selectedData, onChange, textField, idField, isLoading, title, }: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
29
14
  export {};
@@ -1,36 +1,23 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { filterBy } from "@progress/kendo-data-query";
3
- import { ComboBox } from "@progress/kendo-react-dropdowns";
4
- import { useState, useRef } from "react";
5
- const pageSize = 12;
6
- export function GenericDropdown(props) {
7
- var _a, _b, _c, _d;
8
- const filteredData = useRef(props.data.slice());
9
- const [state, setState] = useState({
10
- subsetData: props.data.slice(0, pageSize),
11
- skip: 0,
12
- total: props.data.length,
13
- });
14
- const filterChange = (event) => {
15
- filteredData.current = filterBy(props.data.slice(), event.filter);
16
- const data = filteredData.current.slice(0, pageSize);
17
- setState({
18
- subsetData: data,
19
- skip: 0,
20
- total: filteredData.current.length,
21
- });
2
+ import Select from "react-select";
3
+ export function GenericDropdown({ data, selectedId, selectedData, onChange, textField, idField, isLoading, title, }) {
4
+ const options = data.map((item) => ({
5
+ value: item,
6
+ label: item[textField].toString(),
7
+ }));
8
+ const selectedOption = selectedId
9
+ ? options.find((option) => option.value.id === (selectedId === null || selectedId === void 0 ? void 0 : selectedId.toString()))
10
+ : options.find((option) => option.value === selectedData);
11
+ const handleChange = (selectedOption) => {
12
+ if (selectedOption) {
13
+ const selectedItem = idField
14
+ ? data.find((item) => item[idField].toString() === selectedOption.value.id)
15
+ : data.find((item) => item === selectedOption.value);
16
+ onChange(selectedItem || null);
17
+ }
18
+ else {
19
+ onChange(null);
20
+ }
22
21
  };
23
- const pageChange = (event) => {
24
- const skip = event.page.skip;
25
- const take = event.page.take;
26
- const newSubsetData = filteredData.current.slice(skip, skip + take);
27
- setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
28
- };
29
- 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: {
30
- total: state.total,
31
- pageSize: pageSize,
32
- skip: state.skip,
33
- }, label: (_c = props.title) !== null && _c !== void 0 ? _c : "Select an option", onPageChange: pageChange, onFilterChange: filterChange, filterable: true, popupSettings: {
34
- height: "250px",
35
- }, defaultValue: props, 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), clearButton: props.hideClearButton ? undefined : true }));
22
+ return (_jsx(Select, { options: options, onChange: handleChange, value: selectedOption, isLoading: isLoading, isDisabled: isLoading, placeholder: title || "Select an option" }));
36
23
  }
package/_index.test.js CHANGED
@@ -56,7 +56,7 @@ describe("GenericDropdown", () => {
56
56
  // Set initial selectedData to the second item in the data array
57
57
  let selectedData = data[1];
58
58
  // Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
59
- let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedData = data[e.value]), textField: "name", selectedData: selectedData }));
59
+ let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedData = e), textField: "name", selectedData: selectedData }));
60
60
  // Get the input element by its role of "combobox"
61
61
  // Simulate a change event on the input element by setting its target value to "O"
62
62
  let input = result.getByRole("combobox");
@@ -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.value.id), textField: "name", selectedId: selectedId, idField: "id" }));
75
+ let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedId = (e === null || e === void 0 ? void 0 : e.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");
@@ -88,7 +88,7 @@ describe("GenericDropdown", () => {
88
88
  // Set initial selectedData to the second item in the data array
89
89
  let selectedData = data[1];
90
90
  // Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
91
- let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedData = data[e.value]), textField: "name", selectedData: selectedData }));
91
+ let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedData = e), textField: "name", selectedData: selectedData }));
92
92
  let input = result.getByRole("combobox"); // Get the input element by its role of "combobox"
93
93
  fireEvent.change(input, { target: { value: "9" } }); //simulate a change event on the input element
94
94
  // Query the rendered result for elements with the text "Option 1" and "Option 9", and store the results in variables
package/index.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  export { CommandCellCheckBox } from "./commandCell/CommandCellCheckbox";
2
2
  export { CommandCellDate } from "./commandCell/CommandCellDate";
3
- export { CommandCellDropdown } from "./commandCell/CommandCellDropdown";
4
3
  export { CommandCellPrice } from "./commandCell/CommandCellPrice";
5
4
  export { CommandCellSwitch } from "./commandCell/CommandCellSwitch";
6
- export { FilterCellDropdown } from "./FilterCellDropdown";
7
5
  export { ToolbarButton } from "./Toolbar";
8
6
  export { GenericDropdown } from "./GenericDropdown";
9
7
  export { GridChangeEvent, CommonProps } from "./PropTypes";
package/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  export { CommandCellCheckBox } from "./commandCell/CommandCellCheckbox";
2
2
  export { CommandCellDate } from "./commandCell/CommandCellDate";
3
- export { CommandCellDropdown } from "./commandCell/CommandCellDropdown";
4
3
  export { CommandCellPrice } from "./commandCell/CommandCellPrice";
5
4
  export { CommandCellSwitch } from "./commandCell/CommandCellSwitch";
6
- export { FilterCellDropdown } from "./FilterCellDropdown";
7
5
  export { ToolbarButton } from "./Toolbar";
8
6
  export { GenericDropdown } from "./GenericDropdown";
9
7
  export { MultiSelectDropdown } from "./MultiSelectDropdown";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scheels-softdev/kendoreact-generics",
3
- "version": "2.9.8",
3
+ "version": "3.0.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -23,12 +23,15 @@
23
23
  "@testing-library/react": "^14.0.0",
24
24
  "@types/jest": "^29.5.3",
25
25
  "@types/react": "latest",
26
+ "framer-motion": "^11.0.23",
26
27
  "jest": "^29.6.2",
27
28
  "jest-environment-jsdom": "^29.6.2",
28
29
  "moment": "latest",
29
30
  "npmrc": "latest",
30
31
  "react": "latest",
31
32
  "react-dom": "latest",
33
+ "react-icons": "^5.0.1",
34
+ "react-select": "^5.8.0",
32
35
  "typescript": "latest"
33
36
  },
34
37
  "devDependencies": {
@@ -1,9 +0,0 @@
1
- import { GridFilterCellProps } from "@progress/kendo-react-grid";
2
- interface DropdownFilterCellProps<T> extends GridFilterCellProps {
3
- /** The data to populate the dropdown options */
4
- data: T[];
5
- /** The field names used to extract text values for display */
6
- textField: keyof T;
7
- }
8
- export declare function FilterCellDropdown<T>(props: DropdownFilterCellProps<T>): import("react/jsx-runtime").JSX.Element;
9
- export {};
@@ -1,32 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button } from "@progress/kendo-react-buttons";
3
- import { GenericDropdown } from "./GenericDropdown";
4
- // Define the DropdownFilterCell component with props of type DropdownFilterCellProps
5
- export function FilterCellDropdown(props) {
6
- // Define a function that returns true if a value is not undefined or null, and is different from the default item
7
- let hasValue = (value) => Boolean(value);
8
- // Define an onChange function that will be called when the ComboBox value changes
9
- const onChange = (event) => {
10
- var _a, _b;
11
- // Update the hasValue variable based on the new value of the ComboBox
12
- hasValue = hasValue((_b = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.id);
13
- // Call the onChange function passed down as a prop, passing a filter object with the new value and operator
14
- props.onChange({
15
- value: hasValue ? event.target.value.id : "",
16
- operator: hasValue ? "eq" : "",
17
- syntheticEvent: event.syntheticEvent,
18
- });
19
- };
20
- // Define an onClearButtonClick function that will be called when the Clear button is clicked
21
- const onClearButtonClick = (event) => {
22
- event.preventDefault();
23
- // Call the onChange function passed down as a prop, passing a filter object with empty values
24
- props.onChange({
25
- value: "",
26
- operator: "",
27
- syntheticEvent: event,
28
- });
29
- };
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 }), _jsx(Button, { title: "Clear", disabled: !hasValue(props.value), onClick: onClearButtonClick, icon: "filter-clear" })] })));
32
- }
@@ -1,19 +0,0 @@
1
- import { ComboBoxChangeEvent } from "@progress/kendo-react-dropdowns";
2
- export declare function CommandCellDDWithoutId<T>(props: {
3
- /** The data array for the dropdown options. */
4
- data: T[];
5
- /** The currently selected data item. */
6
- selectedData: T;
7
- /** The field names to use for text values in the dropdown. */
8
- textField: keyof T;
9
- /** Callback function to be called when the selected value changes. */
10
- onChange: (e: ComboBoxChangeEvent) => void;
11
- /** Optional separator to use for concatenating text values. */
12
- separator?: string;
13
- /** Determines if the edit field should be checked. */
14
- checkEditField?: boolean;
15
- /** Determines if the cell is in an editing state. */
16
- isEditing?: boolean;
17
- /** Determines if the clear button should be displayed in the dropdown. */
18
- showClearButton?: boolean;
19
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +0,0 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- import { GenericDropdown } from "../GenericDropdown";
3
- export function CommandCellDDWithoutId(props) {
4
- // Function implementation...
5
- return (_jsx("td", { children: props.checkEditField && !props.isEditing ? (_jsx(_Fragment, {}) //TODO remove this from Marketing display
6
- ) : (
7
- // If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
8
- _jsx(GenericDropdown, Object.assign({}, props))) }));
9
- }
@@ -1,20 +0,0 @@
1
- export declare function CommandCellDropdown<T>(props: {
2
- /** The data array for the dropdown options. */
3
- data: T[];
4
- /** The ID of the currently selected item. */
5
- selectedId: number;
6
- /** The field names to use for text values in the dropdown. */
7
- textField: keyof T;
8
- /** Callback function to be called when the selected value changes. */
9
- onChange: () => void;
10
- /** Optional separator to use for concatenating text values. */
11
- separator?: string;
12
- /** Determines if the edit field should be checked. */
13
- checkEditField?: boolean;
14
- /** Determines if the cell is in an editing state. */
15
- isEditing?: boolean;
16
- /** The field to use as the identity key. */
17
- idField?: keyof T;
18
- /** Determines if the clear button should be displayed in the dropdown. */
19
- showClearButton?: boolean;
20
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +0,0 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- import { GenericDropdown } from "../GenericDropdown";
3
- // This exports a function component called "CommandCellDropdown"
4
- // It takes in various props that are used to render a dropdown in a table cell
5
- export function CommandCellDropdown(props) {
6
- return (_jsx("td", { children: props.checkEditField && !props.isEditing && props.data.length ? (_jsx(_Fragment, {}) //TODO remove this from Marketing display
7
- ) : (
8
- // If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
9
- _jsx(GenericDropdown, Object.assign({}, props))) }));
10
- }