@centreon/ui 25.5.1 → 25.5.3
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/package.json
CHANGED
|
@@ -6,13 +6,13 @@ const loadingIndicatorHeight = 3;
|
|
|
6
6
|
|
|
7
7
|
interface StylesProps {
|
|
8
8
|
dataStyle: TableStyle;
|
|
9
|
-
|
|
9
|
+
gridTemplateColumn: string;
|
|
10
10
|
isResponsive: string;
|
|
11
11
|
rows: Array<unknown>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const useListingStyles = makeStyles<StylesProps>()(
|
|
15
|
-
(theme, { dataStyle,
|
|
15
|
+
(theme, { dataStyle, gridTemplateColumn, rows, isResponsive }) => ({
|
|
16
16
|
actionBar: {
|
|
17
17
|
alignItems: 'center',
|
|
18
18
|
display: 'flex'
|
|
@@ -51,7 +51,7 @@ const useListingStyles = makeStyles<StylesProps>()(
|
|
|
51
51
|
},
|
|
52
52
|
alignItems: 'center',
|
|
53
53
|
display: 'grid',
|
|
54
|
-
gridTemplateColumns:
|
|
54
|
+
gridTemplateColumns: gridTemplateColumn,
|
|
55
55
|
gridTemplateRows: `${theme.spacing(dataStyle.header.height / 8)} repeat(${
|
|
56
56
|
rows?.length || 1
|
|
57
57
|
}, ${isResponsive ? 'auto' : `${dataStyle.body.height}px`})`,
|
package/src/Listing/index.tsx
CHANGED
|
@@ -62,7 +62,7 @@ import {
|
|
|
62
62
|
} from './models';
|
|
63
63
|
import { subItemsPivotsAtom } from './tableAtoms';
|
|
64
64
|
import { labelNoResultFound as defaultLabelNoResultFound } from './translatedLabels';
|
|
65
|
-
import useStyleTable from './useStyleTable';
|
|
65
|
+
import useStyleTable, { useColumnStyle } from './useStyleTable';
|
|
66
66
|
|
|
67
67
|
const subItemPrefixKey = 'listing';
|
|
68
68
|
|
|
@@ -207,11 +207,13 @@ const Listing = <
|
|
|
207
207
|
columnConfiguration,
|
|
208
208
|
columns
|
|
209
209
|
});
|
|
210
|
-
const { dataStyle
|
|
211
|
-
checkable,
|
|
212
|
-
currentVisibleColumns,
|
|
210
|
+
const { dataStyle } = useStyleTable({
|
|
213
211
|
listingVariant
|
|
214
212
|
});
|
|
213
|
+
const gridTemplateColumn = useColumnStyle({
|
|
214
|
+
checkable,
|
|
215
|
+
currentVisibleColumns
|
|
216
|
+
});
|
|
215
217
|
|
|
216
218
|
const { t } = useTranslation();
|
|
217
219
|
|
|
@@ -291,7 +293,7 @@ const Listing = <
|
|
|
291
293
|
|
|
292
294
|
const { classes } = useListingStyles({
|
|
293
295
|
dataStyle,
|
|
294
|
-
|
|
296
|
+
gridTemplateColumn,
|
|
295
297
|
isResponsive,
|
|
296
298
|
rows: rowsToDisplay
|
|
297
299
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useAtomValue, useSetAtom } from 'jotai';
|
|
4
|
-
import { equals, isNil, pick, type } from 'ramda';
|
|
4
|
+
import { equals, isEmpty, isNil, pick, type, update } from 'ramda';
|
|
5
5
|
import { CSSObject } from 'tss-react';
|
|
6
6
|
|
|
7
7
|
import { Theme } from '@mui/material';
|
|
@@ -12,14 +12,11 @@ import { Column, TableStyleAtom as Style } from './models';
|
|
|
12
12
|
import { tableStyleAtom, tableStyleDerivedAtom } from './tableAtoms';
|
|
13
13
|
|
|
14
14
|
interface TableStyle {
|
|
15
|
-
checkable?: boolean;
|
|
16
|
-
currentVisibleColumns?: Array<Column>;
|
|
17
15
|
listingVariant?: ListingVariant;
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
interface TableStyleState {
|
|
21
19
|
dataStyle: Style;
|
|
22
|
-
getGridTemplateColumn: string;
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
const isCompactMode = equals<ListingVariant | undefined>(
|
|
@@ -40,35 +37,11 @@ export const getTextStyleByViewMode = ({
|
|
|
40
37
|
theme.typography[isCompactMode(listingVariant) ? 'body2' : 'body1']
|
|
41
38
|
);
|
|
42
39
|
|
|
43
|
-
const useStyleTable = ({
|
|
44
|
-
checkable,
|
|
45
|
-
currentVisibleColumns,
|
|
46
|
-
listingVariant
|
|
47
|
-
}: TableStyle): TableStyleState => {
|
|
40
|
+
const useStyleTable = ({ listingVariant }: TableStyle): TableStyleState => {
|
|
48
41
|
const dataStyle = useAtomValue(tableStyleAtom);
|
|
49
42
|
|
|
50
43
|
const updateStyleTable = useSetAtom(tableStyleDerivedAtom);
|
|
51
44
|
|
|
52
|
-
const getGridTemplateColumn = (): string => {
|
|
53
|
-
const checkbox = checkable ? 'fit-content(1rem) ' : ''; // SelectAction (checkbox) cell adjusts to content
|
|
54
|
-
|
|
55
|
-
const columnTemplate = currentVisibleColumns
|
|
56
|
-
?.filter((column) => column)
|
|
57
|
-
?.map(({ width, shortLabel }) => {
|
|
58
|
-
if (!isNil(shortLabel)) {
|
|
59
|
-
return 'min-content';
|
|
60
|
-
}
|
|
61
|
-
if (isNil(width)) {
|
|
62
|
-
return 'auto';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return equals(type(width), 'Number') ? `${width}px` : width;
|
|
66
|
-
})
|
|
67
|
-
.join(' ');
|
|
68
|
-
|
|
69
|
-
return `${checkbox}${columnTemplate}`;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
45
|
useEffect(() => {
|
|
73
46
|
if (listingVariant) {
|
|
74
47
|
updateStyleTable({ listingVariant });
|
|
@@ -76,9 +49,62 @@ const useStyleTable = ({
|
|
|
76
49
|
}, [listingVariant]);
|
|
77
50
|
|
|
78
51
|
return {
|
|
79
|
-
dataStyle
|
|
80
|
-
getGridTemplateColumn: getGridTemplateColumn()
|
|
52
|
+
dataStyle
|
|
81
53
|
};
|
|
82
54
|
};
|
|
83
55
|
|
|
84
56
|
export default useStyleTable;
|
|
57
|
+
|
|
58
|
+
interface UseColumnStyleProps {
|
|
59
|
+
checkable?: boolean;
|
|
60
|
+
currentVisibleColumns?: Array<Column>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const useColumnStyle = ({
|
|
64
|
+
checkable,
|
|
65
|
+
currentVisibleColumns
|
|
66
|
+
}: UseColumnStyleProps): string => {
|
|
67
|
+
const gridTemplateColumn = useMemo((): string => {
|
|
68
|
+
const checkbox = checkable ? 'fit-content(1rem) ' : ''; // SelectAction (checkbox) cell adjusts to content
|
|
69
|
+
|
|
70
|
+
const columnTemplate: Array<string> =
|
|
71
|
+
currentVisibleColumns
|
|
72
|
+
?.filter((column) => column)
|
|
73
|
+
?.map(({ width, shortLabel }) => {
|
|
74
|
+
if (!isNil(shortLabel)) {
|
|
75
|
+
return 'min-content';
|
|
76
|
+
}
|
|
77
|
+
if (isNil(width)) {
|
|
78
|
+
return 'auto';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
equals(type(width), 'Number') ? `${width}px` : width
|
|
83
|
+
) as string;
|
|
84
|
+
}) || [];
|
|
85
|
+
|
|
86
|
+
const hasOnlyContainerResponsiveColumns =
|
|
87
|
+
!isEmpty(columnTemplate) &&
|
|
88
|
+
columnTemplate.every(
|
|
89
|
+
(width: string) =>
|
|
90
|
+
width.includes('auto') ||
|
|
91
|
+
width.includes('fr') ||
|
|
92
|
+
width.includes('%') ||
|
|
93
|
+
width.includes('px')
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
if (!hasOnlyContainerResponsiveColumns) {
|
|
97
|
+
const fixedColumnTemplate = update(
|
|
98
|
+
columnTemplate.length - 1,
|
|
99
|
+
'auto',
|
|
100
|
+
columnTemplate
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return `${checkbox}${fixedColumnTemplate.join(' ')}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return `${checkbox}${columnTemplate.join(' ')}`;
|
|
107
|
+
}, [checkable, currentVisibleColumns]);
|
|
108
|
+
|
|
109
|
+
return gridTemplateColumn;
|
|
110
|
+
};
|