@inceptionbg/iui 2.0.5 → 2.0.6

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 (253) hide show
  1. package/dist/icons/index.d.ts +43 -0
  2. package/dist/icons/index.js +1 -0
  3. package/dist/index.d.ts +24 -15
  4. package/dist/index.js +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/iui.css +1 -1
  7. package/idea/Menu/Menu.tsx +119 -0
  8. package/idea/Menu/MenuItem.tsx +74 -0
  9. package/idea/Menu/hooks/useMenuControl.ts +13 -0
  10. package/idea/Menu.tsx +132 -0
  11. package/idea/NoAccessInfo.tsx +193 -0
  12. package/idea/Notifications.tsx +245 -0
  13. package/idea/Table2/Components/Columns/ColumnsList.tsx +56 -0
  14. package/idea/Table2/Components/Columns/SetColumnsList.tsx +107 -0
  15. package/idea/Table2/Components/Edit/ItemActionsMenu.tsx +87 -0
  16. package/idea/Table2/Components/Edit/ItemEditOptionsButtons.tsx +32 -0
  17. package/idea/Table2/Components/Edit/TableEditRow.tsx +56 -0
  18. package/idea/Table2/Components/FilterItem.tsx +20 -0
  19. package/idea/Table2/Components/Header/TableHeader.tsx +35 -0
  20. package/idea/Table2/Components/Header/TableHeaderRow.tsx +37 -0
  21. package/idea/Table2/Components/Print/CustomTablePrint.tsx +119 -0
  22. package/idea/Table2/Components/Print/TablePrint.tsx +208 -0
  23. package/idea/Table2/Components/SetSortList.tsx +33 -0
  24. package/idea/Table2/Components/SetTableFilter.tsx +90 -0
  25. package/idea/Table2/Components/TableFooter.tsx +107 -0
  26. package/idea/Table2/Components/TableOptions.tsx +211 -0
  27. package/idea/Table2/Components/Templates/TemplateCreate.tsx +75 -0
  28. package/idea/Table2/Components/Templates/TemplateCreateDefault.tsx +45 -0
  29. package/idea/Table2/Components/Templates/TemplateList.tsx +167 -0
  30. package/idea/Table2/Components/Templates/repo/TemplateRepo.ts +51 -0
  31. package/idea/Table2/Table.tsx +657 -0
  32. package/idea/Table2/_table.scss +300 -0
  33. package/idea/Table2/hooks/useDefaultTemplate.ts +22 -0
  34. package/idea/Table2/hooks/useTableKeyboard.ts +115 -0
  35. package/package.json +8 -4
  36. package/rollup.config.js +80 -0
  37. package/src/assets/icons/duotone/faCircleUser.ts +17 -0
  38. package/src/assets/icons/index.ts +20 -0
  39. package/src/assets/icons/light/faArrowDownShortWide.ts +15 -0
  40. package/src/assets/icons/light/faArrowDownWideShort.ts +15 -0
  41. package/src/assets/icons/light/faArrowUpArrowDown.ts +15 -0
  42. package/src/assets/icons/light/faArrowUpRightFromSquare.ts +15 -0
  43. package/src/assets/icons/light/faArrowsToLine.ts +15 -0
  44. package/src/assets/icons/light/faArrowsUpDown.ts +15 -0
  45. package/src/assets/icons/light/faCalendarPlus.ts +15 -0
  46. package/src/assets/icons/light/faCheck.ts +15 -0
  47. package/src/assets/icons/light/faChevronDown.ts +15 -0
  48. package/src/assets/icons/light/faChevronRight.ts +15 -0
  49. package/src/assets/icons/light/faCircleInfo.ts +15 -0
  50. package/src/assets/icons/light/faCircleXmark.ts +15 -0
  51. package/src/assets/icons/light/faClockRotateLeft.ts +15 -0
  52. package/src/assets/icons/light/faEllipsisVertical.ts +15 -0
  53. package/src/assets/icons/light/faEye.ts +15 -0
  54. package/src/assets/icons/light/faEyeSlash.ts +15 -0
  55. package/src/assets/icons/light/faFilter.ts +15 -0
  56. package/src/assets/icons/light/faGear.ts +15 -0
  57. package/src/assets/icons/light/faHouse.ts +15 -0
  58. package/src/assets/icons/light/faIdBadge.ts +15 -0
  59. package/src/assets/icons/light/faLineColumns.ts +15 -0
  60. package/src/assets/icons/light/faLink.ts +15 -0
  61. package/src/assets/icons/light/faMagnifyingGlass.ts +15 -0
  62. package/src/assets/icons/light/faPenField.ts +15 -0
  63. package/src/assets/icons/light/faPrint.ts +15 -0
  64. package/src/assets/icons/light/faQuestion.ts +15 -0
  65. package/src/assets/icons/light/faRotateRight.ts +15 -0
  66. package/src/assets/icons/light/faTrashCan.ts +15 -0
  67. package/src/assets/icons/light/faTriangleExclamation.ts +15 -0
  68. package/src/assets/icons/light/faXmark.ts +15 -0
  69. package/src/assets/icons/regular/faArrowLeft.ts +15 -0
  70. package/src/assets/icons/regular/faArrowRightArrowLeft.ts +15 -0
  71. package/src/assets/icons/regular/faCircleCheck.ts +15 -0
  72. package/src/assets/icons/regular/faCircleExclamation.ts +15 -0
  73. package/src/assets/icons/regular/faCircleInfo.ts +15 -0
  74. package/src/assets/icons/regular/faFileArrowDown.ts +15 -0
  75. package/src/assets/icons/regular/faFilterCircleXmark.ts +15 -0
  76. package/src/assets/icons/regular/faTriangleExclamation.ts +15 -0
  77. package/src/assets/icons/solid/faAngleLeft.ts +15 -0
  78. package/src/assets/icons/solid/faAngleRight.ts +15 -0
  79. package/src/assets/icons/solid/faArrowDownWideShort.ts +15 -0
  80. package/src/assets/icons/solid/faCaretDown.ts +15 -0
  81. package/src/assets/icons/solid/faCheck.ts +15 -0
  82. package/src/assets/icons/solid/faEllipsisVertical.ts +15 -0
  83. package/src/assets/icons/solid/faFilter.ts +15 -0
  84. package/src/assets/icons/solid/faFloppyDisk.ts +15 -0
  85. package/src/assets/icons/solid/faGripDotsVertical.ts +15 -0
  86. package/src/assets/icons/solid/faListUl.ts +15 -0
  87. package/src/assets/icons/solid/faMagnifyingGlass.ts +15 -0
  88. package/src/assets/icons/solid/faMinus.ts +15 -0
  89. package/src/assets/icons/solid/faPlus.ts +15 -0
  90. package/src/assets/icons/solid/faPrint.ts +15 -0
  91. package/src/assets/icons/solid/faRotateRight.ts +15 -0
  92. package/src/assets/icons/solid/faXmark.ts +15 -0
  93. package/src/assets/images/logo/mts.svg +5703 -0
  94. package/src/assets/images/logo/paperless.svg +21 -0
  95. package/src/assets/images/logo/pismonosa.png +0 -0
  96. package/src/assets/images/not-found.svg +19 -0
  97. package/src/components/Accordions/Accordions.tsx +64 -0
  98. package/src/components/Alert/Alert.tsx +31 -0
  99. package/src/components/Badge/DotBadge.tsx +16 -0
  100. package/src/components/Badge/NotificationBadge.tsx +29 -0
  101. package/src/components/Badge/PillBadge.tsx +13 -0
  102. package/src/components/Button/Button.tsx +56 -0
  103. package/src/components/Button/IconButton.tsx +49 -0
  104. package/src/components/Dashboard/Dashboard.tsx +9 -0
  105. package/src/components/Dashboard/DashboardWidget.tsx +44 -0
  106. package/src/components/Dashboard/FastLinksWidget/FastLinksWidget.tsx +37 -0
  107. package/src/components/Dialog/DeleteItemDialog.tsx +52 -0
  108. package/src/components/Dialog/Dialog.tsx +226 -0
  109. package/src/components/Dialog/hooks/useDialogKeyboard.ts +41 -0
  110. package/src/components/Dialog/hooks/useDialogObserver.ts +21 -0
  111. package/src/components/Header/Components/ModuleSelect.tsx +55 -0
  112. package/src/components/Header/Components/UserMenu.tsx +44 -0
  113. package/src/components/Header/Header.tsx +36 -0
  114. package/src/components/Helper/Collapse.tsx +52 -0
  115. package/src/components/Inputs/Checkbox.tsx +53 -0
  116. package/src/components/Inputs/CurrencyInput.tsx +123 -0
  117. package/src/components/Inputs/DateInput/DateInput.tsx +176 -0
  118. package/src/components/Inputs/DateInput/components/DatePartInput.tsx +154 -0
  119. package/src/components/Inputs/InputWrapper.tsx +90 -0
  120. package/src/components/Inputs/NumberInput.tsx +83 -0
  121. package/src/components/Inputs/PasswordInput.tsx +38 -0
  122. package/src/components/Inputs/Radio.tsx +59 -0
  123. package/src/components/Inputs/RadioGroup.tsx +48 -0
  124. package/src/components/Inputs/RadioLarge.tsx +39 -0
  125. package/src/components/Inputs/SearchInput.tsx +40 -0
  126. package/src/components/Inputs/Select2/Select.tsx +224 -0
  127. package/src/components/Inputs/Select2/select.scss +43 -0
  128. package/src/components/Inputs/Selects/Select.tsx +17 -0
  129. package/src/components/Inputs/Selects/components/CustomSelectComponents.tsx +19 -0
  130. package/src/components/Inputs/Selects/components/SelectWrapper.tsx +126 -0
  131. package/src/components/Inputs/Selects/utils/selectStyles.ts +104 -0
  132. package/src/components/Inputs/TextAreaInput.tsx +67 -0
  133. package/src/components/Inputs/TextInput.tsx +98 -0
  134. package/src/components/Inputs/TimeInput/TimeInput.tsx +81 -0
  135. package/src/components/Loader/Loader.tsx +53 -0
  136. package/src/components/Menu/Menu.tsx +68 -0
  137. package/src/components/Menu/MenuItem.tsx +47 -0
  138. package/src/components/Menu/NewMenu.tsx +66 -0
  139. package/src/components/Menu/hooks/useMenuPosition.tsx +80 -0
  140. package/src/components/Pullover/Pullover.tsx +89 -0
  141. package/src/components/Router/Router.tsx +51 -0
  142. package/src/components/Sidebar/AddButton.tsx +22 -0
  143. package/src/components/Sidebar/Sidebar.tsx +81 -0
  144. package/src/components/Sidebar/SidebarItem.tsx +84 -0
  145. package/src/components/Sidebar/types/ISidebar.ts +28 -0
  146. package/src/components/Table/Components/Columns/ColumnsList.tsx +61 -0
  147. package/src/components/Table/Components/Columns/SetColumnsList.tsx +113 -0
  148. package/src/components/Table/Components/Edit/ItemActionsMenu.tsx +84 -0
  149. package/src/components/Table/Components/Edit/ItemEditOptionsButtons.tsx +31 -0
  150. package/src/components/Table/Components/Edit/TableEditRow.tsx +56 -0
  151. package/src/components/Table/Components/FilterItem.tsx +20 -0
  152. package/src/components/Table/Components/Header/TableHeader.tsx +45 -0
  153. package/src/components/Table/Components/Header/TableHeaderRow.tsx +37 -0
  154. package/src/components/Table/Components/Print/CustomTablePrint.tsx +114 -0
  155. package/src/components/Table/Components/Print/TablePrint.tsx +207 -0
  156. package/src/components/Table/Components/SetSortList.tsx +30 -0
  157. package/src/components/Table/Components/SetTableFilter.tsx +90 -0
  158. package/src/components/Table/Components/TableFooter.tsx +135 -0
  159. package/src/components/Table/Components/TableOptions.tsx +226 -0
  160. package/src/components/Table/Components/Templates/TemplateCreate.tsx +80 -0
  161. package/src/components/Table/Components/Templates/TemplateCreateDefault.tsx +45 -0
  162. package/src/components/Table/Components/Templates/TemplateList.tsx +167 -0
  163. package/src/components/Table/Components/Templates/repo/TemplateRepo.ts +53 -0
  164. package/src/components/Table/Table.tsx +527 -0
  165. package/src/components/Table/hooks/useDefaultTemplate.ts +20 -0
  166. package/src/components/Table/hooks/useTableKeyboard.ts +138 -0
  167. package/src/components/Table/hooks/useTableSelect.ts +11 -0
  168. package/src/components/Tabs/Tabs.tsx +66 -0
  169. package/src/components/Tooltip/Tooltip.tsx +133 -0
  170. package/src/components/Tree/Tree.tsx +22 -0
  171. package/src/components/Tree/TreeItem.tsx +56 -0
  172. package/src/components/Wrappers/AppLayout.tsx +17 -0
  173. package/src/components/Wrappers/ConditionalWrapper.tsx +10 -0
  174. package/src/components/Wrappers/FormWrapper.tsx +81 -0
  175. package/src/components/Wrappers/PageLayout.tsx +152 -0
  176. package/src/hooks/useBackgroundClose.ts +18 -0
  177. package/src/hooks/useIsMenuOpen.ts +11 -0
  178. package/src/hooks/useOnEsc.ts +14 -0
  179. package/src/hooks/useZendesk.ts +21 -0
  180. package/src/index.ts +324 -0
  181. package/src/pages/NoAccessPage.tsx +27 -0
  182. package/src/pages/NotFoundPage.tsx +26 -0
  183. package/src/styles/App.scss +43 -0
  184. package/src/styles/common/_animations.scss +64 -0
  185. package/src/styles/common/_typography.scss +88 -0
  186. package/src/styles/common/helpers/_base.scss +55 -0
  187. package/src/styles/common/helpers/_color.scss +7 -0
  188. package/src/styles/common/helpers/_display.scss +85 -0
  189. package/src/styles/common/helpers/_size.scss +25 -0
  190. package/src/styles/common/maps/_align.scss +21 -0
  191. package/src/styles/common/maps/_info-types.scss +1 -0
  192. package/src/styles/common/maps/_spacing.scss +78 -0
  193. package/src/styles/common/maps/_text.scss +14 -0
  194. package/src/styles/components/_accordions.scss +46 -0
  195. package/src/styles/components/_alert.scss +23 -0
  196. package/src/styles/components/_badge.scss +76 -0
  197. package/src/styles/components/_button.scss +138 -0
  198. package/src/styles/components/_card.scss +24 -0
  199. package/src/styles/components/_dialog.scss +111 -0
  200. package/src/styles/components/_form.scss +8 -0
  201. package/src/styles/components/_header.scss +109 -0
  202. package/src/styles/components/_input.scss +158 -0
  203. package/src/styles/components/_inputCheckbox.scss +105 -0
  204. package/src/styles/components/_inputDateTime.scss +161 -0
  205. package/src/styles/components/_inputRadio.scss +83 -0
  206. package/src/styles/components/_inputSelect.scss +6 -0
  207. package/src/styles/components/_loader.scss +44 -0
  208. package/src/styles/components/_menu-v2.scss +67 -0
  209. package/src/styles/components/_menu.scss +53 -0
  210. package/src/styles/components/_page.scss +62 -0
  211. package/src/styles/components/_portal.scss +8 -0
  212. package/src/styles/components/_print.scss +87 -0
  213. package/src/styles/components/_pullover.scss +43 -0
  214. package/src/styles/components/_scrollbar.scss +18 -0
  215. package/src/styles/components/_sidebar.scss +206 -0
  216. package/src/styles/components/_smallComponents.scss +23 -0
  217. package/src/styles/components/_table.scss +270 -0
  218. package/src/styles/components/_tabs.scss +33 -0
  219. package/src/styles/components/_tooltip.scss +48 -0
  220. package/src/styles/components/_tree.scss +21 -0
  221. package/src/styles/components/_widget.scss +90 -0
  222. package/src/styles/pages/_fullScreenPage.scss +64 -0
  223. package/src/styles/variables/_bp.scss +5 -0
  224. package/src/styles/variables/_variables.scss +130 -0
  225. package/src/types/Base/custom.d.ts +9 -0
  226. package/src/types/IBasic.ts +31 -0
  227. package/src/types/IError.ts +5 -0
  228. package/src/types/IHeader.ts +24 -0
  229. package/src/types/IInfo.ts +1 -0
  230. package/src/types/IKeyboard.ts +37 -0
  231. package/src/types/IMenu.ts +18 -0
  232. package/src/types/IRouter.ts +6 -0
  233. package/src/types/ISelect.ts +52 -0
  234. package/src/types/ITab.ts +10 -0
  235. package/src/types/ITable.ts +249 -0
  236. package/src/types/ITree.ts +6 -0
  237. package/src/utils/DateUtils.ts +32 -0
  238. package/src/utils/InputPatternValidation.ts +12 -0
  239. package/src/utils/LocalStorageHelper.ts +24 -0
  240. package/src/utils/NumberUtils.ts +21 -0
  241. package/src/utils/ObjectUtils.ts +85 -0
  242. package/src/utils/RootDir.ts +1 -0
  243. package/src/utils/StringUtils.ts +18 -0
  244. package/src/utils/TableUtils.ts +130 -0
  245. package/src/utils/Toasts.ts +6 -0
  246. package/src/utils/UrlUtils.ts +4 -0
  247. package/src/utils/fileUtils.ts +176 -0
  248. package/src/utils/i18n/i18nIUICyrilic.ts +90 -0
  249. package/src/utils/i18n/i18nIUILatin.ts +90 -0
  250. package/src/utils/i18n/i18nIUIMe.ts +88 -0
  251. package/src/utils/icons.ts +13 -0
  252. package/tsconfig.icons.json +5 -0
  253. package/tsconfig.json +19 -0
