@inceptionbg/iui 2.0.8 → 2.0.10

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 (138) hide show
  1. package/dist/icons/index.d.ts +2 -2
  2. package/dist/icons/index.js +1 -1
  3. package/dist/index.d.ts +286 -259
  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/GridTable/GridTable.tsx +119 -0
  8. package/idea/GridTable/gridTable.scss +42 -0
  9. package/{src/components → idea}/Table/Components/Print/CustomTablePrint.tsx +2 -2
  10. package/{src/components → idea}/Table/Components/Print/TablePrint.tsx +2 -2
  11. package/{src/components → idea}/Table/Components/SetTableFilter.tsx +1 -1
  12. package/{src/components → idea}/Table/Components/TableOptions.tsx +4 -4
  13. package/idea/{Table2 → Table}/Table.tsx +151 -281
  14. package/idea/Table/hooks/useDefaultTemplate.ts +20 -0
  15. package/{src/components → idea}/Table/hooks/useTableKeyboard.ts +1 -2
  16. package/idea/Table/hooks/useTableSelect.ts +11 -0
  17. package/package.json +1 -1
  18. package/src/assets/icons/index.ts +1 -1
  19. package/src/assets/icons/light/faClipboardCheck.ts +15 -0
  20. package/src/assets/icons/light/faHouse.ts +15 -15
  21. package/src/assets/icons/light/faIdBadge.ts +15 -15
  22. package/src/assets/icons/light/faPen.ts +15 -0
  23. package/src/components/Button/IconButton.tsx +3 -1
  24. package/src/components/Dialog/Dialog.tsx +59 -123
  25. package/src/components/Dialog/components/DialogFooter.tsx +92 -0
  26. package/src/components/Dialog/hooks/useDialogKeyboard.ts +6 -5
  27. package/src/components/Header/Header.tsx +1 -1
  28. package/src/components/Inputs/DateInput/DateInput.tsx +108 -102
  29. package/src/components/Inputs/DateInput/components/DatePartInput.tsx +7 -3
  30. package/src/components/Inputs/InputWrapper.tsx +6 -1
  31. package/src/components/Inputs/SearchInput.tsx +9 -4
  32. package/src/components/Inputs/Select2/Select.tsx +65 -30
  33. package/src/components/Inputs/Select2/select.scss +13 -14
  34. package/src/components/Inputs/Selects/components/SelectWrapper.tsx +4 -2
  35. package/src/components/Inputs/Selects/utils/selectStyles.ts +9 -12
  36. package/src/components/Menu/Menu.tsx +10 -2
  37. package/src/components/Menu/MenuItem.tsx +11 -10
  38. package/src/components/Menu/hooks/useMenuPosition.tsx +23 -6
  39. package/src/components/Pullover/Pullover.tsx +122 -59
  40. package/src/components/Table/Table.tsx +78 -342
  41. package/src/components/Table/components/edit/TableEditRow.tsx +69 -0
  42. package/src/components/Table/components/filters/FilterItem.tsx +15 -0
  43. package/src/components/Table/components/filters/TableFilters.tsx +125 -0
  44. package/src/components/Table/components/footer/TableFooter.tsx +128 -0
  45. package/src/components/Table/components/header/TableHeader.tsx +42 -0
  46. package/src/components/Table/components/header/TableHeaderRow.tsx +47 -0
  47. package/src/components/Table/components/items/TableItemActions.tsx +66 -0
  48. package/src/components/Table/components/select/TableSelect.tsx +49 -0
  49. package/src/components/Table/components/sort/TableSort.tsx +52 -0
  50. package/src/components/Table/contexts/TableContext.tsx +123 -0
  51. package/src/components/Table/hooks/localHooks/useLocalTableColumns.tsx +73 -0
  52. package/src/components/Table/hooks/localHooks/useLocalTableData.tsx +78 -0
  53. package/src/components/Table/hooks/localHooks/useLocalTableKeyboard.ts +173 -0
  54. package/src/components/Table/hooks/localHooks/useLocalTablePagination.ts +12 -0
  55. package/src/components/Table/hooks/useTableEdit.tsx +111 -0
  56. package/src/components/Table/hooks/useTableFilterFields.tsx +150 -0
  57. package/src/components/Table/hooks/useTablePagination.ts +16 -0
  58. package/src/components/Table/hooks/useTableSearch.ts +29 -0
  59. package/src/components/Table/hooks/useTableSort.ts +8 -0
  60. package/src/components/Tooltip/Tooltip.tsx +1 -1
  61. package/src/components/Wrappers/PageLayout.tsx +9 -12
  62. package/src/hooks/useGetFocusableElements.ts +42 -0
  63. package/src/hooks/useLocalPopoverControl.ts +38 -0
  64. package/src/hooks/usePopupControl.ts +13 -0
  65. package/src/index.ts +53 -39
  66. package/src/styles/components/_accordions.scss +1 -1
  67. package/src/styles/components/_badge.scss +4 -3
  68. package/src/styles/components/_card.scss +1 -1
  69. package/src/styles/components/_dialog.scss +8 -8
  70. package/src/styles/components/_input.scss +1 -1
  71. package/src/styles/components/_inputCheckbox.scss +1 -1
  72. package/src/styles/components/_inputDateTime.scss +2 -2
  73. package/src/styles/components/_inputRadio.scss +1 -1
  74. package/src/styles/components/_inputSelect.scss +6 -4
  75. package/src/styles/components/_menu-v2.scss +1 -1
  76. package/src/styles/components/_menu.scss +23 -15
  77. package/src/styles/components/_pullover.scss +74 -18
  78. package/src/styles/components/_table.scss +151 -142
  79. package/src/styles/components/_widget.scss +1 -1
  80. package/src/styles/variables/_bp.scss +1 -0
  81. package/src/styles/variables/_variables.scss +4 -2
  82. package/src/types/IKeyboard.ts +2 -1
  83. package/src/types/IMenu.ts +1 -0
  84. package/src/types/ISelect.ts +1 -0
  85. package/src/types/ITable.ts +87 -80
  86. package/src/utils/fileUtils.ts +3 -3
  87. package/src/utils/i18n/i18nIUICyrilic.ts +4 -0
  88. package/src/utils/i18n/i18nIUILatin.ts +3 -1
  89. package/src/utils/i18n/i18nIUIMe.ts +4 -0
  90. package/src/utils/{ObjectUtils.ts → objectUtils.ts} +8 -8
  91. package/src/utils/popupUtils.ts +82 -0
  92. package/src/utils/{TableUtils.ts → tableUtils.ts} +5 -5
  93. package/src/utils/{Toasts.ts → toasts.ts} +6 -6
  94. package/src/utils/{UrlUtils.ts → urlUtils.ts} +4 -4
  95. package/idea/Table2/Components/Columns/ColumnsList.tsx +0 -56
  96. package/idea/Table2/Components/Columns/SetColumnsList.tsx +0 -107
  97. package/idea/Table2/Components/Edit/ItemActionsMenu.tsx +0 -87
  98. package/idea/Table2/Components/Edit/ItemEditOptionsButtons.tsx +0 -32
  99. package/idea/Table2/Components/Edit/TableEditRow.tsx +0 -56
  100. package/idea/Table2/Components/FilterItem.tsx +0 -20
  101. package/idea/Table2/Components/Header/TableHeader.tsx +0 -35
  102. package/idea/Table2/Components/Header/TableHeaderRow.tsx +0 -37
  103. package/idea/Table2/Components/Print/CustomTablePrint.tsx +0 -119
  104. package/idea/Table2/Components/Print/TablePrint.tsx +0 -208
  105. package/idea/Table2/Components/SetSortList.tsx +0 -33
  106. package/idea/Table2/Components/SetTableFilter.tsx +0 -90
  107. package/idea/Table2/Components/TableFooter.tsx +0 -107
  108. package/idea/Table2/Components/TableOptions.tsx +0 -211
  109. package/idea/Table2/Components/Templates/TemplateCreate.tsx +0 -75
  110. package/idea/Table2/Components/Templates/TemplateCreateDefault.tsx +0 -45
  111. package/idea/Table2/Components/Templates/TemplateList.tsx +0 -167
  112. package/idea/Table2/Components/Templates/repo/TemplateRepo.ts +0 -51
  113. package/idea/Table2/_table.scss +0 -300
  114. package/idea/Table2/hooks/useDefaultTemplate.ts +0 -22
  115. package/idea/Table2/hooks/useTableKeyboard.ts +0 -115
  116. package/src/assets/icons/light/faPenField.ts +0 -15
  117. package/src/assets/icons/solid/faMagnifyingGlass.ts +0 -15
  118. package/src/components/Dialog/DeleteItemDialog.tsx +0 -52
  119. package/src/components/Dialog/hooks/useDialogObserver.ts +0 -21
  120. /package/{src/components → idea}/Table/Components/Columns/ColumnsList.tsx +0 -0
  121. /package/{src/components → idea}/Table/Components/Columns/SetColumnsList.tsx +0 -0
  122. /package/{src/components → idea}/Table/Components/Edit/ItemActionsMenu.tsx +0 -0
  123. /package/{src/components → idea}/Table/Components/Edit/ItemEditOptionsButtons.tsx +0 -0
  124. /package/{src/components → idea}/Table/Components/Edit/TableEditRow.tsx +0 -0
  125. /package/{src/components → idea}/Table/Components/FilterItem.tsx +0 -0
  126. /package/{src/components → idea}/Table/Components/Header/TableHeader.tsx +0 -0
  127. /package/{src/components → idea}/Table/Components/Header/TableHeaderRow.tsx +0 -0
  128. /package/{src/components → idea}/Table/Components/SetSortList.tsx +0 -0
  129. /package/{src/components → idea}/Table/Components/TableFooter.tsx +0 -0
  130. /package/{src/components → idea}/Table/Components/Templates/TemplateCreate.tsx +0 -0
  131. /package/{src/components → idea}/Table/Components/Templates/TemplateCreateDefault.tsx +0 -0
  132. /package/{src/components → idea}/Table/Components/Templates/TemplateList.tsx +0 -0
  133. /package/{src/components → idea}/Table/Components/Templates/repo/TemplateRepo.ts +0 -0
  134. /package/src/utils/{DateUtils.ts → dateUtils.ts} +0 -0
  135. /package/src/utils/{LocalStorageHelper.ts → localStorageHelper.ts} +0 -0
  136. /package/src/utils/{NumberUtils.ts → numberUtils.ts} +0 -0
  137. /package/src/utils/{RootDir.ts → rootDir.ts} +0 -0
  138. /package/src/utils/{StringUtils.ts → stringUtils.ts} +0 -0
