@natoora-libs/core 0.2.41 → 0.2.42

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.
@@ -16,8 +16,8 @@ declare const TableDesktopFooter: FC<TableDesktopFooterProps>;
16
16
 
17
17
  type BulkChanges = {
18
18
  field: string;
19
- value: string | number | boolean;
20
- label: string | number | boolean;
19
+ value: UpdateEditableCellParams['value'];
20
+ label: UpdateEditableCellParams['label'];
21
21
  }[];
22
22
  type TableColumnConfigurationMenuProps = {
23
23
  anchorEl: HTMLElement | null;
@@ -32,7 +32,7 @@ type ExportCsvDialogProps = {
32
32
  };
33
33
  type BulkChangesDialogProps = {
34
34
  bulkChanges: BulkChanges;
35
- selectedRows: (string | number)[];
35
+ selectedRows: RowId[];
36
36
  shouldUpdateAll: boolean;
37
37
  visibleEditableColumns: HeadCell[];
38
38
  isBulkChangesDialogOpen: boolean;
@@ -43,7 +43,7 @@ type TableDesktopToolbarProps = {
43
43
  toolbarLabel?: string;
44
44
  headCells: HeadCell[];
45
45
  headerFilters: HeaderFilters;
46
- selectedRows: (string | number)[];
46
+ selectedRows: RowId[];
47
47
  isDataEmpty: boolean;
48
48
  totalDataCount?: number;
49
49
  isRowsFromAllPagesSelected: boolean;
@@ -55,6 +55,7 @@ type TableDesktopToolbarProps = {
55
55
  disableBulkChangesMode?: boolean;
56
56
  isBulkChangesMode: boolean;
57
57
  onChangeBulkChangesMode: (checked: boolean) => void;
58
+ onActivateBulkChangesMode?: () => void;
58
59
  renderExportCsvDialog?: (props: ExportCsvDialogProps) => ReactNode;
59
60
  renderBulkChangesDialog?: (props: BulkChangesDialogProps) => ReactNode;
60
61
  renderTableColumnConfigurationMenu?: (props: TableColumnConfigurationMenuProps) => ReactNode;
@@ -63,7 +64,7 @@ type TableDesktopToolbarProps = {
63
64
  declare const TableDesktopToolbar: FC<TableDesktopToolbarProps>;
64
65
 
65
66
  type Order = 'asc' | 'desc';
66
- type EditableCellType = 'select' | 'checkbox' | 'text' | 'numeric';
67
+ type EditableCellType = 'select' | 'multipleSelect' | 'checkbox' | 'text' | 'numeric' | 'date' | 'time' | 'tags';
67
68
  type HeaderFilterObject = {
68
69
  id: number | string;
69
70
  [key: string]: number | string;
@@ -72,6 +73,13 @@ type HeaderFilterOptions = string[] | HeaderFilterObject[];
72
73
  type HeaderFilters = {
73
74
  [key: string]: HeaderFilterOptions;
74
75
  };
76
+ type UpdateEditableCellParams = {
77
+ rowId?: RowId;
78
+ columnId: string;
79
+ value: string | number | boolean | (string | number)[] | null;
80
+ label: string | number | boolean | (string | number)[] | null;
81
+ };
82
+ type RowId = string | number;
75
83
  type HeadCell = {
76
84
  id: string;
77
85
  label?: string;
@@ -82,15 +90,17 @@ type HeadCell = {
82
90
  width?: number | string;
83
91
  enabled?: boolean;
84
92
  disableSort?: boolean;
85
- RenderHeader?: ReactNode;
86
- editableCellType?: EditableCellType;
87
- validateInput?: (value: string | null) => boolean;
88
- onUpdateEditableCell?: (rowId: number, field: string, value: string | number | boolean, label: string | number | boolean) => void;
93
+ renderHeader?: ReactNode;
94
+ filterType?: 'default' | 'autocomplete' | 'boolean';
89
95
  filterOptions?: HeaderFilterOptions;
90
96
  refetchFilterOptions?: () => void;
91
97
  isFetchingFilterOptions?: boolean;
92
- isAutocompleteFilterMenu?: boolean;
93
- onAutocompleteFilterChange?: (value: string) => void;
98
+ editableCellType?: EditableCellType;
99
+ validateInput?: (value: string | null) => boolean;
100
+ onUpdateEditableCell?: (params: UpdateEditableCellParams) => void;
101
+ onAutocompleteSearch?: (value: string) => void;
102
+ allowBlankSelectOption?: boolean;
103
+ bulkUpdateDisabled?: boolean;
94
104
  };
95
105
  type TableDesktopProps = {
96
106
  data: any[];
@@ -115,7 +125,7 @@ type TableDesktopProps = {
115
125
  showClearFilterButton?: boolean;
116
126
  handleClickOnClearFiltersButton?: () => void;
117
127
  deleteItem?: (id: number, contentTypeName?: string, appTypeName?: string) => void;
118
- keyField?: string;
128
+ keyField?: string | ((rowData: any) => string);
119
129
  tableLayout?: 'fixed' | 'auto';
120
130
  onApplyFilters?: (updatedFilters: HeaderFilters, shouldSave: boolean) => void;
121
131
  refetchData?: () => Promise<unknown>;
@@ -123,4 +133,4 @@ type TableDesktopProps = {
123
133
  };
124
134
  declare const TableDesktop: ({ data, headCells, RenderItem, renderToolbar, renderFooter, appliedFilters, headerFilters, children, height, rowHeight, rowsPerPage, totalDataCount, isLoading, enableEditMode, disableInternalSort, updateSort, showClearFilterButton, handleClickOnClearFiltersButton, deleteItem, keyField, tableLayout, onApplyFilters, shouldShowCheckOnFilter, refetchData, }: TableDesktopProps) => react_jsx_runtime.JSX.Element;
125
135
 
126
- export { type BulkChanges as B, type EditableCellType as E, type HeadCell as H, type Order as O, type TableDesktopProps as T, type HeaderFilters as a, type HeaderFilterOptions as b, type HeaderFilterObject as c, TableDesktop as d, TableDesktopFooter as e, type TableDesktopFooterProps as f, TableDesktopToolbar as g, type TableDesktopToolbarProps as h, type TableColumnConfigurationMenuProps as i, type BulkChangesDialogProps as j, type ExportCsvDialogProps as k };
136
+ export { type BulkChanges as B, type EditableCellType as E, type HeadCell as H, type Order as O, type RowId as R, type TableDesktopProps as T, type UpdateEditableCellParams as U, type HeaderFilters as a, type HeaderFilterOptions as b, type HeaderFilterObject as c, type BulkChangesDialogProps as d, type ExportCsvDialogProps as e, type TableColumnConfigurationMenuProps as f, TableDesktop as g, TableDesktopFooter as h, type TableDesktopFooterProps as i, TableDesktopToolbar as j, type TableDesktopToolbarProps as k };
@@ -16,8 +16,8 @@ declare const TableDesktopFooter: FC<TableDesktopFooterProps>;
16
16
 
17
17
  type BulkChanges = {
18
18
  field: string;
19
- value: string | number | boolean;
20
- label: string | number | boolean;
19
+ value: UpdateEditableCellParams['value'];
20
+ label: UpdateEditableCellParams['label'];
21
21
  }[];
22
22
  type TableColumnConfigurationMenuProps = {
23
23
  anchorEl: HTMLElement | null;
@@ -32,7 +32,7 @@ type ExportCsvDialogProps = {
32
32
  };
33
33
  type BulkChangesDialogProps = {
34
34
  bulkChanges: BulkChanges;
35
- selectedRows: (string | number)[];
35
+ selectedRows: RowId[];
36
36
  shouldUpdateAll: boolean;
37
37
  visibleEditableColumns: HeadCell[];
38
38
  isBulkChangesDialogOpen: boolean;
@@ -43,7 +43,7 @@ type TableDesktopToolbarProps = {
43
43
  toolbarLabel?: string;
44
44
  headCells: HeadCell[];
45
45
  headerFilters: HeaderFilters;
46
- selectedRows: (string | number)[];
46
+ selectedRows: RowId[];
47
47
  isDataEmpty: boolean;
48
48
  totalDataCount?: number;
49
49
  isRowsFromAllPagesSelected: boolean;
@@ -55,6 +55,7 @@ type TableDesktopToolbarProps = {
55
55
  disableBulkChangesMode?: boolean;
56
56
  isBulkChangesMode: boolean;
57
57
  onChangeBulkChangesMode: (checked: boolean) => void;
58
+ onActivateBulkChangesMode?: () => void;
58
59
  renderExportCsvDialog?: (props: ExportCsvDialogProps) => ReactNode;
59
60
  renderBulkChangesDialog?: (props: BulkChangesDialogProps) => ReactNode;
60
61
  renderTableColumnConfigurationMenu?: (props: TableColumnConfigurationMenuProps) => ReactNode;
@@ -63,7 +64,7 @@ type TableDesktopToolbarProps = {
63
64
  declare const TableDesktopToolbar: FC<TableDesktopToolbarProps>;
64
65
 
65
66
  type Order = 'asc' | 'desc';
66
- type EditableCellType = 'select' | 'checkbox' | 'text' | 'numeric';
67
+ type EditableCellType = 'select' | 'multipleSelect' | 'checkbox' | 'text' | 'numeric' | 'date' | 'time' | 'tags';
67
68
  type HeaderFilterObject = {
68
69
  id: number | string;
69
70
  [key: string]: number | string;
@@ -72,6 +73,13 @@ type HeaderFilterOptions = string[] | HeaderFilterObject[];
72
73
  type HeaderFilters = {
73
74
  [key: string]: HeaderFilterOptions;
74
75
  };
76
+ type UpdateEditableCellParams = {
77
+ rowId?: RowId;
78
+ columnId: string;
79
+ value: string | number | boolean | (string | number)[] | null;
80
+ label: string | number | boolean | (string | number)[] | null;
81
+ };
82
+ type RowId = string | number;
75
83
  type HeadCell = {
76
84
  id: string;
77
85
  label?: string;
@@ -82,15 +90,17 @@ type HeadCell = {
82
90
  width?: number | string;
83
91
  enabled?: boolean;
84
92
  disableSort?: boolean;
85
- RenderHeader?: ReactNode;
86
- editableCellType?: EditableCellType;
87
- validateInput?: (value: string | null) => boolean;
88
- onUpdateEditableCell?: (rowId: number, field: string, value: string | number | boolean, label: string | number | boolean) => void;
93
+ renderHeader?: ReactNode;
94
+ filterType?: 'default' | 'autocomplete' | 'boolean';
89
95
  filterOptions?: HeaderFilterOptions;
90
96
  refetchFilterOptions?: () => void;
91
97
  isFetchingFilterOptions?: boolean;
92
- isAutocompleteFilterMenu?: boolean;
93
- onAutocompleteFilterChange?: (value: string) => void;
98
+ editableCellType?: EditableCellType;
99
+ validateInput?: (value: string | null) => boolean;
100
+ onUpdateEditableCell?: (params: UpdateEditableCellParams) => void;
101
+ onAutocompleteSearch?: (value: string) => void;
102
+ allowBlankSelectOption?: boolean;
103
+ bulkUpdateDisabled?: boolean;
94
104
  };
95
105
  type TableDesktopProps = {
96
106
  data: any[];
@@ -115,7 +125,7 @@ type TableDesktopProps = {
115
125
  showClearFilterButton?: boolean;
116
126
  handleClickOnClearFiltersButton?: () => void;
117
127
  deleteItem?: (id: number, contentTypeName?: string, appTypeName?: string) => void;
118
- keyField?: string;
128
+ keyField?: string | ((rowData: any) => string);
119
129
  tableLayout?: 'fixed' | 'auto';
120
130
  onApplyFilters?: (updatedFilters: HeaderFilters, shouldSave: boolean) => void;
121
131
  refetchData?: () => Promise<unknown>;
@@ -123,4 +133,4 @@ type TableDesktopProps = {
123
133
  };
124
134
  declare const TableDesktop: ({ data, headCells, RenderItem, renderToolbar, renderFooter, appliedFilters, headerFilters, children, height, rowHeight, rowsPerPage, totalDataCount, isLoading, enableEditMode, disableInternalSort, updateSort, showClearFilterButton, handleClickOnClearFiltersButton, deleteItem, keyField, tableLayout, onApplyFilters, shouldShowCheckOnFilter, refetchData, }: TableDesktopProps) => react_jsx_runtime.JSX.Element;
125
135
 
126
- export { type BulkChanges as B, type EditableCellType as E, type HeadCell as H, type Order as O, type TableDesktopProps as T, type HeaderFilters as a, type HeaderFilterOptions as b, type HeaderFilterObject as c, TableDesktop as d, TableDesktopFooter as e, type TableDesktopFooterProps as f, TableDesktopToolbar as g, type TableDesktopToolbarProps as h, type TableColumnConfigurationMenuProps as i, type BulkChangesDialogProps as j, type ExportCsvDialogProps as k };
136
+ export { type BulkChanges as B, type EditableCellType as E, type HeadCell as H, type Order as O, type RowId as R, type TableDesktopProps as T, type UpdateEditableCellParams as U, type HeaderFilters as a, type HeaderFilterOptions as b, type HeaderFilterObject as c, type BulkChangesDialogProps as d, type ExportCsvDialogProps as e, type TableColumnConfigurationMenuProps as f, TableDesktop as g, TableDesktopFooter as h, type TableDesktopFooterProps as i, TableDesktopToolbar as j, type TableDesktopToolbarProps as k };
@@ -0,0 +1,67 @@
1
+ // src/utils/getSelectOptionFromKeyPress/getSelectOptionFromKeyPress.ts
2
+ var getNextCircularIndex = ({
3
+ isArrowUp,
4
+ currentIndex,
5
+ numOptions,
6
+ iteration
7
+ }) => {
8
+ const step = isArrowUp ? -iteration : iteration;
9
+ return (currentIndex + step + numOptions) % numOptions;
10
+ };
11
+ var getSelectOptionFromKeyPress = ({
12
+ key,
13
+ options,
14
+ currentValue
15
+ }) => {
16
+ const numOptions = options.length;
17
+ const isArrowUp = key === "ArrowUp";
18
+ const isArrowDown = key === "ArrowDown";
19
+ const isArrow = isArrowUp || isArrowDown;
20
+ const searchKey = key.toLowerCase();
21
+ if (!isArrow && searchKey.length !== 1) {
22
+ return void 0;
23
+ }
24
+ if (!numOptions) {
25
+ return void 0;
26
+ }
27
+ const currentIndex = options.findIndex((o) => o.value === currentValue);
28
+ const indicesToCheck = Array.from({ length: numOptions }).map(
29
+ (_, i) => getNextCircularIndex({
30
+ isArrowUp,
31
+ currentIndex,
32
+ numOptions,
33
+ iteration: i + 1
34
+ })
35
+ );
36
+ const nextMatchIndex = indicesToCheck.find((indexToCheck) => {
37
+ const option = options[indexToCheck];
38
+ return !option.disabled && (isArrow || option.label?.toLowerCase().startsWith(searchKey));
39
+ });
40
+ if (nextMatchIndex !== void 0 && nextMatchIndex !== currentIndex) {
41
+ return options[nextMatchIndex];
42
+ }
43
+ return void 0;
44
+ };
45
+
46
+ // src/utils/flattenTableFilters/flattenTableFilters.ts
47
+ var getFlattenedFiltersLabels = (filters, fieldName) => {
48
+ return filters.map((value) => {
49
+ if (typeof value === "object") {
50
+ return value[fieldName] ?? "";
51
+ }
52
+ return value;
53
+ });
54
+ };
55
+ var getFlattenedFiltersIds = (filters) => Object.fromEntries(
56
+ Object.entries(filters).map(([id, values]) => [
57
+ id,
58
+ values.map((value) => typeof value === "object" ? value.id : value)
59
+ ])
60
+ );
61
+
62
+ export {
63
+ getSelectOptionFromKeyPress,
64
+ getFlattenedFiltersLabels,
65
+ getFlattenedFiltersIds
66
+ };
67
+ //# sourceMappingURL=chunk-3UDYWCV6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/getSelectOptionFromKeyPress/getSelectOptionFromKeyPress.ts","../src/utils/flattenTableFilters/flattenTableFilters.ts"],"sourcesContent":["export interface NavigableOption {\n value?: string | number | null;\n label?: string;\n disabled?: boolean;\n}\n\nexport interface GetSelectOptionFromKeyPressParams<T extends NavigableOption> {\n key: string;\n options: T[];\n currentValue?: string | number | null;\n}\n\nconst getNextCircularIndex = ({\n isArrowUp,\n currentIndex,\n numOptions,\n iteration,\n}: {\n isArrowUp: boolean;\n currentIndex: number;\n numOptions: number;\n iteration: number;\n}) => {\n const step = isArrowUp ? -iteration : iteration;\n return (currentIndex + step + numOptions) % numOptions;\n};\n\nexport const getSelectOptionFromKeyPress = <T extends NavigableOption>({\n key,\n options,\n currentValue,\n}: GetSelectOptionFromKeyPressParams<T>): T | undefined => {\n const numOptions = options.length;\n const isArrowUp = key === 'ArrowUp';\n const isArrowDown = key === 'ArrowDown';\n const isArrow = isArrowUp || isArrowDown;\n const searchKey = key.toLowerCase();\n\n // Ignores any input that is not ArrowUp, ArrowDown or a single character.\n if (!isArrow && searchKey.length !== 1) {\n return undefined;\n }\n\n if (!numOptions) {\n return undefined;\n }\n\n const currentIndex = options.findIndex((o) => o.value === currentValue);\n\n // Generates a circular sequence of indices starting from the next item.\n // This ensures that pressing the same key repeatedly cycles through all matching options.\n const indicesToCheck = Array.from({ length: numOptions }).map((_, i) =>\n getNextCircularIndex({\n isArrowUp,\n currentIndex,\n numOptions,\n iteration: i + 1,\n }),\n );\n\n const nextMatchIndex = indicesToCheck.find((indexToCheck) => {\n const option = options[indexToCheck];\n return (\n !option.disabled &&\n (isArrow || option.label?.toLowerCase().startsWith(searchKey))\n );\n });\n\n if (nextMatchIndex !== undefined && nextMatchIndex !== currentIndex) {\n return options[nextMatchIndex];\n }\n\n return undefined;\n};\n","import {\n HeaderFilterObject,\n HeaderFilters,\n} from '@/components/TableDesktop/TableDesktop';\n\nexport type FlattenedFilterIds = {\n [key: string]: (string | number)[];\n};\n\nexport const getFlattenedFiltersLabels = (\n filters: string[] | HeaderFilterObject[],\n fieldName: string,\n): (string | number)[] => {\n return filters.map((value: string | HeaderFilterObject) => {\n if (typeof value === 'object') {\n return value[fieldName] ?? '';\n }\n return value;\n });\n};\n\nexport const getFlattenedFiltersIds = (\n filters: HeaderFilters,\n): FlattenedFilterIds =>\n Object.fromEntries(\n Object.entries(filters).map(([id, values]) => [\n id,\n values.map((value) => (typeof value === 'object' ? value.id : value)),\n ]),\n );\n"],"mappings":";AAYA,IAAM,uBAAuB,CAAC;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,QAAM,OAAO,YAAY,CAAC,YAAY;AACtC,UAAQ,eAAe,OAAO,cAAc;AAC9C;AAEO,IAAM,8BAA8B,CAA4B;AAAA,EACrE;AAAA,EACA;AAAA,EACA;AACF,MAA2D;AACzD,QAAM,aAAa,QAAQ;AAC3B,QAAM,YAAY,QAAQ;AAC1B,QAA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