@etsoo/react 1.5.76 → 1.5.77

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,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import React from 'react';
2
3
  import { Align, GridChildComponentProps, VariableSizeGridProps } from 'react-window';
3
4
  import { GridMethodRef } from '../mu/GridMethodRef';
@@ -15,7 +16,7 @@ export interface ScrollerGridItemRendererProps<T> extends Omit<GridChildComponen
15
16
  /**
16
17
  * Scroller vertical grid props
17
18
  */
18
- export interface ScrollerGridProps<T> extends GridLoader<T>, Omit<VariableSizeGridProps<T>, 'children' | 'rowCount' | 'rowHeight' | 'ref'> {
19
+ export interface ScrollerGridProps<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends GridLoader<T>, Omit<VariableSizeGridProps<T>, 'children' | 'rowCount' | 'rowHeight' | 'ref'> {
19
20
  /**
20
21
  * Default order by asc
21
22
  * @default true
@@ -33,7 +34,7 @@ export interface ScrollerGridProps<T> extends GridLoader<T>, Omit<VariableSizeGr
33
34
  * Id field
34
35
  * @default id
35
36
  */
36
- idField?: string & keyof T;
37
+ idField?: D;
37
38
  /**
38
39
  * Item renderer
39
40
  */
@@ -109,4 +110,4 @@ export interface ScrollerGridForwardRef extends GridMethodRef {
109
110
  * @param props Props
110
111
  * @returns Component
111
112
  */
112
- export declare const ScrollerGrid: <T extends Record<string, unknown>>(props: ScrollerGridProps<T>) => JSX.Element;
113
+ export declare const ScrollerGrid: <T extends Record<string, unknown>>(props: ScrollerGridProps<T, DataTypes.Keys<T, string | number>>) => JSX.Element;
@@ -59,5 +59,5 @@ export interface ScrollerListForwardRef extends GridMethodRef, ScrollerListRef {
59
59
  * @param props Props
60
60
  * @returns Component
61
61
  */
62
- export declare const ScrollerList: <T extends Record<string, any>>(props: ScrollerListProps<T>) => JSX.Element;
62
+ export declare const ScrollerList: <T extends {}>(props: ScrollerListProps<T>) => JSX.Element;
63
63
  export {};
@@ -8,7 +8,7 @@ export interface AutocompleteExtendedProps<T extends {}, D extends DataTypes.Key
8
8
  /**
9
9
  * Id field, default is id
10
10
  */
11
- idField: D;
11
+ idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
12
12
  /**
13
13
  * Id value
14
14
  */
@@ -16,7 +16,7 @@ export interface ComboBoxProps<T extends {}, D extends DataTypes.Keys<T> = DataT
16
16
  /**
17
17
  * Label field
18
18
  */
19
- labelField: D;
19
+ labelField: T extends DataTypes.IdLabelItem ? D | undefined : D;
20
20
  /**
21
21
  * Load data callback
22
22
  */
@@ -12,7 +12,7 @@ import { ReactUtils } from '../app/ReactUtils';
12
12
  */
13
13
  export function ComboBox(props) {
14
14
  // Destruct
15
- const { search = false, autoAddBlankItem = search, idField, idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField, loadData, onLoadData, name, inputAutoComplete = 'off', options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, getOptionLabel = (option) => `${option[labelField]}`, sx = { minWidth: '150px' }, ...rest } = props;
15
+ const { search = false, autoAddBlankItem = search, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, getOptionLabel = (option) => `${option[labelField]}`, sx = { minWidth: '150px' }, ...rest } = props;
16
16
  // Value input ref
17
17
  const inputRef = React.createRef();
18
18
  // Options state
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import React from 'react';
2
3
  import { GridColumn } from '../components/GridColumn';
3
4
  import { GridLoaderStates } from '../components/GridLoader';
@@ -6,7 +7,7 @@ import { MouseEventWithDataHandler } from './MUGlobal';
6
7
  /**
7
8
  * Footer item renderer props
8
9
  */
9
- export interface DataGridExFooterItemRendererProps<T extends Record<string, any>> {
10
+ export interface DataGridExFooterItemRendererProps<T extends {}> {
10
11
  column: GridColumn<T>;
11
12
  index: number;
12
13
  states: GridLoaderStates<T>;
@@ -16,7 +17,7 @@ export interface DataGridExFooterItemRendererProps<T extends Record<string, any>
16
17
  /**
17
18
  * Extended DataGrid with VariableSizeGrid props
18
19
  */
19
- export interface DataGridExProps<T extends Record<string, any>> extends Omit<ScrollerGridProps<T>, 'itemRenderer' | 'columnCount' | 'columnWidth' | 'width'> {
20
+ export interface DataGridExProps<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends Omit<ScrollerGridProps<T, D>, 'itemRenderer' | 'columnCount' | 'columnWidth' | 'width'> {
20
21
  /**
21
22
  * Alternating colors for odd/even rows
22
23
  */
@@ -92,4 +93,4 @@ export declare function DataGridExCalColumns<T>(columns: GridColumn<T>[]): {
92
93
  * @param props Props
93
94
  * @returns Component
94
95
  */
95
- export declare function DataGridEx<T extends Record<string, any>>(props: DataGridExProps<T>): JSX.Element;
96
+ export declare function DataGridEx<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: DataGridExProps<T, D>): JSX.Element;
@@ -1,15 +1,14 @@
1
1
  /// <reference types="react" />
2
- import { IdLabelDto } from '@etsoo/appscript';
3
2
  import { DataTypes } from '@etsoo/shared';
4
3
  import { FormControlProps } from '@mui/material';
5
4
  /**
6
5
  * OptionGroup props
7
6
  */
8
- export interface OptionGroupProps<T extends Record<string, any> = IdLabelDto, D extends DataTypes.IdType = string> extends Omit<FormControlProps<'fieldset'>, 'defaultValue'> {
7
+ export interface OptionGroupProps<T extends {} = DataTypes.IdLabelItem, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends Omit<FormControlProps<'fieldset'>, 'defaultValue'> {
9
8
  /**
10
9
  * Default value
11
10
  */
12
- defaultValue?: D | D[];
11
+ defaultValue?: T[D] | T[D][];
13
12
  /**
14
13
  * Get option label function
15
14
  */
@@ -17,7 +16,7 @@ export interface OptionGroupProps<T extends Record<string, any> = IdLabelDto, D
17
16
  /**
18
17
  * Id field, default is id
19
18
  */
20
- idField?: string & keyof T;
19
+ idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
21
20
  /**
22
21
  * Label
23
22
  */
@@ -25,7 +24,7 @@ export interface OptionGroupProps<T extends Record<string, any> = IdLabelDto, D
25
24
  /**
26
25
  * Label field, default is label
27
26
  */
28
- labelField?: string & keyof T;
27
+ labelField: T extends DataTypes.IdLabelItem ? D | undefined : D;
29
28
  /**
30
29
  * Multiple choose item
31
30
  */
@@ -37,7 +36,7 @@ export interface OptionGroupProps<T extends Record<string, any> = IdLabelDto, D
37
36
  /**
38
37
  * On value change handler
39
38
  */
40
- onValueChange?: (value: D | D[] | undefined) => void;
39
+ onValueChange?: (value: T[D] | T[D][] | undefined) => void;
41
40
  /**
42
41
  * Array of options.
43
42
  */
@@ -56,4 +55,4 @@ export interface OptionGroupProps<T extends Record<string, any> = IdLabelDto, D
56
55
  * @param props Props
57
56
  * @returns Component
58
57
  */
59
- export declare function OptionGroup<T extends Record<string, unknown> = IdLabelDto, D extends DataTypes.IdType = string>(props: OptionGroupProps<T, D>): JSX.Element;
58
+ export declare function OptionGroup<T extends {} = DataTypes.IdLabelItem, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: OptionGroupProps<T, D>): JSX.Element;
@@ -10,7 +10,7 @@ import { ScrollerListExInnerItemRendererProps, ScrollerListExItemSize } from './
10
10
  /**
11
11
  * ResponsibleContainer props
12
12
  */
13
- export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate> extends Omit<DataGridExProps<T>, 'height' | 'itemKey' | 'loadData' | 'mRef' | 'onScroll' | 'onItemsRendered'> {
13
+ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends Omit<DataGridExProps<T, D>, 'height' | 'itemKey' | 'loadData' | 'mRef' | 'onScroll' | 'onItemsRendered'> {
14
14
  /**
15
15
  * Height will be deducted
16
16
  * @param height Current calcuated height
@@ -86,4 +86,4 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
86
86
  * @param props Props
87
87
  * @returns Layout
88
88
  */
89
- export declare function ResponsibleContainer<T extends {}, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate>(props: ResponsibleContainerProps<T, F>): JSX.Element;
89
+ export declare function ResponsibleContainer<T extends {}, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: ResponsibleContainerProps<T, F, D>): JSX.Element;
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import React from 'react';
2
3
  import { ListChildComponentProps } from 'react-window';
3
4
  import { ScrollerListProps } from '../components/ScrollerList';
@@ -33,7 +34,7 @@ export declare type ScrollerListExItemSize = ((index: number) => [number, number
33
34
  /**
34
35
  * Extended ScrollerList Props
35
36
  */
36
- export interface ScrollerListExProps<T> extends Omit<ScrollerListProps<T>, 'itemRenderer' | 'itemSize'> {
37
+ export interface ScrollerListExProps<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends Omit<ScrollerListProps<T>, 'itemRenderer' | 'itemSize'> {
37
38
  /**
38
39
  * Alternating colors for odd/even rows
39
40
  */
@@ -41,7 +42,7 @@ export interface ScrollerListExProps<T> extends Omit<ScrollerListProps<T>, 'item
41
42
  /**
42
43
  * Id field
43
44
  */
44
- idField?: string & keyof T;
45
+ idField?: D;
45
46
  /**
46
47
  * Inner item renderer
47
48
  */
@@ -76,4 +77,4 @@ export interface ScrollerListExProps<T> extends Omit<ScrollerListProps<T>, 'item
76
77
  * @param props Props
77
78
  * @returns Component
78
79
  */
79
- export declare function ScrollerListEx<T extends Record<string, unknown>>(props: ScrollerListExProps<T>): JSX.Element;
80
+ export declare function ScrollerListEx<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: ScrollerListExProps<T, D>): JSX.Element;
@@ -112,7 +112,7 @@ export function ScrollerListEx(props) {
112
112
  return selected;
113
113
  };
114
114
  // Destruct
115
- const { alternatingColors = [undefined, undefined], className, idField = 'id', innerItemRenderer, itemSize, itemKey = (index, data) => { var _a; return (_a = DataTypes.getValue(data, idField)) !== null && _a !== void 0 ? _a : index; }, itemRenderer = (itemProps) => {
115
+ const { alternatingColors = [undefined, undefined], className, idField = 'id', innerItemRenderer, itemSize, itemKey = (index, data) => { var _a; return (_a = DataTypes.getIdValue1(data, idField)) !== null && _a !== void 0 ? _a : index; }, itemRenderer = (itemProps) => {
116
116
  const [itemHeight, space, margins] = calculateItemSize(itemProps.index);
117
117
  return defaultItemRenderer({
118
118
  itemHeight,
@@ -1,5 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { IdLabelDto } from '@etsoo/appscript';
3
2
  import { DataTypes } from '@etsoo/shared';
4
3
  import { OptionGroupProps } from './OptionGroup';
5
4
  /**
@@ -7,4 +6,4 @@ import { OptionGroupProps } from './OptionGroup';
7
6
  * @param props Props
8
7
  * @returns Component
9
8
  */
10
- export declare function SearchOptionGroup<T extends Record<string, any> = IdLabelDto, D extends DataTypes.IdType = string>(props: OptionGroupProps<T, D>): JSX.Element;
9
+ export declare function SearchOptionGroup<T extends {} = DataTypes.IdLabelItem, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: OptionGroupProps<T, D>): JSX.Element;
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { IdLabelDto } from '@etsoo/appscript';
2
+ import { DataTypes } from '@etsoo/shared';
3
3
  import { SelectExProps } from './SelectEx';
4
4
  /**
5
5
  * SelectBool props
6
6
  */
7
- export interface SelectBoolProps extends Omit<SelectExProps<IdLabelDto<string>>, 'options' | 'loadData'> {
7
+ export interface SelectBoolProps extends Omit<SelectExProps<DataTypes.IdLabelItem<string>>, 'options' | 'loadData'> {
8
8
  }
9
9
  /**
10
10
  * SelectBool (yes/no)
@@ -12,7 +12,7 @@ export interface SelectExProps<T extends {}, D extends DataTypes.Keys<T> = DataT
12
12
  /**
13
13
  * Id field
14
14
  */
15
- idField: D;
15
+ idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
16
16
  /**
17
17
  * Item icon renderer
18
18
  */
@@ -20,7 +20,7 @@ export interface SelectExProps<T extends {}, D extends DataTypes.Keys<T> = DataT
20
20
  /**
21
21
  * Label field
22
22
  */
23
- labelField: ((option: T) => string) | D;
23
+ labelField: ((option: T) => string) | (T extends DataTypes.IdLabelItem ? D | undefined : D);
24
24
  /**
25
25
  * Load data callback
26
26
  */
@@ -12,7 +12,7 @@ import { ReactUtils } from '../app/ReactUtils';
12
12
  export function SelectEx(props) {
13
13
  var _a;
14
14
  // Destruct
15
- const { defaultValue, idField, itemIconRenderer, label, labelField, loadData, onItemClick, onLoadData, multiple = false, name, options = [], search = false, autoAddBlankItem = search, value, onChange, fullWidth, ...rest } = props;
15
+ const { defaultValue, idField = 'id', itemIconRenderer, label, labelField = 'label', loadData, onItemClick, onLoadData, multiple = false, name, options = [], search = false, autoAddBlankItem = search, value, onChange, fullWidth, ...rest } = props;
16
16
  // Options state
17
17
  const [localOptions, setOptions] = React.useState(options);
18
18
  const isMounted = React.useRef(true);
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { TableProps } from '@mui/material';
2
3
  import React from 'react';
3
4
  import { GridColumn } from '../components/GridColumn';
@@ -19,7 +20,7 @@ export interface TableExMethodRef extends GridMethodRef {
19
20
  /**
20
21
  * Extended table props
21
22
  */
22
- export interface TableExProps<T extends Record<string, any>> extends TableProps, GridLoader<T> {
23
+ export interface TableExProps<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends TableProps, GridLoader<T> {
23
24
  /**
24
25
  * Alternating colors for odd/even rows
25
26
  */
@@ -35,7 +36,7 @@ export interface TableExProps<T extends Record<string, any>> extends TableProps,
35
36
  /**
36
37
  * Id field
37
38
  */
38
- idField?: string & keyof T;
39
+ idField?: D;
39
40
  /**
40
41
  * Max height
41
42
  */
@@ -62,4 +63,4 @@ export interface TableExProps<T extends Record<string, any>> extends TableProps,
62
63
  * @param props Props
63
64
  * @returns Component
64
65
  */
65
- export declare function TableEx<T extends Record<string, unknown>>(props: TableExProps<T>): JSX.Element;
66
+ export declare function TableEx<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: TableExProps<T, D>): JSX.Element;
package/lib/mu/TableEx.js CHANGED
@@ -259,8 +259,7 @@ export function TableEx(props) {
259
259
  columnIndex,
260
260
  cellProps
261
261
  })) : (React.createElement(React.Fragment, null, "\u00A0"));
262
- return (React.createElement(TableCell, { key: rowId.toString() +
263
- columnIndex, ...cellProps }, child));
262
+ return (React.createElement(TableCell, { key: `${rowId}${columnIndex}`, ...cellProps }, child));
264
263
  })));
265
264
  })))),
266
265
  React.createElement(TablePagination, { component: "div", showFirstButton: true, count: totalRows, rowsPerPage: batchSize, page: currentPage, onPageChange: handleChangePage, onRowsPerPageChange: handleChangeRowsPerPage, rowsPerPageOptions: [
@@ -15,4 +15,4 @@ export interface TiplistProps<T extends {}, D extends DataTypes.Keys<T>> extends
15
15
  * @param props Props
16
16
  * @returns Component
17
17
  */
18
- export declare function Tiplist<T extends {}, D extends DataTypes.Keys<T>>(props: TiplistProps<T, D>): JSX.Element;
18
+ export declare function Tiplist<T extends {} = DataTypes.IdLabelItem, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: TiplistProps<T, D>): JSX.Element;
package/lib/mu/Tiplist.js CHANGED
@@ -12,7 +12,7 @@ import { SearchField } from './SearchField';
12
12
  */
13
13
  export function Tiplist(props) {
14
14
  // Destruct
15
- const { search = false, idField, idValue, inputAutoComplete = 'off', inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, label, loadData, defaultValue, value, name, readOnly, onChange, openOnFocus = true, sx = { minWidth: '180px' }, ...rest } = props;
15
+ const { search = false, idField = 'id', idValue, inputAutoComplete = 'off', inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, label, loadData, defaultValue, value, name, readOnly, onChange, openOnFocus = true, sx = { minWidth: '180px' }, ...rest } = props;
16
16
  // Value input ref
17
17
  const inputRef = React.createRef();
18
18
  // Local value
@@ -20,7 +20,7 @@ export function Tiplist(props) {
20
20
  if (localValue === undefined)
21
21
  localValue = null;
22
22
  // One time calculation for input's default value (uncontrolled)
23
- const localIdValue = idValue !== null && idValue !== void 0 ? idValue : (localValue && localValue[idField]);
23
+ const localIdValue = idValue !== null && idValue !== void 0 ? idValue : DataTypes.getValue(localValue, idField !== null && idField !== void 0 ? idField : 'id');
24
24
  // Changable states
25
25
  const [states, stateUpdate] = React.useReducer((currentState, newState) => {
26
26
  return { ...currentState, ...newState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.5.76",
3
+ "version": "1.5.77",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -51,11 +51,11 @@
51
51
  "@emotion/css": "^11.10.0",
52
52
  "@emotion/react": "^11.10.0",
53
53
  "@emotion/styled": "^11.10.0",
54
- "@etsoo/appscript": "^1.2.79",
54
+ "@etsoo/appscript": "^1.2.81",
55
55
  "@etsoo/notificationbase": "^1.1.6",
56
- "@etsoo/shared": "^1.1.46",
57
- "@mui/icons-material": "^5.8.4",
58
- "@mui/material": "^5.10.1",
56
+ "@etsoo/shared": "^1.1.47",
57
+ "@mui/icons-material": "^5.10.2",
58
+ "@mui/material": "^5.10.2",
59
59
  "@types/pica": "^9.0.1",
60
60
  "@types/pulltorefreshjs": "^0.1.5",
61
61
  "@types/react": "^18.0.17",
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import React from 'react';
2
3
  import {
3
4
  Align,
@@ -25,8 +26,10 @@ export interface ScrollerGridItemRendererProps<T>
25
26
  /**
26
27
  * Scroller vertical grid props
27
28
  */
28
- export interface ScrollerGridProps<T>
29
- extends GridLoader<T>,
29
+ export interface ScrollerGridProps<
30
+ T extends {},
31
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
32
+ > extends GridLoader<T>,
30
33
  Omit<
31
34
  VariableSizeGridProps<T>,
32
35
  'children' | 'rowCount' | 'rowHeight' | 'ref'
@@ -54,7 +57,7 @@ export interface ScrollerGridProps<T>
54
57
  * Id field
55
58
  * @default id
56
59
  */
57
- idField?: string & keyof T;
60
+ idField?: D;
58
61
 
59
62
  /**
60
63
  * Item renderer
@@ -98,9 +98,7 @@ const calculateBatchSize = (
98
98
  * @param props Props
99
99
  * @returns Component
100
100
  */
101
- export const ScrollerList = <T extends Record<string, any>>(
102
- props: ScrollerListProps<T>
103
- ) => {
101
+ export const ScrollerList = <T extends {}>(props: ScrollerListProps<T>) => {
104
102
  // Destruct
105
103
  const {
106
104
  autoLoad = true,
@@ -15,7 +15,7 @@ export interface AutocompleteExtendedProps<
15
15
  /**
16
16
  * Id field, default is id
17
17
  */
18
- idField: D;
18
+ idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
19
19
 
20
20
  /**
21
21
  * Id value
@@ -27,7 +27,7 @@ export interface ComboBoxProps<
27
27
  /**
28
28
  * Label field
29
29
  */
30
- labelField: D;
30
+ labelField: T extends DataTypes.IdLabelItem ? D | undefined : D;
31
31
 
32
32
  /**
33
33
  * Load data callback
@@ -58,7 +58,7 @@ export function ComboBox<
58
58
  const {
59
59
  search = false,
60
60
  autoAddBlankItem = search,
61
- idField,
61
+ idField = 'id' as D,
62
62
  idValue,
63
63
  inputError,
64
64
  inputHelperText,
@@ -68,7 +68,7 @@ export function ComboBox<
68
68
  inputVariant,
69
69
  defaultValue,
70
70
  label,
71
- labelField,
71
+ labelField = 'label' as D,
72
72
  loadData,
73
73
  onLoadData,
74
74
  name,
@@ -1,5 +1,5 @@
1
1
  import { css } from '@emotion/css';
2
- import { Utils } from '@etsoo/shared';
2
+ import { DataTypes, Utils } from '@etsoo/shared';
3
3
  import {
4
4
  Box,
5
5
  BoxProps,
@@ -30,9 +30,7 @@ import { MouseEventWithDataHandler } from './MUGlobal';
30
30
  /**
31
31
  * Footer item renderer props
32
32
  */
33
- export interface DataGridExFooterItemRendererProps<
34
- T extends Record<string, any>
35
- > {
33
+ export interface DataGridExFooterItemRendererProps<T extends {}> {
36
34
  column: GridColumn<T>;
37
35
  index: number;
38
36
  states: GridLoaderStates<T>;
@@ -43,9 +41,11 @@ export interface DataGridExFooterItemRendererProps<
43
41
  /**
44
42
  * Extended DataGrid with VariableSizeGrid props
45
43
  */
46
- export interface DataGridExProps<T extends Record<string, any>>
47
- extends Omit<
48
- ScrollerGridProps<T>,
44
+ export interface DataGridExProps<
45
+ T extends {},
46
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
47
+ > extends Omit<
48
+ ScrollerGridProps<T, D>,
49
49
  'itemRenderer' | 'columnCount' | 'columnWidth' | 'width'
50
50
  > {
51
51
  /**
@@ -210,9 +210,10 @@ export function DataGridExCalColumns<T>(columns: GridColumn<T>[]) {
210
210
  * @param props Props
211
211
  * @returns Component
212
212
  */
213
- export function DataGridEx<T extends Record<string, any>>(
214
- props: DataGridExProps<T>
215
- ) {
213
+ export function DataGridEx<
214
+ T extends {},
215
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
216
+ >(props: DataGridExProps<T, D>) {
216
217
  // Theme
217
218
  const theme = useTheme();
218
219
 
@@ -360,7 +361,7 @@ export function DataGridEx<T extends Record<string, any>>(
360
361
  footerItemRenderer = DataGridRenderers.defaultFooterItemRenderer,
361
362
  hideFooter = false,
362
363
  hoverColor = '#f6f9fb',
363
- idField = 'id',
364
+ idField = 'id' as D,
364
365
  mRef = React.createRef(),
365
366
  onClick,
366
367
  onDoubleClick,
@@ -372,7 +373,7 @@ export function DataGridEx<T extends Record<string, any>>(
372
373
 
373
374
  if (checkable) {
374
375
  const cbColumn: GridColumn<T> = {
375
- field: 'selected',
376
+ field: 'selected' as any, // Avoid validation from data model
376
377
  header: '',
377
378
  sortable: false,
378
379
  width: 50,
@@ -1,4 +1,3 @@
1
- import { IdLabelDto } from '@etsoo/appscript';
2
1
  import { DataTypes, Utils } from '@etsoo/shared';
3
2
  import {
4
3
  Checkbox,
@@ -16,13 +15,13 @@ import React from 'react';
16
15
  * OptionGroup props
17
16
  */
18
17
  export interface OptionGroupProps<
19
- T extends Record<string, any> = IdLabelDto,
20
- D extends DataTypes.IdType = string
18
+ T extends {} = DataTypes.IdLabelItem,
19
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
21
20
  > extends Omit<FormControlProps<'fieldset'>, 'defaultValue'> {
22
21
  /**
23
22
  * Default value
24
23
  */
25
- defaultValue?: D | D[];
24
+ defaultValue?: T[D] | T[D][];
26
25
 
27
26
  /**
28
27
  * Get option label function
@@ -32,7 +31,7 @@ export interface OptionGroupProps<
32
31
  /**
33
32
  * Id field, default is id
34
33
  */
35
- idField?: string & keyof T;
34
+ idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
36
35
 
37
36
  /**
38
37
  * Label
@@ -42,7 +41,7 @@ export interface OptionGroupProps<
42
41
  /**
43
42
  * Label field, default is label
44
43
  */
45
- labelField?: string & keyof T;
44
+ labelField: T extends DataTypes.IdLabelItem ? D | undefined : D;
46
45
 
47
46
  /**
48
47
  * Multiple choose item
@@ -57,7 +56,7 @@ export interface OptionGroupProps<
57
56
  /**
58
57
  * On value change handler
59
58
  */
60
- onValueChange?: (value: D | D[] | undefined) => void;
59
+ onValueChange?: (value: T[D] | T[D][] | undefined) => void;
61
60
 
62
61
  /**
63
62
  * Array of options.
@@ -81,16 +80,16 @@ export interface OptionGroupProps<
81
80
  * @returns Component
82
81
  */
83
82
  export function OptionGroup<
84
- T extends Record<string, unknown> = IdLabelDto,
85
- D extends DataTypes.IdType = string
83
+ T extends {} = DataTypes.IdLabelItem,
84
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
86
85
  >(props: OptionGroupProps<T, D>) {
87
86
  // Destruct
88
87
  const {
89
88
  getOptionLabel,
90
89
  defaultValue,
91
- idField = 'id',
90
+ idField = 'id' as D,
92
91
  label,
93
- labelField = 'label',
92
+ labelField = 'label' as D,
94
93
  multiple = false,
95
94
  name,
96
95
  onValueChange,
@@ -103,10 +102,10 @@ export function OptionGroup<
103
102
 
104
103
  // Get option value
105
104
  // D type should be the source id type
106
- const getOptionValue = (option: T): D | null => {
105
+ const getOptionValue = (option: T): T[D] | null => {
107
106
  const value = DataTypes.getValue(option, idField);
108
107
  if (value == null) return null;
109
- return value as D;
108
+ return value as T[D];
110
109
  };
111
110
 
112
111
  // Checkbox values
@@ -142,7 +141,7 @@ export function OptionGroup<
142
141
  onChange={(event) => {
143
142
  if (firstOptionValue == null) return;
144
143
 
145
- const typeValue = Utils.parseString<D>(
144
+ const typeValue = Utils.parseString(
146
145
  event.target.value,
147
146
  firstOptionValue
148
147
  );
@@ -175,7 +174,7 @@ export function OptionGroup<
175
174
 
176
175
  // Value, convert to string
177
176
  // Will fail when type is number
178
- const value = getOptionValue(option);
177
+ const value = getOptionValue(option) as unknown as React.Key;
179
178
 
180
179
  return (
181
180
  <FormControlLabel
@@ -197,7 +196,7 @@ export function OptionGroup<
197
196
  value={values[0]}
198
197
  onChange={(_event, value) => {
199
198
  if (firstOptionValue == null) return;
200
- const typeValue = Utils.parseString<D>(value, firstOptionValue);
199
+ const typeValue = Utils.parseString(value, firstOptionValue);
201
200
  if (onValueChange) onValueChange(typeValue);
202
201
  setValues([typeValue]);
203
202
  }}
@@ -32,9 +32,10 @@ import { SearchBar } from './SearchBar';
32
32
  */
33
33
  export interface ResponsibleContainerProps<
34
34
  T extends {},
35
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate
35
+ F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
36
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
36
37
  > extends Omit<
37
- DataGridExProps<T>,
38
+ DataGridExProps<T, D>,
38
39
  | 'height'
39
40
  | 'itemKey'
40
41
  | 'loadData'
@@ -163,8 +164,9 @@ function defaultContainerBoxSx(
163
164
  */
164
165
  export function ResponsibleContainer<
165
166
  T extends {},
166
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate
167
- >(props: ResponsibleContainerProps<T, F>) {
167
+ F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
168
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
169
+ >(props: ResponsibleContainerProps<T, F, D>) {
168
170
  // Destruct
169
171
  const {
170
172
  adjustHeight,
@@ -319,7 +321,7 @@ export function ResponsibleContainer<
319
321
 
320
322
  return [
321
323
  <Box className="ListBox" sx={{ height: heightLocal }}>
322
- <ScrollerListEx<T>
324
+ <ScrollerListEx<T, D>
323
325
  autoLoad={!hasFields}
324
326
  height={heightLocal}
325
327
  loadData={localLoadData}
@@ -117,8 +117,10 @@ export type ScrollerListExItemSize =
117
117
  /**
118
118
  * Extended ScrollerList Props
119
119
  */
120
- export interface ScrollerListExProps<T>
121
- extends Omit<ScrollerListProps<T>, 'itemRenderer' | 'itemSize'> {
120
+ export interface ScrollerListExProps<
121
+ T extends {},
122
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
123
+ > extends Omit<ScrollerListProps<T>, 'itemRenderer' | 'itemSize'> {
122
124
  /**
123
125
  * Alternating colors for odd/even rows
124
126
  */
@@ -127,7 +129,7 @@ export interface ScrollerListExProps<T>
127
129
  /**
128
130
  * Id field
129
131
  */
130
- idField?: string & keyof T;
132
+ idField?: D;
131
133
 
132
134
  /**
133
135
  * Inner item renderer
@@ -260,9 +262,10 @@ function defaultItemRenderer<T>({
260
262
  * @param props Props
261
263
  * @returns Component
262
264
  */
263
- export function ScrollerListEx<T extends Record<string, unknown>>(
264
- props: ScrollerListExProps<T>
265
- ) {
265
+ export function ScrollerListEx<
266
+ T extends {},
267
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
268
+ >(props: ScrollerListExProps<T, D>) {
266
269
  // Selected item ref
267
270
  const selectedItem = React.useRef<[HTMLDivElement, T]>();
268
271
 
@@ -295,11 +298,11 @@ export function ScrollerListEx<T extends Record<string, unknown>>(
295
298
  const {
296
299
  alternatingColors = [undefined, undefined],
297
300
  className,
298
- idField = 'id',
301
+ idField = 'id' as D,
299
302
  innerItemRenderer,
300
303
  itemSize,
301
304
  itemKey = (index: number, data: T) =>
302
- DataTypes.getValue(data, idField) ?? index,
305
+ DataTypes.getIdValue1(data, idField) ?? index,
303
306
  itemRenderer = (itemProps) => {
304
307
  const [itemHeight, space, margins] = calculateItemSize(
305
308
  itemProps.index
@@ -1,4 +1,3 @@
1
- import { IdLabelDto } from '@etsoo/appscript';
2
1
  import { DataTypes } from '@etsoo/shared';
3
2
  import React from 'react';
4
3
  import { MUGlobal } from './MUGlobal';
@@ -10,8 +9,8 @@ import { OptionGroup, OptionGroupProps } from './OptionGroup';
10
9
  * @returns Component
11
10
  */
12
11
  export function SearchOptionGroup<
13
- T extends Record<string, any> = IdLabelDto,
14
- D extends DataTypes.IdType = string
12
+ T extends {} = DataTypes.IdLabelItem,
13
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
15
14
  >(props: OptionGroupProps<T, D>) {
16
15
  // Destruct
17
16
  const {
@@ -1,5 +1,4 @@
1
- import { IdLabelDto } from '@etsoo/appscript';
2
- import { Utils } from '@etsoo/shared';
1
+ import { DataTypes, Utils } from '@etsoo/shared';
3
2
  import React from 'react';
4
3
  import { globalApp } from '..';
5
4
  import { SelectEx, SelectExProps } from './SelectEx';
@@ -8,7 +7,10 @@ import { SelectEx, SelectExProps } from './SelectEx';
8
7
  * SelectBool props
9
8
  */
10
9
  export interface SelectBoolProps
11
- extends Omit<SelectExProps<IdLabelDto<string>>, 'options' | 'loadData'> {}
10
+ extends Omit<
11
+ SelectExProps<DataTypes.IdLabelItem<string>>,
12
+ 'options' | 'loadData'
13
+ > {}
12
14
 
13
15
  /**
14
16
  * SelectBool (yes/no)
@@ -20,7 +22,7 @@ export function SelectBool(props: SelectBoolProps) {
20
22
  const { search = true, autoAddBlankItem = search, ...rest } = props;
21
23
 
22
24
  // Options
23
- const options: IdLabelDto<string>[] = [
25
+ const options: DataTypes.IdLabelItem<string>[] = [
24
26
  { id: 'false', label: globalApp.get('no')! },
25
27
  { id: 'true', label: globalApp.get('yes')! }
26
28
  ];
@@ -29,7 +31,7 @@ export function SelectBool(props: SelectBoolProps) {
29
31
 
30
32
  // Layout
31
33
  return (
32
- <SelectEx<IdLabelDto<string>>
34
+ <SelectEx<DataTypes.IdLabelItem<string>>
33
35
  options={options}
34
36
  search={search}
35
37
  {...rest}
@@ -30,7 +30,7 @@ export interface SelectExProps<
30
30
  /**
31
31
  * Id field
32
32
  */
33
- idField: D;
33
+ idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
34
34
 
35
35
  /**
36
36
  * Item icon renderer
@@ -40,7 +40,9 @@ export interface SelectExProps<
40
40
  /**
41
41
  * Label field
42
42
  */
43
- labelField: ((option: T) => string) | D;
43
+ labelField:
44
+ | ((option: T) => string)
45
+ | (T extends DataTypes.IdLabelItem ? D | undefined : D);
44
46
 
45
47
  /**
46
48
  * Load data callback
@@ -80,10 +82,10 @@ export function SelectEx<
80
82
  // Destruct
81
83
  const {
82
84
  defaultValue,
83
- idField,
85
+ idField = 'id' as D,
84
86
  itemIconRenderer,
85
87
  label,
86
- labelField,
88
+ labelField = 'label' as D,
87
89
  loadData,
88
90
  onItemClick,
89
91
  onLoadData,
@@ -47,8 +47,10 @@ export interface TableExMethodRef extends GridMethodRef {
47
47
  /**
48
48
  * Extended table props
49
49
  */
50
- export interface TableExProps<T extends Record<string, any>>
51
- extends TableProps,
50
+ export interface TableExProps<
51
+ T extends {},
52
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
53
+ > extends TableProps,
52
54
  GridLoader<T> {
53
55
  /**
54
56
  * Alternating colors for odd/even rows
@@ -68,7 +70,7 @@ export interface TableExProps<T extends Record<string, any>>
68
70
  /**
69
71
  * Id field
70
72
  */
71
- idField?: string & keyof T;
73
+ idField?: D;
72
74
 
73
75
  /**
74
76
  * Max height
@@ -101,14 +103,13 @@ export interface TableExProps<T extends Record<string, any>>
101
103
  * @param props Props
102
104
  * @returns Component
103
105
  */
104
- export function TableEx<T extends Record<string, unknown>>(
105
- props: TableExProps<T>
106
- ) {
106
+ export function TableEx<
107
+ T extends {},
108
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
109
+ >(props: TableExProps<T, D>) {
107
110
  // Theme
108
111
  const theme = useTheme();
109
112
 
110
- type keyType = string & keyof T;
111
-
112
113
  // Destruct
113
114
  const {
114
115
  alternatingColors = [theme.palette.action.hover, undefined],
@@ -116,7 +117,7 @@ export function TableEx<T extends Record<string, unknown>>(
116
117
  columns,
117
118
  defaultOrderBy,
118
119
  headerColors = [undefined, undefined],
119
- idField = 'id' as keyType,
120
+ idField = 'id' as D,
120
121
  loadBatchSize,
121
122
  loadData,
122
123
  maxHeight,
@@ -451,7 +452,10 @@ export function TableEx<T extends Record<string, unknown>>(
451
452
  : false;
452
453
 
453
454
  return (
454
- <TableRow key={rowId} selected={isItemSelected}>
455
+ <TableRow
456
+ key={rowId as unknown as React.Key}
457
+ selected={isItemSelected}
458
+ >
455
459
  {selectable && (
456
460
  <TableCell padding="checkbox">
457
461
  {row && (
@@ -522,10 +526,7 @@ export function TableEx<T extends Record<string, unknown>>(
522
526
 
523
527
  return (
524
528
  <TableCell
525
- key={
526
- rowId.toString() +
527
- columnIndex
528
- }
529
+ key={`${rowId}${columnIndex}`}
529
530
  {...cellProps}
530
531
  >
531
532
  {child}
@@ -34,13 +34,14 @@ interface States<T extends {}> {
34
34
  * @param props Props
35
35
  * @returns Component
36
36
  */
37
- export function Tiplist<T extends {}, D extends DataTypes.Keys<T>>(
38
- props: TiplistProps<T, D>
39
- ) {
37
+ export function Tiplist<
38
+ T extends {} = DataTypes.IdLabelItem,
39
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
40
+ >(props: TiplistProps<T, D>) {
40
41
  // Destruct
41
42
  const {
42
43
  search = false,
43
- idField,
44
+ idField = 'id' as D,
44
45
  idValue,
45
46
  inputAutoComplete = 'off',
46
47
  inputError,
@@ -69,7 +70,8 @@ export function Tiplist<T extends {}, D extends DataTypes.Keys<T>>(
69
70
  if (localValue === undefined) localValue = null;
70
71
 
71
72
  // One time calculation for input's default value (uncontrolled)
72
- const localIdValue = idValue ?? (localValue && localValue[idField]);
73
+ const localIdValue =
74
+ idValue ?? DataTypes.getValue(localValue, idField ?? 'id');
73
75
 
74
76
  // Changable states
75
77
  const [states, stateUpdate] = React.useReducer(