@scheels-softdev/kendoreact-generics 2.0.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,14 @@
1
1
  export declare function GenericDropdown<T>({ data, // array of data objects
2
2
  selectedId, // id of the selected data object
3
+ selectedObject, //if there is no identity key in the object and you need to compare the entire object, use this instead of selectedId
3
4
  changeEvent, // function to call when the selected value changes
4
5
  textFields, // array of field names to use for text values
5
6
  separator, // optional separator to use for concatenating text values
6
7
  disabled, // boolean to disable the dropdown
7
8
  idField, title, }: {
8
9
  data: T[];
9
- selectedId: number;
10
+ selectedId?: number;
11
+ selectedObject?: T;
10
12
  changeEvent: Function;
11
13
  textFields: (keyof T)[];
12
14
  separator?: string;
@@ -6,11 +6,21 @@ import { getTextValue } from "./Utility";
6
6
  // component that renders a dropdown with a search filter
7
7
  export function GenericDropdown({ data, // array of data objects
8
8
  selectedId, // id of the selected data object
9
+ selectedObject, //if there is no identity key in the object and you need to compare the entire object, use this instead of selectedId
9
10
  changeEvent, // function to call when the selected value changes
10
11
  textFields, // array of field names to use for text values
11
12
  separator, // optional separator to use for concatenating text values
12
13
  disabled, // boolean to disable the dropdown
13
14
  idField, title, }) {
15
+ if (selectedId !== undefined && selectedObject !== undefined) {
16
+ throw new Error("You cannot provide both selectedObject and selectedId to GenericDropdown.");
17
+ }
18
+ if (selectedId === undefined && selectedObject === undefined) {
19
+ throw new Error("You must provide either selectedId or selectedObject to GenericDropdown.");
20
+ }
21
+ if (idField !== undefined && selectedObject !== undefined) {
22
+ console.warn("idField is not necessary if you are using selectedObject instead of selectedId. Doing so may result in something funky");
23
+ }
14
24
  //local state
15
25
  const pageSize = 8;
16
26
  const [dataList, setDataList] = useState(data.map((x) => {
@@ -58,5 +68,5 @@ idField, title, }) {
58
68
  skip: state.skip,
59
69
  }, suggest: true, onPageChange: pageChange, filterable: true, onFilterChange: onFilterChange, popupSettings: {
60
70
  height: "210px",
61
- }, onChange: (e) => e.value && changeEvent(e), onBlur: (e) => e.nativeEvent.preventDefault(), value: dataList.find((item) => selectedId === item[idField || "id"]) }) })));
71
+ }, onChange: (e) => e.value && changeEvent(e), onBlur: (e) => e.nativeEvent.preventDefault(), value: selectedId ? dataList.find((item) => selectedId === item[idField || "id"]) : dataList.find((x) => x === selectedObject) }) })));
62
72
  }
@@ -0,0 +1,11 @@
1
+ import { ComboBoxChangeEvent } from "@progress/kendo-react-dropdowns";
2
+ import { CommonProps } from "../PropTypes";
3
+ export declare function CommandCellDDWithoutId<T extends CommonProps>(props: {
4
+ data: T[];
5
+ selectedData: T;
6
+ textFields: (keyof T)[];
7
+ changeEvent: (e: ComboBoxChangeEvent) => void;
8
+ separator?: string;
9
+ checkEditField?: boolean;
10
+ isEditing?: boolean;
11
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { GenericDropdown } from "../GenericDropdown";
3
+ export function CommandCellDDWithoutId(props) {
4
+ return (_jsx("td", { children: props.checkEditField && !props.isEditing ? (props.textFields.map((x) => props.data.find((y) => y === props.selectedData)[x]).join(props.separator || " ")) : (
5
+ // If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
6
+ _jsx(GenericDropdown, Object.assign({}, props))) }));
7
+ }
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { CommandCellCheckBox } from "./commandCell/CommandCellCheckbox";
2
2
  export { CommandCellDate } from "./commandCell/CommandCellDate";
3
3
  export { CommandCellDropdown } from "./commandCell/CommandCellDropdown";
4
+ export { CommandCellDDWithoutId } from "./commandCell/CommandCellDDWithoutId";
4
5
  export { CommandCellPrice } from "./commandCell/CommandCellPrice";
5
6
  export { CommandCellSwitch } from "./commandCell/CommandCellSwitch";
6
7
  export { FilterCellDropdown } from "./FilterCellDropdown";
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { CommandCellCheckBox } from "./commandCell/CommandCellCheckbox";
2
2
  export { CommandCellDate } from "./commandCell/CommandCellDate";
3
3
  export { CommandCellDropdown } from "./commandCell/CommandCellDropdown";
4
+ export { CommandCellDDWithoutId } from "./commandCell/CommandCellDDWithoutId";
4
5
  export { CommandCellPrice } from "./commandCell/CommandCellPrice";
5
6
  export { CommandCellSwitch } from "./commandCell/CommandCellSwitch";
6
7
  export { FilterCellDropdown } from "./FilterCellDropdown";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scheels-softdev/kendoreact-generics",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",