@scheels-softdev/kendoreact-generics 2.6.5 → 2.6.7

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.
Files changed (40) hide show
  1. package/jest.config.js +4 -0
  2. package/package.json +1 -1
  3. package/src/FilterCellDropdown.tsx +50 -0
  4. package/src/GenericDropdown.tsx +135 -0
  5. package/src/MultiSelectDropdown.tsx +79 -0
  6. package/{PropTypes.d.ts → src/PropTypes.ts} +1 -0
  7. package/src/Toolbar.tsx +27 -0
  8. package/src/Utility.ts +19 -0
  9. package/{_index.test.js → src/_index.test.tsx} +49 -7
  10. package/src/commandCell/CommandCellCheckbox.tsx +28 -0
  11. package/{commandCell/CommandCellDDWithoutId.d.ts → src/commandCell/CommandCellDDWithoutId.tsx} +16 -2
  12. package/src/commandCell/CommandCellDate.tsx +36 -0
  13. package/{commandCell/CommandCellDropdown.d.ts → src/commandCell/CommandCellDropdown.tsx} +18 -2
  14. package/src/commandCell/CommandCellPrice.tsx +9 -0
  15. package/src/commandCell/CommandCellSwitch.tsx +21 -0
  16. package/tsconfig.json +13 -0
  17. package/FilterCellDropdown.d.ts +0 -11
  18. package/FilterCellDropdown.js +0 -32
  19. package/GenericDropdown.d.ts +0 -33
  20. package/GenericDropdown.js +0 -67
  21. package/MultiSelectDropdown.d.ts +0 -14
  22. package/MultiSelectDropdown.js +0 -44
  23. package/PropTypes.js +0 -1
  24. package/Toolbar.d.ts +0 -13
  25. package/Toolbar.js +0 -4
  26. package/Utility.d.ts +0 -4
  27. package/Utility.js +0 -11
  28. package/_index.test.d.ts +0 -1
  29. package/commandCell/CommandCellCheckbox.d.ts +0 -8
  30. package/commandCell/CommandCellCheckbox.js +0 -13
  31. package/commandCell/CommandCellDDWithoutId.js +0 -9
  32. package/commandCell/CommandCellDate.d.ts +0 -9
  33. package/commandCell/CommandCellDate.js +0 -12
  34. package/commandCell/CommandCellDropdown.js +0 -10
  35. package/commandCell/CommandCellPrice.d.ts +0 -3
  36. package/commandCell/CommandCellPrice.js +0 -10
  37. package/commandCell/CommandCellSwitch.d.ts +0 -7
  38. package/commandCell/CommandCellSwitch.js +0 -5
  39. package/index.js +0 -10
  40. /package/{index.d.ts → src/index.ts} +0 -0
