@inceptionbg/iui 2.0.16 → 2.0.19

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.
Files changed (61) hide show
  1. package/dist/index.d.ts +156 -89
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/iui.css +1 -1
  5. package/package.json +3 -5
  6. package/src/assets/icons/duotone/faBell.ts +17 -0
  7. package/src/assets/icons/light/faBell.ts +15 -0
  8. package/src/assets/icons/light/faEnvelope.ts +15 -0
  9. package/src/assets/icons/solid/faEnvelopeDot.ts +15 -0
  10. package/src/components/Button/SplitButton.tsx +5 -5
  11. package/src/components/Header/Components/ModuleSelect.tsx +5 -5
  12. package/src/components/Header/Components/Notifications.tsx +208 -0
  13. package/src/components/Header/Header.tsx +5 -4
  14. package/src/components/Inputs/NumberInput.tsx +3 -0
  15. package/src/components/Inputs/Selects/components/SelectWrapper.tsx +20 -30
  16. package/src/components/Loader/ProgressBar.tsx +1 -1
  17. package/src/components/Pullover/Pullover.tsx +44 -33
  18. package/src/components/Table/Table.tsx +5 -3
  19. package/src/components/Table/components/columns/TableColumnsEdit.tsx +5 -9
  20. package/src/components/Table/components/edit/TableEditRow.tsx +23 -12
  21. package/src/components/Table/components/header/TableHeaderRow.tsx +1 -0
  22. package/src/components/Table/components/items/TableItemActions.tsx +14 -13
  23. package/src/components/Table/components/print/TablePrint.tsx +1 -5
  24. package/src/components/Table/components/templates/CreateTemplateDialog.tsx +48 -0
  25. package/src/components/Table/components/templates/TableTemplates.tsx +24 -4
  26. package/src/components/Table/contexts/TableContext.tsx +33 -24
  27. package/src/components/Table/hooks/localHooks/useLocalTableColumns.tsx +6 -4
  28. package/src/components/Table/hooks/localHooks/useLocalTableData.tsx +17 -11
  29. package/src/components/Table/hooks/localHooks/useLocalTableKeyboard.ts +8 -6
  30. package/src/components/Table/hooks/useTableColumns.ts +1 -3
  31. package/src/components/Table/hooks/useTableEdit.tsx +24 -2
  32. package/src/components/Table/hooks/useTablePrint.ts +12 -4
  33. package/src/components/Table/hooks/useTableSelect.ts +1 -1
  34. package/src/components/Tooltip/Tooltip.tsx +81 -14
  35. package/src/components/Wrappers/FormWrapper.tsx +1 -1
  36. package/src/hooks/useIsMenuOpen.ts +3 -3
  37. package/src/hooks/usePopupControl.ts +9 -4
  38. package/src/index.ts +23 -4
  39. package/src/styles/App.scss +1 -0
  40. package/src/styles/components/_accordions.scss +1 -0
  41. package/src/styles/components/_badge.scss +7 -0
  42. package/src/styles/components/_header.scss +14 -1
  43. package/src/styles/components/_notifications.scss +71 -0
  44. package/src/styles/components/_page.scss +1 -0
  45. package/src/styles/components/_pullover.scss +1 -1
  46. package/src/styles/components/_sidebar.scss +1 -3
  47. package/src/styles/components/_table.scss +96 -54
  48. package/src/types/IKeyboard.ts +0 -5
  49. package/src/types/IMenu.ts +2 -2
  50. package/src/types/INotifications.ts +15 -0
  51. package/src/types/IPopup.ts +2 -2
  52. package/src/types/ISelect.ts +1 -0
  53. package/src/types/ITable.ts +35 -32
  54. package/src/utils/i18n/i18nIUICyrilic.ts +12 -0
  55. package/src/utils/i18n/i18nIUILatin.ts +13 -0
  56. package/src/utils/i18n/i18nIUIMe.ts +12 -0
  57. package/src/utils/objectUtils.ts +19 -0
  58. package/src/utils/tableUtils.ts +1 -1
  59. package/idea/Notifications.tsx +0 -245
  60. package/idea/Table/Components/Columns/ColumnsList.tsx +0 -61
  61. package/idea/Table/Components/Columns/SetColumnsList.tsx +0 -113
