@addev-be/ui 0.2.16 → 0.2.18
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/eslint.config.js +28 -0
- package/package.json +13 -20
- package/src/Icons.tsx +108 -0
- package/src/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.ts +93 -0
- package/src/components/data/AdvancedRequestDataGrid/helpers/columns.tsx +262 -0
- package/src/components/data/AdvancedRequestDataGrid/helpers/index.ts +2 -0
- package/src/components/data/AdvancedRequestDataGrid/index.tsx +267 -0
- package/src/components/data/AdvancedRequestDataGrid/types.ts +47 -0
- package/src/components/data/DataGrid/DataGridCell.tsx +73 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +14 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +59 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +181 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -0
- package/src/components/data/DataGrid/DataGridEditableCell.tsx +43 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/FilterValuesScroller.tsx +120 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +75 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +360 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +96 -0
- package/src/components/data/DataGrid/DataGridFooter.tsx +42 -0
- package/src/components/data/DataGrid/DataGridHeader.tsx +126 -0
- package/src/components/data/DataGrid/DataGridHeaderCell.tsx +132 -0
- package/src/components/data/DataGrid/FilterModalContent/index.tsx +136 -0
- package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -0
- package/src/components/data/DataGrid/VirtualScroller.tsx +46 -0
- package/src/components/data/DataGrid/helpers/columns.tsx +295 -0
- package/src/components/data/DataGrid/helpers/filters.ts +287 -0
- package/src/components/data/DataGrid/helpers/index.ts +2 -0
- package/src/components/data/DataGrid/hooks/index.ts +30 -0
- package/src/components/data/DataGrid/hooks/useDataGrid.tsx +306 -0
- package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +175 -0
- package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +48 -0
- package/src/components/data/DataGrid/index.tsx +140 -0
- package/src/components/data/DataGrid/styles.ts +323 -0
- package/src/components/data/DataGrid/types.ts +267 -0
- package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +277 -0
- package/src/components/data/SqlRequestDataGrid/helpers/index.ts +2 -0
- package/src/components/data/SqlRequestDataGrid/helpers/sqlRequests.ts +16 -0
- package/src/components/data/SqlRequestDataGrid/index.tsx +347 -0
- package/src/components/data/SqlRequestDataGrid/types.ts +47 -0
- package/src/components/data/index.ts +8 -0
- package/src/components/forms/Button.tsx +99 -0
- package/src/components/forms/IconButton.tsx +56 -0
- package/src/components/forms/IndeterminateCheckbox.tsx +46 -0
- package/src/components/forms/Select.tsx +40 -0
- package/src/components/forms/index.ts +5 -0
- package/src/components/forms/styles.ts +20 -0
- package/src/components/index.ts +3 -0
- package/src/components/layout/Dropdown/index.tsx +79 -0
- package/src/components/layout/Dropdown/styles.ts +44 -0
- package/src/components/layout/Loading/index.tsx +29 -0
- package/src/components/layout/Loading/styles.ts +29 -0
- package/src/components/layout/Modal/index.tsx +51 -0
- package/src/components/layout/Modal/styles.ts +110 -0
- package/src/components/layout/index.ts +3 -0
- package/src/components/ui/ContextMenu/index.tsx +79 -0
- package/src/components/ui/ContextMenu/styles.ts +119 -0
- package/src/config/index.ts +14 -0
- package/src/helpers/dates.ts +9 -0
- package/src/helpers/getScrollbarSize.ts +14 -0
- package/src/helpers/numbers.ts +26 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useElementSize.ts +24 -0
- package/src/hooks/useWindowSize.ts +20 -0
- package/src/index.ts +7 -0
- package/src/providers/PortalsProvider/index.tsx +54 -0
- package/src/providers/PortalsProvider/styles.ts +27 -0
- package/src/providers/SettingsProvider/index.tsx +70 -0
- package/src/providers/ThemeProvider/ThemeProvider.ts +55 -0
- package/src/providers/ThemeProvider/defaultTheme.ts +444 -0
- package/src/providers/ThemeProvider/index.ts +3 -0
- package/src/providers/ThemeProvider/types.ts +123 -0
- package/src/providers/UiProviders/index.tsx +65 -0
- package/src/providers/UiProviders/styles.ts +10 -0
- package/src/providers/hooks.ts +8 -0
- package/src/providers/index.ts +5 -0
- package/src/services/HttpService.ts +80 -0
- package/src/services/WebSocketService.ts +147 -0
- package/src/services/advancedRequests.ts +101 -0
- package/src/services/base.ts +31 -0
- package/src/services/globalSearch.ts +27 -0
- package/src/services/hooks.ts +23 -0
- package/src/services/index.ts +2 -0
- package/src/services/sqlRequests.ts +110 -0
- package/src/styles/animations.scss +30 -0
- package/src/styles/index.scss +42 -0
- package/src/typings.d.ts +6 -0
- package/tsconfig.json +18 -0
- package/tsconfig.tsbuildinfo +1 -0
package/eslint.config.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
+
import tseslint from 'typescript-eslint'
|
|
6
|
+
|
|
7
|
+
export default tseslint.config(
|
|
8
|
+
{ ignores: ['dist'] },
|
|
9
|
+
{
|
|
10
|
+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
|
11
|
+
files: ['**/*.{ts,tsx}'],
|
|
12
|
+
languageOptions: {
|
|
13
|
+
ecmaVersion: 2020,
|
|
14
|
+
globals: globals.browser,
|
|
15
|
+
},
|
|
16
|
+
plugins: {
|
|
17
|
+
'react-hooks': reactHooks,
|
|
18
|
+
'react-refresh': reactRefresh,
|
|
19
|
+
},
|
|
20
|
+
rules: {
|
|
21
|
+
...reactHooks.configs.recommended.rules,
|
|
22
|
+
'react-refresh/only-export-components': [
|
|
23
|
+
'warn',
|
|
24
|
+
{ allowConstantExport: true },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
)
|
package/package.json
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@addev-be/ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"watch": "tsc -b --watch",
|
|
7
7
|
"build": "tsc -b",
|
|
8
|
-
"build:vite": "vite build",
|
|
9
8
|
"lint": "eslint .",
|
|
10
9
|
"publish": "yarn npm publish"
|
|
11
10
|
},
|
|
12
11
|
"types": "src/index.ts",
|
|
13
12
|
"exports": {
|
|
14
13
|
".": {
|
|
15
|
-
"
|
|
16
|
-
"import": "./src/index.js"
|
|
14
|
+
"import": "./src/index.ts"
|
|
17
15
|
}
|
|
18
16
|
},
|
|
19
|
-
"files": [
|
|
20
|
-
"dist",
|
|
21
|
-
"assets"
|
|
22
|
-
],
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"fp-ts": "^2.16.9",
|
|
25
|
-
"io-ts": "^2.2.21",
|
|
26
|
-
"lodash": "^4.17.21",
|
|
27
|
-
"moment": "^2.30.1",
|
|
28
|
-
"styled-components": "^6.1.13",
|
|
29
|
-
"uuid": "^10.0.0",
|
|
30
|
-
"vite-plugin-svgr": "^4.2.0"
|
|
31
|
-
},
|
|
32
17
|
"devDependencies": {
|
|
33
18
|
"@eslint/js": "^8.57.0",
|
|
34
19
|
"@types/lodash": "^4",
|
|
@@ -47,11 +32,19 @@
|
|
|
47
32
|
"eslint-plugin-react-refresh": "^0.4.9",
|
|
48
33
|
"globals": "^15.9.0",
|
|
49
34
|
"typescript": "^5.5.3",
|
|
50
|
-
"typescript-eslint": "^8.6.0"
|
|
51
|
-
"vite": "^5.4.10"
|
|
35
|
+
"typescript-eslint": "^8.6.0"
|
|
52
36
|
},
|
|
53
37
|
"peerDependencies": {
|
|
54
38
|
"react": "^18.3.1",
|
|
55
|
-
"react-dom": "^18.3.1"
|
|
39
|
+
"react-dom": "^18.3.1",
|
|
40
|
+
"styled-components": "^6.1.13",
|
|
41
|
+
"vite-plugin-svgr": "^4.2.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"fp-ts": "^2.16.9",
|
|
45
|
+
"io-ts": "^2.2.21",
|
|
46
|
+
"lodash": "^4.17.21",
|
|
47
|
+
"moment": "^2.30.1",
|
|
48
|
+
"uuid": "^10.0.0"
|
|
56
49
|
}
|
|
57
50
|
}
|
package/src/Icons.tsx
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { FC, SVGProps, useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import ArrowDown19Icon from '../assets/icons/arrow-down-1-9.svg?react';
|
|
4
|
+
import ArrowDownAZIcon from '../assets/icons/arrow-down-a-z.svg?react';
|
|
5
|
+
import ArrowDownBigSmallIcon from '../assets/icons/arrow-down-big-small.svg?react';
|
|
6
|
+
import ArrowUp91Icon from '../assets/icons/arrow-up-9-1.svg?react';
|
|
7
|
+
import ArrowUpBigSmallIcon from '../assets/icons/arrow-up-big-small.svg?react';
|
|
8
|
+
import ArrowUpZAIcon from '../assets/icons/arrow-up-z-a.svg?react';
|
|
9
|
+
import ArrowsRotateIcon from '../assets/icons/arrows-rotate.svg?react';
|
|
10
|
+
import ArrowsUpDownIcon from '../assets/icons/arrows-up-down.svg?react';
|
|
11
|
+
import CheckIcon from '../assets/icons/check.svg?react';
|
|
12
|
+
import ChevronDownIcon from '../assets/icons/chevron-down.svg?react';
|
|
13
|
+
import CopyIcon from '../assets/icons/copy.svg?react';
|
|
14
|
+
import DownIcon from '../assets/icons/down.svg?react';
|
|
15
|
+
import EllipsisIcon from '../assets/icons/ellipsis.svg?react';
|
|
16
|
+
import FilterFullIcon from '../assets/icons/filter-full.svg?react';
|
|
17
|
+
import FilterIcon from '../assets/icons/filter.svg?react';
|
|
18
|
+
import FilterSlashIcon from '../assets/icons/filter-slash.svg?react';
|
|
19
|
+
import HashtagIcon from '../assets/icons/hashtag.svg?react';
|
|
20
|
+
import ImageSlashIcon from '../assets/icons/image-slash.svg?react';
|
|
21
|
+
import LeftIcon from '../assets/icons/left.svg?react';
|
|
22
|
+
import MagnifierIcon from '../assets/icons/magnifier.svg?react';
|
|
23
|
+
import PhoneIcon from '../assets/icons/phone.svg?react';
|
|
24
|
+
import PlusIcon from '../assets/icons/plus.svg?react';
|
|
25
|
+
import RightIcon from '../assets/icons/right.svg?react';
|
|
26
|
+
import SigmaIcon from '../assets/icons/sigma.svg?react';
|
|
27
|
+
import SortCalendarAscendingIcon from '../assets/icons/sort-calendar-ascending.svg?react';
|
|
28
|
+
import SortCalendarDescendingIcon from '../assets/icons/sort-calendar-descending.svg?react';
|
|
29
|
+
import SpinnerIcon from '../assets/icons/spinner-third.svg?react';
|
|
30
|
+
import TableColumnsIcon from '../assets/icons/table-columns.svg?react';
|
|
31
|
+
import TableFooterIcon from '../assets/icons/table-footer.svg?react';
|
|
32
|
+
import TableFooterSlashIcon from '../assets/icons/table-footer-slash.svg?react';
|
|
33
|
+
import TableIcon from '../assets/icons/table.svg?react';
|
|
34
|
+
import TallyIcon from '../assets/icons/tally.svg?react';
|
|
35
|
+
import UpIcon from '../assets/icons/up.svg?react';
|
|
36
|
+
import UserTieIcon from '../assets/icons/user-tie.svg?react';
|
|
37
|
+
import XBarIcon from '../assets/icons/x-bar.svg?react';
|
|
38
|
+
|
|
39
|
+
type IconFCProps = SVGProps<SVGSVGElement>;
|
|
40
|
+
export type IconFC = FC<IconFCProps>;
|
|
41
|
+
|
|
42
|
+
type AnimatedIconProps = {
|
|
43
|
+
icons: FC[];
|
|
44
|
+
speed?: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const AnimatedIcon: FC<AnimatedIconProps & IconFCProps> = ({
|
|
48
|
+
icons,
|
|
49
|
+
speed = 150,
|
|
50
|
+
...props
|
|
51
|
+
}) => {
|
|
52
|
+
const [currentIcon, setCurrentIcon] = useState(0);
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const interval = setInterval(() => {
|
|
56
|
+
setCurrentIcon((currentIcon) => (currentIcon + 1) % icons.length);
|
|
57
|
+
}, speed);
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
clearInterval(interval);
|
|
61
|
+
};
|
|
62
|
+
}, [icons.length, speed]);
|
|
63
|
+
|
|
64
|
+
const Icon = icons[currentIcon];
|
|
65
|
+
return <Icon {...props} />;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const LoadingIcon: FC<IconFCProps> = ({ className, ...props }) => (
|
|
69
|
+
<SpinnerIcon className={`animate-spin ${className}`} {...props} />
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
export {
|
|
73
|
+
ArrowDownAZIcon,
|
|
74
|
+
ArrowDown19Icon,
|
|
75
|
+
ArrowDownBigSmallIcon,
|
|
76
|
+
ArrowUpZAIcon,
|
|
77
|
+
ArrowUpBigSmallIcon,
|
|
78
|
+
ArrowUp91Icon,
|
|
79
|
+
ArrowsRotateIcon,
|
|
80
|
+
ArrowsUpDownIcon,
|
|
81
|
+
CheckIcon,
|
|
82
|
+
ChevronDownIcon,
|
|
83
|
+
CopyIcon,
|
|
84
|
+
DownIcon,
|
|
85
|
+
EllipsisIcon,
|
|
86
|
+
FilterFullIcon,
|
|
87
|
+
FilterIcon,
|
|
88
|
+
FilterSlashIcon,
|
|
89
|
+
HashtagIcon,
|
|
90
|
+
ImageSlashIcon,
|
|
91
|
+
LeftIcon,
|
|
92
|
+
MagnifierIcon,
|
|
93
|
+
PhoneIcon,
|
|
94
|
+
PlusIcon,
|
|
95
|
+
RightIcon,
|
|
96
|
+
SigmaIcon,
|
|
97
|
+
SortCalendarAscendingIcon,
|
|
98
|
+
SortCalendarDescendingIcon,
|
|
99
|
+
SpinnerIcon,
|
|
100
|
+
TableColumnsIcon,
|
|
101
|
+
TableFooterIcon,
|
|
102
|
+
TableFooterSlashIcon,
|
|
103
|
+
TableIcon,
|
|
104
|
+
TallyIcon,
|
|
105
|
+
UpIcon,
|
|
106
|
+
UserTieIcon,
|
|
107
|
+
XBarIcon,
|
|
108
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AdvancedRequestDTO,
|
|
5
|
+
ConditionDTO,
|
|
6
|
+
FieldDTO,
|
|
7
|
+
OrderByDTO,
|
|
8
|
+
} from '../../../../services/advancedRequests';
|
|
9
|
+
import {
|
|
10
|
+
AdvancedRequestDataGridColumns,
|
|
11
|
+
AdvancedRequestDataGridFilters,
|
|
12
|
+
} from '../types';
|
|
13
|
+
|
|
14
|
+
import _ from 'lodash';
|
|
15
|
+
|
|
16
|
+
export const getAdvancedRequestDto = <R>({
|
|
17
|
+
type,
|
|
18
|
+
columns,
|
|
19
|
+
conditions = [],
|
|
20
|
+
orderBy = [],
|
|
21
|
+
start = 0,
|
|
22
|
+
length = 100,
|
|
23
|
+
getTotal = false,
|
|
24
|
+
idField = { fieldName: 'Id' },
|
|
25
|
+
}: {
|
|
26
|
+
type: string;
|
|
27
|
+
columns: AdvancedRequestDataGridColumns<R>;
|
|
28
|
+
conditions?: ConditionDTO[];
|
|
29
|
+
orderBy?: OrderByDTO[];
|
|
30
|
+
start?: number;
|
|
31
|
+
length?: number;
|
|
32
|
+
getTotal?: boolean;
|
|
33
|
+
idField?: FieldDTO | null;
|
|
34
|
+
}): AdvancedRequestDTO => ({
|
|
35
|
+
fields: [
|
|
36
|
+
...(idField === null ? [] : [idField]),
|
|
37
|
+
...Object.keys(columns).map((key) =>
|
|
38
|
+
columns[key].field
|
|
39
|
+
? {
|
|
40
|
+
...columns[key].field,
|
|
41
|
+
fieldName: columns[key].field?.fieldName ?? key,
|
|
42
|
+
fieldAlias: key,
|
|
43
|
+
}
|
|
44
|
+
: {
|
|
45
|
+
fieldName: key,
|
|
46
|
+
fieldAlias: key,
|
|
47
|
+
}
|
|
48
|
+
),
|
|
49
|
+
],
|
|
50
|
+
conditions,
|
|
51
|
+
orderBy,
|
|
52
|
+
type,
|
|
53
|
+
start,
|
|
54
|
+
length,
|
|
55
|
+
getTotal,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const convertFiltersToConditions = <R>(
|
|
59
|
+
filters: AdvancedRequestDataGridFilters,
|
|
60
|
+
columns: AdvancedRequestDataGridColumns<R>
|
|
61
|
+
): Record<string, ConditionDTO> =>
|
|
62
|
+
_.mapValues(filters, (filter, columnKey) => ({
|
|
63
|
+
field:
|
|
64
|
+
columns[columnKey].filterField ??
|
|
65
|
+
columns[columnKey].field?.fieldAlias ??
|
|
66
|
+
columns[columnKey].field?.fieldName ??
|
|
67
|
+
columnKey,
|
|
68
|
+
operator: filter.operator,
|
|
69
|
+
value: ['inArray', 'inRange'].includes(filter.operator)
|
|
70
|
+
? filter.values
|
|
71
|
+
: _.castArray<string | number | null>(filter.values)[0],
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
export const parseJsonObjectFields = <R>(
|
|
75
|
+
rows: any[],
|
|
76
|
+
columns: AdvancedRequestDataGridColumns<R>,
|
|
77
|
+
parser?: (row: any) => R
|
|
78
|
+
): R[] => {
|
|
79
|
+
const jsonColumns = Object.keys(columns).filter(
|
|
80
|
+
(key) => columns[key].field?.operator === 'jsonObject'
|
|
81
|
+
);
|
|
82
|
+
const parsedRows =
|
|
83
|
+
jsonColumns.length === 0
|
|
84
|
+
? rows
|
|
85
|
+
: rows.map((row) => {
|
|
86
|
+
const parsedRow = { ...row };
|
|
87
|
+
jsonColumns.forEach((key) => {
|
|
88
|
+
parsedRow[key] = JSON.parse(parsedRow[key] ?? '{}');
|
|
89
|
+
});
|
|
90
|
+
return parsedRow;
|
|
91
|
+
});
|
|
92
|
+
return parser ? parsedRows.map(parser) : parsedRows;
|
|
93
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AdvancedRequestDataGridColumn,
|
|
5
|
+
AdvancedRequestDataGridColumns,
|
|
6
|
+
} from '../types';
|
|
7
|
+
import {
|
|
8
|
+
formatMoney,
|
|
9
|
+
formatNumber,
|
|
10
|
+
formatPercentage,
|
|
11
|
+
} from '../../../../helpers/numbers';
|
|
12
|
+
import { numberFilter, textFilter } from '../../DataGrid/helpers';
|
|
13
|
+
|
|
14
|
+
import { FieldDTO } from '../../../../services/advancedRequests';
|
|
15
|
+
import _ from 'lodash';
|
|
16
|
+
import moment from 'moment';
|
|
17
|
+
|
|
18
|
+
export const withGroupBy = <R extends Record<string, any>>(
|
|
19
|
+
columns: AdvancedRequestDataGridColumns<R>
|
|
20
|
+
): AdvancedRequestDataGridColumns<R> =>
|
|
21
|
+
_.mapValues(columns, (column, key) => ({
|
|
22
|
+
...column,
|
|
23
|
+
field: {
|
|
24
|
+
...(column.field ?? { fieldName: key }),
|
|
25
|
+
groupBy: true,
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
export const advancedTextColumn = <R extends Record<string, any>>(
|
|
30
|
+
key: string,
|
|
31
|
+
title: string,
|
|
32
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
33
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
34
|
+
[key]: {
|
|
35
|
+
name: title,
|
|
36
|
+
render: (row) => row[key] ?? '',
|
|
37
|
+
getter: (row) => row[key] ?? '',
|
|
38
|
+
sortGetter: (row) => row[key] ?? '',
|
|
39
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
40
|
+
...options,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Creates a column with a composed value from multiple fields,
|
|
46
|
+
* and filtered by a text filter on the first field
|
|
47
|
+
*/
|
|
48
|
+
export const advancedComposedColumn = <R extends Record<string, any>>(
|
|
49
|
+
key: string,
|
|
50
|
+
title: string,
|
|
51
|
+
fields: string[],
|
|
52
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
53
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
54
|
+
[key]: {
|
|
55
|
+
field: {
|
|
56
|
+
fieldAlias: key,
|
|
57
|
+
operator: 'jsonObject',
|
|
58
|
+
operands: fields.flatMap((field) => [
|
|
59
|
+
{ constantValue: field },
|
|
60
|
+
{ fieldName: field },
|
|
61
|
+
]),
|
|
62
|
+
},
|
|
63
|
+
name: title,
|
|
64
|
+
render: (row) => row[key] ?? '',
|
|
65
|
+
getter: (row) => row[key] ?? '',
|
|
66
|
+
sortGetter: (row) => row[key] ?? '',
|
|
67
|
+
filter: {
|
|
68
|
+
...textFilter(fields[0]),
|
|
69
|
+
getter: (value) => value[fields[0]] ?? 0,
|
|
70
|
+
},
|
|
71
|
+
filterField: fields[0],
|
|
72
|
+
sortField: fields[0],
|
|
73
|
+
...options,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const advancedMailColumn = <R extends Record<string, any>>(
|
|
78
|
+
key: string,
|
|
79
|
+
title: string,
|
|
80
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
81
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
82
|
+
[key]: {
|
|
83
|
+
name: title,
|
|
84
|
+
render: (row) => <a href={`mailto:${row[key]}`}>{row[key] ?? ''}</a>,
|
|
85
|
+
getter: (row) => row[key] ?? '',
|
|
86
|
+
sortGetter: (row) => row[key] ?? '',
|
|
87
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
88
|
+
...options,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const advancedPhoneColumn = <R extends Record<string, any>>(
|
|
93
|
+
key: string,
|
|
94
|
+
title: string,
|
|
95
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
96
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
97
|
+
[key]: {
|
|
98
|
+
name: title,
|
|
99
|
+
render: (row) => <a href={`tel:${row[key]}`}>{row[key] ?? ''}</a>,
|
|
100
|
+
getter: (row) => row[key] ?? '',
|
|
101
|
+
sortGetter: (row) => row[key] ?? '',
|
|
102
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
103
|
+
...options,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export const advancedDateColumn = <R extends Record<string, any>>(
|
|
108
|
+
key: string,
|
|
109
|
+
title: string,
|
|
110
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
111
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
112
|
+
[key]: {
|
|
113
|
+
name: title,
|
|
114
|
+
render: (row) => moment(row[key]).format('DD/MM/YYYY') ?? '',
|
|
115
|
+
getter: (row) => row[key] ?? '',
|
|
116
|
+
sortGetter: (row) => row[key] ?? '',
|
|
117
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
118
|
+
...options,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export const advancedMonthColumn = <R extends Record<string, any>>(
|
|
123
|
+
key: string,
|
|
124
|
+
title: string,
|
|
125
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
126
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
127
|
+
[key]: {
|
|
128
|
+
name: title,
|
|
129
|
+
render: (row) => (row[key] ? `${row[key]} mois ` : ''),
|
|
130
|
+
getter: (row) => row[key] ?? '',
|
|
131
|
+
sortGetter: (row) => row[key] ?? '',
|
|
132
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
133
|
+
...options,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
export const advancedNumberColumn = <R extends Record<string, any>>(
|
|
138
|
+
key: string,
|
|
139
|
+
title: string,
|
|
140
|
+
decimals = 2,
|
|
141
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
142
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
143
|
+
[key]: {
|
|
144
|
+
name: title,
|
|
145
|
+
render: (row) => formatNumber(row[key], decimals) ?? '',
|
|
146
|
+
excelFormatter: () => '#',
|
|
147
|
+
getter: (row) => row[key] ?? '',
|
|
148
|
+
sortGetter: (row) => row[key] ?? '',
|
|
149
|
+
filter: { ...numberFilter(key), getter: (value) => value[key] ?? 0 },
|
|
150
|
+
...options,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export const advancedMoneyColumn = <R extends Record<string, any>>(
|
|
155
|
+
key: string,
|
|
156
|
+
title: string,
|
|
157
|
+
decimals = 2,
|
|
158
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
159
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
160
|
+
[key]: {
|
|
161
|
+
name: title,
|
|
162
|
+
render: (row) => formatMoney(row[key], decimals) ?? '',
|
|
163
|
+
excelFormatter: () => '#0.00',
|
|
164
|
+
getter: (row) => row[key] ?? '',
|
|
165
|
+
sortGetter: (row) => row[key] ?? '',
|
|
166
|
+
filter: { ...numberFilter(key), getter: (value) => value[key] ?? 0 },
|
|
167
|
+
...options,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
export const advancedPercentageColumn = <R extends Record<string, any>>(
|
|
172
|
+
key: string,
|
|
173
|
+
title: string,
|
|
174
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
175
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
176
|
+
[key]: {
|
|
177
|
+
name: title,
|
|
178
|
+
render: (row) => formatPercentage(row[key]) ?? '',
|
|
179
|
+
excelFormatter: () => '#0.00',
|
|
180
|
+
getter: (row) => row[key] ?? '',
|
|
181
|
+
sortGetter: (row) => row[key] ?? '',
|
|
182
|
+
filter: { ...numberFilter(key), getter: (value) => value[key] ?? 0 },
|
|
183
|
+
...options,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
export const advancedCheckboxColumn = <R extends Record<string, any>>(
|
|
188
|
+
key: string,
|
|
189
|
+
title: string,
|
|
190
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
191
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
192
|
+
[key]: {
|
|
193
|
+
name: title,
|
|
194
|
+
render: (row) => (
|
|
195
|
+
<>
|
|
196
|
+
<input type="checkbox" checked={row[key]} />
|
|
197
|
+
<span>{row[key] ? ' Oui' : ' Non'}</span>
|
|
198
|
+
</>
|
|
199
|
+
),
|
|
200
|
+
getter: (row) => row[key] ?? '',
|
|
201
|
+
sortGetter: (row) => row[key] ?? '',
|
|
202
|
+
filter: { ...numberFilter(key), getter: (value) => value[key] ?? 0 },
|
|
203
|
+
...options,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
export const advancedColorColumn = <R extends Record<string, any>>(
|
|
208
|
+
key: string,
|
|
209
|
+
title: string,
|
|
210
|
+
options?: Partial<AdvancedRequestDataGridColumn<R>>
|
|
211
|
+
): AdvancedRequestDataGridColumns<R> => ({
|
|
212
|
+
[key]: {
|
|
213
|
+
name: title,
|
|
214
|
+
render: (row) => (
|
|
215
|
+
<div style={{ backgroundColor: row[key] }}>{row[key] ?? ''}</div>
|
|
216
|
+
),
|
|
217
|
+
getter: (row) => row[key] ?? '',
|
|
218
|
+
sortGetter: (row) => row[key] ?? '',
|
|
219
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
220
|
+
...options,
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
export const getColumnField = <R,>(
|
|
225
|
+
columns: AdvancedRequestDataGridColumns<R>,
|
|
226
|
+
columnKey: string
|
|
227
|
+
): FieldDTO => {
|
|
228
|
+
return columns[columnKey].field
|
|
229
|
+
? {
|
|
230
|
+
fieldName: columns[columnKey].field?.fieldName ?? columnKey,
|
|
231
|
+
fieldAlias: columnKey,
|
|
232
|
+
}
|
|
233
|
+
: {
|
|
234
|
+
fieldName: columnKey,
|
|
235
|
+
fieldAlias: columnKey,
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
export const getColumnSortField = <R,>(
|
|
239
|
+
columns: AdvancedRequestDataGridColumns<R>,
|
|
240
|
+
columnKey: string
|
|
241
|
+
): FieldDTO => {
|
|
242
|
+
return columns[columnKey].sortField
|
|
243
|
+
? {
|
|
244
|
+
fieldName: columns[columnKey].sortField ?? columnKey,
|
|
245
|
+
fieldAlias: columnKey,
|
|
246
|
+
}
|
|
247
|
+
: {
|
|
248
|
+
fieldName: columnKey,
|
|
249
|
+
fieldAlias: columnKey,
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
export const getFirstColumnField = <R,>(
|
|
253
|
+
columns: AdvancedRequestDataGridColumns<R>
|
|
254
|
+
): FieldDTO => {
|
|
255
|
+
return getColumnField(columns, Object.keys(columns)[0]);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export const getFirstColumnSortField = <R,>(
|
|
259
|
+
columns: AdvancedRequestDataGridColumns<R>
|
|
260
|
+
): FieldDTO => {
|
|
261
|
+
return getColumnSortField(columns, Object.keys(columns)[0]);
|
|
262
|
+
};
|