package/jest.config.js ADDED
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ preset: "ts-jest",
3
+ testEnvironment: "jsdom",
4
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scheels-softdev/kendoreact-generics",
3
- "version": "2.6.5",
3
+ "version": "2.6.7",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -0,0 +1,50 @@
1
+ import { ComboBoxChangeEvent } from "@progress/kendo-react-dropdowns";
2
+ import { GridFilterCellProps } from "@progress/kendo-react-grid";
3
+ import { Button } from "@progress/kendo-react-buttons";
4
+ import { GenericDropdown } from "./GenericDropdown";
5
+
6
+ interface DropdownFilterCellProps<T> extends GridFilterCellProps {
7
+ /** The data to populate the dropdown options */
8
+ data: T[];
9
+ /** The field names used to extract text values for display */
10
+ textField: keyof T;
11
+ /** The separator to use when concatenating multiple text values */
12
+ separator?: string;
13
+ }
14
+
15
+ // Define the DropdownFilterCell component with props of type DropdownFilterCellProps
16
+ export function FilterCellDropdown<T>(props: DropdownFilterCellProps<T>) {
17
+ // Define a function that returns true if a value is not undefined or null, and is different from the default item
18
+ let hasValue: any = (value: string) => Boolean(value);
19
+
20
+ // Define an onChange function that will be called when the ComboBox value changes
21
+ const onChange = (event: ComboBoxChangeEvent) => {
22
+ // Update the hasValue variable based on the new value of the ComboBox
23
+ hasValue = hasValue(event?.target?.value?.id);
24
+ // Call the onChange function passed down as a prop, passing a filter object with the new value and operator
25
+ props.onChange({
26
+ value: hasValue ? event.target.value.id : "", // Use the ID of the selected value as the filter value
27
+ operator: hasValue ? "eq" : "", // Use the "eq" operator if the value is non-empty, otherwise use an empty string
28
+ syntheticEvent: event.syntheticEvent,
29
+ });
30
+ };
31
+
32
+ // Define an onClearButtonClick function that will be called when the Clear button is clicked
33
+ const onClearButtonClick = (event: any) => {
34
+ event.preventDefault();
35
+ // Call the onChange function passed down as a prop, passing a filter object with empty values
36
+ props.onChange({
37
+ value: "", // Set the filter value to an empty string
38
+ operator: "", // Set the operator to an empty string
39
+ syntheticEvent: event,
40
+ });
41
+ };
42
+
43
+ // Render a div containing a GenericDropdownWithSearch component and a Clear button
44
+ return (
45
+ <div className="k-filtercell" data-testid="dropdownFilter">
46
+ <GenericDropdown data={props.data} onChange={onChange} selectedId={props.value} textField={props.textField} separator={props.separator} />
47
+ <Button title="Clear" disabled={!hasValue(props.value)} onClick={onClearButtonClick} icon="filter-clear" />
48
+ </div>
49
+ );
50
+ }
@@ -0,0 +1,135 @@
1
+ import { ComboBox, ComboBoxFilterChangeEvent, ComboBoxPageChangeEvent } from "@progress/kendo-react-dropdowns";
2
+ import { filterBy, process } from "@progress/kendo-data-query";
3
+ import { CSSProperties, useEffect, useRef, useState } from "react";
4
+ import { Skeleton } from "@progress/kendo-react-indicators";
5
+ import { Guard } from "@scheels-softdev/frontend-utility-functions";
6
+ //TODO add a style property
7
+ //TODO add metadata documentation
8
+ // component that renders a dropdown with a search filter
9
+ /**
10
+ * JSX Component for displaying items in a virtualized combobox
11
+ * @template T - The type of the data objects in the dropdown.
12
+ * @param {object} props - The component props.
13
+ * @returns {JSX.Element}
14
+ */
15
+
16
+ type GenericDDProps<T> = {
17
+ /*1* The data to populate the dropdown options */
18
+ data: T[];
19
+ /** The ID of the currently selected item. (optional)*/
20
+ selectedId?: number;
21
+ /** The currently selected data object. (optional)*/
22
+ selectedData?: T;
23
+ /** Callback function triggered when the selected value changes*/
24
+ onChange: Function;
25
+ /** The field names used to extract text values for display */
26
+ textField: keyof T;
27
+ /** The separator to use when concatenating multiple text values. (optional)*/
28
+ separator?: string;
29
+ /** Determines whether the dropdown is disabled. (optional)*/
30
+ idField?: keyof T;
31
+ /** The field name used as the identity key (optional)*/
32
+ disabled?: boolean;
33
+ /** The label displayed for the dropdown (optional)*/
34
+ title?: string;
35
+ /** The Determines whether the clear button is hidden from the dropdown. (optional)*/
36
+ hideClearButton?: boolean;
37
+ /** Custom CSS properties for the component. (optional)*/
38
+ style?: CSSProperties;
39
+ isLoading?: boolean;
40
+ };
41
+ export function GenericDropdown<T>({
42
+ data,
43
+ selectedId,
44
+ selectedData,
45
+ onChange,
46
+ textField,
47
+ disabled,
48
+ idField,
49
+ title,
50
+ hideClearButton,
51
+ style,
52
+ isLoading,
53
+ }: GenericDDProps<T>) {
54
+ //local state
55
+ const pageSize = 8;
56
+ if (selectedId !== undefined && selectedData !== undefined) {
57
+ throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
58
+ }
59
+
60
+ //useState
61
+ const [selectedObject, setSelectedObject] = useState<T | null>(null);
62
+ const [state, setState] = useState({
63
+ skip: 0,
64
+ total: data.length,
65
+ subsetData: data.slice(0, pageSize),
66
+ });
67
+
68
+ //trigger functions
69
+ useEffect(() => {
70
+ setSelectedObject(
71
+ selectedId
72
+ ? data.find((item: any) => selectedId === item[idField || "id"]) ?? null
73
+ : data.find((x) => Guard.Ensure.EqualObjects({ ...x, ...selectedData }, { ...x! })) ?? null
74
+ );
75
+ }, [selectedId, selectedData, data]);
76
+ useEffect(() => {
77
+ setState({
78
+ skip: 0,
79
+ total: data.length,
80
+ subsetData: data.slice(0, pageSize),
81
+ });
82
+ }, [data]);
83
+
84
+ //external function variables
85
+ let filteredData = useRef(data.slice());
86
+
87
+ //function creation
88
+ // function to handle filter changes
89
+ const onFilterChange = (event: ComboBoxFilterChangeEvent) => {
90
+ if (event.filter.value?.length) filteredData.current = filterBy(data.slice(), event.filter);
91
+ else filteredData.current = data;
92
+ const newData = filteredData.current.slice(0, pageSize);
93
+ setState({
94
+ subsetData: newData,
95
+ skip: 0,
96
+ total: filteredData.current.length,
97
+ });
98
+ };
99
+ // function to handle page changes for virtualization
100
+ const pageChange = (event: ComboBoxPageChangeEvent) => {
101
+ console.log("page change data: ", event.page, filteredData.current);
102
+ const skip = event.page.skip;
103
+ const take = event.page.take;
104
+ const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) : data.slice(skip, skip + take);
105
+ setState({ ...state, subsetData: newSubsetData, skip: skip });
106
+ };
107
+ return (
108
+ <div data-testid={"dropdown"}>
109
+ <ComboBox
110
+ style={style}
111
+ label={title}
112
+ disabled={disabled || isLoading}
113
+ data={state.subsetData} // data to display in the dropdown
114
+ textField={textField.toString()}
115
+ virtual={{
116
+ // enable virtualization for large datasets
117
+ total: state.total,
118
+ pageSize: pageSize,
119
+ skip: state.skip,
120
+ }}
121
+ suggest
122
+ onPageChange={pageChange} // handle page changes for virtualization
123
+ filterable={true} // enable filter
124
+ onFilterChange={onFilterChange} // handle filter changes
125
+ popupSettings={{
126
+ height: "210px",
127
+ }}
128
+ onChange={(e) => onChange(e)}
129
+ onBlur={(e) => e.nativeEvent.preventDefault()}
130
+ clearButton={!hideClearButton}
131
+ value={selectedObject}
132
+ />
133
+ </div>
134
+ );
135
+ }
@@ -0,0 +1,79 @@
1
+ import { useRef, useState } from "react";
2
+ import { filterBy } from "@progress/kendo-data-query";
3
+ import { MultiSelect, MultiSelectPageChangeEvent, MultiSelectFilterChangeEvent } from "@progress/kendo-react-dropdowns";
4
+ export function MultiSelectDropdown<T>({
5
+ data,
6
+ selectedData,
7
+ textField,
8
+ onSelect,
9
+ title,
10
+ limit,
11
+ }: {
12
+ /** The data array for the dropdown options. */
13
+ data: T[];
14
+ /** The array of selected data items. */
15
+ selectedData: T[];
16
+ /** The field names to use for text values in the dropdown. */
17
+ textField: keyof T;
18
+ /** The function to call when an item is selected or deselected. */
19
+ onSelect: Function;
20
+ /** The optional title of the dropdown. */
21
+ title?: string;
22
+ /** The optional limit of the maximum number of selected items. */
23
+ limit?: number;
24
+ }) {
25
+ //local state
26
+ const pageSize = 8;
27
+ const [state, setState] = useState({
28
+ skip: 0,
29
+ total: data.length,
30
+ subsetData: data.slice(0, pageSize),
31
+ });
32
+
33
+ //external function variables
34
+ const filteredData = useRef(data.slice());
35
+ //function creation
36
+ // function to handle filter changes
37
+ const onFilterChange = (event: MultiSelectFilterChangeEvent) => {
38
+ if (event.filter.value?.length) filteredData.current = filterBy(data.slice(), event.filter);
39
+ else filteredData.current = data;
40
+ const newData = filteredData.current.slice(0, pageSize);
41
+ setState({
42
+ subsetData: newData,
43
+ skip: 0,
44
+ total: filteredData.current.length,
45
+ });
46
+ };
47
+ // function to handle page changes for virtualization
48
+ const pageChange = (event: MultiSelectPageChangeEvent) => {
49
+ const skip = event.page.skip;
50
+ const take = event.page.take;
51
+ const newSubsetData = filteredData.current.slice(skip, skip + take);
52
+ setState({ ...state, subsetData: newSubsetData, skip: skip });
53
+ };
54
+
55
+ return (
56
+ <div data-testid={"multiselect"} style={{ width: "100%" }}>
57
+ <MultiSelect
58
+ label={title}
59
+ data={state.subsetData}
60
+ textField={textField.toString()} // name of the field to use for display text
61
+ style={{ width: "100%" }}
62
+ virtual={{
63
+ total: state.total,
64
+ pageSize: pageSize,
65
+ skip: state.skip,
66
+ }}
67
+ onPageChange={pageChange}
68
+ filterable={true}
69
+ onFilterChange={onFilterChange}
70
+ popupSettings={{
71
+ height: "210px",
72
+ }}
73
+ onChange={(e) => onSelect(limit && e.value.length ? e.value.slice(0, limit) : e.value)}
74
+ autoClose={false}
75
+ value={selectedData} ///right now: clears selected values whenever selected Vendor Value changes. This will need to be changed to something better in the future
76
+ />
77
+ </div>
78
+ );
79
+ }
@@ -2,6 +2,7 @@ export type CommonProps = {
2
2
  isEditing?: boolean;
3
3
  id?: number;
4
4
  };