@@ -2,14 +2,14 @@ import { ComponentProps, FC, ReactNode } from 'react';
2
2
  import { UserMenu } from './Components/UserMenu';
3
3
  import { ModuleSelect } from './Components/ModuleSelect';
4
4
  import { IHeaderUserMenuProps } from '../../types/IHeader';
5
+ import { INotificationsProps, Notifications } from './Components/Notifications';
5
6
 
6
7
  interface Props {
7
8
  customTitle?: string;
8
9
  modulesProps?: ComponentProps<typeof ModuleSelect>;
9
- // actions: {
10
- // icon: IconDefinition;
11
- // };
10
+ // actions: { icon: IconDefinition };
12
11
  userMenuProps: IHeaderUserMenuProps;
12
+ notificationsProps?: INotificationsProps;
13
13
  children?: ReactNode;
14
14
  }
15
15
 
@@ -17,6 +17,7 @@ export const Header: FC<Props> = ({
17
17
  customTitle,
18
18
  modulesProps,
19
19
  userMenuProps,
20
+ notificationsProps,
20
21
  children,
21
22
  }) => (
22
23
  <div className="iui-header">
@@ -24,7 +25,7 @@ export const Header: FC<Props> = ({
24
25
  {customTitle && <h3 className="ml-3">{customTitle}</h3>}
25
26
  <div className="flex gap-2 align-center">
26
27
  {children}
27
- {/* {!hideNotifications && <Notifications />} */}
28
+ {notificationsProps && <Notifications {...notificationsProps} />}
28
29
  <UserMenu {...userMenuProps} />
29
30
  </div>
30
31
  </div>
@@ -11,6 +11,7 @@ export interface INumberInputProps {
11
11
  placeholder?: string;
12
12
  endText?: string;
13
13
  isClearable?: boolean;
14
+ onClear?: () => void;
14
15
  helperText?: string;
15
16
  errorText?: string;
16
17
  error?: boolean;
@@ -32,6 +33,7 @@ export const NumberInput: FC<INumberInputProps> = ({
32
33
  placeholder,
33
34
  endText,
34
35
  isClearable,
36
+ onClear,
35
37
  helperText,
36
38
  errorText,
37
39
  error,
@@ -64,6 +66,7 @@ export const NumberInput: FC<INumberInputProps> = ({
64
66
  disabled={disabled}
65
67
  endText={endText}
66
68
  isClearable={isClearable}
69
+ onClear={onClear}
67
70
  placeholder={
68
71
  placeholder ? placeholder : decimalPlaces ? `0.${'0'.repeat(decimalPlaces)}` : '0'
69
72
  }
@@ -68,35 +68,6 @@ export const SelectWrapper = forwardRef<any, ISelectProps>((props, forwardedRef)
68
68
  formatOptionLabel,
69
69
  };
70
70
 
71
- const renderSelect = () => {
72
- switch (variant) {
73
- case 'basic':
74
- return <ReactSelect {...commonProps} options={props.options} />;
75
- case 'async':
76
- return (
77
- <AsyncPaginate
78
- {...commonProps}
79
- loadOptions={props.loadOptions}
80
- defaultOptions={props.defaultData ?? true}
81
- />
82
- );
83
- case 'async-creatable':
84
- return (
85
- <AsyncCreatableSelect
86
- {...commonProps}
87
- loadOptions={props.loadOptions}
88
- defaultOptions={props.defaultData ?? true}
89
- onCreateOption={props.onCreate}
90
- formatCreateLabel={(inputValue: string) => (
91
- <p>{`${t('FreeText')} "${inputValue}"`}</p>
92
- )}
93
- />
94
- );
95
- default:
96
- return null;
97
- }
98
- };
99
-
100
71
  return (
101
72
  <InputWrapper
102
73
  label={label}
@@ -109,7 +80,26 @@ export const SelectWrapper = forwardRef<any, ISelectProps>((props, forwardedRef)
109
80
  minWidth={minWidth}
110
81
  heightAuto
111
82
  >
112
- {renderSelect()}
83
+ {variant === 'async' ? (
84
+ <AsyncPaginate
85
+ {...commonProps}
86
+ loadOptions={props.loadOptions}
87
+ defaultOptions={props.defaultData ?? false}
88
+ cacheUniqs={props.refresh}
89
+ />
90
+ ) : variant === 'async-creatable' ? (
91
+ <AsyncCreatableSelect
92
+ {...commonProps}
93
+ loadOptions={props.loadOptions}
94
+ defaultOptions={props.defaultData ?? false}
95
+ onCreateOption={props.onCreate}
96
+ formatCreateLabel={(inputValue: string) => (
97
+ <p>{`${t('FreeText')} "${inputValue}"`}</p>
98
+ )}
99
+ />
100
+ ) : (
101
+ <ReactSelect {...commonProps} options={props.options} />
102
+ )}
113
103
  {required && !disabled && (
114
104
  <input
115
105
  className="fake-input"
@@ -27,7 +27,7 @@ export const ProgressBar: FC<Props> = ({ progress, label }) => {
27
27
  {
28
28
  '--progress-clip': `${now}%`,
29
29
  '--progress-text': `'${now}%'`,
30
- } as CSSProperties
30
+ } as CSSProperties & { [key: string]: string }
31
31
  }
32
32
  >
33
33
  <div
@@ -13,6 +13,8 @@ import { onPopupKeyDown } from '../../utils/popupUtils';
13
13
  import { ILocalPopupControl } from '../../types/IPopup';
14
14
  import { Loader } from '../Loader/Loader';
15
15
  import { SplitButton } from '../Button/SplitButton';
16
+ import { IconButton } from '../Button/IconButton';
17
+ import { faXmark } from '../../assets/icons';
16
18
 
17
19
  interface Props {
18
20
  id?: string;
@@ -108,13 +110,16 @@ export const Pullover: FC<Props> = ({
108
110
  {header && (
109
111
  <div className="pullover-header no-print">
110
112
  <h3>{header.title}</h3>
111
- {header.onSearch && (
112
- <SearchInput
113
- ref={searchRef}
114
- onSearch={header.onSearch}
115
- className="search-input"
116
- />
117
- )}
113
+ <div className="flex gap-2">
114
+ {header.onSearch && (
115
+ <SearchInput
116
+ ref={searchRef}
117
+ onSearch={header.onSearch}
118
+ className="search-input"
119
+ />
120
+ )}
121
+ <IconButton icon={faXmark} onClick={onClose} color="neutral" />
122
+ </div>
118
123
  </div>
119
124
  )}
120
125
  <ConditionalWrapper
@@ -147,34 +152,40 @@ export const Pullover: FC<Props> = ({
147
152
  )}
148
153
 
149
154
  {/* FOOTER */}
150
- <div className={clsx('pullover-footer no-print', className)}>
151
- {footer?.additionalButton && (
155
+ {footer && (
156
+ <div className={clsx('pullover-footer no-print', className)}>
157
+ {footer.additionalButton && (
158
+ <Button
159
+ {...footer.additionalButton}
160
+ disabled={
161
+ footer.additionalButton.disabled || isFetching || isLoading
162
+ }
163
+ variant="simple"
164
+ className="mr-auto"
165
+ />
166
+ )}
152
167
  <Button
153
- {...footer.additionalButton}
154
- disabled={
155
- footer.additionalButton.disabled || isFetching || isLoading
156
- }
157
- variant="simple"
158
- className="mr-auto"
159
- />
160
- )}
161
- <Button
162
- label={t(footer ? 'Cancel' : 'Close')}
163
- variant="outlined"
164
- onClick={onClose}
165
- disabled={isFetching || isLoading}
166
- />
167
- {footer?.confirmButton && (
168
- <ConfirmButton
169
- {...footer.confirmButton}
170
- label={footer.confirmButton.label ?? t('Confirm')}
171
- disabled={footer.confirmButton.disabled || isFetching || isLoading}
172
- type={
173
- (footer.confirmButton.type ?? onFormSubmit) ? 'submit' : 'button'
174
- }
168
+ label={t('Cancel')}
169
+ variant="outlined"
170
+ onClick={onClose}
171
+ disabled={isFetching || isLoading}
175
172
  />
176
- )}
177
- </div>
173
+ {footer.confirmButton && (
174
+ <ConfirmButton
175
+ {...footer.confirmButton}
176
+ label={footer.confirmButton.label ?? t('Confirm')}
177
+ disabled={
178
+ footer.confirmButton.disabled || isFetching || isLoading
179
+ }
180
+ type={
181
+ (footer.confirmButton.type ?? onFormSubmit)
182
+ ? 'submit'
183
+ : 'button'
184
+ }
185
+ />
186
+ )}
187
+ </div>
188
+ )}
178
189
  </ConditionalWrapper>
179
190
  </div>
180
191
  </div>
@@ -155,8 +155,9 @@ export const TableContent: FC = () => {
155
155
  cell?.className,
156
156
  rowHeight,
157
157
  {
158
+ 'sticky-column': column.sticky,
158
159
  link: cell?.link,
159
- 'clickable-column': cell?.onClick,
160
+ 'clickable-cell': cell?.onClick,
160
161
  'word-break': column.break,
161
162
  }
162
163
  )}
@@ -249,8 +250,9 @@ export const TableContent: FC = () => {
249
250
  );
250
251
  };
251
252
 
252
- export const Table: FC<ITable> = props => (
253
- <TableProvider {...props}>
253
+ export const Table = <T,>(props: ITable<T>) => (
254
+ <TableProvider<T> {...props}>
254
255
  <TableContent />
256
+ {props.itemDeleteData?.DeleteDialog}
255
257
  </TableProvider>
256
258
  );
@@ -20,7 +20,7 @@ export const TableColumnsEdit: FC = () => {
20
20
 
21
21
  const { t } = useTranslation();
22
22
  const {
23
- columnData: { defaultColumns, setColumns },
23
+ columnData: { columns, setColumns },
24
24
  } = useTableContext();
25
25
  const { control, onClose, onOpen } = usePopupControl();
26
26
 
@@ -28,13 +28,13 @@ export const TableColumnsEdit: FC = () => {
28
28
  if (control.isOpen) {
29
29
  let hiddenCols: ITableColumn[] = [];
30
30
  let visibleCols: ITableColumn[] = [];
31
- defaultColumns.forEach(col =>
31
+ columns.forEach(col =>
32
32
  !!col.hidden ? hiddenCols.push(col) : visibleCols.push(col)
33
33
  );
34
34
  setHidden(hiddenCols);
35
35
  setVisible(visibleCols);
36
36
  }
37
- }, [control.isOpen, defaultColumns]);
37
+ }, [control.isOpen, columns]);
38
38
 
39
39
  const onDragEnd = ({ source, destination }: DropResult) => {
40
40
  if (!destination) return;
@@ -79,6 +79,7 @@ export const TableColumnsEdit: FC = () => {
79
79
  <Pullover
80
80
  control={control}
81
81
  header={{ title: t('Columns') }}
82
+ className="column-pullover"
82
83
  footer={{
83
84
  confirmButton: {
84
85
  label: t('Confirm'),
@@ -93,19 +94,14 @@ export const TableColumnsEdit: FC = () => {
93
94
  <div />
94
95
  <p className="bold ml-2">{t('SelectedColumns')}:</p>
95
96
 
96
- {/* {withSearch && (
97
- <> */}
98
97
  <SearchInput onSearch={setSearchHidden} />
99
98
  <div />
100
99
  <SearchInput onSearch={setSearchVisible} />
101
- {/* </>
102
- )} */}
103
- <ColumnsList id="hidden" items={hidden} search={searchHidden} />
104
100
 
101
+ <ColumnsList id="hidden" items={hidden} search={searchHidden} />
105
102
  <div className="exchange-icon">
106
103
  <FontAwesomeIcon icon={faArrowRightArrowLeft} />
107
104
  </div>
108
-
109
105
  <ColumnsList id="visible" items={visible} search={searchVisible} />
110
106
  </div>
111
107
  </div>
@@ -4,6 +4,7 @@ import { IconButton } from '../../../Button/IconButton';
4
4
  import { faCheck, faXmark } from '../../../../assets/icons';
5
5
  import { useTableContext } from '../../contexts/TableContext';
6
6
  import { useGetFocusableElements } from '../../../../hooks/useGetFocusableElements';
7
+ import clsx from 'clsx';
7
8
 
8
9
  export const TableEditRow: FC<{ columns: ITableColumn[] }> = ({ columns }) => {
9
10
  const { editable } = useTableContext();
@@ -20,7 +21,9 @@ export const TableEditRow: FC<{ columns: ITableColumn[] }> = ({ columns }) => {
20
21
  }, [focusableElements]);
21
22
 
22
23
  useEffect(() => {
23
- editable!.setEditData(editable!.selectedItem ?? editable!.defaultDataValue ?? {});
24
+ editable!.setEditData(
25
+ editable!.selectedItem?.item ?? editable!.defaultDataValue ?? {}
26
+ );
24
27
  // eslint-disable-next-line
25
28
  }, [editable?.setEditData, editable?.selectedItem, editable?.defaultDataValue]);
26
29
 
@@ -47,20 +50,28 @@ export const TableEditRow: FC<{ columns: ITableColumn[] }> = ({ columns }) => {
47
50
  },
48
51
  };
49
52
 
50
- const rowData: ITableDataItem = { uuid: editable?.selectedItem?.uuid, cells: rowCells };
53
+ const rowData: ITableDataItem = {
54
+ uuid: editable?.selectedItem?.uuid as string,
55
+ cells: rowCells,
56
+ };
51
57
 
52
58
  return (
53
59
  <tr ref={elementRef} data-id={rowData.uuid} className="edit-row">
54
- {columns.map(column => (
55
- <td
56
- key={column.id}
57
- align={column.align}
58
- colSpan={rowData.cells[column.id]?.span}
59
- className={rowData.cells[column.id]?.className}
60
- >
61
- {rowData.cells[column.id]?.value ?? ''}
62
- </td>
63
- ))}
60
+ {columns.map(column => {
61
+ const item = rowData.cells[column.id];
62
+ return (
63
+ <td
64
+ key={column.id}
65
+ align={column.align}
66
+ colSpan={item?.span}
67
+ className={clsx(item?.className, {
68
+ editable: typeof item?.value === 'object',
69
+ })}
70
+ >
71
+ {item?.value ?? ''}
72
+ </td>
73
+ );
74
+ })}
64
75
  </tr>
65
76
  );
66
77
  };
@@ -23,6 +23,7 @@ export const TableHeaderRow: FC<Props> = ({ row, print }) => {
23
23
  print
24
24
  ? undefined
25
25
  : clsx(col.color, col.className, {
26
+ 'sticky-column': col.sticky,
26
27
  'not-first-cell': col.notFirstCell,
27
28
  })
28
29
  }
@@ -6,12 +6,12 @@ import { useIsMenuOpen } from '../../../../hooks/useIsMenuOpen';
6
6
  import { Menu } from '../../../Menu/Menu';
7
7
  import { ITableDataItem } from '../../../../types/ITable';
8
8
 
9
- export const TableItemActions: FC<{ tableDataItem: ITableDataItem }> = ({
9
+ export const TableItemActions: FC<{ tableDataItem: ITableDataItem<any> }> = ({
10
10
  tableDataItem,
11
11
  }) => {
12
- const { isMenuOpen, onMenuClose, onMenuOpen } = useIsMenuOpen();
12
+ const { isOpen, onClose, onOpen } = useIsMenuOpen();
13
13
 
14
- const { dataActions, editable } = useTableContext();
14
+ const { dataActions, itemDeleteData, editable } = useTableContext();
15
15
 
16
16
  if (!dataActions?.hasItemActions) {
17
17
  return null;
@@ -24,7 +24,7 @@ export const TableItemActions: FC<{ tableDataItem: ITableDataItem }> = ({
24
24
  icon={faPen}
25
25
  onClick={e => {
26
26
  e.stopPropagation();
27
- editable?.setSelectedItem(tableDataItem.item ?? null);
27
+ editable?.setSelectedItem(tableDataItem);
28
28
  }}
29
29
  size="s"
30
30
  />
@@ -34,37 +34,38 @@ export const TableItemActions: FC<{ tableDataItem: ITableDataItem }> = ({
34
34
  icon={faTrashCan}
35
35
  onClick={e => {
36
36
  e.stopPropagation();
37
- dataActions.delete?.onClick?.(tableDataItem.uuid);
37
+ itemDeleteData?.setItemToDeleteUuids([tableDataItem.uuid]);
38
38
  }}
39
39
  size="s"
40
40
  color="danger"
41
41
  />
42
42
  )}
43
43
 
44
- {!!dataActions.actions?.length && (
44
+ {!!dataActions.filteredActions?.length && (
45
45
  <Menu
46
- isOpen={isMenuOpen}
47
- onClose={onMenuClose}
46
+ isOpen={isOpen}
47
+ onClose={onClose}
48
48
  placement="bottom-right"
49
49
  renderButton={ref => (
50
50
  <IconButton
51
51
  ref={ref}
52
52
  icon={faEllipsisVertical}
53
- active={isMenuOpen}
53
+ active={isOpen}
54
54
  onClick={e => {
55
55
  e.stopPropagation();
56
- onMenuOpen();
56
+ onOpen();
57
57
  }}
58
58
  size="s"
59
59
  />
60
60
  )}
61
61
  items={
62
- dataActions.actions?.map(action => ({
62
+ dataActions.actions?.(tableDataItem.item)?.map(action => ({
63
63
  label: action.label,
64
64
  hidden: !action.hasAccess,
65
+ disabled: action.disabled,
65
66
  onClick: () => {
66
- action.onClick(tableDataItem);
67
- onMenuClose();
67
+ action.onClick();
68
+ onClose();
68
69
  },
69
70
  })) ?? []
70
71
  }
@@ -28,7 +28,6 @@ export const TablePrint: FC = () => {
28
28
  paginationControl,
29
29
  printPopupControl,
30
30
  customHeader,
31
- excludeColumnIds,
32
31
  filters,
33
32
  optionalNode,
34
33
  organization,
@@ -37,10 +36,7 @@ export const TablePrint: FC = () => {
37
36
  } = useMemo(() => (printData ?? {}) as IPrintData, [printData]);
38
37
  const { control, onOpen } = printPopupControl;
39
38
 
40
- const cols = useMemo(
41
- () => columns.filter(e => !['actions', 'select', excludeColumnIds].includes(e.id)),
42
- [columns, excludeColumnIds]
43
- );
39
+ const cols = useMemo(() => columns.filter(e => !e.hidden && !e.printHidden), [columns]);
44
40
 
45
41
  useEffect(() => {
46
42
  if (control.isOpen) {
@@ -0,0 +1,48 @@
1
+ import { useState, type FC } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import type { ILocalPopupControl } from '../../../../types/IPopup';
4
+ import type { IReportTemplate } from '../../../../types/ITable';
5
+ import { Dialog } from '../../../Dialog/Dialog';
6
+ import { TextInput } from '../../../Inputs/TextInput';
7
+ import { Checkbox } from '../../../Inputs/Checkbox';
8
+ import { useTableContext } from '../../contexts/TableContext';
9
+
10
+ interface Props {
11
+ control: ILocalPopupControl;
12
+ }
13
+
14
+ export const CreateTemplateDialog: FC<Props> = ({ control }) => {
15
+ const { t } = useTranslation();
16
+ const { templateData: { createItem } = {} } = useTableContext();
17
+
18
+ const [formData, setFormData] = useState<Partial<IReportTemplate>>({});
19
+
20
+ return (
21
+ <Dialog
22
+ title={t('CreateTemplateLong')}
23
+ control={control}
24
+ onFormSubmit={() => createItem?.onCreate(formData)}
25
+ footer={{
26
+ confirmButton: {
27
+ label: t('CreateTemplate'),
28
+ type: 'submit',
29
+ },
30
+ }}
31
+ onCloseCallback={() => setFormData({})}
32
+ >
33
+ <TextInput
34
+ label={t('TemplateName')}
35
+ required
36
+ value={formData.name}
37
+ setValue={name => setFormData({ ...formData, name })}
38
+ />
39
+ {createItem?.allowPublicCreate && (
40
+ <Checkbox
41
+ label={t('PublicTemplate')}
42
+ value={formData.isPublic}
43
+ setValue={isPublic => setFormData({ ...formData, isPublic })}
44
+ />
45
+ )}
46
+ </Dialog>
47
+ );
48
+ };
@@ -1,4 +1,4 @@
1
- import { type FC } from 'react';
1
+ import { useEffect, type FC } from 'react';
2
2
  import { IconButton } from '../../../Button/IconButton';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { useTableContext } from '../../contexts/TableContext';
@@ -6,11 +6,30 @@ import { faBookmark, faBookmarkSlash, faTrashCan } from '../../../../assets/icon
6
6
  import { Pullover } from '../../../Pullover/Pullover';
7
7
  import { List } from '../../../List/List';
8
8
  import { setTemplateData } from '../../../../utils/tableUtils';
9
+ import { usePopupControl } from '../../../../hooks/usePopupControl';
10
+ import { CreateTemplateDialog } from './CreateTemplateDialog';
9
11
 
10
12
  export const TableTemplates: FC = () => {
11
13
  const { t } = useTranslation();
12
14
  const { templateData, columnData, filterData, sortData } = useTableContext();
13
15
 
16
+ const createTemplatePopupController = usePopupControl();
17
+
18
+ useEffect(() => {
19
+ if (templateData?.defaultTemplate) {
20
+ setTemplateData({
21
+ template: templateData.defaultTemplate,
22
+ columnData,
23
+ setFilters: e => {
24
+ filterData?.setSearchData(e);
25
+ filterData?.onSearch(e);
26
+ },
27
+ setSort: sortData?.setSort,
28
+ });
29
+ }
30
+ // eslint-disable-next-line
31
+ }, [templateData?.defaultTemplate]);
32
+
14
33
  if (!templateData) return null;
15
34
 
16
35
  return (
@@ -34,12 +53,12 @@ export const TableTemplates: FC = () => {
34
53
  footer={{
35
54
  confirmButton: {
36
55
  label: t('CreateTemplate'),
37
- onClick: templateData.initiateCreate,
56
+ onClick: createTemplatePopupController.onOpen,
38
57
  splitActions: [
39
58
  {
40
59
  label: t('CreateDefaultTemplate'),
41
60
  icon: faBookmark,
42
- onClick: templateData.initiateCreateDefault,
61
+ onClick: templateData.createItem.onCreateDefault,
43
62
  },
44
63
  ],
45
64
  },
@@ -86,7 +105,8 @@ export const TableTemplates: FC = () => {
86
105
  noItemsMessage={t('NoTemplatesAvailable')}
87
106
  />
88
107
  </Pullover>
89
- {templateData.TemplateNode}
108
+ <CreateTemplateDialog control={createTemplatePopupController.control} />
109
+ {templateData.DeleteDialog}
90
110
  </>
91
111
  );
92
112
  };