@scheels-softdev/kendoreact-generics 2.8.9 → 2.8.10
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.
- package/jest.config.js +4 -0
- package/package.json +1 -1
- package/src/FilterCellDropdown.tsx +50 -0
- package/src/GenericDropdown.tsx +151 -0
- package/src/MultiSelectDropdown.tsx +79 -0
- package/{PropTypes.d.ts → src/PropTypes.ts} +1 -0
- package/src/Toolbar.tsx +27 -0
- package/src/Utility.ts +19 -0
- package/{_index.test.js → src/_index.test.tsx} +49 -7
- package/src/commandCell/CommandCellCheckbox.tsx +31 -0
- package/{commandCell/CommandCellDDWithoutId.d.ts → src/commandCell/CommandCellDDWithoutId.tsx} +16 -2
- package/src/commandCell/CommandCellDate.tsx +36 -0
- package/{commandCell/CommandCellDropdown.d.ts → src/commandCell/CommandCellDropdown.tsx} +18 -2
- package/src/commandCell/CommandCellPrice.tsx +9 -0
- package/src/commandCell/CommandCellSwitch.tsx +21 -0
- package/tsconfig.json +13 -0
- package/FilterCellDropdown.d.ts +0 -11
- package/FilterCellDropdown.js +0 -32
- package/GenericDropdown.d.ts +0 -44
- package/GenericDropdown.js +0 -82
- package/MultiSelectDropdown.d.ts +0 -14
- package/MultiSelectDropdown.js +0 -44
- package/PropTypes.js +0 -1
- package/Toolbar.d.ts +0 -13
- package/Toolbar.js +0 -4
- package/Utility.d.ts +0 -4
- package/Utility.js +0 -11
- package/_index.test.d.ts +0 -1
- package/commandCell/CommandCellCheckbox.d.ts +0 -10
- package/commandCell/CommandCellCheckbox.js +0 -13
- package/commandCell/CommandCellDDWithoutId.js +0 -9
- package/commandCell/CommandCellDate.d.ts +0 -9
- package/commandCell/CommandCellDate.js +0 -12
- package/commandCell/CommandCellDropdown.js +0 -10
- package/commandCell/CommandCellPrice.d.ts +0 -3
- package/commandCell/CommandCellPrice.js +0 -10
- package/commandCell/CommandCellSwitch.d.ts +0 -7
- package/commandCell/CommandCellSwitch.js +0 -5
- package/index.js +0 -10
- /package/{index.d.ts → src/index.ts} +0 -0
package/jest.config.js
ADDED
package/package.json
CHANGED
@@ -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,151 @@
|
|
1
|
+
import { ComboBox, ComboBoxFilterChangeEvent, ComboBoxPageChangeEvent } from "@progress/kendo-react-dropdowns";
|
2
|
+
import { filterBy } from "@progress/kendo-data-query";
|
3
|
+
import { CSSProperties, useEffect, useRef, useState } from "react";
|
4
|
+
import { Guard } from "@scheels-softdev/frontend-utility-functions";
|
5
|
+
import { ComboBoxChangeEvent } from "@progress/kendo-react-dropdowns";
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Handles the change event of a dropdown.
|
9
|
+
*
|
10
|
+
* @param {ComboBoxChangeEvent} e - The change event object.
|
11
|
+
* @param {(value: T) => void} setFunction - The function to set the value.
|
12
|
+
* @param {T} nullEventValue - The value to set when the event value is null.
|
13
|
+
* @param {string} valueKey - The key to access the value in the event object.
|
14
|
+
*/
|
15
|
+
export function handleDropdownChange<T>(e: ComboBoxChangeEvent, setFunction: (value: T) => void, nullEventValue: T, valueKey?: string) {
|
16
|
+
Guard.Catch.NullEmptyOrWhitespace(e.target.value)
|
17
|
+
? setFunction(nullEventValue)
|
18
|
+
: setFunction(Guard.Catch.NullEmptyOrWhitespace(valueKey) ? e.target.value : e.target.value[valueKey ?? ""]);
|
19
|
+
}
|
20
|
+
|
21
|
+
//TODO add a style property
|
22
|
+
//TODO add metadata documentation
|
23
|
+
// component that renders a dropdown with a search filter
|
24
|
+
/**
|
25
|
+
* JSX Component for displaying items in a virtualized combobox
|
26
|
+
* @template T - The type of the data objects in the dropdown.
|
27
|
+
* @param {object} props - The component props.
|
28
|
+
* @returns {JSX.Element}
|
29
|
+
*/
|
30
|
+
|
31
|
+
type GenericDDProps<T> = {
|
32
|
+
/*1* The data to populate the dropdown options */
|
33
|
+
data: T[];
|
34
|
+
/** The ID of the currently selected item. (optional)*/
|
35
|
+
selectedId?: number;
|
36
|
+
/** The currently selected data object. (optional)*/
|
37
|
+
selectedData?: T;
|
38
|
+
/** Callback function triggered when the selected value changes*/
|
39
|
+
onChange: Function;
|
40
|
+
/** The field names used to extract text values for display */
|
41
|
+
textField: keyof T;
|
42
|
+
/** The separator to use when concatenating multiple text values. (optional)*/
|
43
|
+
separator?: string;
|
44
|
+
/** Determines whether the dropdown is disabled. (optional)*/
|
45
|
+
idField?: keyof T;
|
46
|
+
/** The field name used as the identity key (optional)*/
|
47
|
+
disabled?: boolean;
|
48
|
+
/** The label displayed for the dropdown (optional)*/
|
49
|
+
title?: string;
|
50
|
+
/** The Determines whether the clear button is hidden from the dropdown. (optional)*/
|
51
|
+
hideClearButton?: boolean;
|
52
|
+
/** Custom CSS properties for the component. (optional)*/
|
53
|
+
style?: CSSProperties;
|
54
|
+
isLoading?: boolean;
|
55
|
+
suggest?: boolean;
|
56
|
+
};
|
57
|
+
export function GenericDropdown<T>({
|
58
|
+
data,
|
59
|
+
selectedId,
|
60
|
+
selectedData,
|
61
|
+
onChange,
|
62
|
+
textField,
|
63
|
+
disabled,
|
64
|
+
idField,
|
65
|
+
title,
|
66
|
+
hideClearButton,
|
67
|
+
style,
|
68
|
+
isLoading,
|
69
|
+
suggest,
|
70
|
+
}: GenericDDProps<T>) {
|
71
|
+
//local state
|
72
|
+
const pageSize = 8;
|
73
|
+
if (selectedId !== undefined && selectedData !== undefined) {
|
74
|
+
throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
|
75
|
+
}
|
76
|
+
|
77
|
+
//useState
|
78
|
+
const [selectedObject, setSelectedObject] = useState<T | null>(null);
|
79
|
+
const [state, setState] = useState({
|
80
|
+
skip: 0,
|
81
|
+
total: data.length,
|
82
|
+
subsetData: data.slice(0, pageSize),
|
83
|
+
});
|
84
|
+
|
85
|
+
//trigger functions
|
86
|
+
useEffect(() => {
|
87
|
+
setSelectedObject(
|
88
|
+
selectedId
|
89
|
+
? data.find((item: any) => selectedId === item[idField || "id"]) ?? null
|
90
|
+
: data.find((x) => Guard.Ensure.EqualObjects({ ...x, ...selectedData }, { ...(x ?? {}) })) ?? null
|
91
|
+
);
|
92
|
+
}, [selectedId, selectedData, data]);
|
93
|
+
useEffect(() => {
|
94
|
+
setState({
|
95
|
+
skip: 0,
|
96
|
+
total: data.length,
|
97
|
+
subsetData: data.slice(0, pageSize),
|
98
|
+
});
|
99
|
+
}, [data]);
|
100
|
+
|
101
|
+
//external function variables
|
102
|
+
let filteredData = useRef(data.slice());
|
103
|
+
|
104
|
+
//function creation
|
105
|
+
// function to handle filter changes
|
106
|
+
const onFilterChange = (event: ComboBoxFilterChangeEvent) => {
|
107
|
+
if (event.filter.value?.length) filteredData.current = filterBy(data.slice(), event.filter);
|
108
|
+
else filteredData.current = data;
|
109
|
+
const newData = filteredData.current.slice(0, pageSize);
|
110
|
+
setState({
|
111
|
+
subsetData: newData,
|
112
|
+
skip: 0,
|
113
|
+
total: filteredData.current.length,
|
114
|
+
});
|
115
|
+
};
|
116
|
+
// function to handle page changes for virtualization
|
117
|
+
const pageChange = (event: ComboBoxPageChangeEvent) => {
|
118
|
+
const skip = event.page.skip;
|
119
|
+
const take = event.page.take;
|
120
|
+
const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) : data.slice(skip, skip + take);
|
121
|
+
setState({ ...state, subsetData: newSubsetData, skip: skip });
|
122
|
+
};
|
123
|
+
return (
|
124
|
+
<div data-testid={"dropdown"}>
|
125
|
+
<ComboBox
|
126
|
+
style={style}
|
127
|
+
label={title}
|
128
|
+
disabled={disabled || isLoading}
|
129
|
+
data={state.subsetData} // data to display in the dropdown
|
130
|
+
textField={textField.toString()}
|
131
|
+
virtual={{
|
132
|
+
// enable virtualization for large datasets
|
133
|
+
total: state.total,
|
134
|
+
pageSize: pageSize,
|
135
|
+
skip: state.skip,
|
136
|
+
}}
|
137
|
+
suggest={suggest}
|
138
|
+
onPageChange={pageChange} // handle page changes for virtualization
|
139
|
+
filterable={true} // enable filter
|
140
|
+
onFilterChange={onFilterChange} // handle filter changes
|
141
|
+
popupSettings={{
|
142
|
+
height: "210px",
|
143
|
+
}}
|
144
|
+
onChange={(e) => handleDropdownChange(e, onChange(e), {} as T, idField?.toString())}
|
145
|
+
onBlur={(e) => e.nativeEvent.preventDefault()}
|
146
|
+
clearButton={!hideClearButton}
|
147
|
+
value={selectedObject}
|
148
|
+
/>
|
149
|
+
</div>
|
150
|
+
);
|
151
|
+
}
|
@@ -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
|
+
}
|
package/src/Toolbar.tsx
ADDED
@@ -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(
|
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(
|
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(
|
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(
|
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(
|
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,31 @@
|
|
1
|
+
import { Checkbox } from "@progress/kendo-react-inputs";
|
2
|
+
|
3
|
+
export function CommandCellCheckBox({
|
4
|
+
checked,
|
5
|
+
onCheck,
|
6
|
+
onUncheck,
|
7
|
+
disabled,
|
8
|
+
}: {
|
9
|
+
/** Boolean value indicating whether the checkbox is checked (`true`) or unchecked (`false`). */
|
10
|
+
checked: boolean;
|
11
|
+
/** Callback function to be called when the checkbox is checked. */
|
12
|
+
onCheck: Function;
|
13
|
+
/** Callback function to be called when the checkbox is unchecked. */
|
14
|
+
onUncheck: Function;
|
15
|
+
/** Boolean value indicating whether the checkbox is disabled. */
|
16
|
+
disabled?: boolean;
|
17
|
+
}) {
|
18
|
+
const functionToRun = () => {
|
19
|
+
if (checked) {
|
20
|
+
onUncheck();
|
21
|
+
} else {
|
22
|
+
onCheck();
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
return (
|
27
|
+
<td className="justify-content-center" data-testid="checkbox">
|
28
|
+
<Checkbox checked={checked} onChange={functionToRun} disabled={disabled} />
|
29
|
+
</td>
|
30
|
+
);
|
31
|
+
}
|
package/{commandCell/CommandCellDDWithoutId.d.ts → src/commandCell/CommandCellDDWithoutId.tsx}
RENAMED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { ComboBoxChangeEvent } from "@progress/kendo-react-dropdowns";
|
2
|
-
|
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
|
-
})
|
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
|
-
|
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
|
-
})
|
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
package/FilterCellDropdown.d.ts
DELETED
@@ -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 {};
|
package/FilterCellDropdown.js
DELETED
@@ -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
|
-
}
|
package/GenericDropdown.d.ts
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
import { CSSProperties } from "react";
|
2
|
-
import { ComboBoxChangeEvent } from "@progress/kendo-react-dropdowns";
|
3
|
-
/**
|
4
|
-
* Handles the change event of a dropdown.
|
5
|
-
*
|
6
|
-
* @param {ComboBoxChangeEvent} e - The change event object.
|
7
|
-
* @param {(value: T) => void} setFunction - The function to set the value.
|
8
|
-
* @param {T} nullEventValue - The value to set when the event value is null.
|
9
|
-
* @param {string} valueKey - The key to access the value in the event object.
|
10
|
-
*/
|
11
|
-
export declare function handleDropdownChange<T>(e: ComboBoxChangeEvent, setFunction: (value: T) => void, nullEventValue: T, valueKey?: string): void;
|
12
|
-
/**
|
13
|
-
* JSX Component for displaying items in a virtualized combobox
|
14
|
-
* @template T - The type of the data objects in the dropdown.
|
15
|
-
* @param {object} props - The component props.
|
16
|
-
* @returns {JSX.Element}
|
17
|
-
*/
|
18
|
-
type GenericDDProps<T> = {
|
19
|
-
data: T[];
|
20
|
-
/** The ID of the currently selected item. (optional)*/
|
21
|
-
selectedId?: number;
|
22
|
-
/** The currently selected data object. (optional)*/
|
23
|
-
selectedData?: T;
|
24
|
-
/** Callback function triggered when the selected value changes*/
|
25
|
-
onChange: Function;
|
26
|
-
/** The field names used to extract text values for display */
|
27
|
-
textField: keyof T;
|
28
|
-
/** The separator to use when concatenating multiple text values. (optional)*/
|
29
|
-
separator?: string;
|
30
|
-
/** Determines whether the dropdown is disabled. (optional)*/
|
31
|
-
idField?: keyof T;
|
32
|
-
/** The field name used as the identity key (optional)*/
|
33
|
-
disabled?: boolean;
|
34
|
-
/** The label displayed for the dropdown (optional)*/
|
35
|
-
title?: string;
|
36
|
-
/** The Determines whether the clear button is hidden from the dropdown. (optional)*/
|
37
|
-
hideClearButton?: boolean;
|
38
|
-
/** Custom CSS properties for the component. (optional)*/
|
39
|
-
style?: CSSProperties;
|
40
|
-
isLoading?: boolean;
|
41
|
-
suggest?: boolean;
|
42
|
-
};
|
43
|
-
export declare function GenericDropdown<T>({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, suggest, }: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
|
44
|
-
export {};
|
package/GenericDropdown.js
DELETED
@@ -1,82 +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 { Guard } from "@scheels-softdev/frontend-utility-functions";
|
6
|
-
/**
|
7
|
-
* Handles the change event of a dropdown.
|
8
|
-
*
|
9
|
-
* @param {ComboBoxChangeEvent} e - The change event object.
|
10
|
-
* @param {(value: T) => void} setFunction - The function to set the value.
|
11
|
-
* @param {T} nullEventValue - The value to set when the event value is null.
|
12
|
-
* @param {string} valueKey - The key to access the value in the event object.
|
13
|
-
*/
|
14
|
-
export function handleDropdownChange(e, setFunction, nullEventValue, valueKey) {
|
15
|
-
Guard.Catch.NullEmptyOrWhitespace(e.target.value)
|
16
|
-
? setFunction(nullEventValue)
|
17
|
-
: setFunction(Guard.Catch.NullEmptyOrWhitespace(valueKey) ? e.target.value : e.target.value[valueKey !== null && valueKey !== void 0 ? valueKey : ""]);
|
18
|
-
}
|
19
|
-
export function GenericDropdown({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, suggest, }) {
|
20
|
-
//local state
|
21
|
-
const pageSize = 8;
|
22
|
-
if (selectedId !== undefined && selectedData !== undefined) {
|
23
|
-
throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
|
24
|
-
}
|
25
|
-
//useState
|
26
|
-
const [selectedObject, setSelectedObject] = useState(undefined);
|
27
|
-
const [state, setState] = useState({
|
28
|
-
skip: 0,
|
29
|
-
total: data.length,
|
30
|
-
subsetData: data.slice(0, pageSize),
|
31
|
-
});
|
32
|
-
//trigger functions
|
33
|
-
useEffect(() => {
|
34
|
-
var _a, _b;
|
35
|
-
if (!selectedId && !selectedData)
|
36
|
-
setSelectedObject(undefined);
|
37
|
-
else {
|
38
|
-
setSelectedObject(selectedId
|
39
|
-
? (_a = data.find((item) => selectedId === item[idField || "id"])) !== null && _a !== void 0 ? _a : undefined
|
40
|
-
: (_b = data.find((x) => Guard.Ensure.EqualObjects(Object.assign(Object.assign({}, x), selectedData), Object.assign({}, (x !== null && x !== void 0 ? x : {}))))) !== null && _b !== void 0 ? _b : undefined);
|
41
|
-
}
|
42
|
-
}, [selectedId, selectedData, data]);
|
43
|
-
useEffect(() => {
|
44
|
-
setState({
|
45
|
-
skip: 0,
|
46
|
-
total: data.length,
|
47
|
-
subsetData: data.slice(0, pageSize),
|
48
|
-
});
|
49
|
-
}, [data]);
|
50
|
-
//external function variables
|
51
|
-
let filteredData = useRef(data.slice());
|
52
|
-
//function creation
|
53
|
-
// function to handle filter changes
|
54
|
-
const onFilterChange = (event) => {
|
55
|
-
var _a;
|
56
|
-
if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
|
57
|
-
filteredData.current = filterBy(data.slice(), event.filter);
|
58
|
-
else
|
59
|
-
filteredData.current = data;
|
60
|
-
const newData = filteredData.current.slice(0, pageSize);
|
61
|
-
setState({
|
62
|
-
subsetData: newData,
|
63
|
-
skip: 0,
|
64
|
-
total: filteredData.current.length,
|
65
|
-
});
|
66
|
-
};
|
67
|
-
// function to handle page changes for virtualization
|
68
|
-
const pageChange = (event) => {
|
69
|
-
const skip = event.page.skip;
|
70
|
-
const take = event.page.take;
|
71
|
-
const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) : data.slice(skip, skip + take);
|
72
|
-
setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
|
73
|
-
};
|
74
|
-
return (_jsx("div", Object.assign({ "data-testid": "dropdown" }, { children: _jsx(ComboBox, { style: style, label: title, disabled: disabled || isLoading, data: state.subsetData, textField: textField.toString(), virtual: {
|
75
|
-
// enable virtualization for large datasets
|
76
|
-
total: state.total,
|
77
|
-
pageSize: pageSize,
|
78
|
-
skip: state.skip,
|
79
|
-
}, suggest: suggest, onPageChange: pageChange, filterable: true, onFilterChange: onFilterChange, popupSettings: {
|
80
|
-
height: "210px",
|
81
|
-
}, onChange: (e) => handleDropdownChange(e, onChange(e), {}, idField === null || idField === void 0 ? void 0 : idField.toString()), onBlur: (e) => e.nativeEvent.preventDefault(), clearButton: !hideClearButton, value: selectedObject !== null && selectedObject !== void 0 ? selectedObject : undefined }) })));
|
82
|
-
}
|
package/MultiSelectDropdown.d.ts
DELETED
@@ -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;
|
package/MultiSelectDropdown.js
DELETED
@@ -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
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,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: Function;
|
6
|
-
/** Callback function to be called when the checkbox is unchecked. */
|
7
|
-
onUncheck: Function;
|
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 { 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,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
|