@addev-be/ui 2.7.5 → 2.7.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.
- package/assets/icons/arrow-down-1-9.svg +1 -1
- package/assets/icons/arrow-down-a-z.svg +1 -1
- package/assets/icons/arrow-up-z-a.svg +1 -1
- package/assets/icons/check.svg +1 -1
- package/assets/icons/circle-check.svg +1 -1
- package/assets/icons/down.svg +1 -1
- package/assets/icons/filter-full.svg +1 -1
- package/assets/icons/filter.svg +1 -1
- package/assets/icons/hashtag.svg +1 -1
- package/assets/icons/image-slash.svg +1 -1
- package/assets/icons/left.svg +1 -1
- package/assets/icons/magnifier.svg +1 -1
- package/assets/icons/phone.svg +1 -1
- package/assets/icons/right.svg +1 -1
- package/assets/icons/sort-calendar-ascending.svg +5 -5
- package/assets/icons/spinner-third.svg +1 -1
- package/assets/icons/table-columns.svg +1 -1
- package/assets/icons/table-footer-slash.svg +4 -4
- package/assets/icons/table-footer.svg +3 -3
- package/assets/icons/up.svg +1 -1
- package/assets/icons/user-tie.svg +1 -1
- package/assets/icons/x-bar.svg +3 -3
- package/dist/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.js +9 -8
- package/dist/components/data/AdvancedRequestDataGrid/helpers/columns.js +21 -72
- package/dist/components/data/AdvancedRequestDataGrid/index.js +2 -2
- package/dist/components/data/AdvancedRequestDataGrid/types.d.ts +1 -1
- package/dist/components/data/DataGrid/AdvancedRequestDataGrid.d.ts +10 -0
- package/dist/components/data/DataGrid/AdvancedRequestDataGrid.js +173 -0
- package/dist/components/data/DataGrid/FilterValuesScroller.d.ts +13 -0
- package/dist/components/data/DataGrid/FilterValuesScroller.js +73 -0
- package/dist/components/data/DataGrid/VirtualScroller.d.ts +11 -0
- package/dist/components/data/DataGrid/VirtualScroller.js +41 -0
- package/dist/components/data/DataGrid/helpers/advancedRequests.d.ts +12 -0
- package/dist/components/data/DataGrid/helpers/advancedRequests.js +53 -0
- package/dist/components/data/DataGrid/helpers.d.ts +28 -0
- package/dist/components/data/DataGrid/helpers.js +436 -0
- package/dist/components/data/SmartQueryDataGrid/helpers/columns.d.ts +20 -0
- package/dist/components/data/SmartQueryDataGrid/helpers/columns.js +160 -0
- package/dist/components/data/SmartQueryDataGrid/helpers/hooks.d.ts +5 -0
- package/dist/components/data/SmartQueryDataGrid/helpers/hooks.js +41 -0
- package/dist/components/data/SmartQueryDataGrid/helpers/index.d.ts +2 -0
- package/dist/components/data/SmartQueryDataGrid/helpers/index.js +18 -0
- package/dist/components/data/SmartQueryDataGrid/helpers/smartQueries.d.ts +3 -0
- package/dist/components/data/SmartQueryDataGrid/helpers/smartQueries.js +15 -0
- package/dist/components/data/SmartQueryDataGrid/hooks.d.ts +9 -0
- package/dist/components/data/SmartQueryDataGrid/hooks.js +63 -0
- package/dist/components/data/SmartQueryDataGrid/index.d.ts +12 -0
- package/dist/components/data/SmartQueryDataGrid/index.js +242 -0
- package/dist/components/data/SmartQueryDataGrid/types.d.ts +22 -0
- package/dist/components/data/SmartQueryDataGrid/types.js +2 -0
- package/dist/components/data/SqlRequestDataGrid/SqlRequestForeignListEditableCell.d.ts +2 -1
- package/dist/components/data/SqlRequestDataGrid/SqlRequestForeignListEditableCell.js +2 -3
- package/dist/components/forms/Form/InputWithLabel.d.ts +2 -0
- package/dist/components/forms/Form/InputWithLabel.js +10 -0
- package/dist/components/forms/Form/types.d.ts +7 -0
- package/dist/components/forms/Form/types.js +2 -0
- package/dist/config/types.d.ts +11 -0
- package/dist/config/types.js +2 -0
- package/dist/helpers/react.d.ts +2 -0
- package/dist/helpers/react.js +8 -0
- package/dist/services/index.js +17 -7
- package/dist/services/requests/userPermissions.d.ts +4 -0
- package/dist/services/requests/userPermissions.js +20 -0
- package/eslint.config.js +3 -3
- package/package.json +2 -2
- package/src/Icons.tsx +138 -138
- package/src/components/auth/LoginForm.tsx +86 -86
- package/src/components/auth/LoginPage.tsx +32 -32
- package/src/components/auth/PasswordRecoveryForm.tsx +53 -53
- package/src/components/auth/PasswordResetForm.tsx +112 -112
- package/src/components/auth/styles.ts +14 -14
- package/src/components/data/DataGrid/DataGridCell.tsx +81 -81
- package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +9 -9
- package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +59 -59
- package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +182 -182
- package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -104
- package/src/components/data/DataGrid/DataGridEditableCell/CheckboxEditableCell.tsx +37 -37
- package/src/components/data/DataGrid/DataGridEditableCell/DateEditableCell.tsx +38 -38
- package/src/components/data/DataGrid/DataGridEditableCell/NumberEditableCell.tsx +71 -71
- package/src/components/data/DataGrid/DataGridEditableCell/TextEditableCell.tsx +37 -37
- package/src/components/data/DataGrid/DataGridEditableCell/index.tsx +106 -106
- package/src/components/data/DataGrid/DataGridEditableCell/styles.ts +35 -35
- package/src/components/data/DataGrid/DataGridEditableCell/types.ts +18 -18
- package/src/components/data/DataGrid/DataGridFilterMenu/FilterValuesScroller.tsx +129 -129
- package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +81 -81
- package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +370 -370
- package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +97 -97
- package/src/components/data/DataGrid/DataGridFooter.tsx +47 -47
- package/src/components/data/DataGrid/DataGridHeader.tsx +74 -74
- package/src/components/data/DataGrid/DataGridHeaderCell.tsx +112 -112
- package/src/components/data/DataGrid/DataGridRowTemplate.tsx +83 -83
- package/src/components/data/DataGrid/DataGridToolbar.tsx +134 -134
- package/src/components/data/DataGrid/FilterModalContent/index.tsx +137 -137
- package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -22
- package/src/components/data/DataGrid/constants.ts +6 -6
- package/src/components/data/DataGrid/helpers/columns.tsx +449 -449
- package/src/components/data/DataGrid/helpers/filters.ts +287 -287
- package/src/components/data/DataGrid/helpers/index.ts +2 -2
- package/src/components/data/DataGrid/hooks/index.ts +29 -29
- package/src/components/data/DataGrid/hooks/useDataGrid.tsx +383 -383
- package/src/components/data/DataGrid/hooks/useDataGridChangedRows.ts +97 -97
- package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +174 -174
- package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +48 -48
- package/src/components/data/DataGrid/hooks/useRefreshModal.tsx +48 -48
- package/src/components/data/DataGrid/index.tsx +111 -111
- package/src/components/data/DataGrid/styles.ts +434 -434
- package/src/components/data/DataGrid/types.ts +380 -380
- package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +526 -526
- package/src/components/data/SqlRequestDataGrid/helpers/index.ts +2 -2
- package/src/components/data/SqlRequestDataGrid/helpers/rows.ts +24 -24
- package/src/components/data/SqlRequestDataGrid/helpers/sqlRequests.ts +17 -17
- package/src/components/data/SqlRequestDataGrid/index.tsx +417 -417
- package/src/components/data/SqlRequestDataGrid/styles.ts +15 -15
- package/src/components/data/SqlRequestDataGrid/types.ts +74 -74
- package/src/components/data/SqlRequestForeignList/index.tsx +254 -254
- package/src/components/data/SqlRequestForeignList/styles.ts +43 -43
- package/src/components/data/SqlRequestForeignList/types.ts +32 -32
- package/src/components/data/SqlRequestGrid/filters/FiltersSidebar.tsx +108 -108
- package/src/components/data/SqlRequestGrid/filters/styles.ts +88 -88
- package/src/components/data/SqlRequestGrid/helpers/index.ts +1 -1
- package/src/components/data/SqlRequestGrid/helpers/sqlRequests.ts +16 -16
- package/src/components/data/SqlRequestGrid/index.tsx +304 -304
- package/src/components/data/SqlRequestGrid/styles.ts +20 -20
- package/src/components/data/SqlRequestGrid/types.ts +73 -73
- package/src/components/data/VirtualScroller/hooks.ts +71 -71
- package/src/components/data/VirtualScroller/index.tsx +89 -89
- package/src/components/data/VirtualScroller/styles.ts +57 -57
- package/src/components/data/VirtualScroller/types.ts +10 -10
- package/src/components/forms/AutoTextArea.tsx +48 -48
- package/src/components/forms/BillitIdentifier/index.tsx +78 -78
- package/src/components/forms/BillitIdentifier/styles.tsx +43 -43
- package/src/components/forms/Button.tsx +132 -132
- package/src/components/forms/Form/Checkbox.tsx +12 -12
- package/src/components/forms/Form/CustomSelect.tsx +86 -86
- package/src/components/forms/Form/FormGroup.tsx +33 -33
- package/src/components/forms/Form/Input.tsx +16 -16
- package/src/components/forms/Form/Row.tsx +28 -28
- package/src/components/forms/Form/Select.tsx +99 -99
- package/src/components/forms/Form/TextArea.tsx +17 -17
- package/src/components/forms/Form/index.tsx +48 -48
- package/src/components/forms/Form/styles.ts +148 -148
- package/src/components/forms/IconButton.tsx +61 -61
- package/src/components/forms/IndeterminateCheckbox.tsx +46 -46
- package/src/components/forms/NumberInput.tsx +53 -53
- package/src/components/forms/Select.tsx +34 -34
- package/src/components/forms/VerticalLabel.tsx +20 -20
- package/src/components/forms/styles.ts +42 -42
- package/src/components/layout/Columns.ts +28 -28
- package/src/components/layout/Dropdown/index.tsx +113 -113
- package/src/components/layout/Dropdown/styles.ts +53 -53
- package/src/components/layout/Flexbox.ts +21 -21
- package/src/components/layout/Grid/index.tsx +8 -8
- package/src/components/layout/Grid/styles.ts +34 -34
- package/src/components/layout/Loading/index.tsx +29 -29
- package/src/components/layout/Loading/styles.ts +29 -29
- package/src/components/layout/Masonry/index.tsx +29 -29
- package/src/components/layout/Masonry/styles.ts +20 -20
- package/src/components/layout/Modal/index.tsx +51 -51
- package/src/components/layout/Modal/styles.ts +125 -125
- package/src/components/search/HighlightedText.tsx +41 -41
- package/src/components/search/QuickSearchBar.tsx +102 -102
- package/src/components/search/QuickSearchResults.tsx +86 -86
- package/src/components/search/styles.ts +96 -96
- package/src/components/search/types.ts +29 -29
- package/src/components/ui/Avatar/index.tsx +54 -54
- package/src/components/ui/Card/index.tsx +16 -16
- package/src/components/ui/Card/styles.ts +41 -41
- package/src/components/ui/ContextMenu/index.tsx +79 -79
- package/src/components/ui/ContextMenu/styles.ts +119 -119
- package/src/components/ui/Ellipsis.tsx +33 -33
- package/src/components/ui/Label.tsx +93 -93
- package/src/components/ui/Message/index.tsx +57 -57
- package/src/components/ui/Message/styles.ts +44 -44
- package/src/components/ui/TabsView/TabsList.tsx +49 -49
- package/src/components/ui/TabsView/TabsView.tsx +42 -42
- package/src/components/ui/TabsView/styles.ts +84 -84
- package/src/components/ui/TabsView/types.ts +15 -15
- package/src/config/index.ts +10 -10
- package/src/helpers/components.ts +9 -9
- package/src/helpers/dates.ts +17 -17
- package/src/helpers/getScrollbarSize.ts +14 -14
- package/src/helpers/numbers.ts +63 -63
- package/src/helpers/responsive.ts +83 -83
- package/src/helpers/styled/space.ts +114 -114
- package/src/helpers/styled/typography.ts +25 -25
- package/src/helpers/text.ts +13 -13
- package/src/helpers/types.ts +9 -9
- package/src/hooks/useContainerMediaQuery.ts +7 -7
- package/src/hooks/useElementSize.ts +24 -24
- package/src/hooks/useMediaQuery.ts +9 -9
- package/src/hooks/useMediaQueryForWidth.ts +35 -35
- package/src/hooks/useMutableState.test.ts +410 -410
- package/src/hooks/useMutableState.ts +39 -39
- package/src/hooks/useShowArchived.ts +28 -28
- package/src/hooks/useWindowSize.ts +20 -20
- package/src/index.ts +103 -103
- package/src/providers/AuthenticationProvider/helpers.ts +3 -3
- package/src/providers/AuthenticationProvider/index.tsx +303 -303
- package/src/providers/LoadingProvider/index.tsx +47 -47
- package/src/providers/PortalsProvider/index.tsx +54 -54
- package/src/providers/PortalsProvider/styles.ts +31 -31
- package/src/providers/SettingsProvider/index.tsx +70 -70
- package/src/providers/ThemeProvider/defaultTheme.ts +471 -471
- package/src/providers/ThemeProvider/helpers.ts +84 -84
- package/src/providers/ThemeProvider/index.ts +73 -73
- package/src/providers/ThemeProvider/types.ts +134 -134
- package/src/providers/ToastProvider/index.tsx +93 -93
- package/src/providers/TrackingProvider/index.tsx +71 -71
- package/src/providers/UiProviders/index.tsx +76 -76
- package/src/providers/UiProviders/styles.ts +10 -10
- package/src/providers/hooks.ts +14 -14
- package/src/services/HttpService.ts +92 -92
- package/src/services/WebSocketService.ts +155 -155
- package/src/services/advancedRequests.ts +102 -102
- package/src/services/base.ts +23 -23
- package/src/services/globalSearch.ts +32 -32
- package/src/services/hooks.ts +92 -92
- package/src/services/requests/auth.ts +44 -44
- package/src/services/requests/generic.ts +62 -62
- package/src/services/requests/printing.ts +12 -12
- package/src/services/requests/tracking.ts +12 -12
- package/src/services/requests/userProfiles.ts +35 -35
- package/src/services/requests/users.ts +28 -28
- package/src/services/smartQueries.ts +122 -122
- package/src/services/sqlRequests.ts +119 -119
- package/src/services/types/auth.ts +98 -98
- package/src/services/types/base.ts +10 -10
- package/src/services/types/generic.ts +82 -82
- package/src/services/types/printing.ts +10 -10
- package/src/services/types/tracking.ts +29 -29
- package/src/services/types/userProfiles.ts +79 -79
- package/src/services/types/users.ts +74 -74
- package/src/services/updateSqlRequests.ts +32 -32
- package/src/styles/animations.scss +30 -30
- package/src/styles/index.scss +42 -42
- package/src/types.ts +8 -8
- package/src/typings.d.ts +2 -2
- package/tsconfig.json +18 -18
|
@@ -1,526 +1,526 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
import { SqlImage, SqlImageWrapper } from '../styles';
|
|
4
|
-
import {
|
|
5
|
-
SqlRequestDataGridCheckboxColumn,
|
|
6
|
-
SqlRequestDataGridDateColumn,
|
|
7
|
-
SqlRequestDataGridForeignListColumn,
|
|
8
|
-
SqlRequestDataGridNumberColumn,
|
|
9
|
-
SqlRequestDataGridTextColumn,
|
|
10
|
-
} from '../types';
|
|
11
|
-
import {
|
|
12
|
-
buildExcelFormat,
|
|
13
|
-
dateFilter,
|
|
14
|
-
numberFilter,
|
|
15
|
-
textFilter,
|
|
16
|
-
} from '../../DataGrid/helpers';
|
|
17
|
-
import { convertItemToPartialRow, convertRowToItem } from './rows';
|
|
18
|
-
import { formatDate, formatDateTime } from '../../../../helpers/dates';
|
|
19
|
-
import {
|
|
20
|
-
formatMoney,
|
|
21
|
-
formatNumber,
|
|
22
|
-
formatNumberInvariant,
|
|
23
|
-
formatPercentage,
|
|
24
|
-
} from '../../../../helpers/numbers';
|
|
25
|
-
|
|
26
|
-
import { CheckboxEditableCell } from '../../DataGrid/DataGridEditableCell/CheckboxEditableCell';
|
|
27
|
-
import { DEFAULT_ROW_HEIGHT } from '../../DataGrid/constants';
|
|
28
|
-
import { DateEditableCell } from '../../DataGrid/DataGridEditableCell/DateEditableCell';
|
|
29
|
-
import { DeepPartial } from '../../../../types';
|
|
30
|
-
import { NumberEditableCell } from '../../DataGrid/DataGridEditableCell/NumberEditableCell';
|
|
31
|
-
import { SqlRequestForeignList } from '../../SqlRequestForeignList';
|
|
32
|
-
import { SqlRequestForeignListItemFC } from '../../SqlRequestForeignList/types';
|
|
33
|
-
import { StyledTypography } from '../../../../helpers/styled/typography';
|
|
34
|
-
import { TextEditableCell } from '../../DataGrid/DataGridEditableCell/TextEditableCell';
|
|
35
|
-
import { merge } from 'lodash';
|
|
36
|
-
import { useContext } from 'react';
|
|
37
|
-
|
|
38
|
-
export const sqlTextColumn = <R extends Record<string, any>>(
|
|
39
|
-
key: string,
|
|
40
|
-
title: React.ReactNode,
|
|
41
|
-
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
42
|
-
): SqlRequestDataGridTextColumn<R> =>
|
|
43
|
-
merge(
|
|
44
|
-
{
|
|
45
|
-
key,
|
|
46
|
-
type: 'text',
|
|
47
|
-
name: title,
|
|
48
|
-
render: (value) => (
|
|
49
|
-
<StyledTypography {...options?.typography}>{value}</StyledTypography>
|
|
50
|
-
),
|
|
51
|
-
getter: (row) => row[key] ?? '',
|
|
52
|
-
sortGetter: (row) => row[key] ?? '',
|
|
53
|
-
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
54
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
55
|
-
editComponent: TextEditableCell,
|
|
56
|
-
} as SqlRequestDataGridTextColumn<R>,
|
|
57
|
-
options
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
export const sqlMailColumn = <R extends Record<string, any>>(
|
|
61
|
-
key: string,
|
|
62
|
-
title: string,
|
|
63
|
-
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
64
|
-
): SqlRequestDataGridTextColumn<R> =>
|
|
65
|
-
merge(
|
|
66
|
-
{
|
|
67
|
-
key,
|
|
68
|
-
type: 'text',
|
|
69
|
-
name: title,
|
|
70
|
-
render: (value) => (
|
|
71
|
-
<StyledTypography
|
|
72
|
-
href={`mailto:${value}`}
|
|
73
|
-
{...options?.typography}
|
|
74
|
-
as={'a'}
|
|
75
|
-
>
|
|
76
|
-
{value}
|
|
77
|
-
</StyledTypography>
|
|
78
|
-
),
|
|
79
|
-
getter: (row) => row[key] ?? '',
|
|
80
|
-
sortGetter: (row) => row[key] ?? '',
|
|
81
|
-
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
82
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
83
|
-
editComponent: TextEditableCell,
|
|
84
|
-
} as SqlRequestDataGridTextColumn<R>,
|
|
85
|
-
options
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
export const sqlPhoneColumn = <R extends Record<string, any>>(
|
|
89
|
-
key: string,
|
|
90
|
-
title: string,
|
|
91
|
-
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
92
|
-
): SqlRequestDataGridTextColumn<R> =>
|
|
93
|
-
merge(
|
|
94
|
-
{
|
|
95
|
-
key,
|
|
96
|
-
type: 'text',
|
|
97
|
-
name: title,
|
|
98
|
-
render: (value) => (
|
|
99
|
-
<StyledTypography
|
|
100
|
-
href={`tel:${value}`}
|
|
101
|
-
{...options?.typography}
|
|
102
|
-
as={'a'}
|
|
103
|
-
>
|
|
104
|
-
{value}
|
|
105
|
-
</StyledTypography>
|
|
106
|
-
),
|
|
107
|
-
getter: (row) => row[key] ?? '',
|
|
108
|
-
sortGetter: (row) => row[key] ?? '',
|
|
109
|
-
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
110
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
111
|
-
editComponent: TextEditableCell,
|
|
112
|
-
} as SqlRequestDataGridTextColumn<R>,
|
|
113
|
-
options
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
export const sqlDateColumn = <R extends Record<string, any>>(
|
|
117
|
-
key: string,
|
|
118
|
-
title: string,
|
|
119
|
-
options?: DeepPartial<SqlRequestDataGridDateColumn<R>>
|
|
120
|
-
): SqlRequestDataGridDateColumn<R> =>
|
|
121
|
-
merge(
|
|
122
|
-
{
|
|
123
|
-
key,
|
|
124
|
-
name: title,
|
|
125
|
-
type: 'date',
|
|
126
|
-
render: (value) => (
|
|
127
|
-
<StyledTypography {...options?.typography}>
|
|
128
|
-
{formatDate(value)}
|
|
129
|
-
</StyledTypography>
|
|
130
|
-
),
|
|
131
|
-
getter: (row) => row[key] ?? '',
|
|
132
|
-
sortGetter: (row) => row[key] ?? '',
|
|
133
|
-
excelOptions: {
|
|
134
|
-
formatter: () => 'dd/mm/yyyy',
|
|
135
|
-
valueGetter: (value) => formatDate(value, 'YYYY-MM-DD'),
|
|
136
|
-
},
|
|
137
|
-
filter: {
|
|
138
|
-
...dateFilter(key),
|
|
139
|
-
getter: (value) => value[key] ?? '',
|
|
140
|
-
formatter: (value) => formatDate(value),
|
|
141
|
-
renderer: (value) => formatDate(value),
|
|
142
|
-
},
|
|
143
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
144
|
-
editComponent: DateEditableCell,
|
|
145
|
-
} as SqlRequestDataGridDateColumn<R>,
|
|
146
|
-
options
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
export const sqlDateTimeColumn = <R extends Record<string, any>>(
|
|
150
|
-
key: string,
|
|
151
|
-
title: string,
|
|
152
|
-
options?: DeepPartial<SqlRequestDataGridDateColumn<R>>
|
|
153
|
-
): SqlRequestDataGridDateColumn<R> =>
|
|
154
|
-
merge(
|
|
155
|
-
{
|
|
156
|
-
key,
|
|
157
|
-
name: title,
|
|
158
|
-
type: 'date',
|
|
159
|
-
render: (value) => (
|
|
160
|
-
<StyledTypography {...options?.typography}>
|
|
161
|
-
{formatDateTime(value)}
|
|
162
|
-
</StyledTypography>
|
|
163
|
-
),
|
|
164
|
-
getter: (row) => row[key] ?? '',
|
|
165
|
-
sortGetter: (row) => row[key] ?? '',
|
|
166
|
-
excelOptions: {
|
|
167
|
-
formatter: () => 'dd/mm/yyyy hh:mm:ss',
|
|
168
|
-
valueGetter: (value) => formatDateTime(value, 'YYYY-MM-DD HH:mm:ss'),
|
|
169
|
-
},
|
|
170
|
-
filter: {
|
|
171
|
-
...dateFilter(key),
|
|
172
|
-
getter: (value) => value[key] ?? '',
|
|
173
|
-
formatter: (value) => formatDateTime(value),
|
|
174
|
-
renderer: (value) => formatDateTime(value),
|
|
175
|
-
},
|
|
176
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
177
|
-
editComponent: DateEditableCell,
|
|
178
|
-
} as SqlRequestDataGridDateColumn<R>,
|
|
179
|
-
options
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
export const sqlMonthColumn = <R extends Record<string, any>>(
|
|
183
|
-
key: string,
|
|
184
|
-
title: string,
|
|
185
|
-
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
186
|
-
): SqlRequestDataGridTextColumn<R> =>
|
|
187
|
-
merge(
|
|
188
|
-
{
|
|
189
|
-
key,
|
|
190
|
-
type: 'text',
|
|
191
|
-
name: title,
|
|
192
|
-
render: (value) => (
|
|
193
|
-
<StyledTypography {...options?.typography}>
|
|
194
|
-
{value + 'Mois'}
|
|
195
|
-
</StyledTypography>
|
|
196
|
-
),
|
|
197
|
-
getter: (row) => row[key] ?? '',
|
|
198
|
-
sortGetter: (row) => row[key] ?? '',
|
|
199
|
-
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
200
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
201
|
-
} as SqlRequestDataGridTextColumn<R>,
|
|
202
|
-
options
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
export const sqlNumberColumn = <R extends Record<string, any>>(
|
|
206
|
-
key: string,
|
|
207
|
-
title: string,
|
|
208
|
-
decimals = 2,
|
|
209
|
-
options?: DeepPartial<SqlRequestDataGridNumberColumn<R>>
|
|
210
|
-
): SqlRequestDataGridNumberColumn<R> => {
|
|
211
|
-
const column: SqlRequestDataGridNumberColumn<R> = {
|
|
212
|
-
key,
|
|
213
|
-
name: title,
|
|
214
|
-
type: 'number',
|
|
215
|
-
decimals,
|
|
216
|
-
textAlign: 'right',
|
|
217
|
-
render: (value) => (
|
|
218
|
-
<StyledTypography {...options?.typography}>
|
|
219
|
-
{formatNumber(value, decimals)}
|
|
220
|
-
</StyledTypography>
|
|
221
|
-
),
|
|
222
|
-
excelOptions: {
|
|
223
|
-
formatter: () => buildExcelFormat(decimals),
|
|
224
|
-
valueGetter: (value) => formatNumberInvariant(value, decimals),
|
|
225
|
-
},
|
|
226
|
-
getter: (row) => row[key] ?? '',
|
|
227
|
-
sortGetter: (row) => row[key] ?? 0,
|
|
228
|
-
filter: {
|
|
229
|
-
...numberFilter(key),
|
|
230
|
-
getter: (value) => value[key] ?? 0,
|
|
231
|
-
renderer: (value) => formatNumber(value, decimals) ?? '',
|
|
232
|
-
},
|
|
233
|
-
footer: {
|
|
234
|
-
sum: (rows) => formatNumber(rows[0]?.[key] ?? 0, decimals),
|
|
235
|
-
avg: (rows) => formatNumber(rows[0]?.[key] ?? 0, decimals),
|
|
236
|
-
count: (rows) => `${rows[0]?.[key] ?? 0} éléments`,
|
|
237
|
-
max: (rows) => formatNumber(rows[0]?.[key] ?? 0, decimals),
|
|
238
|
-
min: (rows) => formatNumber(rows[0]?.[key] ?? 0, decimals),
|
|
239
|
-
},
|
|
240
|
-
editComponent: ({ ref, ...otherProps }) => (
|
|
241
|
-
<NumberEditableCell<R>
|
|
242
|
-
ref={ref}
|
|
243
|
-
decimals={column.decimals}
|
|
244
|
-
currency={column.currency}
|
|
245
|
-
prefix={column.prefix}
|
|
246
|
-
suffix={column.suffix}
|
|
247
|
-
{...otherProps}
|
|
248
|
-
/>
|
|
249
|
-
),
|
|
250
|
-
};
|
|
251
|
-
return merge(column, options);
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
export const sqlMoneyColumn = <R extends Record<string, any>>(
|
|
255
|
-
key: string,
|
|
256
|
-
title: string,
|
|
257
|
-
decimals = 2,
|
|
258
|
-
currency: string | ((row: R) => string) = 'EUR',
|
|
259
|
-
options?: DeepPartial<SqlRequestDataGridNumberColumn<R>>
|
|
260
|
-
): SqlRequestDataGridNumberColumn<R> => {
|
|
261
|
-
const column: SqlRequestDataGridNumberColumn<R> = {
|
|
262
|
-
key,
|
|
263
|
-
name: title,
|
|
264
|
-
type: 'number',
|
|
265
|
-
decimals,
|
|
266
|
-
currency,
|
|
267
|
-
textAlign: 'right',
|
|
268
|
-
render:
|
|
269
|
-
typeof currency === 'function'
|
|
270
|
-
? (value, row) => (
|
|
271
|
-
<StyledTypography {...options?.typography}>
|
|
272
|
-
{formatMoney(value, decimals, currency(row))}
|
|
273
|
-
</StyledTypography>
|
|
274
|
-
)
|
|
275
|
-
: (value) => (
|
|
276
|
-
<StyledTypography {...options?.typography}>
|
|
277
|
-
{formatMoney(value, decimals, currency)}
|
|
278
|
-
</StyledTypography>
|
|
279
|
-
),
|
|
280
|
-
excelOptions: {
|
|
281
|
-
formatter:
|
|
282
|
-
typeof currency === 'function'
|
|
283
|
-
? (row) => buildExcelFormat(decimals, currency(row))
|
|
284
|
-
: () => buildExcelFormat(decimals, currency),
|
|
285
|
-
valueGetter: (value) => formatNumberInvariant(value, decimals),
|
|
286
|
-
},
|
|
287
|
-
getter: (row) => row[key] ?? '',
|
|
288
|
-
sortGetter: (row) => row[key] ?? 0,
|
|
289
|
-
filter: {
|
|
290
|
-
...numberFilter(key),
|
|
291
|
-
getter: (value) => value[key] ?? 0,
|
|
292
|
-
renderer:
|
|
293
|
-
typeof currency === 'function'
|
|
294
|
-
? (value) => formatMoney(value, decimals, currency(value)) ?? ''
|
|
295
|
-
: (value) => formatMoney(value, decimals, currency) ?? '',
|
|
296
|
-
},
|
|
297
|
-
footer: {
|
|
298
|
-
sum: (rows) =>
|
|
299
|
-
formatMoney(
|
|
300
|
-
rows[0]?.[key] ?? 0,
|
|
301
|
-
decimals,
|
|
302
|
-
typeof currency === 'function' ? 'EUR' : currency
|
|
303
|
-
),
|
|
304
|
-
avg: (rows) =>
|
|
305
|
-
formatMoney(
|
|
306
|
-
rows[0]?.[key] ?? 0,
|
|
307
|
-
decimals,
|
|
308
|
-
typeof currency === 'function' ? 'EUR' : currency
|
|
309
|
-
),
|
|
310
|
-
count: (rows) => `${rows[0]?.[key] ?? 0} éléments`,
|
|
311
|
-
max: (rows) =>
|
|
312
|
-
formatMoney(
|
|
313
|
-
rows[0]?.[key] ?? 0,
|
|
314
|
-
decimals,
|
|
315
|
-
typeof currency === 'function' ? 'EUR' : currency
|
|
316
|
-
),
|
|
317
|
-
min: (rows) =>
|
|
318
|
-
formatMoney(
|
|
319
|
-
rows[0]?.[key] ?? 0,
|
|
320
|
-
decimals,
|
|
321
|
-
typeof currency === 'function' ? 'EUR' : currency
|
|
322
|
-
),
|
|
323
|
-
},
|
|
324
|
-
editComponent: ({ ref, ...otherProps }) => (
|
|
325
|
-
<NumberEditableCell<R>
|
|
326
|
-
ref={ref}
|
|
327
|
-
decimals={column.decimals}
|
|
328
|
-
currency={column.currency}
|
|
329
|
-
{...otherProps}
|
|
330
|
-
/>
|
|
331
|
-
),
|
|
332
|
-
};
|
|
333
|
-
return merge(column, options);
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
export const sqlPercentageColumn = <R extends Record<string, any>>(
|
|
337
|
-
key: string,
|
|
338
|
-
title: string,
|
|
339
|
-
decimals = 2,
|
|
340
|
-
options?: DeepPartial<SqlRequestDataGridNumberColumn<R>>
|
|
341
|
-
): SqlRequestDataGridNumberColumn<R> => {
|
|
342
|
-
const column: SqlRequestDataGridNumberColumn<R> = {
|
|
343
|
-
key,
|
|
344
|
-
name: title,
|
|
345
|
-
type: 'number',
|
|
346
|
-
render: (value) => (
|
|
347
|
-
<StyledTypography {...options?.typography}>
|
|
348
|
-
{formatPercentage(value)}
|
|
349
|
-
</StyledTypography>
|
|
350
|
-
),
|
|
351
|
-
excelOptions: {
|
|
352
|
-
formatter: () => buildExcelFormat(decimals, '%'),
|
|
353
|
-
valueGetter: (value) => formatNumberInvariant(value, decimals + 2),
|
|
354
|
-
},
|
|
355
|
-
getter: (row) => row[key] ?? '',
|
|
356
|
-
sortGetter: (row) => row[key] ?? 0,
|
|
357
|
-
filter: {
|
|
358
|
-
...numberFilter(key),
|
|
359
|
-
getter: (value) => value[key] ?? 0,
|
|
360
|
-
renderer: (value) => formatPercentage(value, decimals) ?? '',
|
|
361
|
-
},
|
|
362
|
-
editComponent: ({ ref, ...otherProps }) => (
|
|
363
|
-
<NumberEditableCell<R>
|
|
364
|
-
ref={ref}
|
|
365
|
-
decimals={column.decimals}
|
|
366
|
-
currency={column.currency}
|
|
367
|
-
{...otherProps}
|
|
368
|
-
/>
|
|
369
|
-
),
|
|
370
|
-
};
|
|
371
|
-
return merge(column, options);
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
export const sqlCheckboxColumn = <R extends Record<string, any>>(
|
|
375
|
-
key: string,
|
|
376
|
-
title: string,
|
|
377
|
-
options?: DeepPartial<SqlRequestDataGridCheckboxColumn<R>>
|
|
378
|
-
): SqlRequestDataGridCheckboxColumn<R> =>
|
|
379
|
-
merge(
|
|
380
|
-
{
|
|
381
|
-
key,
|
|
382
|
-
name: title,
|
|
383
|
-
type: 'checkbox',
|
|
384
|
-
render: (value) => {
|
|
385
|
-
const normalized = typeof value === 'string' ? value : String(value);
|
|
386
|
-
const isChecked = normalized === 'true' || normalized === '1';
|
|
387
|
-
return (
|
|
388
|
-
<>
|
|
389
|
-
<input type="checkbox" checked={isChecked} readOnly />
|
|
390
|
-
<span>{isChecked ? ' Oui' : ' Non'}</span>
|
|
391
|
-
</>
|
|
392
|
-
);
|
|
393
|
-
},
|
|
394
|
-
getter: (row) => row[key] ?? '',
|
|
395
|
-
sortGetter: (row) => row[key] ?? '',
|
|
396
|
-
filter: { ...numberFilter(key), getter: (value) => +(value[key] ?? 0) },
|
|
397
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
398
|
-
editComponent: CheckboxEditableCell,
|
|
399
|
-
} as SqlRequestDataGridCheckboxColumn<R>,
|
|
400
|
-
options
|
|
401
|
-
);
|
|
402
|
-
|
|
403
|
-
export const sqlImageColumn = <R extends Record<string, any>>(
|
|
404
|
-
key: string,
|
|
405
|
-
title: string,
|
|
406
|
-
urlPrefix: string,
|
|
407
|
-
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
408
|
-
): SqlRequestDataGridTextColumn<R> =>
|
|
409
|
-
merge(
|
|
410
|
-
{
|
|
411
|
-
key,
|
|
412
|
-
type: 'text',
|
|
413
|
-
name: title,
|
|
414
|
-
render: (value) => (
|
|
415
|
-
<SqlImageWrapper>
|
|
416
|
-
<SqlImage
|
|
417
|
-
src={value ? `${urlPrefix}${value}` : `${urlPrefix}no-image.png`}
|
|
418
|
-
alt={title}
|
|
419
|
-
/>
|
|
420
|
-
</SqlImageWrapper>
|
|
421
|
-
),
|
|
422
|
-
getter: (row) => row[key] ?? '',
|
|
423
|
-
sortGetter: (row) => row[key] ?? '',
|
|
424
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
425
|
-
} as SqlRequestDataGridTextColumn<R>,
|
|
426
|
-
options
|
|
427
|
-
);
|
|
428
|
-
|
|
429
|
-
export const sqlColorColumn = <R extends Record<string, any>>(
|
|
430
|
-
key: string,
|
|
431
|
-
title: string,
|
|
432
|
-
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
433
|
-
): SqlRequestDataGridTextColumn<R> =>
|
|
434
|
-
merge(
|
|
435
|
-
{
|
|
436
|
-
key,
|
|
437
|
-
type: 'text',
|
|
438
|
-
name: title,
|
|
439
|
-
render: (value) => (
|
|
440
|
-
<div style={{ position: 'absolute', inset: 0, backgroundColor: value }}>
|
|
441
|
-
|
|
442
|
-
</div>
|
|
443
|
-
),
|
|
444
|
-
excelOptions: {
|
|
445
|
-
valueGetter: () => '',
|
|
446
|
-
colorGetter: (value) => value,
|
|
447
|
-
},
|
|
448
|
-
getter: (row) => row[key] ?? '',
|
|
449
|
-
sortGetter: (row) => row[key] ?? '',
|
|
450
|
-
filter: {
|
|
451
|
-
...textFilter(key),
|
|
452
|
-
getter: (value) => value[key] ?? '',
|
|
453
|
-
renderer: (value) => (
|
|
454
|
-
<div
|
|
455
|
-
style={{
|
|
456
|
-
backgroundColor: value,
|
|
457
|
-
width: 'var(--space-16)',
|
|
458
|
-
height: '1em',
|
|
459
|
-
}}
|
|
460
|
-
>
|
|
461
|
-
|
|
462
|
-
</div>
|
|
463
|
-
),
|
|
464
|
-
},
|
|
465
|
-
} as SqlRequestDataGridTextColumn<R>,
|
|
466
|
-
options
|
|
467
|
-
);
|
|
468
|
-
|
|
469
|
-
export const sqlForeignListColumn = <
|
|
470
|
-
R extends Record<string, any>,
|
|
471
|
-
T extends Record<string, any>,
|
|
472
|
-
C extends string
|
|
473
|
-
>(
|
|
474
|
-
key: string,
|
|
475
|
-
columnMapping: Record<keyof R, C>,
|
|
476
|
-
title: string,
|
|
477
|
-
requestName: string,
|
|
478
|
-
ItemTemplate: SqlRequestForeignListItemFC<T>,
|
|
479
|
-
options?: DeepPartial<SqlRequestDataGridForeignListColumn<R, T | null>>
|
|
480
|
-
): SqlRequestDataGridForeignListColumn<R, T | null> => {
|
|
481
|
-
const column: SqlRequestDataGridForeignListColumn<R, T | null> = {
|
|
482
|
-
key,
|
|
483
|
-
name: title,
|
|
484
|
-
type: 'foreignList',
|
|
485
|
-
getter: (row) => row[key] ?? '',
|
|
486
|
-
sortGetter: (row) => row[key] ?? '',
|
|
487
|
-
render: (value, row) => (
|
|
488
|
-
<ItemTemplate
|
|
489
|
-
item={convertRowToItem<R, T>(row, columnMapping)}
|
|
490
|
-
index={0}
|
|
491
|
-
/>
|
|
492
|
-
),
|
|
493
|
-
filter: {
|
|
494
|
-
...textFilter(key),
|
|
495
|
-
getter: (value) => value[key] ?? '',
|
|
496
|
-
renderer: (value) => value,
|
|
497
|
-
},
|
|
498
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
499
|
-
requestName,
|
|
500
|
-
idColumn: 'Id',
|
|
501
|
-
itemTemplate: ItemTemplate,
|
|
502
|
-
columns: Object.values(columnMapping),
|
|
503
|
-
editComponent: ({ row, onChange, onClose, context, ref }) => {
|
|
504
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
505
|
-
const { rowHeight = DEFAULT_ROW_HEIGHT } = useContext(context);
|
|
506
|
-
return (
|
|
507
|
-
<SqlRequestForeignList<T>
|
|
508
|
-
initialValue={convertRowToItem<R, T>(row, columnMapping)}
|
|
509
|
-
maxRows={10}
|
|
510
|
-
rowHeight={rowHeight - 2}
|
|
511
|
-
onItemChanged={onChange}
|
|
512
|
-
onBlur={() => onClose(true)}
|
|
513
|
-
ref={ref}
|
|
514
|
-
requestName={column.requestName}
|
|
515
|
-
idColumn={column.idColumn}
|
|
516
|
-
columns={column.columns}
|
|
517
|
-
itemTemplate={column.itemTemplate}
|
|
518
|
-
valueTemplate={column.valueTemplate}
|
|
519
|
-
/>
|
|
520
|
-
);
|
|
521
|
-
},
|
|
522
|
-
itemToPartialRow: (key, row, value) =>
|
|
523
|
-
convertItemToPartialRow(key, row, value, columnMapping),
|
|
524
|
-
};
|
|
525
|
-
return merge(column, options);
|
|
526
|
-
};
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import { SqlImage, SqlImageWrapper } from '../styles';
|
|
4
|
+
import {
|
|
5
|
+
SqlRequestDataGridCheckboxColumn,
|
|
6
|
+
SqlRequestDataGridDateColumn,
|
|
7
|
+
SqlRequestDataGridForeignListColumn,
|
|
8
|
+
SqlRequestDataGridNumberColumn,
|
|
9
|
+
SqlRequestDataGridTextColumn,
|
|
10
|
+
} from '../types';
|
|
11
|
+
import {
|
|
12
|
+
buildExcelFormat,
|
|
13
|
+
dateFilter,
|
|
14
|
+
numberFilter,
|
|
15
|
+
textFilter,
|
|
16
|
+
} from '../../DataGrid/helpers';
|
|
17
|
+
import { convertItemToPartialRow, convertRowToItem } from './rows';
|
|
18
|
+
import { formatDate, formatDateTime } from '../../../../helpers/dates';
|
|
19
|
+
import {
|
|
20
|
+
formatMoney,
|
|
21
|
+
formatNumber,
|
|
22
|
+
formatNumberInvariant,
|
|
23
|
+
formatPercentage,
|
|
24
|
+
} from '../../../../helpers/numbers';
|
|
25
|
+
|
|
26
|
+
import { CheckboxEditableCell } from '../../DataGrid/DataGridEditableCell/CheckboxEditableCell';
|
|
27
|
+
import { DEFAULT_ROW_HEIGHT } from '../../DataGrid/constants';
|
|
28
|
+
import { DateEditableCell } from '../../DataGrid/DataGridEditableCell/DateEditableCell';
|
|
29
|
+
import { DeepPartial } from '../../../../types';
|
|
30
|
+
import { NumberEditableCell } from '../../DataGrid/DataGridEditableCell/NumberEditableCell';
|
|
31
|
+
import { SqlRequestForeignList } from '../../SqlRequestForeignList';
|
|
32
|
+
import { SqlRequestForeignListItemFC } from '../../SqlRequestForeignList/types';
|
|
33
|
+
import { StyledTypography } from '../../../../helpers/styled/typography';
|
|
34
|
+
import { TextEditableCell } from '../../DataGrid/DataGridEditableCell/TextEditableCell';
|
|
35
|
+
import { merge } from 'lodash';
|
|
36
|
+
import { useContext } from 'react';
|
|
37
|
+
|
|
38
|
+
export const sqlTextColumn = <R extends Record<string, any>>(
|
|
39
|
+
key: string,
|
|
40
|
+
title: React.ReactNode,
|
|
41
|
+
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
42
|
+
): SqlRequestDataGridTextColumn<R> =>
|
|
43
|
+
merge(
|
|
44
|
+
{
|
|
45
|
+
key,
|
|
46
|
+
type: 'text',
|
|
47
|
+
name: title,
|
|
48
|
+
render: (value) => (
|
|
49
|
+
<StyledTypography {...options?.typography}>{value}</StyledTypography>
|
|
50
|
+
),
|
|
51
|
+
getter: (row) => row[key] ?? '',
|
|
52
|
+
sortGetter: (row) => row[key] ?? '',
|
|
53
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
54
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
55
|
+
editComponent: TextEditableCell,
|
|
56
|
+
} as SqlRequestDataGridTextColumn<R>,
|
|
57
|
+
options
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export const sqlMailColumn = <R extends Record<string, any>>(
|
|
61
|
+
key: string,
|
|
62
|
+
title: string,
|
|
63
|
+
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
64
|
+
): SqlRequestDataGridTextColumn<R> =>
|
|
65
|
+
merge(
|
|
66
|
+
{
|
|
67
|
+
key,
|
|
68
|
+
type: 'text',
|
|
69
|
+
name: title,
|
|
70
|
+
render: (value) => (
|
|
71
|
+
<StyledTypography
|
|
72
|
+
href={`mailto:${value}`}
|
|
73
|
+
{...options?.typography}
|
|
74
|
+
as={'a'}
|
|
75
|
+
>
|
|
76
|
+
{value}
|
|
77
|
+
</StyledTypography>
|
|
78
|
+
),
|
|
79
|
+
getter: (row) => row[key] ?? '',
|
|
80
|
+
sortGetter: (row) => row[key] ?? '',
|
|
81
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
82
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
83
|
+
editComponent: TextEditableCell,
|
|
84
|
+
} as SqlRequestDataGridTextColumn<R>,
|
|
85
|
+
options
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
export const sqlPhoneColumn = <R extends Record<string, any>>(
|
|
89
|
+
key: string,
|
|
90
|
+
title: string,
|
|
91
|
+
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
92
|
+
): SqlRequestDataGridTextColumn<R> =>
|
|
93
|
+
merge(
|
|
94
|
+
{
|
|
95
|
+
key,
|
|
96
|
+
type: 'text',
|
|
97
|
+
name: title,
|
|
98
|
+
render: (value) => (
|
|
99
|
+
<StyledTypography
|
|
100
|
+
href={`tel:${value}`}
|
|
101
|
+
{...options?.typography}
|
|
102
|
+
as={'a'}
|
|
103
|
+
>
|
|
104
|
+
{value}
|
|
105
|
+
</StyledTypography>
|
|
106
|
+
),
|
|
107
|
+
getter: (row) => row[key] ?? '',
|
|
108
|
+
sortGetter: (row) => row[key] ?? '',
|
|
109
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
110
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
111
|
+
editComponent: TextEditableCell,
|
|
112
|
+
} as SqlRequestDataGridTextColumn<R>,
|
|
113
|
+
options
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
export const sqlDateColumn = <R extends Record<string, any>>(
|
|
117
|
+
key: string,
|
|
118
|
+
title: string,
|
|
119
|
+
options?: DeepPartial<SqlRequestDataGridDateColumn<R>>
|
|
120
|
+
): SqlRequestDataGridDateColumn<R> =>
|
|
121
|
+
merge(
|
|
122
|
+
{
|
|
123
|
+
key,
|
|
124
|
+
name: title,
|
|
125
|
+
type: 'date',
|
|
126
|
+
render: (value) => (
|
|
127
|
+
<StyledTypography {...options?.typography}>
|
|
128
|
+
{formatDate(value)}
|
|
129
|
+
</StyledTypography>
|
|
130
|
+
),
|
|
131
|
+
getter: (row) => row[key] ?? '',
|
|
132
|
+
sortGetter: (row) => row[key] ?? '',
|
|
133
|
+
excelOptions: {
|
|
134
|
+
formatter: () => 'dd/mm/yyyy',
|
|
135
|
+
valueGetter: (value) => formatDate(value, 'YYYY-MM-DD'),
|
|
136
|
+
},
|
|
137
|
+
filter: {
|
|
138
|
+
...dateFilter(key),
|
|
139
|
+
getter: (value) => value[key] ?? '',
|
|
140
|
+
formatter: (value) => formatDate(value),
|
|
141
|
+
renderer: (value) => formatDate(value),
|
|
142
|
+
},
|
|
143
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
144
|
+
editComponent: DateEditableCell,
|
|
145
|
+
} as SqlRequestDataGridDateColumn<R>,
|
|
146
|
+
options
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
export const sqlDateTimeColumn = <R extends Record<string, any>>(
|
|
150
|
+
key: string,
|
|
151
|
+
title: string,
|
|
152
|
+
options?: DeepPartial<SqlRequestDataGridDateColumn<R>>
|
|
153
|
+
): SqlRequestDataGridDateColumn<R> =>
|
|
154
|
+
merge(
|
|
155
|
+
{
|
|
156
|
+
key,
|
|
157
|
+
name: title,
|
|
158
|
+
type: 'date',
|
|
159
|
+
render: (value) => (
|
|
160
|
+
<StyledTypography {...options?.typography}>
|
|
161
|
+
{formatDateTime(value)}
|
|
162
|
+
</StyledTypography>
|
|
163
|
+
),
|
|
164
|
+
getter: (row) => row[key] ?? '',
|
|
165
|
+
sortGetter: (row) => row[key] ?? '',
|
|
166
|
+
excelOptions: {
|
|
167
|
+
formatter: () => 'dd/mm/yyyy hh:mm:ss',
|
|
168
|
+
valueGetter: (value) => formatDateTime(value, 'YYYY-MM-DD HH:mm:ss'),
|
|
169
|
+
},
|
|
170
|
+
filter: {
|
|
171
|
+
...dateFilter(key),
|
|
172
|
+
getter: (value) => value[key] ?? '',
|
|
173
|
+
formatter: (value) => formatDateTime(value),
|
|
174
|
+
renderer: (value) => formatDateTime(value),
|
|
175
|
+
},
|
|
176
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
177
|
+
editComponent: DateEditableCell,
|
|
178
|
+
} as SqlRequestDataGridDateColumn<R>,
|
|
179
|
+
options
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
export const sqlMonthColumn = <R extends Record<string, any>>(
|
|
183
|
+
key: string,
|
|
184
|
+
title: string,
|
|
185
|
+
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
186
|
+
): SqlRequestDataGridTextColumn<R> =>
|
|
187
|
+
merge(
|
|
188
|
+
{
|
|
189
|
+
key,
|
|
190
|
+
type: 'text',
|
|
191
|
+
name: title,
|
|
192
|
+
render: (value) => (
|
|
193
|
+
<StyledTypography {...options?.typography}>
|
|
194
|
+
{value + 'Mois'}
|
|
195
|
+
</StyledTypography>
|
|
196
|
+
),
|
|
197
|
+
getter: (row) => row[key] ?? '',
|
|
198
|
+
sortGetter: (row) => row[key] ?? '',
|
|
199
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
200
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
201
|
+
} as SqlRequestDataGridTextColumn<R>,
|
|
202
|
+
options
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
export const sqlNumberColumn = <R extends Record<string, any>>(
|
|
206
|
+
key: string,
|
|
207
|
+
title: string,
|
|
208
|
+
decimals = 2,
|
|
209
|
+
options?: DeepPartial<SqlRequestDataGridNumberColumn<R>>
|
|
210
|
+
): SqlRequestDataGridNumberColumn<R> => {
|
|
211
|
+
const column: SqlRequestDataGridNumberColumn<R> = {
|
|
212
|
+
key,
|
|
213
|
+
name: title,
|
|
214
|
+
type: 'number',
|
|
215
|
+
decimals,
|
|
216
|
+
textAlign: 'right',
|
|
217
|
+
render: (value) => (
|
|
218
|
+
<StyledTypography {...options?.typography}>
|
|
219
|
+
{formatNumber(value, decimals)}
|
|
220
|
+
</StyledTypography>
|
|
221
|
+
),
|
|
222
|
+
excelOptions: {
|
|
223
|
+
formatter: () => buildExcelFormat(decimals),
|
|
224
|
+
valueGetter: (value) => formatNumberInvariant(value, decimals),
|
|
225
|
+
},
|
|
226
|
+
getter: (row) => row[key] ?? '',
|
|
227
|
+
sortGetter: (row) => row[key] ?? 0,
|
|
228
|
+
filter: {
|
|
229
|
+
...numberFilter(key),
|
|
230
|
+
getter: (value) => value[key] ?? 0,
|
|
231
|
+
renderer: (value) => formatNumber(value, decimals) ?? '',
|
|
232
|
+
},
|
|
233
|
+
footer: {
|
|
234
|
+
sum: (rows) => formatNumber(rows[0]?.[key] ?? 0, decimals),
|
|
235
|
+
avg: (rows) => formatNumber(rows[0]?.[key] ?? 0, decimals),
|
|
236
|
+
count: (rows) => `${rows[0]?.[key] ?? 0} éléments`,
|
|
237
|
+
max: (rows) => formatNumber(rows[0]?.[key] ?? 0, decimals),
|
|
238
|
+
min: (rows) => formatNumber(rows[0]?.[key] ?? 0, decimals),
|
|
239
|
+
},
|
|
240
|
+
editComponent: ({ ref, ...otherProps }) => (
|
|
241
|
+
<NumberEditableCell<R>
|
|
242
|
+
ref={ref}
|
|
243
|
+
decimals={column.decimals}
|
|
244
|
+
currency={column.currency}
|
|
245
|
+
prefix={column.prefix}
|
|
246
|
+
suffix={column.suffix}
|
|
247
|
+
{...otherProps}
|
|
248
|
+
/>
|
|
249
|
+
),
|
|
250
|
+
};
|
|
251
|
+
return merge(column, options);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export const sqlMoneyColumn = <R extends Record<string, any>>(
|
|
255
|
+
key: string,
|
|
256
|
+
title: string,
|
|
257
|
+
decimals = 2,
|
|
258
|
+
currency: string | ((row: R) => string) = 'EUR',
|
|
259
|
+
options?: DeepPartial<SqlRequestDataGridNumberColumn<R>>
|
|
260
|
+
): SqlRequestDataGridNumberColumn<R> => {
|
|
261
|
+
const column: SqlRequestDataGridNumberColumn<R> = {
|
|
262
|
+
key,
|
|
263
|
+
name: title,
|
|
264
|
+
type: 'number',
|
|
265
|
+
decimals,
|
|
266
|
+
currency,
|
|
267
|
+
textAlign: 'right',
|
|
268
|
+
render:
|
|
269
|
+
typeof currency === 'function'
|
|
270
|
+
? (value, row) => (
|
|
271
|
+
<StyledTypography {...options?.typography}>
|
|
272
|
+
{formatMoney(value, decimals, currency(row))}
|
|
273
|
+
</StyledTypography>
|
|
274
|
+
)
|
|
275
|
+
: (value) => (
|
|
276
|
+
<StyledTypography {...options?.typography}>
|
|
277
|
+
{formatMoney(value, decimals, currency)}
|
|
278
|
+
</StyledTypography>
|
|
279
|
+
),
|
|
280
|
+
excelOptions: {
|
|
281
|
+
formatter:
|
|
282
|
+
typeof currency === 'function'
|
|
283
|
+
? (row) => buildExcelFormat(decimals, currency(row))
|
|
284
|
+
: () => buildExcelFormat(decimals, currency),
|
|
285
|
+
valueGetter: (value) => formatNumberInvariant(value, decimals),
|
|
286
|
+
},
|
|
287
|
+
getter: (row) => row[key] ?? '',
|
|
288
|
+
sortGetter: (row) => row[key] ?? 0,
|
|
289
|
+
filter: {
|
|
290
|
+
...numberFilter(key),
|
|
291
|
+
getter: (value) => value[key] ?? 0,
|
|
292
|
+
renderer:
|
|
293
|
+
typeof currency === 'function'
|
|
294
|
+
? (value) => formatMoney(value, decimals, currency(value)) ?? ''
|
|
295
|
+
: (value) => formatMoney(value, decimals, currency) ?? '',
|
|
296
|
+
},
|
|
297
|
+
footer: {
|
|
298
|
+
sum: (rows) =>
|
|
299
|
+
formatMoney(
|
|
300
|
+
rows[0]?.[key] ?? 0,
|
|
301
|
+
decimals,
|
|
302
|
+
typeof currency === 'function' ? 'EUR' : currency
|
|
303
|
+
),
|
|
304
|
+
avg: (rows) =>
|
|
305
|
+
formatMoney(
|
|
306
|
+
rows[0]?.[key] ?? 0,
|
|
307
|
+
decimals,
|
|
308
|
+
typeof currency === 'function' ? 'EUR' : currency
|
|
309
|
+
),
|
|
310
|
+
count: (rows) => `${rows[0]?.[key] ?? 0} éléments`,
|
|
311
|
+
max: (rows) =>
|
|
312
|
+
formatMoney(
|
|
313
|
+
rows[0]?.[key] ?? 0,
|
|
314
|
+
decimals,
|
|
315
|
+
typeof currency === 'function' ? 'EUR' : currency
|
|
316
|
+
),
|
|
317
|
+
min: (rows) =>
|
|
318
|
+
formatMoney(
|
|
319
|
+
rows[0]?.[key] ?? 0,
|
|
320
|
+
decimals,
|
|
321
|
+
typeof currency === 'function' ? 'EUR' : currency
|
|
322
|
+
),
|
|
323
|
+
},
|
|
324
|
+
editComponent: ({ ref, ...otherProps }) => (
|
|
325
|
+
<NumberEditableCell<R>
|
|
326
|
+
ref={ref}
|
|
327
|
+
decimals={column.decimals}
|
|
328
|
+
currency={column.currency}
|
|
329
|
+
{...otherProps}
|
|
330
|
+
/>
|
|
331
|
+
),
|
|
332
|
+
};
|
|
333
|
+
return merge(column, options);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
export const sqlPercentageColumn = <R extends Record<string, any>>(
|
|
337
|
+
key: string,
|
|
338
|
+
title: string,
|
|
339
|
+
decimals = 2,
|
|
340
|
+
options?: DeepPartial<SqlRequestDataGridNumberColumn<R>>
|
|
341
|
+
): SqlRequestDataGridNumberColumn<R> => {
|
|
342
|
+
const column: SqlRequestDataGridNumberColumn<R> = {
|
|
343
|
+
key,
|
|
344
|
+
name: title,
|
|
345
|
+
type: 'number',
|
|
346
|
+
render: (value) => (
|
|
347
|
+
<StyledTypography {...options?.typography}>
|
|
348
|
+
{formatPercentage(value)}
|
|
349
|
+
</StyledTypography>
|
|
350
|
+
),
|
|
351
|
+
excelOptions: {
|
|
352
|
+
formatter: () => buildExcelFormat(decimals, '%'),
|
|
353
|
+
valueGetter: (value) => formatNumberInvariant(value, decimals + 2),
|
|
354
|
+
},
|
|
355
|
+
getter: (row) => row[key] ?? '',
|
|
356
|
+
sortGetter: (row) => row[key] ?? 0,
|
|
357
|
+
filter: {
|
|
358
|
+
...numberFilter(key),
|
|
359
|
+
getter: (value) => value[key] ?? 0,
|
|
360
|
+
renderer: (value) => formatPercentage(value, decimals) ?? '',
|
|
361
|
+
},
|
|
362
|
+
editComponent: ({ ref, ...otherProps }) => (
|
|
363
|
+
<NumberEditableCell<R>
|
|
364
|
+
ref={ref}
|
|
365
|
+
decimals={column.decimals}
|
|
366
|
+
currency={column.currency}
|
|
367
|
+
{...otherProps}
|
|
368
|
+
/>
|
|
369
|
+
),
|
|
370
|
+
};
|
|
371
|
+
return merge(column, options);
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
export const sqlCheckboxColumn = <R extends Record<string, any>>(
|
|
375
|
+
key: string,
|
|
376
|
+
title: string,
|
|
377
|
+
options?: DeepPartial<SqlRequestDataGridCheckboxColumn<R>>
|
|
378
|
+
): SqlRequestDataGridCheckboxColumn<R> =>
|
|
379
|
+
merge(
|
|
380
|
+
{
|
|
381
|
+
key,
|
|
382
|
+
name: title,
|
|
383
|
+
type: 'checkbox',
|
|
384
|
+
render: (value) => {
|
|
385
|
+
const normalized = typeof value === 'string' ? value : String(value);
|
|
386
|
+
const isChecked = normalized === 'true' || normalized === '1';
|
|
387
|
+
return (
|
|
388
|
+
<>
|
|
389
|
+
<input type="checkbox" checked={isChecked} readOnly />
|
|
390
|
+
<span>{isChecked ? ' Oui' : ' Non'}</span>
|
|
391
|
+
</>
|
|
392
|
+
);
|
|
393
|
+
},
|
|
394
|
+
getter: (row) => row[key] ?? '',
|
|
395
|
+
sortGetter: (row) => row[key] ?? '',
|
|
396
|
+
filter: { ...numberFilter(key), getter: (value) => +(value[key] ?? 0) },
|
|
397
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
398
|
+
editComponent: CheckboxEditableCell,
|
|
399
|
+
} as SqlRequestDataGridCheckboxColumn<R>,
|
|
400
|
+
options
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
export const sqlImageColumn = <R extends Record<string, any>>(
|
|
404
|
+
key: string,
|
|
405
|
+
title: string,
|
|
406
|
+
urlPrefix: string,
|
|
407
|
+
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
408
|
+
): SqlRequestDataGridTextColumn<R> =>
|
|
409
|
+
merge(
|
|
410
|
+
{
|
|
411
|
+
key,
|
|
412
|
+
type: 'text',
|
|
413
|
+
name: title,
|
|
414
|
+
render: (value) => (
|
|
415
|
+
<SqlImageWrapper>
|
|
416
|
+
<SqlImage
|
|
417
|
+
src={value ? `${urlPrefix}${value}` : `${urlPrefix}no-image.png`}
|
|
418
|
+
alt={title}
|
|
419
|
+
/>
|
|
420
|
+
</SqlImageWrapper>
|
|
421
|
+
),
|
|
422
|
+
getter: (row) => row[key] ?? '',
|
|
423
|
+
sortGetter: (row) => row[key] ?? '',
|
|
424
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
425
|
+
} as SqlRequestDataGridTextColumn<R>,
|
|
426
|
+
options
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
export const sqlColorColumn = <R extends Record<string, any>>(
|
|
430
|
+
key: string,
|
|
431
|
+
title: string,
|
|
432
|
+
options?: DeepPartial<SqlRequestDataGridTextColumn<R>>
|
|
433
|
+
): SqlRequestDataGridTextColumn<R> =>
|
|
434
|
+
merge(
|
|
435
|
+
{
|
|
436
|
+
key,
|
|
437
|
+
type: 'text',
|
|
438
|
+
name: title,
|
|
439
|
+
render: (value) => (
|
|
440
|
+
<div style={{ position: 'absolute', inset: 0, backgroundColor: value }}>
|
|
441
|
+
|
|
442
|
+
</div>
|
|
443
|
+
),
|
|
444
|
+
excelOptions: {
|
|
445
|
+
valueGetter: () => '',
|
|
446
|
+
colorGetter: (value) => value,
|
|
447
|
+
},
|
|
448
|
+
getter: (row) => row[key] ?? '',
|
|
449
|
+
sortGetter: (row) => row[key] ?? '',
|
|
450
|
+
filter: {
|
|
451
|
+
...textFilter(key),
|
|
452
|
+
getter: (value) => value[key] ?? '',
|
|
453
|
+
renderer: (value) => (
|
|
454
|
+
<div
|
|
455
|
+
style={{
|
|
456
|
+
backgroundColor: value,
|
|
457
|
+
width: 'var(--space-16)',
|
|
458
|
+
height: '1em',
|
|
459
|
+
}}
|
|
460
|
+
>
|
|
461
|
+
|
|
462
|
+
</div>
|
|
463
|
+
),
|
|
464
|
+
},
|
|
465
|
+
} as SqlRequestDataGridTextColumn<R>,
|
|
466
|
+
options
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
export const sqlForeignListColumn = <
|
|
470
|
+
R extends Record<string, any>,
|
|
471
|
+
T extends Record<string, any>,
|
|
472
|
+
C extends string
|
|
473
|
+
>(
|
|
474
|
+
key: string,
|
|
475
|
+
columnMapping: Record<keyof R, C>,
|
|
476
|
+
title: string,
|
|
477
|
+
requestName: string,
|
|
478
|
+
ItemTemplate: SqlRequestForeignListItemFC<T>,
|
|
479
|
+
options?: DeepPartial<SqlRequestDataGridForeignListColumn<R, T | null>>
|
|
480
|
+
): SqlRequestDataGridForeignListColumn<R, T | null> => {
|
|
481
|
+
const column: SqlRequestDataGridForeignListColumn<R, T | null> = {
|
|
482
|
+
key,
|
|
483
|
+
name: title,
|
|
484
|
+
type: 'foreignList',
|
|
485
|
+
getter: (row) => row[key] ?? '',
|
|
486
|
+
sortGetter: (row) => row[key] ?? '',
|
|
487
|
+
render: (value, row) => (
|
|
488
|
+
<ItemTemplate
|
|
489
|
+
item={convertRowToItem<R, T>(row, columnMapping)}
|
|
490
|
+
index={0}
|
|
491
|
+
/>
|
|
492
|
+
),
|
|
493
|
+
filter: {
|
|
494
|
+
...textFilter(key),
|
|
495
|
+
getter: (value) => value[key] ?? '',
|
|
496
|
+
renderer: (value) => value,
|
|
497
|
+
},
|
|
498
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
499
|
+
requestName,
|
|
500
|
+
idColumn: 'Id',
|
|
501
|
+
itemTemplate: ItemTemplate,
|
|
502
|
+
columns: Object.values(columnMapping),
|
|
503
|
+
editComponent: ({ row, onChange, onClose, context, ref }) => {
|
|
504
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
505
|
+
const { rowHeight = DEFAULT_ROW_HEIGHT } = useContext(context);
|
|
506
|
+
return (
|
|
507
|
+
<SqlRequestForeignList<T>
|
|
508
|
+
initialValue={convertRowToItem<R, T>(row, columnMapping)}
|
|
509
|
+
maxRows={10}
|
|
510
|
+
rowHeight={rowHeight - 2}
|
|
511
|
+
onItemChanged={onChange}
|
|
512
|
+
onBlur={() => onClose(true)}
|
|
513
|
+
ref={ref}
|
|
514
|
+
requestName={column.requestName}
|
|
515
|
+
idColumn={column.idColumn}
|
|
516
|
+
columns={column.columns}
|
|
517
|
+
itemTemplate={column.itemTemplate}
|
|
518
|
+
valueTemplate={column.valueTemplate}
|
|
519
|
+
/>
|
|
520
|
+
);
|
|
521
|
+
},
|
|
522
|
+
itemToPartialRow: (key, row, value) =>
|
|
523
|
+
convertItemToPartialRow(key, row, value, columnMapping),
|
|
524
|
+
};
|
|
525
|
+
return merge(column, options);
|
|
526
|
+
};
|