5
+
5
6
  export type GridChangeEvent = {
6
7
  value: any;
7
8
  field?: string;
@@ -0,0 +1,27 @@
1
+ type CommonProps = {
2
+ id: number;
3
+ isEditing?: boolean;
4
+ };
5
+ export function ToolbarButton<T extends CommonProps>({
6
+ item,
7
+ data,
8
+ setData,
9
+ }: {
10
+ /** The item object to add. */
11
+ item: T;
12
+ /** The data array. */
13
+ data: T[];
14
+ /** The function to set the updated data. */
15
+ setData: Function;
16
+ }) {
17
+ return (
18
+ <button
19
+ title="Add new"
20
+ className="k-button k-button-md k-rounded-md k-button-solid k-button-solid-primary"
21
+ onClick={() => setData([{ ...item, isEditing: true, id: 0 }, ...data])}
22
+ disabled={data.find((x) => x.isEditing) ? true : false}
23
+ >
24
+ Add Another
25
+ </button>
26
+ );
27
+ }
package/src/Utility.ts ADDED
@@ -0,0 +1,19 @@
1
+ // function to concatenate text values from dataItem using specified fields and separator
2
+ export const getTextValue = (dataItem: any, fields: string[], separator?: string) => {
3
+ let textValue = "";
4
+ fields.forEach((field, index) => (textValue += index > 0 ? (separator ? separator : " ") + dataItem[field] : dataItem[field]));
5
+ return textValue;
6
+ };
7
+
8
+ export const getDropdownArray = <T>(data: T[], textFields: (keyof T)[], separator: string) => {
9
+ return data.map((x) => {
10
+ return {
11
+ ...x,
12
+ textValue: getTextValue(
13
+ x,
14
+ textFields.map((x) => x.toString()),
15
+ separator
16
+ ),
17
+ };
18
+ });
19
+ };
@@ -1,70 +1,97 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
1
  import { GenericDropdown } from "./GenericDropdown";
2
+ import { GridChangeEvent } from "./PropTypes";
3
3
  import { fireEvent, render } from "@testing-library/react";
4
+ type DataType = {
5
+ id: number;
6
+ name: string;
7
+ };
4
8
  describe("GenericDropdown", () => {
5
- const data = [];
9
+ const data: DataType[] = [];
6
10
  for (let i = 1; i < 20; i++) {
7
11
  data.push({ id: i, name: `Option ${i}` });
8
12
  }
9
13
  test("renders virtualized ordering by index when passed selectedData", () => {
10
14
  // Set initial selectedData to the second item in the data array
11
15
  let selectedData = data[1];
16
+
12
17
  // Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
13
- let result = render(_jsx(GenericDropdown, { data: data, onChange: () => { }, textField: "name", selectedData: selectedData }));
18
+ let result = render(<GenericDropdown data={data} onChange={() => {}} textField="name" selectedData={selectedData} />);
19
+
14
20
  // Get the input element by its role of "combobox"
15
21
  const input = result.getByRole("combobox");
22
+
16
23
  expect(input.getAttribute("value")).toBe("Option 2");
17
24
  // Simulate a change event on the input element by setting its target value to "O"
18
25
  fireEvent.change(input, { target: { value: "O" } });
26
+
19
27
  // Simulate a key down event on the input element with the key value of "ArrowDown"
20
28
  fireEvent.keyDown(input, { key: "ArrowDown" });
29
+
21
30
  // Query the rendered result for elements with the text "Option 1", "Option 2", and "Option 3"
22
31
  let item1 = result.queryByText("Option 1");
23
32
  let item2 = result.queryByText("Option 2");
24
33
  let item3 = result.queryByText("Option 3");
34
+
25
35
  // Ensure that item1, item2, and item3 are not undefined (i.e., they are rendered)
26
36
  expect(item1).not.toBeUndefined();
27
37
  expect(item2).not.toBeUndefined();
28
38
  expect(item3).not.toBeUndefined();
39
+
29
40
  // Ensure that there are no elements with the text "Option 9" (i.e., it is not rendered)
30
41
  expect(result.queryAllByText("Option 9")).toHaveLength(0);
31
42
  });
32
43
  test("renders virtualized ordering by index when passed selectedId", () => {
33
44
  // Set initial selectedData to the second item in the data array
34
45
  let selectedId = 2;
46
+
35
47
  // 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 }));
48
+ let result = render(<GenericDropdown data={data} onChange={() => {}} textField="name" selectedId={selectedId} />);
49
+
37
50
  // Get the input element by its role of "combobox"
38
51
  const input = result.getByRole("combobox");
52
+
39
53
  expect(input.getAttribute("value")).toBe("Option 2");
40
54
  // Simulate a change event on the input element by setting its target value to "O"
41
55
  fireEvent.change(input, { target: { value: "O" } });
56
+
42
57
  // Simulate a key down event on the input element with the key value of "ArrowDown"
43
58
  fireEvent.keyDown(input, { key: "ArrowDown" });
59
+
44
60
  // Query the rendered result for elements with the text "Option 1", "Option 2", and "Option 3"
45
61
  let item1 = result.queryByText("Option 1");
46
62
  let item2 = result.queryByText("Option 2");
47
63
  let item3 = result.queryByText("Option 3");
64
+
48
65
  // Ensure that item1, item2, and item3 are not undefined (i.e., they are rendered)
49
66
  expect(item1).not.toBeUndefined();
50
67
  expect(item2).not.toBeUndefined();
51
68
  expect(item3).not.toBeUndefined();
69
+
52
70
  // Ensure that there are no elements with the text "Option 9" (i.e., it is not rendered)
53
71
  expect(result.queryAllByText("Option 9")).toHaveLength(0);
54
72
  });
73
+
55
74
  test("handles change event when selecting by object", () => {
56
75
  // Set initial selectedData to the second item in the data array
57
76
  let selectedData = data[1];
77
+
58
78
  // 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 }));
79
+ let result = render(
80
+ <GenericDropdown data={data} onChange={(e: GridChangeEvent) => (selectedData = data[e.value])} textField="name" selectedData={selectedData} />
81
+ );
82
+
60
83
  // Get the input element by its role of "combobox"
84
+
61
85
  // Simulate a change event on the input element by setting its target value to "O"
62
86
  let input = result.getByRole("combobox");
63
87
  fireEvent.change(input, { target: { value: "O" } });
88
+
64
89
  // Get the item element with the text "Option 2"
65
90
  let item2 = result.getByText("Option 2");
91
+
66
92
  // Simulate a click event on the item element
67
93
  fireEvent.click(item2);
94
+
68
95
  // Ensure that the input element's value attribute is set to "Option 2"
69
96
  expect(selectedData.id).toBe(2);
70
97
  });
@@ -72,28 +99,43 @@ describe("GenericDropdown", () => {
72
99
  // Set initial selectedData to the second item in the data array
73
100
  let selectedId = 1;
74
101
  // 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" }));
102
+ let result = render(
103
+ <GenericDropdown data={data} onChange={(e: GridChangeEvent) => (selectedId = e.value.id)} textField="name" selectedId={selectedId} idField="id" />
104
+ );
105
+
76
106
  // Get the input element by its role of "combobox"
107
+
77
108
  // Simulate a change event on the input element by setting its target value to "O"
78
109
  let input = result.getByRole("combobox");
79
110
  fireEvent.change(input, { target: { value: "O" } });
111
+
80
112
  // Get the item element with the text "Option 2"
81
113
  let item2 = result.getByText("Option 2");
114
+
82
115
  // Simulate a click event on the item element
116
+
83
117
  fireEvent.click(item2);
118
+
84
119
  // Ensure that the input element's value attribute is set to "Option 2"
85
120
  expect(selectedId).toBe(2);
86
121
  });
122
+
87
123
  test("only displays items that match the search", () => {
88
124
  // Set initial selectedData to the second item in the data array
89
125
  let selectedData = data[1];
126
+
90
127
  // 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 }));
128
+ let result = render(
129
+ <GenericDropdown data={data} onChange={(e: GridChangeEvent) => (selectedData = data[e.value])} textField="name" selectedData={selectedData} />
130
+ );
131
+
92
132
  let input = result.getByRole("combobox"); // Get the input element by its role of "combobox"
93
133
  fireEvent.change(input, { target: { value: "9" } }); //simulate a change event on the input element
134
+
94
135
  // Query the rendered result for elements with the text "Option 1" and "Option 9", and store the results in variables
95
136
  let item1 = result.queryAllByText("Option 1");
96
137
  let item9 = result.queryAllByText("Option 9");
138
+
97
139
  // Ensure that there are no elements with the text "Option 1" and at least one element with the text "Option 9"
98
140
  expect(item1).toHaveLength(0);
99
141
  expect(item9.length).toBeGreaterThan(0);
@@ -0,0 +1,28 @@
1
+ import { Checkbox } from "@progress/kendo-react-inputs";
2
+
3
+ export function CommandCellCheckBox({
4
+ checked,
5
+ onCheck,
6
+ onUncheck,
7
+ }: {
8
+ /** Boolean value indicating whether the checkbox is checked (`true`) or unchecked (`false`). */
9
+ checked: boolean;
10
+ /** Callback function to be called when the checkbox is checked. */
11
+ onCheck: Function;
12
+ /** Callback function to be called when the checkbox is unchecked. */
13
+ onUncheck: Function;
14
+ }) {
15
+ const functionToRun = () => {
16
+ if (checked) {
17
+ onUncheck();
18
+ } else {
19
+ onCheck();
20
+ }
21
+ };
22
+
23
+ return (
24
+ <td className="justify-content-center" data-testid="checkbox">
25
+ <Checkbox checked={checked} onChange={functionToRun} />
26
+ </td>
27
+ );
28
+ }
@@ -1,5 +1,7 @@
1
1
  import { ComboBoxChangeEvent } from "@progress/kendo-react-dropdowns";
2
- export declare function CommandCellDDWithoutId<T>(props: {
2
+ import { GenericDropdown } from "../GenericDropdown";
3
+
4
+ export function CommandCellDDWithoutId<T>(props: {
3
5
  /** The data array for the dropdown options. */
4
6
  data: T[];
5
7
  /** The currently selected data item. */
@@ -16,4 +18,16 @@ export declare function CommandCellDDWithoutId<T>(props: {
16
18
  isEditing?: boolean;
17
19
  /** Determines if the clear button should be displayed in the dropdown. */
18
20
  showClearButton?: boolean;
19
- }): import("react/jsx-runtime").JSX.Element;
21
+ }) {
22
+ // Function implementation...
23
+ return (
24
+ <td>
25
+ {props.checkEditField && !props.isEditing ? (
26
+ <></> //TODO remove this from Marketing display
27
+ ) : (
28
+ // If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
29
+ <GenericDropdown {...props} />
30
+ )}
31
+ </td>
32
+ );
33
+ }
@@ -0,0 +1,36 @@
1
+ import { DatePicker } from "@progress/kendo-react-dateinputs";
2
+ import moment from "moment";
3
+ import { CommonProps, GridChangeEvent } from "../PropTypes";
4
+ export function CommandCellDate<T extends CommonProps>({
5
+ dataItem,
6
+ onChange,
7
+ field,
8
+ }: {
9
+ /** The data item for the cell. */
10
+ dataItem: T;
11
+ /** Callback function to be called when the value changes. */
12
+ onChange: (e: GridChangeEvent) => void;
13
+ /** The field of the data item to display in the cell. this field must be formattable into a date. */
14
+ field: keyof T;
15
+ }) {
16
+ let valString = "" + dataItem[field];
17
+ let date = moment(valString).format("MM/DD/YY");
18
+ return (
19
+ <td data-testid="date">
20
+ {valString === undefined || dataItem.isEditing ? (
21
+ <DatePicker
22
+ value={new Date(moment(valString).format("MMMM, DD YYYY"))}
23
+ onChange={(e) =>
24
+ onChange({
25
+ field: field.toString(),
26
+ value: moment(e.value),
27
+ dataItem: dataItem,
28
+ })
29
+ }
30
+ />
31
+ ) : (
32
+ date
33
+ )}
34
+ </td>
35
+ );
36
+ }
@@ -1,5 +1,10 @@
1
1
  import { ComboBoxChangeEvent } from "@progress/kendo-react-dropdowns";
2
- export declare function CommandCellDropdown<T>(props: {
2
+ import { GenericDropdown } from "../GenericDropdown";
3
+ import { CommonProps } from "../PropTypes";
4
+
5
+ // This exports a function component called "CommandCellDropdown"
6
+ // It takes in various props that are used to render a dropdown in a table cell
7
+ export function CommandCellDropdown<T>(props: {
3
8
  /** The data array for the dropdown options. */
4
9
  data: T[];
5
10
  /** The ID of the currently selected item. */
@@ -18,4 +23,15 @@ export declare function CommandCellDropdown<T>(props: {
18
23
  idField?: keyof T;
19
24
  /** Determines if the clear button should be displayed in the dropdown. */
20
25
  showClearButton?: boolean;
21
- }): import("react/jsx-runtime").JSX.Element;
26
+ }) {
27
+ return (
28
+ <td>
29
+ {props.checkEditField && !props.isEditing && props.data.length ? (
30
+ <></> //TODO remove this from Marketing display
31
+ ) : (
32
+ // If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
33
+ <GenericDropdown {...props} />
34
+ )}
35
+ </td>
36
+ );
37
+ }
@@ -0,0 +1,9 @@
1
+ export function CommandCellPrice({ cost }: { /** The cost value for the cell. */ cost: number }) {
2
+ let formattedCost: any = new Intl.NumberFormat("en", {
3
+ style: "currency",
4
+ currency: "USD",
5
+ minimumSignificantDigits: 2,
6
+ maximumFractionDigits: 3,
7
+ }).format(cost);
8
+ return <td data-testid="price">{formattedCost}</td>;
9
+ }
@@ -0,0 +1,21 @@
1
+ import { GridCellProps } from "@progress/kendo-react-grid";
2
+ import { Switch } from "@progress/kendo-react-inputs";
3
+ export function CommandCellSwitch({
4
+ props,
5
+ changeFunction,
6
+ }: {
7
+ /** The GridCellProps object containing cell-related properties. */
8
+ props: GridCellProps;
9
+ /** The function to call when the switch value changes. */
10
+ changeFunction: Function;
11
+ }) {
12
+ return (
13
+ <td data-testid="switch">
14
+ {props.dataItem.isEditing ? (
15
+ <Switch onChange={() => changeFunction()} checked={props.dataItem[props.field!]} />
16
+ ) : (
17
+ props.dataItem[props.field!].toString()
18
+ )}
19
+ </td>
20
+ );
21
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "jsx": "react-jsx",
5
+ "declaration": true,
6
+ "esModuleInterop": true,
7
+ "outDir": "dist",
8
+ "target": "es6",
9
+ "module": "es6",
10
+ "moduleResolution": "node"
11
+ },
12
+ "include": ["src"]
13
+ }
@@ -1,11 +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
- /** The separator to use when concatenating multiple text values */
8
- separator?: string;
9
- }
10
- export declare function FilterCellDropdown<T>(props: DropdownFilterCellProps<T>): import("react/jsx-runtime").JSX.Element;
11
- 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, separator: props.separator }), _jsx(Button, { title: "Clear", disabled: !hasValue(props.value), onClick: onClearButtonClick, icon: "filter-clear" })] })));
32
- }
@@ -1,33 +0,0 @@
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
- */
8
- type GenericDDProps<T> = {
9
- data: T[];
10
- /** The ID of the currently selected item. (optional)*/
11
- selectedId?: number;
12
- /** The currently selected data object. (optional)*/
13
- 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 */
17
- textField: keyof T;
18
- /** The separator to use when concatenating multiple text values. (optional)*/
19
- separator?: string;
20
- /** Determines whether the dropdown is disabled. (optional)*/
21
- 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
- /** The Determines whether the clear button is hidden from the dropdown. (optional)*/
27
- hideClearButton?: boolean;
28
- /** Custom CSS properties for the component. (optional)*/
29
- style?: CSSProperties;
30
- isLoading?: boolean;
31
- };
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
- export {};
@@ -1,67 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
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 { Skeleton } from "@progress/kendo-react-indicators";
6
- import { Guard } from "@scheels-softdev/frontend-utility-functions";
7
- export function GenericDropdown({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, }) {
8
- //local state
9
- const pageSize = 8;
10
- if (selectedId !== undefined && selectedData !== undefined) {
11
- throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
12
- }
13
- //useState
14
- const [selectedObject, setSelectedObject] = useState(null);
15
- const [state, setState] = useState({
16
- skip: 0,
17
- total: data.length,
18
- subsetData: data.slice(0, pageSize),
19
- });
20
- //trigger functions
21
- useEffect(() => {
22
- var _a, _b;
23
- setSelectedObject(selectedId
24
- ? (_a = data.find((item) => selectedId === item[idField || "id"])) !== null && _a !== void 0 ? _a : null
25
- : (_b = data.find((x) => Guard.Ensure.EqualObjects(Object.assign(Object.assign({}, x), selectedData), Object.assign({}, x)))) !== null && _b !== void 0 ? _b : null);
26
- }, [selectedId, selectedData, data]);
27
- useEffect(() => {
28
- setState({
29
- skip: 0,
30
- total: data.length,
31
- subsetData: data.slice(0, pageSize),
32
- });
33
- }, [data]);
34
- //external function variables
35
- let filteredData = useRef(data.slice());
36
- //function creation
37
- // function to handle filter changes
38
- const onFilterChange = (event) => {
39
- var _a;
40
- if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
41
- filteredData.current = filterBy(data.slice(), event.filter);
42
- else
43
- filteredData.current = data;
44
- const newData = filteredData.current.slice(0, pageSize);
45
- setState({
46
- subsetData: newData,
47
- skip: 0,
48
- total: filteredData.current.length,
49
- });
50
- };
51
- // function to handle page changes for virtualization
52
- const pageChange = (event) => {
53
- console.log("page change data: ", event.page, filteredData.current);
54
- const skip = event.page.skip;
55
- const take = event.page.take;
56
- const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) : data.slice(skip, skip + take);
57
- setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
58
- };
59
- 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: {
60
- // enable virtualization for large datasets
61
- total: state.total,
62
- pageSize: pageSize,
63
- skip: state.skip,
64
- }, suggest: true, onPageChange: pageChange, filterable: true, onFilterChange: onFilterChange, popupSettings: {
65
- height: "210px",
66
- }, onChange: (e) => onChange(e), onBlur: (e) => e.nativeEvent.preventDefault(), clearButton: !hideClearButton, value: selectedObject })) : (_jsx(Skeleton, { shape: "rectangle", style: style ? style : { height: "40px", width: "100%" } })) })));
67
- }
@@ -1,14 +0,0 @@
1
- export declare function MultiSelectDropdown<T>({ data, selectedData, textField, onSelect, title, limit, }: {
2
- /** The data array for the dropdown options. */
3
- data: T[];
4
- /** The array of selected data items. */
5
- selectedData: T[];
6
- /** The field names to use for text values in the dropdown. */
7
- textField: keyof T;
8
- /** The function to call when an item is selected or deselected. */
9
- onSelect: Function;
10
- /** The optional title of the dropdown. */
11
- title?: string;
12
- /** The optional limit of the maximum number of selected items. */
13
- limit?: number;
14
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,44 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useRef, useState } from "react";
3
- import { filterBy } from "@progress/kendo-data-query";
4
- import { MultiSelect } from "@progress/kendo-react-dropdowns";
5
- export function MultiSelectDropdown({ data, selectedData, textField, onSelect, title, limit, }) {
6
- //local state
7
- const pageSize = 8;
8
- const [state, setState] = useState({
9
- skip: 0,
10
- total: data.length,
11
- subsetData: data.slice(0, pageSize),
12
- });
13
- //external function variables
14
- const filteredData = useRef(data.slice());
15
- //function creation
16
- // function to handle filter changes
17
- const onFilterChange = (event) => {
18
- var _a;
19
- if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
20
- filteredData.current = filterBy(data.slice(), event.filter);
21
- else
22
- filteredData.current = data;
23
- const newData = filteredData.current.slice(0, pageSize);
24
- setState({
25
- subsetData: newData,
26
- skip: 0,
27
- total: filteredData.current.length,
28
- });
29
- };
30
- // function to handle page changes for virtualization
31
- const pageChange = (event) => {
32
- const skip = event.page.skip;
33
- const take = event.page.take;
34
- const newSubsetData = filteredData.current.slice(skip, skip + take);
35
- setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
36
- };
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: {
38
- total: state.total,
39
- pageSize: pageSize,
40
- skip: state.skip,
41
- }, onPageChange: pageChange, filterable: true, onFilterChange: onFilterChange, popupSettings: {
42
- height: "210px",
43
- }, onChange: (e) => onSelect(limit && e.value.length ? e.value.slice(0, limit) : e.value), autoClose: false, value: selectedData }) })));
44
- }
package/PropTypes.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/Toolbar.d.ts DELETED
@@ -1,13 +0,0 @@
1
- type CommonProps = {
2
- id: number;
3
- isEditing?: boolean;
4
- };
5
- export declare function ToolbarButton<T extends CommonProps>({ item, data, setData, }: {
6
- /** The item object to add. */
7
- item: T;
8
- /** The data array. */
9
- data: T[];
10
- /** The function to set the updated data. */
11
- setData: Function;
12
- }): import("react/jsx-runtime").JSX.Element;
13
- export {};
package/Toolbar.js DELETED
@@ -1,4 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- export function ToolbarButton({ item, data, setData, }) {
3
- return (_jsx("button", Object.assign({ title: "Add new", className: "k-button k-button-md k-rounded-md k-button-solid k-button-solid-primary", onClick: () => setData([Object.assign(Object.assign({}, item), { isEditing: true, id: 0 }), ...data]), disabled: data.find((x) => x.isEditing) ? true : false }, { children: "Add Another" })));
4
- }
package/Utility.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare const getTextValue: (dataItem: any, fields: string[], separator?: string) => string;
2
- export declare const getDropdownArray: <T>(data: T[], textFields: (keyof T)[], separator: string) => (T & {
3
- textValue: string;
4
- })[];
package/Utility.js DELETED
@@ -1,11 +0,0 @@
1
- // function to concatenate text values from dataItem using specified fields and separator
2
- export const getTextValue = (dataItem, fields, separator) => {
3
- let textValue = "";
4
- fields.forEach((field, index) => (textValue += index > 0 ? (separator ? separator : " ") + dataItem[field] : dataItem[field]));
5
- return textValue;
6
- };
7
- export const getDropdownArray = (data, textFields, separator) => {
8
- return data.map((x) => {
9
- return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
10
- });
11
- };
package/_index.test.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- export declare function CommandCellCheckBox({ checked, onCheck, onUncheck, }: {
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: Function;
6
- /** Callback function to be called when the checkbox is unchecked. */
7
- onUncheck: Function;
8
- }): 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, }) {
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 }) })));
13
- }
@@ -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,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,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
- }
@@ -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,7 +0,0 @@
1
- import { GridCellProps } from "@progress/kendo-react-grid";
2
- export declare function CommandCellSwitch({ props, changeFunction, }: {
3
- /** The GridCellProps object containing cell-related properties. */
4
- props: GridCellProps;
5
- /** The function to call when the switch value changes. */
6
- changeFunction: Function;
7
- }): 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
- }
package/index.js DELETED
@@ -1,10 +0,0 @@
1
- export { CommandCellCheckBox } from "./commandCell/CommandCellCheckbox";
2
- export { CommandCellDate } from "./commandCell/CommandCellDate";
3
- export { CommandCellDropdown } from "./commandCell/CommandCellDropdown";
4
- export { CommandCellDDWithoutId } from "./commandCell/CommandCellDDWithoutId";
5
- export { CommandCellPrice } from "./commandCell/CommandCellPrice";
6
- export { CommandCellSwitch } from "./commandCell/CommandCellSwitch";
7
- export { FilterCellDropdown } from "./FilterCellDropdown";
8
- export { ToolbarButton } from "./Toolbar";
9
- export { GenericDropdown } from "./GenericDropdown";
10
- export { MultiSelectDropdown } from "./MultiSelectDropdown";
File without changes