@@ -1,90 +0,0 @@
1
- import { FC, useMemo, useState } from 'react';
2
- import { faFilterCircleXmark } from '../../../icons/regular/faFilterCircleXmark';
3
- import { faMagnifyingGlass } from '../../../icons/solid/faMagnifyingGlass';
4
- import { faXmark } from '../../../icons/solid/faXmark';
5
- import { ITableFilterData, ITableFilterItem } from '../../../types/ITable';
6
- import { deleteEmptyPropsIncludingArray, deleteProps } from '../../../utils/ObjectUtils';
7
- import { Dialog } from '../../Dialog/Dialog';
8
- import { FilterItem } from './FilterItem';
9
- import { useTranslation } from 'react-i18next';
10
- import { SearchInput } from '../../Inputs/SearchInput';
11
-
12
- interface Props extends ITableFilterData {
13
- isOpen: boolean;
14
- onClose: () => void;
15
- }
16
-
17
- export const SetTableFilter: FC<Props> = ({
18
- columns,
19
- filters,
20
- additionalFilters,
21
- excludeFromSearch,
22
- searchData,
23
- setSearchData,
24
- onSubmit,
25
- resetData,
26
- isOpen,
27
- onClose,
28
- }) => {
29
- const [search, setSearch] = useState('');
30
-
31
- const { t } = useTranslation();
32
-
33
- const visibleFilters = useMemo(
34
- () =>
35
- columns.reduce(
36
- (arr: ITableFilterItem[], col) =>
37
- !!filters[col] ? arr.concat(filters[col]) : arr,
38
- []
39
- ),
40
- [columns, filters]
41
- );
42
-
43
- const filteredFilters = useMemo(
44
- () =>
45
- visibleFilters.filter(e => e?.label.toLowerCase().includes(search.toLowerCase())),
46
- [visibleFilters, search]
47
- );
48
-
49
- return (
50
- <Dialog
51
- className="iui-table-filter"
52
- titleEl={
53
- <div className="filters-search">
54
- <h1>{t('Filter')}</h1>
55
- <SearchInput onSearch={setSearch} className="search-input" />
56
- </div>
57
- }
58
- isOpen={isOpen}
59
- onClose={() => {
60
- setSearch('');
61
- onClose();
62
- }}
63
- cancelButton={{ icon: faXmark }}
64
- additionalButton={{
65
- label: t('ResetFilter'),
66
- icon: faFilterCircleXmark,
67
- onClick: () => {
68
- setSearchData(resetData || {});
69
- onSubmit(resetData || {});
70
- },
71
- disabled: resetData
72
- ? JSON.stringify(searchData) === JSON.stringify(resetData)
73
- : Object.keys(searchData).length === 0,
74
- }}
75
- confirmButton={{
76
- label: t('Search'),
77
- icon: faMagnifyingGlass,
78
- onFormSubmit: () => {
79
- const data = deleteEmptyPropsIncludingArray(searchData);
80
- onSubmit(excludeFromSearch ? deleteProps(data, excludeFromSearch) : data);
81
- },
82
- }}
83
- >
84
- {filteredFilters?.map(item => (
85
- <FilterItem key={item.label} item={item} />
86
- ))}
87
- {additionalFilters && <div className="pb-1">{additionalFilters}</div>}
88
- </Dialog>
89
- );
90
- };
@@ -1,107 +0,0 @@
1
- import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
2
- import { ChangeEvent, FC, MouseEventHandler } from 'react';
3
- import { faAngleLeft } from '../../../icons/solid/faAngleLeft';
4
- import { faAngleRight } from '../../../icons/solid/faAngleRight';
5
- import { faRotateRight } from '../../../icons/solid/faRotateRight';
6
- import { IconButton } from '../../Button/IconButton';
7
- import { useTranslation } from 'react-i18next';
8
- import { IServerSidePagination } from '../../../types/ITable';
9
-
10
- interface Props {
11
- pagination: IServerSidePagination;
12
- noTotalRows?: boolean;
13
- footerAction?: {
14
- icon?: IconDefinition;
15
- onClick: MouseEventHandler<HTMLButtonElement>;
16
- };
17
- customLimit?: number[];
18
- }
19
-
20
- export const TableFooter: FC<Props> = ({
21
- pagination: { limit, offset, setLimit, setOffset, totalRows },
22
- noTotalRows,
23
- footerAction,
24
- customLimit,
25
- }) => {
26
- const { t } = useTranslation();
27
-
28
- const handleChangeLimit = (event: ChangeEvent<HTMLSelectElement>) => {
29
- const newLimit = Math.floor(+event.target.value);
30
- setLimit(newLimit);
31
- setOffset(0);
32
- };
33
-
34
- const maxOffset = Math.ceil(totalRows / limit);
35
-
36
- return (
37
- <div className={`table-footer ${footerAction ? 'justify-between' : 'justify-right'}`}>
38
- {!!footerAction && (
39
- <IconButton
40
- icon={footerAction.icon || faRotateRight}
41
- onClick={footerAction.onClick}
42
- />
43
- )}
44
- <div className="pagination">
45
- <div className="flex align-center">
46
- <p>{t('rowsPerPage')}</p>
47
-
48
- <select value={limit} onChange={handleChangeLimit}>
49
- {(customLimit || [5, 10, 25, 50, 100]).map(e => (
50
- <option key={e} value={e}>
51
- {e ? e : t('allResults')}
52
- </option>
53
- ))}
54
- </select>
55
- {!noTotalRows && (
56
- <p className="mr-4">
57
- {limit
58
- ? `${offset * limit + 1}-${
59
- offset * limit + limit <= totalRows
60
- ? offset * limit + limit
61
- : totalRows
62
- } ${t('of')} ${totalRows}`
63
- : `${t('allResults')} ${t('of')} ${totalRows} `}
64
- </p>
65
- )}
66
- </div>
67
- <div className="flex gap-1 align-center">
68
- {noTotalRows ? (
69
- <p>{`${t('page')}: ${offset + 1}`}</p>
70
- ) : (
71
- <p>{`${t('page')}: ${offset + 1}/${maxOffset}`}</p>
72
- )}
73
- <IconButton
74
- disabled={offset < 1}
75
- icon={faAngleLeft}
76
- onClick={() => setOffset(offset - 1)}
77
- size="s"
78
- />
79
- {!noTotalRows && (
80
- <input
81
- className="offset-input"
82
- placeholder={`1-${maxOffset}`}
83
- onKeyUp={e => {
84
- if (e.key === 'Enter') {
85
- const value = +(e.target as HTMLInputElement).value;
86
- if (typeof value === 'number' && value >= 0 && value <= maxOffset)
87
- setOffset(value - 1);
88
- (e.target as HTMLInputElement).value = '';
89
- }
90
- }}
91
- />
92
- )}
93
- <IconButton
94
- disabled={
95
- noTotalRows /* && serverSidePagination */
96
- ? limit > totalRows
97
- : offset + 1 >= maxOffset
98
- }
99
- icon={faAngleRight}
100
- onClick={() => setOffset(offset + 1)}
101
- size="s"
102
- />
103
- </div>
104
- </div>
105
- </div>
106
- );
107
- };
@@ -1,211 +0,0 @@
1
- import { FC, ReactNode, useState } from 'react';
2
- import { faPrint } from '../../../icons/solid/faPrint';
3
- import {
4
- ITableSortData,
5
- ITableColumn,
6
- ITableFilterData,
7
- IPrintData,
8
- ITableColumnsData,
9
- ITable,
10
- ICustomPrintData,
11
- } from '../../../types/ITable';
12
- import { getActiveFilterNumber, setTemplateData } from '../../../utils/TableUtils';
13
- import { NotificationBadge } from '../../Badge/NotificationBadge';
14
- import { Button } from '../../Button/Button';
15
- import { Menu } from '../../Menu/Menu';
16
- import { TablePrint } from './Print/TablePrint';
17
- import { SetColumnsList } from './Columns/SetColumnsList';
18
- import { SetSortList } from './SetSortList';
19
- import { SetTableFilter } from './SetTableFilter';
20
- import { faCaretDown } from '../../../icons/solid/faCaretDown';
21
- import { useTranslation } from 'react-i18next';
22
- import { TemplateList } from './Templates/TemplateList';
23
- import { MenuItem } from '../../Menu/MenuItem';
24
- import { TemplateCreate } from './Templates/TemplateCreate';
25
- import { maxChar } from '../../../utils/StringUtils';
26
- import { TemplateCreateDefault } from './Templates/TemplateCreateDefault';
27
- import { deletePropsThatEndsWith } from '../../../utils/ObjectUtils';
28
- import { CustomTablePrint } from './Print/CustomTablePrint';
29
-
30
- interface Props {
31
- columns: ITableColumn[];
32
- columnsData?: ITableColumnsData;
33
- filterData?: ITableFilterData;
34
- sortData?: ITableSortData;
35
- printData?: IPrintData;
36
- customPrintData?: ICustomPrintData;
37
- templates?: ITable['templates'];
38
- additionsalOptions?: ReactNode;
39
- }
40
- export const TableOptions: FC<Props> = ({
41
- columns,
42
- columnsData,
43
- filterData,
44
- sortData,
45
- printData,
46
- customPrintData,
47
- templates,
48
- additionsalOptions,
49
- }) => {
50
- const [selectedTemplateName, setSelectedTemplateName] = useState('');
51
- const [opened, setOpened] = useState<
52
- 'filter' | 'sort' | 'columns' | 'print' | 'templates' | ''
53
- >('');
54
-
55
- const { t } = useTranslation();
56
-
57
- const onClose = () => setOpened('');
58
-
59
- return (
60
- <div className="table-options gap-2">
61
- <div className="flex align-center gap-2">
62
- {filterData && (
63
- <>
64
- <NotificationBadge number={getActiveFilterNumber(filterData.search)} small>
65
- <Button
66
- label={t('Filter')}
67
- active={opened === 'filter'}
68
- onClick={() => setOpened('filter')}
69
- className="table-options-btn"
70
- size="s"
71
- />
72
- </NotificationBadge>
73
- <SetTableFilter
74
- {...filterData}
75
- onSubmit={search => {
76
- filterData.onSubmit(search);
77
- setSelectedTemplateName('');
78
- }}
79
- isOpen={opened === 'filter'}
80
- onClose={onClose}
81
- />
82
- </>
83
- )}
84
- {columnsData && (
85
- <>
86
- <Button
87
- label={t('Columns')}
88
- active={opened === 'columns'}
89
- onClick={() => setOpened('columns')}
90
- className="table-options-btn"
91
- size="s"
92
- />
93
- {opened === 'columns' && (
94
- <SetColumnsList
95
- columns={columnsData.columns}
96
- setColumns={data => {
97
- columnsData.setColumns(data);
98
- setSelectedTemplateName('');
99
- }}
100
- isOpen={true}
101
- onClose={onClose}
102
- withSearch={columnsData.withSearch}
103
- />
104
- )}
105
- </>
106
- )}
107
- {sortData && (
108
- <Menu
109
- renderButton={ref => (
110
- <Button
111
- label={t('Sort')}
112
- iconEnd={faCaretDown}
113
- active={opened === 'sort'}
114
- onClick={() => setOpened('sort')}
115
- ref={ref}
116
- className="table-options-btn"
117
- size="s"
118
- />
119
- )}
120
- isOpen={opened === 'sort'}
121
- onClose={onClose}
122
- size={sortData.menuSize}
123
- >
124
- <SetSortList
125
- {...sortData}
126
- setSort={data => {
127
- sortData.setSort(data);
128
- setSelectedTemplateName('');
129
- }}
130
- />
131
- </Menu>
132
- )}
133
- {templates && (
134
- <Menu
135
- renderButton={ref => (
136
- <Button
137
- label={
138
- selectedTemplateName
139
- ? `${t('Templates')} (${maxChar(selectedTemplateName, 30)})`
140
- : t('Templates')
141
- }
142
- iconEnd={faCaretDown}
143
- active={opened === 'templates'}
144
- onClick={() => setOpened('templates')}
145
- ref={ref}
146
- className="table-options-btn"
147
- size="s"
148
- />
149
- )}
150
- isOpen={opened === 'templates'}
151
- onClose={onClose}
152
- >
153
- <TemplateList
154
- identifier={templates.identifier}
155
- onSelect={template => {
156
- setTemplateData({
157
- template,
158
- columnsData,
159
- setFilters: e => {
160
- filterData?.setSearchData(e);
161
- filterData?.onSubmit(deletePropsThatEndsWith(e, 'Obj'));
162
- },
163
- setSort: sortData?.setSort,
164
- });
165
- setSelectedTemplateName(template.name);
166
- onClose();
167
- }}
168
- />
169
- <MenuItem
170
- label={t('RemoveFiltersAndLook')}
171
- onClick={() => {
172
- templates.onClearFilters();
173
- setSelectedTemplateName('');
174
- onClose();
175
- }}
176
- />
177
- <TemplateCreate
178
- identifier={templates.identifier}
179
- data={templates.data}
180
- onSubmitCallback={onClose}
181
- />
182
- <TemplateCreateDefault
183
- identifier={templates.identifier}
184
- data={templates.data}
185
- onClose={onClose}
186
- />
187
- </Menu>
188
- )}
189
- {additionsalOptions}
190
- </div>
191
- {(printData ?? customPrintData) && (
192
- <>
193
- <Button
194
- label={t('PrintExport')}
195
- icon={faPrint}
196
- onClick={() => setOpened('print')}
197
- size="s"
198
- />
199
- {opened === 'print' &&
200
- (printData ? (
201
- <TablePrint {...printData} isOpen onClose={onClose} columns={columns} />
202
- ) : (
203
- customPrintData && (
204
- <CustomTablePrint {...customPrintData} isOpen onClose={onClose} />
205
- )
206
- ))}
207
- </>
208
- )}
209
- </div>
210
- );
211
- };
@@ -1,75 +0,0 @@
1
- import { FC, useState } from 'react';
2
- import { MenuItem } from '../../../Menu/MenuItem';
3
- import { useTranslation } from 'react-i18next';
4
- import { Dialog } from '../../../Dialog/Dialog';
5
- import { createReportTemplate } from './repo/TemplateRepo';
6
- import { IReportTemplate, IReportTemplateData } from '../../../../types/ITable';
7
- import { deleteEmptyProps } from '../../../../utils/ObjectUtils';
8
- import { TextInput } from '../../../Inputs/TextInput';
9
- import { Checkbox } from '../../../Inputs/Checkbox';
10
- import { convertSearchToReportTemplateFilter } from '../../../../utils/TableUtils';
11
-
12
- interface Props {
13
- identifier: string;
14
- data: IReportTemplateData;
15
- onSubmitCallback: () => void;
16
- }
17
-
18
- export const TemplateCreate: FC<Props> = ({
19
- identifier,
20
- data: { searchData, visibleColumns, sorts },
21
- onSubmitCallback,
22
- }) => {
23
- const [isOpen, setIsOpen] = useState(false);
24
- const [formData, setFormData] = useState<Partial<IReportTemplate>>({});
25
- const [isLoading, setIsLoading] = useState(false);
26
-
27
- const { t } = useTranslation();
28
-
29
- const onFormSubmit = () => {
30
- setIsLoading(true);
31
- const data = deleteEmptyProps({
32
- identifier,
33
- name: formData.name,
34
- isPrivate: formData.isPrivate,
35
- filterValues: convertSearchToReportTemplateFilter(searchData),
36
- columns: visibleColumns,
37
- sorts,
38
- }) as Partial<IReportTemplate>;
39
-
40
- createReportTemplate(data)
41
- .then(() => {
42
- setIsOpen(false);
43
- onSubmitCallback();
44
- })
45
- .catch(() => {})
46
- .finally(() => setIsLoading(false));
47
- };
48
-
49
- return (
50
- <>
51
- <MenuItem label={t('CreateTemplateLong')} onClick={() => setIsOpen(true)} />
52
- <Dialog
53
- title={t('CreateTemplate')}
54
- isOpen={isOpen}
55
- onClose={() => setIsOpen(false)}
56
- size="l"
57
- isLoading={isLoading}
58
- confirmButton={{ onFormSubmit, keepOpen: true }}
59
- >
60
- <div className="flex column gap-3">
61
- <TextInput
62
- label={t('Name')}
63
- value={formData.name}
64
- setValue={name => setFormData({ ...formData, name })}
65
- />
66
- <Checkbox
67
- label={t('PrivateTemplate')}
68
- value={formData.isPrivate}
69
- setValue={isPrivate => setFormData({ ...formData, isPrivate })}
70
- />
71
- </div>
72
- </Dialog>
73
- </>
74
- );
75
- };
@@ -1,45 +0,0 @@
1
- import { FC } from 'react';
2
- import { MenuItem } from '../../../Menu/MenuItem';
3
- import { useTranslation } from 'react-i18next';
4
- import { createReportTemplate } from './repo/TemplateRepo';
5
- import { IReportTemplate, IReportTemplateData } from '../../../../types/ITable';
6
- import { deleteEmptyProps } from '../../../../utils/ObjectUtils';
7
- import { convertSearchToReportTemplateFilter } from '../../../../utils/TableUtils';
8
-
9
- interface Props {
10
- identifier: string;
11
- data: IReportTemplateData;
12
- onClose: () => void;
13
- }
14
-
15
- export const TemplateCreateDefault: FC<Props> = ({
16
- identifier,
17
- data: { searchData, visibleColumns, sorts },
18
- onClose,
19
- }) => {
20
- const { t } = useTranslation();
21
-
22
- const onSubmit = () => {
23
- const data: Partial<IReportTemplate> = deleteEmptyProps({
24
- identifier,
25
- name: identifier,
26
- isPrivate: true,
27
- isDefault: true,
28
- filterValues: convertSearchToReportTemplateFilter(searchData),
29
- columns: visibleColumns,
30
- sorts,
31
- });
32
-
33
- createReportTemplate(data);
34
- };
35
-
36
- return (
37
- <MenuItem
38
- label={t('CreateDefaultTemplate')}
39
- onClick={() => {
40
- onSubmit();
41
- onClose();
42
- }}
43
- />
44
- );
45
- };
@@ -1,167 +0,0 @@
1
- import { FC, useCallback, useEffect, useState } from 'react';
2
- import { MenuItem } from '../../../Menu/MenuItem';
3
- import { useTranslation } from 'react-i18next';
4
- import { Dialog } from '../../../Dialog/Dialog';
5
- import {
6
- IReportTemplate,
7
- ITableColumn,
8
- ITableDataItem,
9
- ITableFilter,
10
- } from '../../../../types/ITable';
11
- import { Table } from '../../Table';
12
- import { deleteReportTemplate, getReportTemplates } from './repo/TemplateRepo';
13
- import { ItemActionsMenu } from '../Edit/ItemActionsMenu';
14
- import { deleteEmptyProps, deleteProps } from '../../../../utils/ObjectUtils';
15
- import { DeleteItemDialog } from '../../../Dialog/DeleteItemDialog';
16
- import { IAnyObject } from '../../../../types/IBasic';
17
- import { TextInput } from '../../../Inputs/TextInput';
18
- import { Select } from '../../../Inputs/Selects/Select';
19
- import {
20
- getActiveFilterNumber,
21
- getVisibleColumnsIds,
22
- } from '../../../../utils/TableUtils';
23
-
24
- interface Props {
25
- identifier: string;
26
- onSelect: (template: IReportTemplate) => void;
27
- }
28
-
29
- export const TemplateList: FC<Props> = ({ identifier, onSelect }) => {
30
- const [isOpen, setIsOpen] = useState(false);
31
- const [data, setData] = useState<ITableDataItem[]>([]);
32
- const [limit, setLimit] = useState(5);
33
- const [offset, setOffset] = useState(0);
34
- const [totalRows, setTotalRows] = useState(0);
35
- const [search, setSearch] = useState<{ nameLike?: string }>({});
36
- const [searchData, setSearchData] = useState<{ nameLike?: string }>({});
37
- const [isLoading, setIsLoading] = useState(false);
38
- const [itemToDeleteUuid, setItemToDeleteUuid] = useState('');
39
-
40
- const { t } = useTranslation();
41
-
42
- const columns: ITableColumn[] = [
43
- { id: 'name', label: t('Name') },
44
- { id: 'private', label: t('PrivateTemplate') },
45
- { id: 'actions', label: t('Actions'), width: '70px' },
46
- ];
47
-
48
- const handleGetTemplates = useCallback(() => {
49
- if (isOpen) {
50
- setIsLoading(true);
51
- getReportTemplates({ limit, offset }, { identifier, ...deleteEmptyProps(search) }, [
52
- 'FILTER_VALUES',
53
- ])
54
- .then(({ templates, totalRows }) => {
55
- setData(
56
- templates.map(
57
- e =>
58
- ({
59
- uuid: e.uuid,
60
- onRowClick: () => {
61
- onSelect(e);
62
- setIsOpen(false);
63
- },
64
- cells: {
65
- name: { value: e.name },
66
- private: { value: t(e.isPrivate ? 'Yes' : 'No') },
67
- actions: {
68
- value: (
69
- <ItemActionsMenu
70
- item={e}
71
- // setSelectedItem={e => setSelectedItem(e)}
72
- setItemToDeleteUuid={() => setItemToDeleteUuid(e.uuid)}
73
- />
74
- ),
75
- unclickable: true,
76
- },
77
- },
78
- } as ITableDataItem)
79
- )
80
- );
81
- setTotalRows(totalRows);
82
- })
83
- .catch(() => {})
84
- .finally(() => setIsLoading(false));
85
- }
86
- }, [isOpen, limit, offset, identifier, search]);
87
-
88
- useEffect(handleGetTemplates, [handleGetTemplates]);
89
-
90
- return (
91
- <>
92
- <MenuItem label={t('SelectTemplate')} onClick={() => setIsOpen(true)} />
93
- <Dialog
94
- title={t('TemplateList')}
95
- isOpen={isOpen}
96
- onClose={() => setIsOpen(false)}
97
- size="l"
98
- >
99
- <Table
100
- columns={columns}
101
- data={data}
102
- isLoading={isLoading}
103
- serverSidePagination={{ limit, offset, setLimit, setOffset, totalRows }}
104
- filterData={{
105
- activeFilterNo: getActiveFilterNumber(search),
106
- columns: getVisibleColumnsIds(columns),
107
- filters: filters(searchData, setSearchData, t),
108
- search,
109
- searchData,
110
- setSearchData,
111
- onSubmit: (search: IAnyObject) => {
112
- setOffset(0);
113
- setSearch(search);
114
- },
115
- }}
116
- />
117
- </Dialog>
118
- <DeleteItemDialog
119
- itemUuid={itemToDeleteUuid}
120
- setItemUuid={setItemToDeleteUuid}
121
- textId="Template"
122
- deleteItemFunction={deleteReportTemplate}
123
- reloadItems={handleGetTemplates}
124
- />
125
- </>
126
- );
127
- };
128
-
129
- const filters: (
130
- search: IAnyObject,
131
- setSearch: (search: IAnyObject) => void,
132
- t: any
133
- ) => ITableFilter = (search, setSearch, t) => ({
134
- name: {
135
- label: t('Name'),
136
- field: (
137
- <TextInput
138
- placeholder={t('AddInput') + '...'}
139
- value={search.nameLike}
140
- setValue={nameLike => setSearch({ ...search, nameLike })}
141
- />
142
- ),
143
- resetField: () => setSearch(deleteProps(search, ['nameLike'])),
144
- },
145
- private: {
146
- label: t('PrivateTemplate'),
147
- field: (
148
- <Select
149
- label={t('Choose')}
150
- value={
151
- search.isPrivate !== undefined
152
- ? {
153
- value: search.isPrivate,
154
- label: t(search.isPrivate ? 'Yes' : 'No'),
155
- }
156
- : null
157
- }
158
- options={[
159
- { value: true, label: t(`Yes`) },
160
- { value: false, label: t(`No`) },
161
- ]}
162
- onChange={e => setSearch({ ...search, isPrivate: e.value })}
163
- />
164
- ),
165
- resetField: () => setSearch(deleteProps(search, ['isPrivate'])),
166
- },
167
- });