@addev-be/ui 0.2.13 → 0.2.15
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/dist/Icons.d.ts +3 -1
- package/dist/Icons.js +5 -1
- package/dist/components/data/DataGrid/{FilterValuesScroller.d.ts → DataGridFilterMenu/FilterValuesScroller.d.ts} +1 -1
- package/dist/components/data/DataGrid/{FilterValuesScroller.js → DataGridFilterMenu/FilterValuesScroller.js} +6 -9
- package/dist/components/data/DataGrid/DataGridFilterMenu/index.js +3 -3
- package/dist/components/data/DataGrid/DataGridFilterMenu/styles.d.ts +9 -0
- package/dist/components/data/DataGrid/DataGridFilterMenu/styles.js +12 -2
- package/dist/components/data/DataGrid/FilterModalContent/index.js +18 -9
- package/dist/components/data/DataGrid/helpers/columns.d.ts +1 -0
- package/dist/components/data/DataGrid/helpers/columns.js +7 -6
- package/dist/components/data/DataGrid/helpers/filters.d.ts +1 -0
- package/dist/components/data/DataGrid/helpers/filters.js +71 -2
- package/dist/components/data/DataGrid/hooks/useDataGrid.js +2 -1
- package/dist/components/data/DataGrid/hooks/useDataGridCopy.js +2 -0
- package/dist/components/data/DataGrid/styles.d.ts +0 -9
- package/dist/components/data/DataGrid/styles.js +2 -12
- package/dist/components/data/DataGrid/types.d.ts +2 -0
- package/dist/components/data/SqlRequestDataGrid/helpers/columns.js +6 -6
- package/dist/helpers/numbers.d.ts +1 -0
- package/dist/helpers/numbers.js +9 -1
- package/dist/services/globalSearch.d.ts +13 -0
- package/dist/services/globalSearch.js +8 -0
- package/package.json +18 -12
- package/dist/components/data/DataGrid/AdvancedRequestDataGrid.d.ts +0 -9
- package/dist/components/data/DataGrid/AdvancedRequestDataGrid.js +0 -171
- package/dist/components/data/DataGrid/helpers/advancedRequests.d.ts +0 -12
- package/dist/components/data/DataGrid/helpers/advancedRequests.js +0 -53
- package/eslint.config.js +0 -28
- package/src/Icons.tsx +0 -108
- package/src/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.ts +0 -93
- package/src/components/data/AdvancedRequestDataGrid/helpers/columns.tsx +0 -262
- package/src/components/data/AdvancedRequestDataGrid/helpers/index.ts +0 -2
- package/src/components/data/AdvancedRequestDataGrid/index.tsx +0 -267
- package/src/components/data/AdvancedRequestDataGrid/types.ts +0 -47
- package/src/components/data/DataGrid/DataGridCell.tsx +0 -73
- package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +0 -14
- package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +0 -59
- package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +0 -181
- package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +0 -104
- package/src/components/data/DataGrid/DataGridEditableCell.tsx +0 -43
- package/src/components/data/DataGrid/DataGridFilterMenu/FilterValuesScroller.tsx +0 -120
- package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +0 -75
- package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +0 -360
- package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +0 -96
- package/src/components/data/DataGrid/DataGridFooter.tsx +0 -42
- package/src/components/data/DataGrid/DataGridHeader.tsx +0 -126
- package/src/components/data/DataGrid/DataGridHeaderCell.tsx +0 -132
- package/src/components/data/DataGrid/FilterModalContent/index.tsx +0 -136
- package/src/components/data/DataGrid/FilterModalContent/styles.ts +0 -22
- package/src/components/data/DataGrid/VirtualScroller.tsx +0 -46
- package/src/components/data/DataGrid/helpers/columns.tsx +0 -295
- package/src/components/data/DataGrid/helpers/filters.ts +0 -287
- package/src/components/data/DataGrid/helpers/index.ts +0 -2
- package/src/components/data/DataGrid/hooks/index.ts +0 -30
- package/src/components/data/DataGrid/hooks/useDataGrid.tsx +0 -306
- package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +0 -175
- package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +0 -48
- package/src/components/data/DataGrid/index.tsx +0 -140
- package/src/components/data/DataGrid/styles.ts +0 -323
- package/src/components/data/DataGrid/types.ts +0 -267
- package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +0 -277
- package/src/components/data/SqlRequestDataGrid/helpers/index.ts +0 -2
- package/src/components/data/SqlRequestDataGrid/helpers/sqlRequests.ts +0 -16
- package/src/components/data/SqlRequestDataGrid/index.tsx +0 -347
- package/src/components/data/SqlRequestDataGrid/types.ts +0 -47
- package/src/components/data/index.ts +0 -8
- package/src/components/forms/Button.tsx +0 -99
- package/src/components/forms/IconButton.tsx +0 -56
- package/src/components/forms/IndeterminateCheckbox.tsx +0 -46
- package/src/components/forms/Select.tsx +0 -40
- package/src/components/forms/index.ts +0 -5
- package/src/components/forms/styles.ts +0 -20
- package/src/components/index.ts +0 -3
- package/src/components/layout/Dropdown/index.tsx +0 -79
- package/src/components/layout/Dropdown/styles.ts +0 -44
- package/src/components/layout/Loading/index.tsx +0 -29
- package/src/components/layout/Loading/styles.ts +0 -29
- package/src/components/layout/Modal/index.tsx +0 -51
- package/src/components/layout/Modal/styles.ts +0 -110
- package/src/components/layout/index.ts +0 -3
- package/src/components/ui/ContextMenu/index.tsx +0 -79
- package/src/components/ui/ContextMenu/styles.ts +0 -119
- package/src/config/index.ts +0 -14
- package/src/helpers/dates.ts +0 -9
- package/src/helpers/getScrollbarSize.ts +0 -14
- package/src/helpers/numbers.ts +0 -26
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useElementSize.ts +0 -24
- package/src/hooks/useWindowSize.ts +0 -20
- package/src/index.ts +0 -7
- package/src/providers/PortalsProvider/index.tsx +0 -54
- package/src/providers/PortalsProvider/styles.ts +0 -27
- package/src/providers/SettingsProvider/index.tsx +0 -70
- package/src/providers/ThemeProvider/ThemeProvider.ts +0 -55
- package/src/providers/ThemeProvider/defaultTheme.ts +0 -444
- package/src/providers/ThemeProvider/index.ts +0 -3
- package/src/providers/ThemeProvider/types.ts +0 -123
- package/src/providers/UiProviders/index.tsx +0 -65
- package/src/providers/UiProviders/styles.ts +0 -10
- package/src/providers/hooks.ts +0 -8
- package/src/providers/index.ts +0 -5
- package/src/services/HttpService.ts +0 -80
- package/src/services/WebSocketService.ts +0 -147
- package/src/services/advancedRequests.ts +0 -101
- package/src/services/base.ts +0 -31
- package/src/services/globalSearch.ts +0 -27
- package/src/services/hooks.ts +0 -23
- package/src/services/index.ts +0 -2
- package/src/services/sqlRequests.ts +0 -110
- package/src/styles/animations.scss +0 -30
- package/src/styles/index.scss +0 -42
- package/src/typings.d.ts +0 -6
- package/tsconfig.json +0 -18
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
3
|
-
|
|
4
|
-
import * as styles from './styles';
|
|
5
|
-
|
|
6
|
-
import { MouseEvent, useCallback, useMemo, useRef, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import { ChevronDownIcon } from '../../../Icons';
|
|
9
|
-
import { DataGridFilterMenu } from './DataGridFilterMenu';
|
|
10
|
-
import { DataGridHeaderCellProps } from './types';
|
|
11
|
-
import { Dropdown } from '../../layout';
|
|
12
|
-
import { IconButton } from '../../forms/IconButton';
|
|
13
|
-
import { useDataGridContext } from './hooks';
|
|
14
|
-
import { useUi } from '../../../providers';
|
|
15
|
-
|
|
16
|
-
export const DataGridHeaderCell = <R,>({
|
|
17
|
-
columnKey,
|
|
18
|
-
columnIndex,
|
|
19
|
-
column,
|
|
20
|
-
context,
|
|
21
|
-
}: DataGridHeaderCellProps<R>) => {
|
|
22
|
-
const { getElementScreenRect } = useUi();
|
|
23
|
-
const contextValue = useDataGridContext(context);
|
|
24
|
-
const {
|
|
25
|
-
filters = {},
|
|
26
|
-
setColumnWidth,
|
|
27
|
-
saveSettings,
|
|
28
|
-
headerColor,
|
|
29
|
-
} = contextValue;
|
|
30
|
-
const filterButtonRef = useRef<HTMLButtonElement | null>(null);
|
|
31
|
-
|
|
32
|
-
/** RESIZING */
|
|
33
|
-
|
|
34
|
-
const [isResizing, setIsResizing] = useState(false);
|
|
35
|
-
const resizingOffset = useRef(0);
|
|
36
|
-
|
|
37
|
-
const onResizeStart = useCallback(
|
|
38
|
-
(e: MouseEvent) => {
|
|
39
|
-
resizingOffset.current = e.screenX - (column.width || 150);
|
|
40
|
-
setIsResizing(true);
|
|
41
|
-
},
|
|
42
|
-
[column.width]
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const onResizeMove = useCallback(
|
|
46
|
-
(e: MouseEvent) => {
|
|
47
|
-
if (isResizing) {
|
|
48
|
-
const newWidth = Math.max(86, e.screenX - resizingOffset.current);
|
|
49
|
-
setColumnWidth(columnKey, newWidth);
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
[columnKey, isResizing, setColumnWidth]
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const onResizeEnd = useCallback(() => {
|
|
56
|
-
setIsResizing(false);
|
|
57
|
-
saveSettings();
|
|
58
|
-
}, [saveSettings]);
|
|
59
|
-
|
|
60
|
-
const [isFilterDropdownVisible, setIsFilterDropdownVisible] = useState(false);
|
|
61
|
-
const filterDropdown = useMemo(() => {
|
|
62
|
-
if (!isFilterDropdownVisible || !filterButtonRef.current || !columnKey) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
const filterButtonRect = getElementScreenRect(filterButtonRef.current);
|
|
66
|
-
filterButtonRect.x += window.scrollX;
|
|
67
|
-
filterButtonRect.y += window.scrollY;
|
|
68
|
-
return (
|
|
69
|
-
<Dropdown
|
|
70
|
-
$sourceRect={filterButtonRect}
|
|
71
|
-
onClose={() => setIsFilterDropdownVisible(false)}
|
|
72
|
-
$width={320}
|
|
73
|
-
$height={[250, 400]}
|
|
74
|
-
$autoPositionX
|
|
75
|
-
>
|
|
76
|
-
<DataGridFilterMenu
|
|
77
|
-
columnKey={columnKey}
|
|
78
|
-
columnIndex={columnIndex}
|
|
79
|
-
context={context}
|
|
80
|
-
onClose={() => setIsFilterDropdownVisible(false)}
|
|
81
|
-
/>
|
|
82
|
-
</Dropdown>
|
|
83
|
-
);
|
|
84
|
-
}, [
|
|
85
|
-
columnIndex,
|
|
86
|
-
columnKey,
|
|
87
|
-
context,
|
|
88
|
-
getElementScreenRect,
|
|
89
|
-
isFilterDropdownVisible,
|
|
90
|
-
]);
|
|
91
|
-
|
|
92
|
-
const onFilterButtonClicked = useCallback(() => {
|
|
93
|
-
setIsFilterDropdownVisible(true);
|
|
94
|
-
}, []);
|
|
95
|
-
|
|
96
|
-
const hasFilters = filters[columnKey]?.values.length > 0;
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<styles.DataGridHeaderCellContainer
|
|
100
|
-
$headerColor={headerColor}
|
|
101
|
-
$isResizing={isResizing}
|
|
102
|
-
>
|
|
103
|
-
{filterDropdown}
|
|
104
|
-
<span>{column.name}</span>
|
|
105
|
-
{!!column.filter && (
|
|
106
|
-
<IconButton
|
|
107
|
-
size="small"
|
|
108
|
-
className={hasFilters ? 'danger' : ''}
|
|
109
|
-
ref={filterButtonRef}
|
|
110
|
-
icon={ChevronDownIcon}
|
|
111
|
-
color={hasFilters ? 'danger' : headerColor}
|
|
112
|
-
onClick={onFilterButtonClicked}
|
|
113
|
-
/>
|
|
114
|
-
)}
|
|
115
|
-
{column.resizable !== false && (
|
|
116
|
-
<>
|
|
117
|
-
<styles.DataGridResizeGrip
|
|
118
|
-
className={isResizing ? 'active' : ''}
|
|
119
|
-
$headerColor={headerColor}
|
|
120
|
-
onMouseDown={onResizeStart}
|
|
121
|
-
/>
|
|
122
|
-
{isResizing && (
|
|
123
|
-
<styles.ResizeBackdrop
|
|
124
|
-
onMouseMove={onResizeMove}
|
|
125
|
-
onMouseUp={onResizeEnd}
|
|
126
|
-
/>
|
|
127
|
-
)}
|
|
128
|
-
</>
|
|
129
|
-
)}
|
|
130
|
-
</styles.DataGridHeaderCellContainer>
|
|
131
|
-
);
|
|
132
|
-
};
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
3
|
-
|
|
4
|
-
import * as styles from './styles';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
DataGridFilter,
|
|
8
|
-
DataGridFilterOperator,
|
|
9
|
-
DataGridFilterType,
|
|
10
|
-
} from '../types';
|
|
11
|
-
import { Input, Select } from '../../../forms';
|
|
12
|
-
import { useEffect, useRef } from 'react';
|
|
13
|
-
|
|
14
|
-
// import { Select } from '../../Select';
|
|
15
|
-
// import clx from 'classnames';
|
|
16
|
-
|
|
17
|
-
const filterOperators: {
|
|
18
|
-
[K in DataGridFilterType]: Partial<{
|
|
19
|
-
[K2 in DataGridFilterOperator<K>]: string;
|
|
20
|
-
}>;
|
|
21
|
-
} = {
|
|
22
|
-
date: {
|
|
23
|
-
after: 'Après',
|
|
24
|
-
before: 'Avant',
|
|
25
|
-
equals: 'Égal à',
|
|
26
|
-
notEquals: 'Différent de',
|
|
27
|
-
inRange: "Dans l'intervalle",
|
|
28
|
-
},
|
|
29
|
-
number: {
|
|
30
|
-
equals: 'Égal à',
|
|
31
|
-
notEquals: 'Différent de',
|
|
32
|
-
greaterThan: 'Supérieur à',
|
|
33
|
-
greaterThanOrEqual: 'Supérieur ou égal à',
|
|
34
|
-
lessThan: 'Inférieur à',
|
|
35
|
-
lessThanOrEqual: 'Inférieur ou égal à',
|
|
36
|
-
inRange: "Dans l'intervalle",
|
|
37
|
-
},
|
|
38
|
-
text: {
|
|
39
|
-
equals: 'Égal à',
|
|
40
|
-
notEquals: 'Différent de',
|
|
41
|
-
contains: 'Contient',
|
|
42
|
-
notContains: 'Ne contient pas',
|
|
43
|
-
startsWith: 'Commence par',
|
|
44
|
-
endsWith: 'Finit par',
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
type FilterModalContentProps = {
|
|
49
|
-
filter: DataGridFilter;
|
|
50
|
-
onFilterChanged: (filter: DataGridFilter) => void;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const FilterModalContent = ({
|
|
54
|
-
filter,
|
|
55
|
-
onFilterChanged,
|
|
56
|
-
}: FilterModalContentProps) => {
|
|
57
|
-
const value1Ref = useRef<HTMLInputElement>(null);
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
setTimeout(() => value1Ref.current?.focus(), 100);
|
|
60
|
-
}, []);
|
|
61
|
-
|
|
62
|
-
if (!filter) return null;
|
|
63
|
-
|
|
64
|
-
const { operator, type, values } = filter;
|
|
65
|
-
return (
|
|
66
|
-
<styles.FilterModalContentContainer>
|
|
67
|
-
<label htmlFor="filterOperator">
|
|
68
|
-
<span>Opérateur :</span>
|
|
69
|
-
<Select
|
|
70
|
-
name="filterOperator"
|
|
71
|
-
items={Object.entries(filterOperators[filter.type])}
|
|
72
|
-
itemKey={0}
|
|
73
|
-
itemLabel={1}
|
|
74
|
-
value={String(operator)}
|
|
75
|
-
className="text-sm"
|
|
76
|
-
onChange={(e) =>
|
|
77
|
-
onFilterChanged({ ...filter, operator: e.target.value as any })
|
|
78
|
-
}
|
|
79
|
-
/>
|
|
80
|
-
</label>
|
|
81
|
-
<label htmlFor="filterValue1">
|
|
82
|
-
<span>{operator === 'inRange' ? 'Entre' : 'Valeur'} :</span>
|
|
83
|
-
<Input
|
|
84
|
-
ref={value1Ref}
|
|
85
|
-
name="filterValue1"
|
|
86
|
-
type={filter.type}
|
|
87
|
-
value={values[0] ?? ''}
|
|
88
|
-
onChange={(e) => {
|
|
89
|
-
if (type === 'number') {
|
|
90
|
-
const newValues = [...values];
|
|
91
|
-
newValues[0] = Number(e.target.value);
|
|
92
|
-
onFilterChanged({
|
|
93
|
-
...filter,
|
|
94
|
-
values: newValues,
|
|
95
|
-
});
|
|
96
|
-
} else {
|
|
97
|
-
const newValues = [...values];
|
|
98
|
-
newValues[0] = String(e.target.value) as any;
|
|
99
|
-
onFilterChanged({
|
|
100
|
-
...filter,
|
|
101
|
-
values: newValues,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}}
|
|
105
|
-
/>
|
|
106
|
-
</label>
|
|
107
|
-
{operator === 'inRange' && (
|
|
108
|
-
<label htmlFor="filterValue2">
|
|
109
|
-
<span>et</span>
|
|
110
|
-
<Input
|
|
111
|
-
name="filterValue2"
|
|
112
|
-
type={filter.type}
|
|
113
|
-
value={values[1] ?? ''}
|
|
114
|
-
onChange={(e) => {
|
|
115
|
-
if (type === 'number') {
|
|
116
|
-
const newValues = [...values];
|
|
117
|
-
newValues[1] = Number(e.target.value);
|
|
118
|
-
onFilterChanged({
|
|
119
|
-
...filter,
|
|
120
|
-
values: newValues,
|
|
121
|
-
});
|
|
122
|
-
} else {
|
|
123
|
-
const newValues = [...values];
|
|
124
|
-
newValues[1] = String(e.target.value) as any;
|
|
125
|
-
onFilterChanged({
|
|
126
|
-
...filter,
|
|
127
|
-
values: newValues,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}}
|
|
131
|
-
/>
|
|
132
|
-
</label>
|
|
133
|
-
)}
|
|
134
|
-
</styles.FilterModalContentContainer>
|
|
135
|
-
);
|
|
136
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import styled from 'styled-components';
|
|
2
|
-
|
|
3
|
-
export const FilterModalContentContainer = styled.div.attrs({
|
|
4
|
-
className: 'FilterModalContentContainer',
|
|
5
|
-
})`
|
|
6
|
-
display: flex;
|
|
7
|
-
flex-direction: column;
|
|
8
|
-
font-size: var(--text-base);
|
|
9
|
-
gap: var(--space-1);
|
|
10
|
-
|
|
11
|
-
& > label {
|
|
12
|
-
display: flex;
|
|
13
|
-
flex-direction: row;
|
|
14
|
-
gap: var(--space-1);
|
|
15
|
-
align-items: center;
|
|
16
|
-
|
|
17
|
-
& > span {
|
|
18
|
-
font-weight: bold;
|
|
19
|
-
width: var(--space-32);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
`;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import * as styles from './styles';
|
|
2
|
-
|
|
3
|
-
import { ReactNode, useContext } from 'react';
|
|
4
|
-
|
|
5
|
-
import { DataGridContext } from './types';
|
|
6
|
-
|
|
7
|
-
type VirtualScrollerProps<R> = {
|
|
8
|
-
showAllRows?: boolean;
|
|
9
|
-
rowTemplate: (row: R, index: number) => ReactNode;
|
|
10
|
-
hasFooter?: boolean;
|
|
11
|
-
context: DataGridContext<R>;
|
|
12
|
-
onRangeChange?: (startIndex: number, length: number) => void;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const VirtualScroller = <R,>(props: VirtualScrollerProps<R>) => {
|
|
16
|
-
const {
|
|
17
|
-
rowHeight = styles.DEFAULT_ROW_HEIGHT,
|
|
18
|
-
// headerRowHeight = styles.DEFAULT_HEADER_ROW_HEIGHT,
|
|
19
|
-
sortedRows,
|
|
20
|
-
index,
|
|
21
|
-
visibleRows,
|
|
22
|
-
gridTemplateColumns,
|
|
23
|
-
} = useContext(props.context);
|
|
24
|
-
const {
|
|
25
|
-
rowTemplate,
|
|
26
|
-
// hasFooter, onRangeChange
|
|
27
|
-
} = props;
|
|
28
|
-
|
|
29
|
-
const totalHeight = sortedRows.length * rowHeight;
|
|
30
|
-
const topPadding =
|
|
31
|
-
Math.max(0, index - styles.VIRTUAL_SCROLL_TOLERANCE) * rowHeight;
|
|
32
|
-
// const headerAndFooterHeight =
|
|
33
|
-
// 2 * headerRowHeight + (hasFooter ? rowHeight : 0) + 2;
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<styles.VirtualScrollerContainer $height={totalHeight}>
|
|
37
|
-
<styles.VirtualScrollerRowsContainer
|
|
38
|
-
$gridTemplateColumns={gridTemplateColumns}
|
|
39
|
-
$topPadding={topPadding}
|
|
40
|
-
$rowHeight={rowHeight}
|
|
41
|
-
>
|
|
42
|
-
{visibleRows.map(rowTemplate)}
|
|
43
|
-
</styles.VirtualScrollerRowsContainer>
|
|
44
|
-
</styles.VirtualScrollerContainer>
|
|
45
|
-
);
|
|
46
|
-
};
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
import { DataGridColumn, DataGridColumns, DataGridSettings } from '../types';
|
|
4
|
-
import { dateFilter, numberFilter, textFilter } from './filters';
|
|
5
|
-
import {
|
|
6
|
-
formatMoney,
|
|
7
|
-
formatNumber,
|
|
8
|
-
formatNumberInvariant,
|
|
9
|
-
formatPercentage,
|
|
10
|
-
} from '../../../../helpers/numbers';
|
|
11
|
-
|
|
12
|
-
import moment from 'moment';
|
|
13
|
-
import { repeat } from 'lodash';
|
|
14
|
-
|
|
15
|
-
export const isColumnVisible = <R,>(
|
|
16
|
-
obj: DataGridColumn<R> | DataGridSettings
|
|
17
|
-
): boolean => obj?.order !== -1;
|
|
18
|
-
|
|
19
|
-
export const buildExcelFormat = (decimals = 2, suffix = '') =>
|
|
20
|
-
`#0${decimals > 0 ? `.${repeat('0', decimals)}` : ''}${suffix}`;
|
|
21
|
-
|
|
22
|
-
export const textColumn = <R extends Record<string, any>>(
|
|
23
|
-
key: string,
|
|
24
|
-
title: string,
|
|
25
|
-
options?: Partial<DataGridColumn<R>>
|
|
26
|
-
): DataGridColumns<R> => ({
|
|
27
|
-
[key]: {
|
|
28
|
-
name: title,
|
|
29
|
-
render: (row) => row[key] ?? '',
|
|
30
|
-
getter: (row) => row[key] ?? '',
|
|
31
|
-
sortGetter: (row) => row[key] ?? '',
|
|
32
|
-
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
33
|
-
filter: textFilter(key),
|
|
34
|
-
...options,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
export const mailColumn = <R extends Record<string, any>>(
|
|
39
|
-
key: string,
|
|
40
|
-
title: string,
|
|
41
|
-
options?: Partial<DataGridColumn<R>>
|
|
42
|
-
): DataGridColumns<R> => ({
|
|
43
|
-
[key]: {
|
|
44
|
-
name: title,
|
|
45
|
-
render: (row) => (
|
|
46
|
-
<a
|
|
47
|
-
// className="text-blue-500 hover:text-blue-700"
|
|
48
|
-
href={`mailto:${row[key]}`}
|
|
49
|
-
>
|
|
50
|
-
{row[key] ?? ''}
|
|
51
|
-
</a>
|
|
52
|
-
),
|
|
53
|
-
getter: (row) => row[key] ?? '',
|
|
54
|
-
sortGetter: (row) => row[key] ?? '',
|
|
55
|
-
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
56
|
-
filter: textFilter(key),
|
|
57
|
-
...options,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
export const phoneColumn = <R extends Record<string, any>>(
|
|
62
|
-
key: string,
|
|
63
|
-
title: string,
|
|
64
|
-
options?: Partial<DataGridColumn<R>>
|
|
65
|
-
): DataGridColumns<R> => ({
|
|
66
|
-
[key]: {
|
|
67
|
-
name: title,
|
|
68
|
-
render: (row) => (
|
|
69
|
-
<a
|
|
70
|
-
// className="text-blue-500 hover:text-blue-700"
|
|
71
|
-
href={`tel:${row[key]}`}
|
|
72
|
-
>
|
|
73
|
-
{row[key] ?? ''}
|
|
74
|
-
</a>
|
|
75
|
-
),
|
|
76
|
-
getter: (row) => row[key] ?? '',
|
|
77
|
-
sortGetter: (row) => row[key] ?? '',
|
|
78
|
-
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
79
|
-
filter: textFilter(key),
|
|
80
|
-
...options,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
export const dateColumn = <R extends Record<string, any>>(
|
|
85
|
-
key: string,
|
|
86
|
-
title: string,
|
|
87
|
-
options?: Partial<DataGridColumn<R>>
|
|
88
|
-
): DataGridColumns<R> => ({
|
|
89
|
-
[key]: {
|
|
90
|
-
name: title,
|
|
91
|
-
type: 'date',
|
|
92
|
-
render: (row) => moment(row[key]).format('DD/MM/YYYY') ?? '',
|
|
93
|
-
getter: (row) => row[key] ?? '',
|
|
94
|
-
sortGetter: (row) => row[key] ?? '',
|
|
95
|
-
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
96
|
-
filter: {
|
|
97
|
-
...dateFilter(key),
|
|
98
|
-
renderer: (value) => moment(value).format('DD/MM/YYYY') ?? '',
|
|
99
|
-
},
|
|
100
|
-
...options,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
export const monthColumn = <R extends Record<string, any>>(
|
|
105
|
-
key: string,
|
|
106
|
-
title: string,
|
|
107
|
-
options?: Partial<DataGridColumn<R>>
|
|
108
|
-
): DataGridColumns<R> => ({
|
|
109
|
-
[key]: {
|
|
110
|
-
name: title,
|
|
111
|
-
render: (row) => (row[key] ? `${row[key]} mois ` : ''),
|
|
112
|
-
getter: (row) => row[key] ?? '',
|
|
113
|
-
sortGetter: (row) => row[key] ?? '',
|
|
114
|
-
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
115
|
-
filter: textFilter(key),
|
|
116
|
-
...options,
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
export const numberColumn = <R extends Record<string, any>>(
|
|
121
|
-
key: string,
|
|
122
|
-
title: string,
|
|
123
|
-
decimals = 2,
|
|
124
|
-
options?: Partial<DataGridColumn<R>>
|
|
125
|
-
): DataGridColumns<R> => ({
|
|
126
|
-
[key]: {
|
|
127
|
-
name: title,
|
|
128
|
-
render: (row) => formatNumber(row[key], decimals) ?? '',
|
|
129
|
-
excelFormatter: () => buildExcelFormat(decimals),
|
|
130
|
-
excelValue: (value) => formatNumberInvariant(value, decimals),
|
|
131
|
-
getter: (row) => row[key] ?? '',
|
|
132
|
-
sortGetter: (row) => row[key] ?? '',
|
|
133
|
-
footer: {
|
|
134
|
-
sum: (_, filteredRows) =>
|
|
135
|
-
formatNumber(
|
|
136
|
-
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
|
|
137
|
-
decimals
|
|
138
|
-
),
|
|
139
|
-
average: (_, filteredRows) =>
|
|
140
|
-
formatNumber(
|
|
141
|
-
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
|
|
142
|
-
(filteredRows.length || 1),
|
|
143
|
-
decimals
|
|
144
|
-
),
|
|
145
|
-
count: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
146
|
-
max: (_, filteredRows) =>
|
|
147
|
-
formatNumber(
|
|
148
|
-
Math.max(...filteredRows.map((row) => row[key] ?? 0)),
|
|
149
|
-
decimals
|
|
150
|
-
),
|
|
151
|
-
min: (_, filteredRows) =>
|
|
152
|
-
formatNumber(
|
|
153
|
-
Math.min(...filteredRows.map((row) => row[key] ?? 0)),
|
|
154
|
-
decimals
|
|
155
|
-
),
|
|
156
|
-
},
|
|
157
|
-
filter: {
|
|
158
|
-
...numberFilter(key),
|
|
159
|
-
renderer: (value) => formatNumber(value, decimals) ?? '',
|
|
160
|
-
},
|
|
161
|
-
...options,
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
export const moneyColumn = <R extends Record<string, any>>(
|
|
166
|
-
key: string,
|
|
167
|
-
title: string,
|
|
168
|
-
decimals = 2,
|
|
169
|
-
options?: Partial<DataGridColumn<R>>
|
|
170
|
-
): DataGridColumns<R> => ({
|
|
171
|
-
[key]: {
|
|
172
|
-
name: title,
|
|
173
|
-
render: (row) => formatMoney(row[key], decimals) ?? '',
|
|
174
|
-
excelFormatter: () => buildExcelFormat(decimals, ' €'),
|
|
175
|
-
excelValue: (value) => formatNumberInvariant(value, decimals),
|
|
176
|
-
getter: (row) => row[key] ?? '',
|
|
177
|
-
sortGetter: (row) => row[key] ?? '',
|
|
178
|
-
filter: {
|
|
179
|
-
...numberFilter(key),
|
|
180
|
-
renderer: (value) => formatMoney(value, decimals) ?? '',
|
|
181
|
-
},
|
|
182
|
-
footer: {
|
|
183
|
-
sum: (_, filteredRows) =>
|
|
184
|
-
formatMoney(
|
|
185
|
-
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
|
|
186
|
-
decimals
|
|
187
|
-
),
|
|
188
|
-
average: (_, filteredRows) =>
|
|
189
|
-
formatMoney(
|
|
190
|
-
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
|
|
191
|
-
(filteredRows.length || 1),
|
|
192
|
-
decimals
|
|
193
|
-
),
|
|
194
|
-
count: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
195
|
-
max: (_, filteredRows) =>
|
|
196
|
-
formatMoney(
|
|
197
|
-
Math.max(...filteredRows.map((row) => row[key] ?? 0)),
|
|
198
|
-
decimals
|
|
199
|
-
),
|
|
200
|
-
min: (_, filteredRows) =>
|
|
201
|
-
formatMoney(
|
|
202
|
-
Math.min(...filteredRows.map((row) => row[key] ?? 0)),
|
|
203
|
-
decimals
|
|
204
|
-
),
|
|
205
|
-
},
|
|
206
|
-
...options,
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
export const percentageColumn = <R extends Record<string, any>>(
|
|
211
|
-
key: string,
|
|
212
|
-
title: string,
|
|
213
|
-
decimals = 2,
|
|
214
|
-
options?: Partial<DataGridColumn<R>>
|
|
215
|
-
): DataGridColumns<R> => ({
|
|
216
|
-
[key]: {
|
|
217
|
-
name: title,
|
|
218
|
-
render: (row) => formatPercentage(row[key]) ?? '',
|
|
219
|
-
excelFormatter: () => buildExcelFormat(decimals, '%'),
|
|
220
|
-
excelValue: (value) => formatNumberInvariant(value, decimals),
|
|
221
|
-
getter: (row) => row[key] ?? '',
|
|
222
|
-
sortGetter: (row) => row[key] ?? '',
|
|
223
|
-
filter: numberFilter(key),
|
|
224
|
-
footer: {
|
|
225
|
-
average: (_, filteredRows) =>
|
|
226
|
-
formatNumber(
|
|
227
|
-
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
|
|
228
|
-
(filteredRows.length || 1),
|
|
229
|
-
decimals
|
|
230
|
-
),
|
|
231
|
-
count: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
232
|
-
max: (_, filteredRows) =>
|
|
233
|
-
formatNumber(
|
|
234
|
-
Math.max(...filteredRows.map((row) => row[key] ?? 0)),
|
|
235
|
-
decimals
|
|
236
|
-
),
|
|
237
|
-
min: (_, filteredRows) =>
|
|
238
|
-
formatNumber(
|
|
239
|
-
Math.min(...filteredRows.map((row) => row[key] ?? 0)),
|
|
240
|
-
decimals
|
|
241
|
-
),
|
|
242
|
-
sum: (_, filteredRows) =>
|
|
243
|
-
formatNumber(
|
|
244
|
-
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
|
|
245
|
-
decimals
|
|
246
|
-
),
|
|
247
|
-
},
|
|
248
|
-
...options,
|
|
249
|
-
},
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
export const checkboxColumn = <R extends Record<string, any>>(
|
|
253
|
-
key: string,
|
|
254
|
-
title: string,
|
|
255
|
-
options?: Partial<DataGridColumn<R>>
|
|
256
|
-
): DataGridColumns<R> => ({
|
|
257
|
-
[key]: {
|
|
258
|
-
name: title,
|
|
259
|
-
render: (row) => (
|
|
260
|
-
<>
|
|
261
|
-
<input type="checkbox" checked={row[key]} />
|
|
262
|
-
<span>{row[key] ? ' Oui' : ' Non'}</span>
|
|
263
|
-
</>
|
|
264
|
-
),
|
|
265
|
-
getter: (row) => row[key] ?? '',
|
|
266
|
-
sortGetter: (row) => row[key] ?? '',
|
|
267
|
-
filter: numberFilter(key),
|
|
268
|
-
footer: {
|
|
269
|
-
count: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
270
|
-
checked: (_, filteredRows) =>
|
|
271
|
-
`${filteredRows.filter((row) => !!row[key]).length} cochés`,
|
|
272
|
-
unchecked: (_, filteredRows) =>
|
|
273
|
-
`${filteredRows.filter((row) => !row[key]).length} décochés`,
|
|
274
|
-
},
|
|
275
|
-
...options,
|
|
276
|
-
},
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
export const colorColumn = <R extends Record<string, any>>(
|
|
280
|
-
key: string,
|
|
281
|
-
title: string,
|
|
282
|
-
options?: Partial<DataGridColumn<R>>
|
|
283
|
-
): DataGridColumns<R> => ({
|
|
284
|
-
[key]: {
|
|
285
|
-
name: title,
|
|
286
|
-
render: (row) => (
|
|
287
|
-
<div style={{ backgroundColor: row[key] }}>{row[key] ?? ''}</div>
|
|
288
|
-
),
|
|
289
|
-
getter: (row) => row[key] ?? '',
|
|
290
|
-
sortGetter: (row) => row[key] ?? '',
|
|
291
|
-
filter: textFilter(key),
|
|
292
|
-
footer: (rows) => `${rows.length} éléments`,
|
|
293
|
-
...options,
|
|
294
|
-
},
|
|
295
|
-
});
|