@@ -0,0 +1,527 @@
1
+ import clsx from 'clsx';
2
+ import { FC, Fragment, useEffect, useState } from 'react';
3
+ import {
4
+ ITable,
5
+ ITableColumn,
6
+ ITableDataItem,
7
+ ITableSelectedActions,
8
+ } from '../../types/ITable';
9
+ import { Loader } from '../Loader/Loader';
10
+ import { Tooltip } from '../Tooltip/Tooltip';
11
+ import { ConditionalWrapper } from '../Wrappers/ConditionalWrapper';
12
+ import { TableFooter } from './Components/TableFooter';
13
+ import { HeaderTable } from './Components/Header/TableHeader';
14
+ import { TableOptions } from './Components/TableOptions';
15
+ import { useTranslation } from 'react-i18next';
16
+ import { Checkbox } from '../Inputs/Checkbox';
17
+ import { Menu } from '../Menu/Menu';
18
+ import { faEllipsisVertical } from '../../assets/icons/solid/faEllipsisVertical';
19
+ import { MenuItem } from '../Menu/MenuItem';
20
+ import { Button } from '../Button/Button';
21
+ import { useTableKeyboard } from './hooks/useTableKeyboard';
22
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
23
+ import { faPlus } from '../../assets/icons/solid/faPlus';
24
+
25
+ export const Table: FC<ITable> = ({
26
+ columns,
27
+ setColumns,
28
+ withColumnsSearch,
29
+ customHeader,
30
+ data: tableData,
31
+ sumRows,
32
+ isLoading,
33
+ headerWrap,
34
+ serverSidePagination,
35
+ customPagination,
36
+ selectedRowUuid,
37
+ footerAction,
38
+ hideFooter,
39
+ noTotalRows,
40
+ showLastBorder,
41
+ className,
42
+ filterData,
43
+ sortData,
44
+ printData,
45
+ customPrintData,
46
+ templates,
47
+ additionsalOptions,
48
+ rowSelect,
49
+ rowHeight = 'm',
50
+ maxHeight,
51
+ editable,
52
+ keyboard,
53
+ }) => {
54
+ const [limit, setLimit] = useState(customPagination?.defaultLimit ?? 5);
55
+ const [offset, setOffset] = useState(0);
56
+ const [cols, setCols] = useState<ITableColumn[]>([]);
57
+ const [data, setData] = useState<ITableDataItem[]>([]);
58
+ const [extendedRow, setExtendedRow] = useState('');
59
+ const [editableData, setEditableData] = useState<object>({});
60
+ const [isAdding, setIsAdding] = useState(false);
61
+ const [selectedActionOpen, setSelectedActionOpen] = useState(false);
62
+ const [activeSelectOptions, setActiveSelectOptions] = useState<ITableSelectedActions[]>(
63
+ []
64
+ );
65
+
66
+ const { t } = useTranslation();
67
+
68
+ const pagination = {
69
+ limit: serverSidePagination?.limit || limit,
70
+ offset: serverSidePagination?.offset || offset,
71
+ setLimit: serverSidePagination?.setLimit || setLimit,
72
+ setOffset: serverSidePagination?.setOffset || setOffset,
73
+ totalRows: serverSidePagination?.totalRows || tableData.length,
74
+ };
75
+
76
+ const focusedRow = useTableKeyboard({
77
+ enabled: !!keyboard?.enabled,
78
+ rows: data,
79
+ selected: {
80
+ enabled: !!rowSelect && activeSelectOptions.length > 0,
81
+ rows: rowSelect?.selectedRows ?? new Set<string>(),
82
+ resetSelected: () => rowSelect?.setSelectedRows(new Set<string>()),
83
+ },
84
+ actions: {
85
+ moveDisabled: !!keyboard?.actions?.moveDisabled || isAdding,
86
+ ...keyboard?.actions,
87
+ add: {
88
+ isAdding,
89
+ setIsAdding,
90
+ enabled: !!editable?.EditableRow && !editable.addDisabled,
91
+ },
92
+ edit: {
93
+ item: editable?.selectedItem,
94
+ setItem: editable?.setSelectedItem!,
95
+ enabled:
96
+ !!editable && !!editable!.setSelectedItem && !keyboard?.actions.editDisabled,
97
+ },
98
+ additional: additionalProps => [
99
+ ...(keyboard?.actions?.additional?.(additionalProps) || []),
100
+ {
101
+ key: 'PageUp',
102
+ isActive: !additionalProps.isEditing,
103
+ onAction: () =>
104
+ pagination.offset > 0 && pagination.setOffset(pagination.offset - 1),
105
+ },
106
+ {
107
+ key: 'PageDown',
108
+ isActive: !additionalProps.isEditing,
109
+ onAction: () => {
110
+ if (
111
+ noTotalRows
112
+ ? pagination.limit <= pagination.totalRows
113
+ : pagination.offset + 1 <
114
+ Math.ceil(pagination.totalRows / pagination.limit)
115
+ ) {
116
+ pagination.setOffset(pagination.offset + 1);
117
+ }
118
+ },
119
+ },
120
+ {
121
+ key: ' ',
122
+ isActive: activeSelectOptions.length > 0 && !!focusedRow?.uuid,
123
+ onAction: () => {
124
+ const rowUuid = focusedRow?.uuid!;
125
+ const isRowSelected = rowSelect?.selectedRows.has(rowUuid);
126
+ rowSelect?.setSelectedRows(oldSet => {
127
+ const newSet = new Set(oldSet);
128
+ newSet[isRowSelected ? 'delete' : 'add'](rowUuid);
129
+ return newSet;
130
+ });
131
+ },
132
+ },
133
+ ],
134
+ },
135
+ });
136
+
137
+ // Set Active Select Options
138
+ useEffect(() => {
139
+ rowSelect?.actions.length &&
140
+ setActiveSelectOptions(rowSelect.actions.filter(e => !e.hidden) || []);
141
+ }, [rowSelect?.actions]);
142
+
143
+ useEffect(
144
+ () => {
145
+ // Active Column
146
+ const activeColumns = columns.filter(e => !e.hidden && !e.unavailable);
147
+
148
+ // Select Column
149
+ let selectCol;
150
+ if (rowSelect && activeSelectOptions.length > 0) {
151
+ const selectableData = data.filter(e => !e.disableSelect);
152
+ const selectedSome =
153
+ !!rowSelect.selectedRows.size &&
154
+ selectableData.some(e => !rowSelect.selectedRows.has(e.uuid));
155
+ const selectedAll = !!rowSelect.selectedRows.size && !selectedSome;
156
+ selectCol = {
157
+ id: 'select',
158
+ label: (
159
+ <Checkbox
160
+ value={selectedSome ? 'middle' : selectedAll}
161
+ // label={`${selected.size}`}
162
+ setValue={() => {
163
+ selectedAll
164
+ ? rowSelect.setSelectedRows(new Set<string>())
165
+ : rowSelect.setSelectedRows(oldValue => {
166
+ let newSet = new Set(oldValue);
167
+ selectableData.forEach(e => newSet.add(e.uuid!));
168
+ return newSet;
169
+ });
170
+ }}
171
+ />
172
+ ),
173
+ width: '50px',
174
+ };
175
+ }
176
+
177
+ let newCols: ITableColumn[] = [];
178
+
179
+ selectCol && newCols.push(selectCol);
180
+ newCols = newCols.concat(activeColumns);
181
+
182
+ setCols(newCols);
183
+ },
184
+ // eslint-disable-next-line
185
+ [
186
+ columns,
187
+ editable,
188
+ rowSelect?.selectedRows,
189
+ activeSelectOptions,
190
+ serverSidePagination,
191
+ ]
192
+ );
193
+
194
+ useEffect(() => {
195
+ // const data = editable
196
+ // ? tableData.map((e) => ({
197
+ // ...e,
198
+ // cells: {
199
+ // ...e.cells,
200
+ // actions: {
201
+ // value: (
202
+ // <ItemActionsMenu
203
+ // item={e}
204
+ // setSelectedItem={editable!.setSelectedItem}
205
+ // />
206
+ // ),
207
+ // },
208
+ // },
209
+ // }))
210
+ // : tableData;
211
+ const data =
212
+ serverSidePagination || limit <= 0
213
+ ? tableData
214
+ : tableData.slice(offset * limit, offset * limit + limit);
215
+
216
+ rowSelect &&
217
+ activeSelectOptions.length > 0 &&
218
+ data.map(
219
+ e =>
220
+ (e.cells.select = {
221
+ value: (
222
+ <Checkbox
223
+ value={rowSelect.selectedRows.has(e.uuid!)}
224
+ setValue={checked => {
225
+ rowSelect.setSelectedRows(oldSet => {
226
+ const newSet = new Set(oldSet);
227
+ checked ? newSet.add(e.uuid!) : newSet.delete(e.uuid!);
228
+ return newSet;
229
+ });
230
+ }}
231
+ disabled={e.disableSelect}
232
+ />
233
+ ),
234
+ unclickable: true,
235
+ })
236
+ );
237
+ setData(data);
238
+ }, [
239
+ tableData,
240
+ limit,
241
+ offset,
242
+ rowSelect?.selectedRows,
243
+ activeSelectOptions,
244
+ serverSidePagination,
245
+ rowSelect,
246
+ ]);
247
+
248
+ const EditableRow = editable?.EditableRow;
249
+
250
+ return (
251
+ <Loader isLoading={!!isLoading}>
252
+ <div
253
+ className={clsx('iui-table', className, {
254
+ 'pb-3': data.length === 0,
255
+ })}
256
+ >
257
+ <div className="flex column gap-2">
258
+ {(!!filterData ||
259
+ !!sortData ||
260
+ !!setColumns ||
261
+ !!printData ||
262
+ !!customPrintData) && (
263
+ <TableOptions
264
+ columns={cols}
265
+ columnsData={
266
+ setColumns
267
+ ? { columns, setColumns, withSearch: withColumnsSearch }
268
+ : undefined
269
+ }
270
+ filterData={filterData}
271
+ sortData={sortData}
272
+ printData={printData}
273
+ customPrintData={customPrintData}
274
+ templates={templates}
275
+ additionsalOptions={additionsalOptions}
276
+ />
277
+ )}
278
+ {/* ////// SELECT ////// */}
279
+ {!!rowSelect && activeSelectOptions.length > 0 && (
280
+ <div className="flex gap-2 align-center pl-3">
281
+ <p className="fs-12">{`${t('Selected')}: ${
282
+ rowSelect.selectedRows.size
283
+ }`}</p>
284
+ <Menu
285
+ isOpen={selectedActionOpen}
286
+ onClose={() => setSelectedActionOpen(false)}
287
+ placement="bottom-left"
288
+ renderButton={ref => (
289
+ <Button
290
+ ref={ref}
291
+ label={t('Actions')}
292
+ icon={faEllipsisVertical}
293
+ active={selectedActionOpen}
294
+ disabled={!rowSelect.selectedRows.size}
295
+ onClick={() => setSelectedActionOpen(!selectedActionOpen)}
296
+ size="s"
297
+ />
298
+ )}
299
+ >
300
+ {activeSelectOptions.map(action => (
301
+ <MenuItem
302
+ key={action.label}
303
+ label={action.label}
304
+ disabled={action.disabled}
305
+ onClick={() => {
306
+ action.onClick!(rowSelect.selectedRows);
307
+ setSelectedActionOpen(false);
308
+ action.clearSelected &&
309
+ rowSelect.setSelectedRows(new Set<string>());
310
+ }}
311
+ />
312
+ ))}
313
+ </Menu>
314
+ </div>
315
+ )}
316
+ </div>
317
+ <div className="table-container" style={{ maxHeight }}>
318
+ <ConditionalWrapper
319
+ condition={!!editable}
320
+ wrapper={children => (
321
+ <form
322
+ onSubmit={e => {
323
+ e.preventDefault();
324
+ e.stopPropagation();
325
+ editable!.onSubmit(editableData, () => {
326
+ !editable?.keepEditOnSubmit &&
327
+ editable!.inputFocusRef?.current?.focus();
328
+ if (!editable?.selectedItem || !editable?.keepEditOnSubmit) {
329
+ setEditableData(editable!.defaultDataValue ?? {});
330
+ editable?.setSelectedItem && editable.setSelectedItem(null);
331
+ }
332
+ });
333
+ }}
334
+ >
335
+ {children}
336
+ </form>
337
+ )}
338
+ >
339
+ <table className="full-width">
340
+ <HeaderTable
341
+ columns={cols}
342
+ headerWrap={headerWrap}
343
+ customHeader={customHeader}
344
+ sticky={!!maxHeight}
345
+ />
346
+ <tbody
347
+ className={clsx({ 'no-last-border': hideFooter && !showLastBorder })}
348
+ >
349
+ {data.length ? (
350
+ <>
351
+ {data.map(row => {
352
+ const isExtended =
353
+ row.extendable &&
354
+ !row.extendable.isLoading &&
355
+ extendedRow === row.uuid;
356
+ return (
357
+ <Fragment key={row.uuid}>
358
+ {/* ////// EDITABLE ROW ////// */}
359
+ {!!EditableRow &&
360
+ row.uuid === editable?.selectedItem?.uuid &&
361
+ editable.setSelectedItem ? (
362
+ <EditableRow
363
+ columns={cols}
364
+ data={editableData}
365
+ setData={setEditableData}
366
+ item={editable.selectedItem}
367
+ clearItem={() => editable.setSelectedItem!(null)}
368
+ defaultDataValue={editable.defaultDataValue}
369
+ inputFocusRef={editable.inputFocusRef}
370
+ />
371
+ ) : (
372
+ ////// REGULAR ROW //////
373
+ <tr
374
+ data-id={row.uuid}
375
+ className={clsx(row.className, {
376
+ selected:
377
+ !!selectedRowUuid && selectedRowUuid === row.uuid,
378
+ clickable: !!row.onRowClick || !!row.extendable,
379
+ focused: !!focusedRow && focusedRow.uuid === row.uuid,
380
+ loading: row.extendable?.isLoading,
381
+ })}
382
+ onClick={e => {
383
+ row.onRowClick && row.onRowClick(e);
384
+ row.extendable &&
385
+ setExtendedRow(
386
+ extendedRow === row.uuid ? '' : row.uuid
387
+ );
388
+ }}
389
+ >
390
+ {cols.map(column => {
391
+ const cell = row.cells[column.id];
392
+ return (
393
+ <Tooltip
394
+ key={column.id}
395
+ label={cell?.tooltip!}
396
+ position="top"
397
+ disabled={!cell?.tooltip}
398
+ >
399
+ <td
400
+ data-th={
401
+ column.id === 'select'
402
+ ? t('Selected') + ':'
403
+ : column.label
404
+ ? column.label + ': '
405
+ : '/'
406
+ }
407
+ align={cell?.align || column.align}
408
+ onClick={
409
+ cell?.onClick || cell?.unclickable
410
+ ? e => {
411
+ e.stopPropagation();
412
+ cell?.onClick && cell?.onClick!(e);
413
+ }
414
+ : undefined
415
+ }
416
+ className={clsx(
417
+ column.color,
418
+ cell?.className,
419
+ rowHeight,
420
+ {
421
+ link: cell?.link,
422
+ 'p-0': !cell?.value && cell?.value !== 0,
423
+ 'clickable-column': cell?.onClick,
424
+ 'word-break': column.break,
425
+ 'no-border': isExtended,
426
+ }
427
+ )}
428
+ colSpan={cell?.span}
429
+ >
430
+ {cell?.value}
431
+ </td>
432
+ </Tooltip>
433
+ );
434
+ })}
435
+ </tr>
436
+ )}
437
+ {/* ////// EXTENDABLE ROW ////// */}
438
+ {isExtended && (
439
+ <tr>
440
+ <td colSpan={cols.length} className={rowHeight}>
441
+ {row.extendable!.element}
442
+ </td>
443
+ </tr>
444
+ )}
445
+ </Fragment>
446
+ );
447
+ })}
448
+ </>
449
+ ) : (
450
+ <tr>
451
+ <td className="no-border" colSpan={cols.length}>
452
+ {t('NoResults')}
453
+ </td>
454
+ </tr>
455
+ )}
456
+ </tbody>
457
+ <tfoot
458
+ // className="sticky-footer"
459
+ >
460
+ {!!EditableRow &&
461
+ !editable.selectedItem &&
462
+ !editable.addDisabled &&
463
+ // TO DO -> Remove keyboard condition to enable this for every table
464
+ (keyboard?.enabled && !isAdding ? (
465
+ ////// NEW ITEM ROW //////
466
+ <tr
467
+ data-id="add"
468
+ className={`clickable${
469
+ focusedRow?.uuid === 'add' ? ' focused' : ''
470
+ }`}
471
+ onClick={() => setIsAdding(true)}
472
+ >
473
+ <td className={`text-center ${rowHeight}`} colSpan={columns.length}>
474
+ <div className="flex center gap-2">
475
+ <FontAwesomeIcon icon={faPlus} className="c-primary icon24" />
476
+ <p>{editable.addLabel || t('AddItem')}</p>
477
+ </div>
478
+ </td>
479
+ </tr>
480
+ ) : (
481
+ <EditableRow
482
+ columns={cols}
483
+ data={editableData}
484
+ setData={setEditableData}
485
+ defaultDataValue={editable.defaultDataValue}
486
+ clearItem={() => {
487
+ editable.setSelectedItem?.(null);
488
+ isAdding && setIsAdding(false);
489
+ }}
490
+ inputFocusRef={editable.inputFocusRef}
491
+ />
492
+ ))}
493
+ {!!sumRows &&
494
+ !!data.length &&
495
+ sumRows.map(row => (
496
+ <tr key={row.uuid}>
497
+ {cols.map(({ id: columnId }) => (
498
+ <td
499
+ key={columnId}
500
+ align={row.cells[columnId]?.align || 'right'}
501
+ colSpan={row.cells[columnId]?.span}
502
+ className={rowHeight}
503
+ >
504
+ <strong>{row.cells[columnId]?.value}</strong>
505
+ </td>
506
+ ))}
507
+ </tr>
508
+ ))}
509
+ </tfoot>
510
+ </table>
511
+ </ConditionalWrapper>
512
+ </div>
513
+ {!hideFooter &&
514
+ (!!data.length ||
515
+ (noTotalRows && (serverSidePagination?.offset || offset) > 0)) && (
516
+ <TableFooter
517
+ customLimit={customPagination?.customLimit}
518
+ pagination={pagination}
519
+ footerAction={footerAction}
520
+ noTotalRows={noTotalRows}
521
+ dataLength={data.length}
522
+ />
523
+ )}
524
+ </div>
525
+ </Loader>
526
+ );
527
+ };
@@ -0,0 +1,20 @@
1
+ // import { useEffect, useState } from 'react';
2
+ // import { getDefaultReportTemplate } from '../Components/Templates/repo/TemplateRepo';
3
+ // import { IReportTemplate } from '../../../types/ITable';
4
+
5
+ export const useDefaultTemplate = (identifier?: string) => {
6
+ // const [template, setTemplate] = useState<IReportTemplate | null>(null);
7
+ // const [isLoading, setIsLoading] = useState(true);
8
+ // useEffect(() => {
9
+ // if (identifier) {
10
+ // getDefaultReportTemplate(identifier)
11
+ // .then(setTemplate)
12
+ // .catch(() => {})
13
+ // .finally(() => setIsLoading(false));
14
+ // }
15
+ // }, [identifier]);
16
+ // return {
17
+ // defaultTemplate: template,
18
+ // isLoadingDefaultTemplate: !!identifier && isLoading,
19
+ // };
20
+ };
@@ -0,0 +1,138 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { ITableDataItem } from '../../../types/ITable';
3
+ import { IKeyboardAction, ITableKeyboardActionsProp } from '../../../types/IKeyboard';
4
+ import { useDialogObserver } from '../../Dialog/hooks/useDialogObserver';
5
+ import { scrollToRow } from '../../../utils/TableUtils';
6
+
7
+ export const useTableKeyboard = ({
8
+ enabled,
9
+ rows,
10
+ selected,
11
+ actions,
12
+ }: {
13
+ enabled: boolean;
14
+ rows: ITableDataItem[];
15
+ selected: {
16
+ enabled: boolean;
17
+ rows: Set<string>;
18
+ resetSelected: () => void;
19
+ };
20
+ actions: ITableKeyboardActionsProp;
21
+ }) => {
22
+ const [focusedRow, setFocusedRow] = useState<ITableDataItem | null>(null);
23
+ const isDialogOpen = useDialogObserver();
24
+
25
+ useEffect(() => {
26
+ if (enabled && !isDialogOpen) {
27
+ const isEditing = !!actions.edit?.item;
28
+ const isAdding = !!actions.add?.isAdding;
29
+
30
+ const handleKeyDown = (event: KeyboardEvent) => {
31
+ const isControlKeyPressed = event.ctrlKey || event.metaKey;
32
+ const rowIndex = focusedRow
33
+ ? rows.findIndex(row => row.uuid === focusedRow.uuid)
34
+ : -1;
35
+
36
+ const allActions: IKeyboardAction[] = [
37
+ {
38
+ key: 'ArrowDown',
39
+ disabled: isEditing || actions.moveDisabled,
40
+ onAction: () => {
41
+ // Leave action enabled to prevent default scroll movement
42
+ const nextRow = rowIndex + 1;
43
+ if (nextRow < rows.length) {
44
+ // rowIndex will be -1 if no row is selected so the next row will be 0
45
+ setFocusedRow(rows[nextRow]);
46
+ scrollToRow(rows[nextRow].uuid);
47
+ }
48
+ },
49
+ },
50
+ {
51
+ key: 'ArrowUp',
52
+ disabled: isEditing || actions.moveDisabled,
53
+ onAction: () => {
54
+ if (rowIndex !== 0) {
55
+ const prevRow = rowIndex > 0 ? rowIndex - 1 : rows.length - 1;
56
+ setFocusedRow(rows[prevRow]);
57
+ scrollToRow(rows[prevRow].uuid);
58
+ }
59
+ },
60
+ },
61
+ {
62
+ key: 'e',
63
+ normalizedKey: true,
64
+ ctrl: true,
65
+ disabled: !actions.edit?.enabled || !focusedRow,
66
+ onAction: () => !isEditing && actions.edit?.setItem(focusedRow?.item ?? null),
67
+ },
68
+ {
69
+ key: 'Enter',
70
+ disabled: isEditing || isAdding || !focusedRow?.onRowClick,
71
+ onAction: focusedRow?.onRowClick!,
72
+ },
73
+ {
74
+ key: 'Escape',
75
+ disabled: !focusedRow && !isAdding,
76
+ // isActive: !!focusedRow || !!isAdding,
77
+ onAction: () =>
78
+ isAdding
79
+ ? actions.add?.setIsAdding(false)
80
+ : actions.edit?.item
81
+ ? actions.edit?.setItem(null)
82
+ : setFocusedRow(null),
83
+ },
84
+ ...['Insert', '+'].map(
85
+ key =>
86
+ ({
87
+ key,
88
+ disabled: !actions.add?.enabled || isAdding || isEditing,
89
+ onAction: () => {
90
+ actions.add?.setIsAdding(true);
91
+ setFocusedRow(null);
92
+ },
93
+ } as IKeyboardAction)
94
+ ),
95
+ {
96
+ key: 'Delete',
97
+ disabled: isEditing || !actions.delete?.enabled || !focusedRow,
98
+ onAction: () =>
99
+ actions.delete?.onAction ??
100
+ actions.delete?.setItemToDeleteUuids(
101
+ selected.enabled && selected.rows && selected.rows.size > 0
102
+ ? Array.from(selected.rows)
103
+ : [focusedRow!.uuid]
104
+ ),
105
+ },
106
+ ...(actions?.additional?.({
107
+ focusedRow,
108
+ isEditing,
109
+ isAdding,
110
+ }) || []),
111
+ ];
112
+
113
+ allActions.forEach(item => {
114
+ if (
115
+ !item.disabled &&
116
+ item.key === (item.normalizedKey ? event.key.toLowerCase() : event.key) &&
117
+ !!item.ctrl === isControlKeyPressed
118
+ ) {
119
+ event.preventDefault();
120
+ event.stopPropagation();
121
+ if (item.onBulkAction && selected?.enabled && selected.rows.size > 0) {
122
+ item.onBulkAction(Array.from(selected.rows));
123
+ } else {
124
+ item.onAction();
125
+ }
126
+ }
127
+ });
128
+ };
129
+
130
+ window.addEventListener('keydown', handleKeyDown);
131
+ return () => {
132
+ window.removeEventListener('keydown', handleKeyDown);
133
+ };
134
+ }
135
+ }, [enabled, rows, focusedRow, actions, isDialogOpen, selected.enabled, selected.rows]);
136
+
137
+ return focusedRow;
138
+ };
@@ -0,0 +1,11 @@
1
+ import { useState } from 'react';
2
+
3
+ export const useTableSelect = () => {
4
+ const [selectedRows, setSelectedRows] = useState(new Set<string>());
5
+
6
+ return {
7
+ selectedRows,
8
+ setSelectedRows,
9
+ resetSelectedRows: () => setSelectedRows(new Set<string>()),
10
+ };
11
+ };