@scheels-softdev/kendoreact-generics 2.6.0 → 2.6.2
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/FilterCellDropdown.d.ts +1 -1
- package/FilterCellDropdown.js +1 -1
- package/GenericDropdown.d.ts +2 -2
- package/GenericDropdown.js +14 -31
- package/MultiSelectDropdown.d.ts +3 -5
- package/MultiSelectDropdown.js +9 -19
- package/README.md +39 -206
- package/_index.test.d.ts +1 -0
- package/_index.test.js +101 -0
- package/commandCell/CommandCellDDWithoutId.d.ts +1 -1
- package/commandCell/CommandCellDDWithoutId.js +3 -2
- package/commandCell/CommandCellDropdown.d.ts +1 -1
- package/commandCell/CommandCellDropdown.js +3 -4
- package/package.json +7 -2
package/FilterCellDropdown.d.ts
CHANGED
@@ -3,7 +3,7 @@ interface DropdownFilterCellProps<T> extends GridFilterCellProps {
|
|
3
3
|
/** The data to populate the dropdown options */
|
4
4
|
data: T[];
|
5
5
|
/** The field names used to extract text values for display */
|
6
|
-
|
6
|
+
textField: keyof T;
|
7
7
|
/** The separator to use when concatenating multiple text values */
|
8
8
|
separator?: string;
|
9
9
|
}
|
package/FilterCellDropdown.js
CHANGED
@@ -28,5 +28,5 @@ export function FilterCellDropdown(props) {
|
|
28
28
|
});
|
29
29
|
};
|
30
30
|
// Render a div containing a GenericDropdownWithSearch component and a Clear button
|
31
|
-
return (_jsxs("div", Object.assign({ className: "k-filtercell", "data-testid": "dropdownFilter" }, { children: [_jsx(GenericDropdown, { data: props.data, onChange: onChange, selectedId: props.value,
|
31
|
+
return (_jsxs("div", Object.assign({ className: "k-filtercell", "data-testid": "dropdownFilter" }, { children: [_jsx(GenericDropdown, { data: props.data, onChange: onChange, selectedId: props.value, textField: props.textField, separator: props.separator }), _jsx(Button, { title: "Clear", disabled: !hasValue(props.value), onClick: onClearButtonClick, icon: "filter-clear" })] })));
|
32
32
|
}
|
package/GenericDropdown.d.ts
CHANGED
@@ -14,7 +14,7 @@ type GenericDDProps<T> = {
|
|
14
14
|
/** Callback function triggered when the selected value changes*/
|
15
15
|
onChange: Function;
|
16
16
|
/** The field names used to extract text values for display */
|
17
|
-
|
17
|
+
textField: keyof T;
|
18
18
|
/** The separator to use when concatenating multiple text values. (optional)*/
|
19
19
|
separator?: string;
|
20
20
|
/** Determines whether the dropdown is disabled. (optional)*/
|
@@ -29,5 +29,5 @@ type GenericDDProps<T> = {
|
|
29
29
|
style?: CSSProperties;
|
30
30
|
isLoading?: boolean;
|
31
31
|
};
|
32
|
-
export declare function GenericDropdown<T>({ data, selectedId, selectedData, onChange,
|
32
|
+
export declare function GenericDropdown<T>({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, }: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
|
33
33
|
export {};
|
package/GenericDropdown.js
CHANGED
@@ -1,31 +1,29 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { ComboBox } from "@progress/kendo-react-dropdowns";
|
3
|
-
import { filterBy } from "@progress/kendo-data-query";
|
3
|
+
import { filterBy, process } from "@progress/kendo-data-query";
|
4
4
|
import { useEffect, useRef, useState } from "react";
|
5
|
-
import { getTextValue } from "./Utility";
|
6
5
|
import { Skeleton } from "@progress/kendo-react-indicators";
|
7
|
-
export function GenericDropdown({ data, selectedId, selectedData, onChange,
|
6
|
+
export function GenericDropdown({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, }) {
|
8
7
|
if (selectedId !== undefined && selectedData !== undefined) {
|
9
8
|
throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
|
10
9
|
}
|
11
10
|
//local state
|
12
11
|
const pageSize = 8;
|
13
|
-
const [dataList, setDataList] = useState([]);
|
14
12
|
const [state, setState] = useState({
|
15
13
|
skip: 0,
|
16
|
-
total:
|
17
|
-
subsetData:
|
14
|
+
total: data.length,
|
15
|
+
subsetData: data.slice(0, pageSize),
|
18
16
|
});
|
19
17
|
//external function variables
|
20
|
-
let filteredData = useRef(
|
18
|
+
let filteredData = useRef(data.slice());
|
21
19
|
//function creation
|
22
20
|
// function to handle filter changes
|
23
21
|
const onFilterChange = (event) => {
|
24
22
|
var _a;
|
25
23
|
if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
|
26
|
-
filteredData.current = filterBy(
|
24
|
+
filteredData.current = filterBy(data.slice(), event.filter);
|
27
25
|
else
|
28
|
-
filteredData.current =
|
26
|
+
filteredData.current = data;
|
29
27
|
const newData = filteredData.current.slice(0, pageSize);
|
30
28
|
setState({
|
31
29
|
subsetData: newData,
|
@@ -38,36 +36,21 @@ export function GenericDropdown({ data, selectedId, selectedData, onChange, text
|
|
38
36
|
console.log("page change data: ", event.page, filteredData.current);
|
39
37
|
const skip = event.page.skip;
|
40
38
|
const take = event.page.take;
|
41
|
-
const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) :
|
39
|
+
const newSubsetData = filteredData.current.length ? filteredData.current.slice(skip, skip + take) : data.slice(skip, skip + take);
|
42
40
|
setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
|
43
41
|
};
|
44
|
-
//change event listeners
|
45
|
-
useEffect(() => {
|
46
|
-
dataList;
|
47
|
-
});
|
48
|
-
useEffect(() => {
|
49
|
-
if (data.length) {
|
50
|
-
setDataList(data.map((x) => {
|
51
|
-
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
52
|
-
}));
|
53
|
-
setState(Object.assign(Object.assign({}, state), { total: data.length, subsetData: data.map((x) => {
|
54
|
-
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
55
|
-
}) }));
|
56
|
-
}
|
57
|
-
}, [data, textFields, separator]);
|
58
42
|
const findByIndex = (id, idKey) => {
|
59
|
-
|
60
|
-
const item = dataList.find((item) => id === item[idKey || "id"]);
|
61
|
-
console.log(item);
|
43
|
+
const item = data.find((item) => id === item[idKey || "id"]);
|
62
44
|
return item;
|
63
45
|
};
|
64
46
|
const findByValue = (item) => {
|
65
|
-
|
66
|
-
const returnVal = dataList.find((x) => JSON.stringify(Object.assign(Object.assign({}, x), selectedData)) === JSON.stringify(Object.assign({}, x)));
|
67
|
-
console.log(returnVal);
|
47
|
+
const returnVal = data.find((x) => JSON.stringify(Object.assign(Object.assign({}, x), selectedData)) === JSON.stringify(Object.assign({}, x)));
|
68
48
|
return returnVal;
|
69
49
|
};
|
70
|
-
|
50
|
+
useEffect(() => {
|
51
|
+
setState((current) => (Object.assign(Object.assign({}, current), { subsetData: process(data, current).data })));
|
52
|
+
}, [data]);
|
53
|
+
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: {
|
71
54
|
// enable virtualization for large datasets
|
72
55
|
total: state.total,
|
73
56
|
pageSize: pageSize,
|
package/MultiSelectDropdown.d.ts
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
export declare function MultiSelectDropdown<T>({ data, selectedData,
|
1
|
+
export declare function MultiSelectDropdown<T>({ data, selectedData, textField, onSelect, title, limit, }: {
|
2
2
|
/** The data array for the dropdown options. */
|
3
3
|
data: T[];
|
4
4
|
/** The array of selected data items. */
|
5
5
|
selectedData: T[];
|
6
6
|
/** The field names to use for text values in the dropdown. */
|
7
|
-
|
7
|
+
textField: keyof T;
|
8
8
|
/** The function to call when an item is selected or deselected. */
|
9
|
-
|
9
|
+
onSelect: Function;
|
10
10
|
/** The optional title of the dropdown. */
|
11
11
|
title?: string;
|
12
|
-
/** The optional separator to use for concatenating text values. */
|
13
|
-
separator?: string;
|
14
12
|
/** The optional limit of the maximum number of selected items. */
|
15
13
|
limit?: number;
|
16
14
|
}): import("react/jsx-runtime").JSX.Element;
|
package/MultiSelectDropdown.js
CHANGED
@@ -1,29 +1,25 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import {
|
2
|
+
import { useRef, useState } from "react";
|
3
3
|
import { filterBy } from "@progress/kendo-data-query";
|
4
4
|
import { MultiSelect } from "@progress/kendo-react-dropdowns";
|
5
|
-
|
6
|
-
export function MultiSelectDropdown({ data, selectedData, textFields, selectEvent, title, separator, limit, }) {
|
5
|
+
export function MultiSelectDropdown({ data, selectedData, textField, onSelect, title, limit, }) {
|
7
6
|
//local state
|
8
7
|
const pageSize = 8;
|
9
|
-
const [dataList, setDataList] = useState(data.map((x) => {
|
10
|
-
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
11
|
-
}));
|
12
8
|
const [state, setState] = useState({
|
13
9
|
skip: 0,
|
14
|
-
total:
|
15
|
-
subsetData:
|
10
|
+
total: data.length,
|
11
|
+
subsetData: data.slice(0, pageSize),
|
16
12
|
});
|
17
13
|
//external function variables
|
18
|
-
const filteredData = useRef(
|
14
|
+
const filteredData = useRef(data.slice());
|
19
15
|
//function creation
|
20
16
|
// function to handle filter changes
|
21
17
|
const onFilterChange = (event) => {
|
22
18
|
var _a;
|
23
19
|
if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
|
24
|
-
filteredData.current = filterBy(
|
20
|
+
filteredData.current = filterBy(data.slice(), event.filter);
|
25
21
|
else
|
26
|
-
filteredData.current =
|
22
|
+
filteredData.current = data;
|
27
23
|
const newData = filteredData.current.slice(0, pageSize);
|
28
24
|
setState({
|
29
25
|
subsetData: newData,
|
@@ -38,17 +34,11 @@ export function MultiSelectDropdown({ data, selectedData, textFields, selectEven
|
|
38
34
|
const newSubsetData = filteredData.current.slice(skip, skip + take);
|
39
35
|
setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
|
40
36
|
};
|
41
|
-
|
42
|
-
useEffect(() => {
|
43
|
-
setDataList(data.map((x) => {
|
44
|
-
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
45
|
-
}));
|
46
|
-
}, [data, textFields, separator]);
|
47
|
-
return (_jsx("div", Object.assign({ "data-testid": "multiselect", style: { width: "100%" } }, { children: _jsx(MultiSelect, { label: title, data: state.subsetData, textField: "textValue", style: { width: "100%" }, virtual: {
|
37
|
+
return (_jsx("div", Object.assign({ "data-testid": "multiselect", style: { width: "100%" } }, { children: _jsx(MultiSelect, { label: title, data: state.subsetData, textField: textField.toString(), style: { width: "100%" }, virtual: {
|
48
38
|
total: state.total,
|
49
39
|
pageSize: pageSize,
|
50
40
|
skip: state.skip,
|
51
41
|
}, onPageChange: pageChange, filterable: true, onFilterChange: onFilterChange, popupSettings: {
|
52
42
|
height: "210px",
|
53
|
-
}, onChange: (e) =>
|
43
|
+
}, onChange: (e) => onSelect(limit && e.value.length ? e.value.slice(0, limit) : e.value), autoClose: false, value: selectedData }) })));
|
54
44
|
}
|
package/README.md
CHANGED
@@ -36,56 +36,59 @@ Note: This package has only been tested with typescript. if you're using javascr
|
|
36
36
|
selectedId: number;
|
37
37
|
selectedData?: T;
|
38
38
|
onChange: event: (ComboBoxChangeEvent) => void;
|
39
|
-
|
40
|
-
separator?: string;
|
41
|
-
idField?: keyof T;
|
39
|
+
textField: keyof T;
|
42
40
|
disabled?: boolean;
|
41
|
+
idField?: keyof T;
|
43
42
|
title?: string;
|
44
|
-
|
43
|
+
hideClearButton?: boolean;
|
44
|
+
style?: React.CSSProperties;
|
45
|
+
isLoading?: boolean;
|
45
46
|
|
46
47
|
#### data
|
47
48
|
|
48
49
|
- Array of T. the Definition of what T is matters for the "textFields" prop
|
49
50
|
|
50
|
-
####
|
51
|
-
|
52
|
-
- Event passed is a ComboBoxChangeEvent (from kendo-react-dropdowns)
|
53
|
-
|
54
|
-
#### selectedId
|
51
|
+
#### selectedId OR selectedData
|
55
52
|
|
56
|
-
-
|
53
|
+
- selectedId is the unique identifier of the item selected. By default the dropdown will assume your item has an "id" property. if it doesn't have an Id but has a unique identifier, see optional keys (idField)
|
54
|
+
- selectedData is a reference to the full selected object.
|
55
|
+
- Only one of these 2 is needed. it will just use selectedId if both are provided
|
57
56
|
|
58
|
-
####
|
57
|
+
#### onChange
|
59
58
|
|
60
|
-
-
|
59
|
+
- Event passed is a ComboBoxChangeEvent (from kendo-react-dropdowns)
|
61
60
|
|
62
|
-
####
|
61
|
+
#### textField
|
63
62
|
|
64
|
-
-
|
65
|
-
- For example, if my dropdown is fed a list of employee objects with a firstName, lastName, and id key, I would pass
|
63
|
+
- The field of each object to actually display
|
64
|
+
- For example, if my dropdown is fed a list of employee objects with a firstName, lastName, and id key, I would pass "firstName" to see "John" or "lastName" to see "Doe".
|
65
|
+
If you need to include multiple fields of the object, see https://www.npmjs.com/package/@scheels-softdev/frontend-utility-functions?activeTab=readme
|
66
66
|
|
67
|
-
####
|
67
|
+
#### disabled (optional)
|
68
68
|
|
69
|
-
-
|
70
|
-
- For example, if we want our employee's names separated by a comma, we would pass ", " here
|
69
|
+
- If you want to conditionally disable the dropdown you can do that here
|
71
70
|
|
72
71
|
#### idField (optional)
|
73
72
|
|
74
73
|
- IdField is a keyof T, much like textFields. while textFields determines what's displayed in the dropdown, idField overrides what field of each object the dropdown looks at to compare against the selectedId prop
|
75
74
|
- For example, if our employee's id field is employeeId instead of just id, we would pass "employeeId" here
|
76
75
|
|
77
|
-
#### disabled (optional)
|
78
|
-
|
79
|
-
- If you want to conditionally disable the dropdown you can do that here
|
80
|
-
|
81
76
|
#### title (optional)
|
82
77
|
|
83
78
|
- The label that appears in your multiselect when there aren't any options selected, or just above the multiselect when there are
|
84
79
|
- For example, if we want to use it to send a letter to an employee, we would pass "Selected Employee" here
|
85
80
|
|
86
|
-
####
|
81
|
+
#### hideClearButton (optional)
|
82
|
+
|
83
|
+
- A boolean indicating whether the clear button should be hidden. by default it will be shown
|
84
|
+
|
85
|
+
#### style (optional)
|
87
86
|
|
88
|
-
-
|
87
|
+
- An override to the default styling that ships with kendo
|
88
|
+
|
89
|
+
#### isLoading (optional)
|
90
|
+
|
91
|
+
- A boolean indicating whether your data is still loading or not
|
89
92
|
|
90
93
|
---
|
91
94
|
|
@@ -95,10 +98,9 @@ Note: This package has only been tested with typescript. if you're using javascr
|
|
95
98
|
|
96
99
|
data: T[];
|
97
100
|
selectedData: T[];
|
98
|
-
|
99
|
-
|
101
|
+
textField: keyof T;
|
102
|
+
onSelect: Function;
|
100
103
|
title?: string;
|
101
|
-
separator?: string;
|
102
104
|
limit?: number;
|
103
105
|
|
104
106
|
#### data
|
@@ -109,12 +111,13 @@ Note: This package has only been tested with typescript. if you're using javascr
|
|
109
111
|
|
110
112
|
- The id of the item selected. By default the dropdown will assume your item has an "id" property. if it doesn't, see optional parameters
|
111
113
|
|
112
|
-
####
|
114
|
+
#### textField
|
113
115
|
|
114
|
-
-
|
115
|
-
- For example, if my dropdown is fed a list of employee objects with a firstName, lastName, and id key, I would pass
|
116
|
+
- The field of each object to actually display
|
117
|
+
- For example, if my dropdown is fed a list of employee objects with a firstName, lastName, and id key, I would pass "firstName" to see "John" or "lastName" to see "Doe".
|
118
|
+
If you need to include multiple fields of the object, see https://www.npmjs.com/package/@scheels-softdev/frontend-utility-functions?activeTab=readme
|
116
119
|
|
117
|
-
####
|
120
|
+
#### onSelect
|
118
121
|
|
119
122
|
- "Event" you're given should just be your new array of selected Items
|
120
123
|
|
@@ -123,11 +126,6 @@ Note: This package has only been tested with typescript. if you're using javascr
|
|
123
126
|
- The label that appears in your multiselect when there aren't any options selected, or just above the multiselect when there are
|
124
127
|
- For example, if we want to use it to send work anniversary letters to multiple employees, we would pass "Selected Employees" here
|
125
128
|
|
126
|
-
#### separator (optional)
|
127
|
-
|
128
|
-
- This defines what your text fields are separated by. by default, it is assumed you only want a space between them. Use this prop if you want to change this
|
129
|
-
- For example, if we want our employee's names separated by a comma, we would pass ", " here
|
130
|
-
|
131
129
|
#### limit (optional)
|
132
130
|
|
133
131
|
- The upper limit of how many items the user can select at once.
|
@@ -141,7 +139,7 @@ Note: This package has only been tested with typescript. if you're using javascr
|
|
141
139
|
|
142
140
|
{...GridFilterCellProps} (from @progress/kendo-react-grid)
|
143
141
|
data: T[];
|
144
|
-
|
142
|
+
textField: keyof T;
|
145
143
|
separator?: string;
|
146
144
|
|
147
145
|
#### {...FilterCellProps}
|
@@ -152,10 +150,11 @@ Note: This package has only been tested with typescript. if you're using javascr
|
|
152
150
|
|
153
151
|
- Array of T. What you want to display in the dropdown. the Definition of what T is matters for the "textFields" prop
|
154
152
|
|
155
|
-
####
|
153
|
+
#### textField
|
156
154
|
|
157
|
-
-
|
158
|
-
- For example, if my dropdown is fed a list of employee
|
155
|
+
- The field of each object to actually display
|
156
|
+
- For example, if my dropdown is fed a list of employee objects with a firstName, lastName, and id key, I would pass "firstName" to see "John" or "lastName" to see "Doe".
|
157
|
+
If you need to include multiple fields of the object, see https://www.npmjs.com/package/@scheels-softdev/frontend-utility-functions?activeTab=readme
|
159
158
|
|
160
159
|
#### separator (optional)
|
161
160
|
|
@@ -164,172 +163,6 @@ Note: This package has only been tested with typescript. if you're using javascr
|
|
164
163
|
|
165
164
|
---
|
166
165
|
|
167
|
-
## Command Cell Dropdown
|
168
|
-
|
169
|
-
### Props
|
170
|
-
|
171
|
-
data: T[];
|
172
|
-
selectedId: number;
|
173
|
-
textFields: (keyof T)[];
|
174
|
-
onChange: (e: ComboBoxChangeEvent) => void;
|
175
|
-
separator?: string;
|
176
|
-
checkEditField?: boolean;
|
177
|
-
isEditing?: boolean;
|
178
|
-
|
179
|
-
#### data
|
180
|
-
|
181
|
-
- Array of T. What you want to display in the dropdown. the Definition of what T is matters for the "textFields" prop
|
182
|
-
|
183
|
-
#### selectedId
|
184
|
-
|
185
|
-
- all of the default props that are passed from kendo grid when trying to override the filter cell
|
186
|
-
|
187
|
-
#### textFields
|
188
|
-
|
189
|
-
- This is defined as (keyof T)[].
|
190
|
-
- For example, if my dropdown is fed a list of employee Statuses, I could feed it a "StatusName" field (assuming my Status objects have that key) and it could display something like "Active", "Terminated", or "On Leave"
|
191
|
-
|
192
|
-
#### onChange
|
193
|
-
|
194
|
-
- Pass what you want the event to do. the event you will be passed is a ComboBoxChangeEvent. The relevant information you're likely to need is stored in e.target.value
|
195
|
-
|
196
|
-
#### separator (optional)
|
197
|
-
|
198
|
-
- This defines what your text fields are separated by. by default, it is assumed you only want a space between them. Use this prop if you want to change this
|
199
|
-
- For example, if some of our associates only know the status IDs for Active, Terminated, or On Leave and we want to display them side by side, we might want to add a "dash" seporator. to do this we would pass " - " here
|
200
|
-
|
201
|
-
#### checkEditField (optional)
|
202
|
-
|
203
|
-
- This is for optional conditional rendering. If this is true, it will only render a dropdown if isEditing is true. if this is false, it will always render a dropdown
|
204
|
-
|
205
|
-
#### isEditing (optional)
|
206
|
-
|
207
|
-
- This goes along with the checkEditField prop. If both are true, it will render a dropdown. Otherwise, only text containing the selected value will be displayed
|
208
|
-
|
209
|
-
---
|
210
|
-
|
211
|
-
## Command Cell Date
|
212
|
-
|
213
|
-
### Props
|
214
|
-
|
215
|
-
dataItem: T;
|
216
|
-
chgFn: (e: GridChangeEvent) => void;
|
217
|
-
field: keyof T;
|
218
|
-
|
219
|
-
#### dataItem
|
220
|
-
|
221
|
-
- an object containing a date. if used per Telerik(Kendo)'s documentation, the value will come from props.dataItem
|
222
|
-
|
223
|
-
#### field
|
224
|
-
|
225
|
-
- which key in your dataItem object is a date?
|
226
|
-
|
227
|
-
#### chgFn
|
228
|
-
|
229
|
-
- A handler function for a gridchangeevent.
|
230
|
-
|
231
|
-
---
|
232
|
-
|
233
|
-
## Command Cell Checkbox
|
234
|
-
|
235
|
-
### Props
|
236
|
-
|
237
|
-
checked: boolean;
|
238
|
-
onCheck: Function;
|
239
|
-
onUncheck: Function;
|
240
|
-
|
241
|
-
#### checked
|
242
|
-
|
243
|
-
- boolean value for whether or not the checkbox should display a checkmark
|
244
|
-
|
245
|
-
#### onCheck
|
246
|
-
|
247
|
-
- what function do you want to run when checking the checkbox. I highly recommend a function that actually changes your value passed into `checked` to true.
|
248
|
-
|
249
|
-
#### onUncheck
|
250
|
-
|
251
|
-
- what function do you want to run when unchecking the checkbox. I highly recommend a function that actually changes your value passed into `checked` to false.
|
252
|
-
|
253
|
-
---
|
254
|
-
|
255
|
-
## Command Cell Switch
|
256
|
-
|
257
|
-
### Props
|
258
|
-
|
259
|
-
props: GridCellProps
|
260
|
-
changeFunction: Function
|
261
|
-
|
262
|
-
### props
|
263
|
-
|
264
|
-
- this component will assume you have an isEditing key in your object, otherwise it will just generate a string (in the current version)
|
265
|
-
|
266
|
-
### changeFunction
|
267
|
-
|
268
|
-
- what function do you want to run on change? I highly recommend a function that actually toggles the value of the field you're trying to change.
|
269
|
-
|
270
|
-
---
|
271
|
-
|
272
|
-
## CommandCellPrice
|
273
|
-
|
274
|
-
### Props
|
275
|
-
|
276
|
-
cost: number
|
277
|
-
|
278
|
-
### cost
|
279
|
-
|
280
|
-
- the number you want formatted to USD. support for other currencies or for thousandths will come eventually with optional props, but those don't exist yet
|
281
|
-
|
282
|
-
---
|
283
|
-
|
284
|
-
## Command Cell Dropdown Without ID
|
285
|
-
|
286
|
-
### Props
|
287
|
-
|
288
|
-
data: T[]
|
289
|
-
selectedData: T
|
290
|
-
textFields: (keyof T)[]
|
291
|
-
onChange: (e: ComboBoxChangeEvent) => void
|
292
|
-
separator?: string
|
293
|
-
checkEditField?: boolean
|
294
|
-
isEditing?: boolean
|
295
|
-
showClearButton?: boolean
|
296
|
-
|
297
|
-
#### data
|
298
|
-
|
299
|
-
- Array of T. What you want to display in the dropdown. The definition of what T is matters for the "textFields" prop.
|
300
|
-
|
301
|
-
#### selectedData
|
302
|
-
|
303
|
-
- The item selected. The dropdown will compare this object to the list of objects you gave it for the data prop to try to find the right index.
|
304
|
-
|
305
|
-
#### textFields
|
306
|
-
|
307
|
-
- This is defined as (keyof T)[].
|
308
|
-
- For example, if my dropdown is fed a list of employee objects with a `firstName`, `lastName`, and `id` key, I would pass `["firstName","lastName"]` to see "John Williams", or `["firstName","lastName","id"]` to see "John Doe 19382032141".
|
309
|
-
|
310
|
-
#### onChange
|
311
|
-
|
312
|
-
- Pass what you want the event to do. The event you will be passed is a ComboBoxChangeEvent. The relevant information you're likely to need is stored in `e.target.value`.
|
313
|
-
|
314
|
-
#### separator (optional)
|
315
|
-
|
316
|
-
- This defines what your text fields are separated by. By default, it is assumed you only want a space between them. Use this prop if you want to change this.
|
317
|
-
- For example, if some of our associates only know the status IDs for Active, Terminated, or On Leave and we want to display them side by side, we might want to add a "dash" separator. To do this, we would pass " - " here.
|
318
|
-
|
319
|
-
#### checkEditField (optional)
|
320
|
-
|
321
|
-
- This is for optional conditional rendering. If this is true, it will only render a dropdown if `isEditing` is true. If this is false, it will always render a dropdown.
|
322
|
-
|
323
|
-
#### isEditing (optional)
|
324
|
-
|
325
|
-
- This goes along with the `checkEditField` prop. If both are true, it will render a dropdown. Otherwise, only text containing the selected value will be displayed.
|
326
|
-
|
327
|
-
#### showClearButton (optional)
|
328
|
-
|
329
|
-
- A boolean indicating whether the clear button should show up or not.
|
330
|
-
|
331
|
-
---
|
332
|
-
|
333
166
|
## ToolbarButton
|
334
167
|
|
335
168
|
### Props
|
package/_index.test.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/_index.test.js
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { GenericDropdown } from "./GenericDropdown";
|
3
|
+
import { fireEvent, render } from "@testing-library/react";
|
4
|
+
describe("GenericDropdown", () => {
|
5
|
+
const data = [];
|
6
|
+
for (let i = 1; i < 20; i++) {
|
7
|
+
data.push({ id: i, name: `Option ${i}` });
|
8
|
+
}
|
9
|
+
test("renders virtualized ordering by index when passed selectedData", () => {
|
10
|
+
// Set initial selectedData to the second item in the data array
|
11
|
+
let selectedData = data[1];
|
12
|
+
// 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 }));
|
14
|
+
// Get the input element by its role of "combobox"
|
15
|
+
const input = result.getByRole("combobox");
|
16
|
+
expect(input.getAttribute("value")).toBe("Option 2");
|
17
|
+
// Simulate a change event on the input element by setting its target value to "O"
|
18
|
+
fireEvent.change(input, { target: { value: "O" } });
|
19
|
+
// Simulate a key down event on the input element with the key value of "ArrowDown"
|
20
|
+
fireEvent.keyDown(input, { key: "ArrowDown" });
|
21
|
+
// Query the rendered result for elements with the text "Option 1", "Option 2", and "Option 3"
|
22
|
+
let item1 = result.queryByText("Option 1");
|
23
|
+
let item2 = result.queryByText("Option 2");
|
24
|
+
let item3 = result.queryByText("Option 3");
|
25
|
+
// Ensure that item1, item2, and item3 are not undefined (i.e., they are rendered)
|
26
|
+
expect(item1).not.toBeUndefined();
|
27
|
+
expect(item2).not.toBeUndefined();
|
28
|
+
expect(item3).not.toBeUndefined();
|
29
|
+
// Ensure that there are no elements with the text "Option 9" (i.e., it is not rendered)
|
30
|
+
expect(result.queryAllByText("Option 9")).toHaveLength(0);
|
31
|
+
});
|
32
|
+
test("renders virtualized ordering by index when passed selectedId", () => {
|
33
|
+
// Set initial selectedData to the second item in the data array
|
34
|
+
let selectedId = 2;
|
35
|
+
// Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
|
36
|
+
let result = render(_jsx(GenericDropdown, { data: data, onChange: () => { }, textField: "name", selectedId: selectedId }));
|
37
|
+
// Get the input element by its role of "combobox"
|
38
|
+
const input = result.getByRole("combobox");
|
39
|
+
expect(input.getAttribute("value")).toBe("Option 2");
|
40
|
+
// Simulate a change event on the input element by setting its target value to "O"
|
41
|
+
fireEvent.change(input, { target: { value: "O" } });
|
42
|
+
// Simulate a key down event on the input element with the key value of "ArrowDown"
|
43
|
+
fireEvent.keyDown(input, { key: "ArrowDown" });
|
44
|
+
// Query the rendered result for elements with the text "Option 1", "Option 2", and "Option 3"
|
45
|
+
let item1 = result.queryByText("Option 1");
|
46
|
+
let item2 = result.queryByText("Option 2");
|
47
|
+
let item3 = result.queryByText("Option 3");
|
48
|
+
// Ensure that item1, item2, and item3 are not undefined (i.e., they are rendered)
|
49
|
+
expect(item1).not.toBeUndefined();
|
50
|
+
expect(item2).not.toBeUndefined();
|
51
|
+
expect(item3).not.toBeUndefined();
|
52
|
+
// Ensure that there are no elements with the text "Option 9" (i.e., it is not rendered)
|
53
|
+
expect(result.queryAllByText("Option 9")).toHaveLength(0);
|
54
|
+
});
|
55
|
+
test("handles change event when selecting by object", () => {
|
56
|
+
// Set initial selectedData to the second item in the data array
|
57
|
+
let selectedData = data[1];
|
58
|
+
// Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
|
59
|
+
let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedData = data[e.value]), textField: "name", selectedData: selectedData }));
|
60
|
+
// Get the input element by its role of "combobox"
|
61
|
+
// Simulate a change event on the input element by setting its target value to "O"
|
62
|
+
let input = result.getByRole("combobox");
|
63
|
+
fireEvent.change(input, { target: { value: "O" } });
|
64
|
+
// Get the item element with the text "Option 2"
|
65
|
+
let item2 = result.getByText("Option 2");
|
66
|
+
// Simulate a click event on the item element
|
67
|
+
fireEvent.click(item2);
|
68
|
+
// Ensure that the input element's value attribute is set to "Option 2"
|
69
|
+
expect(selectedData.id).toBe(2);
|
70
|
+
});
|
71
|
+
test("handles change event when selecting by id", () => {
|
72
|
+
// Set initial selectedData to the second item in the data array
|
73
|
+
let selectedId = 1;
|
74
|
+
// Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
|
75
|
+
let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedId = e.value.id), textField: "name", selectedId: selectedId, idField: "id" }));
|
76
|
+
// Get the input element by its role of "combobox"
|
77
|
+
// Simulate a change event on the input element by setting its target value to "O"
|
78
|
+
let input = result.getByRole("combobox");
|
79
|
+
fireEvent.change(input, { target: { value: "O" } });
|
80
|
+
// Get the item element with the text "Option 2"
|
81
|
+
let item2 = result.getByText("Option 2");
|
82
|
+
// Simulate a click event on the item element
|
83
|
+
fireEvent.click(item2);
|
84
|
+
// Ensure that the input element's value attribute is set to "Option 2"
|
85
|
+
expect(selectedId).toBe(2);
|
86
|
+
});
|
87
|
+
test("only displays items that match the search", () => {
|
88
|
+
// Set initial selectedData to the second item in the data array
|
89
|
+
let selectedData = data[1];
|
90
|
+
// Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
|
91
|
+
let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedData = data[e.value]), textField: "name", selectedData: selectedData }));
|
92
|
+
let input = result.getByRole("combobox"); // Get the input element by its role of "combobox"
|
93
|
+
fireEvent.change(input, { target: { value: "9" } }); //simulate a change event on the input element
|
94
|
+
// Query the rendered result for elements with the text "Option 1" and "Option 9", and store the results in variables
|
95
|
+
let item1 = result.queryAllByText("Option 1");
|
96
|
+
let item9 = result.queryAllByText("Option 9");
|
97
|
+
// Ensure that there are no elements with the text "Option 1" and at least one element with the text "Option 9"
|
98
|
+
expect(item1).toHaveLength(0);
|
99
|
+
expect(item9.length).toBeGreaterThan(0);
|
100
|
+
});
|
101
|
+
});
|
@@ -5,7 +5,7 @@ export declare function CommandCellDDWithoutId<T>(props: {
|
|
5
5
|
/** The currently selected data item. */
|
6
6
|
selectedData: T;
|
7
7
|
/** The field names to use for text values in the dropdown. */
|
8
|
-
|
8
|
+
textField: keyof T;
|
9
9
|
/** Callback function to be called when the selected value changes. */
|
10
10
|
onChange: (e: ComboBoxChangeEvent) => void;
|
11
11
|
/** Optional separator to use for concatenating text values. */
|
@@ -1,8 +1,9 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { GenericDropdown } from "../GenericDropdown";
|
3
3
|
export function CommandCellDDWithoutId(props) {
|
4
4
|
// Function implementation...
|
5
|
-
return (_jsx("td", { children: props.checkEditField && !props.isEditing ? (
|
5
|
+
return (_jsx("td", { children: props.checkEditField && !props.isEditing ? (_jsx(_Fragment, {}) //TODO remove this from Marketing display
|
6
|
+
) : (
|
6
7
|
// If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
|
7
8
|
_jsx(GenericDropdown, Object.assign({}, props))) }));
|
8
9
|
}
|
@@ -5,7 +5,7 @@ export declare function CommandCellDropdown<T>(props: {
|
|
5
5
|
/** The ID of the currently selected item. */
|
6
6
|
selectedId: number;
|
7
7
|
/** The field names to use for text values in the dropdown. */
|
8
|
-
|
8
|
+
textField: keyof T;
|
9
9
|
/** Callback function to be called when the selected value changes. */
|
10
10
|
onChange: (e: ComboBoxChangeEvent) => void;
|
11
11
|
/** Optional separator to use for concatenating text values. */
|
@@ -1,11 +1,10 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { GenericDropdown } from "../GenericDropdown";
|
3
3
|
// This exports a function component called "CommandCellDropdown"
|
4
4
|
// It takes in various props that are used to render a dropdown in a table cell
|
5
5
|
export function CommandCellDropdown(props) {
|
6
|
-
return (_jsx("td", { children: props.checkEditField && !props.isEditing && props.data.length ? (
|
7
|
-
|
8
|
-
.join(props.separator || " ")) : (
|
6
|
+
return (_jsx("td", { children: props.checkEditField && !props.isEditing && props.data.length ? (_jsx(_Fragment, {}) //TODO remove this from Marketing display
|
7
|
+
) : (
|
9
8
|
// If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
|
10
9
|
_jsx(GenericDropdown, Object.assign({}, props))) }));
|
11
10
|
}
|
package/package.json
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "@scheels-softdev/kendoreact-generics",
|
3
|
-
"version": "2.6.
|
3
|
+
"version": "2.6.2",
|
4
4
|
"main": "index.js",
|
5
5
|
"scripts": {
|
6
|
-
"test": "
|
6
|
+
"test": "jest",
|
7
7
|
"clean": "rmdir /S /Q dist && mkdir dist",
|
8
8
|
"build": "npm run clean && tsc && copy package.json .\\dist && copy README.md .\\dist "
|
9
9
|
},
|
@@ -19,8 +19,12 @@
|
|
19
19
|
"@progress/kendo-react-grid": "latest",
|
20
20
|
"@progress/kendo-react-indicators": "^5.14.1",
|
21
21
|
"@progress/kendo-react-inputs": "latest",
|
22
|
+
"@testing-library/react": "^14.0.0",
|
23
|
+
"@types/jest": "^29.5.3",
|
22
24
|
"@types/moment": "latest",
|
23
25
|
"@types/react": "latest",
|
26
|
+
"jest": "^29.6.2",
|
27
|
+
"jest-environment-jsdom": "^29.6.2",
|
24
28
|
"moment": "latest",
|
25
29
|
"npmrc": "latest",
|
26
30
|
"react": "latest",
|
@@ -37,6 +41,7 @@
|
|
37
41
|
"moment": "^2.29.4",
|
38
42
|
"react": "^18.2.0",
|
39
43
|
"react-dom": "^18.2.0",
|
44
|
+
"ts-jest": "^29.1.1",
|
40
45
|
"typescript": "^4.9.5"
|
41
46
|
},
|
42
47
|
"description": ""
|