@centreon/ui 25.10.17 → 25.10.19
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
|
@@ -22,7 +22,8 @@ const MemoizedPagination = memo(
|
|
|
22
22
|
equals(prevProps.page, nextProps.page) &&
|
|
23
23
|
equals(prevProps.count, nextProps.count) &&
|
|
24
24
|
equals(prevProps.labelRowsPerPage, nextProps.labelRowsPerPage) &&
|
|
25
|
-
equals(prevProps.className, nextProps.className)
|
|
25
|
+
equals(prevProps.className, nextProps.className) &&
|
|
26
|
+
prevProps.labelDisplayedRows === nextProps.labelDisplayedRows
|
|
26
27
|
);
|
|
27
28
|
|
|
28
29
|
export default MemoizedPagination;
|
|
@@ -5,13 +5,32 @@ import { makeStyles } from 'tss-react/mui';
|
|
|
5
5
|
|
|
6
6
|
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
|
|
7
7
|
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
|
|
8
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
|
8
9
|
import Divider from '@mui/material/Divider';
|
|
10
|
+
import Tooltip from '@mui/material/Tooltip';
|
|
9
11
|
|
|
10
12
|
import { ListingVariant, userAtom } from '@centreon/ui-context';
|
|
11
13
|
|
|
12
|
-
import {
|
|
14
|
+
import { useAtomValue } from 'jotai';
|
|
15
|
+
import { equals, isEmpty, isNil, not, pick } from 'ramda';
|
|
16
|
+
import {
|
|
17
|
+
type ChangeEvent,
|
|
18
|
+
type MouseEvent,
|
|
19
|
+
type ReactNode,
|
|
20
|
+
useCallback
|
|
21
|
+
} from 'react';
|
|
22
|
+
import { useTranslation } from 'react-i18next';
|
|
23
|
+
import { makeStyles } from 'tss-react/mui';
|
|
24
|
+
|
|
25
|
+
import { IconButton, type ListingProps } from '../..';
|
|
13
26
|
import { useMemoComponent } from '../../utils';
|
|
14
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
labelApproximateCount,
|
|
29
|
+
labelApproximateCountTooltip,
|
|
30
|
+
labelComputingExactCount,
|
|
31
|
+
labelOf,
|
|
32
|
+
labelRowsPerPage
|
|
33
|
+
} from '../translatedLabels';
|
|
15
34
|
|
|
16
35
|
import ColumnMultiSelect from './ColumnMultiSelect';
|
|
17
36
|
import StyledPagination from './Pagination';
|
|
@@ -88,6 +107,9 @@ type Props = Pick<
|
|
|
88
107
|
| 'customPaginationClassName'
|
|
89
108
|
| 'listingVariant'
|
|
90
109
|
| 'viewerModeConfiguration'
|
|
110
|
+
| 'approximateTotalRows'
|
|
111
|
+
| 'onApproximateCountClick'
|
|
112
|
+
| 'isApproximateCountLoading'
|
|
91
113
|
>;
|
|
92
114
|
|
|
93
115
|
const MemoListingActionBar = ({
|
|
@@ -107,7 +129,10 @@ const MemoListingActionBar = ({
|
|
|
107
129
|
widthToMoveTablePagination = 550,
|
|
108
130
|
actionsBarMemoProps = [],
|
|
109
131
|
viewerModeConfiguration,
|
|
110
|
-
listingVariant
|
|
132
|
+
listingVariant,
|
|
133
|
+
approximateTotalRows = false,
|
|
134
|
+
onApproximateCountClick,
|
|
135
|
+
isApproximateCountLoading = false
|
|
111
136
|
}: Props): JSX.Element => {
|
|
112
137
|
const marginWidthTableListing = 30;
|
|
113
138
|
const { classes, cx } = useStyles({
|
|
@@ -118,17 +143,89 @@ const MemoListingActionBar = ({
|
|
|
118
143
|
|
|
119
144
|
const { themeMode } = useAtomValue(userAtom);
|
|
120
145
|
|
|
121
|
-
const changeRowPerPage = (
|
|
146
|
+
const changeRowPerPage = (
|
|
147
|
+
event: ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
|
|
148
|
+
): void => {
|
|
122
149
|
onLimitChange?.(event.target.value);
|
|
123
150
|
onPaginate?.(0);
|
|
124
151
|
};
|
|
125
152
|
|
|
126
|
-
const changePage = (
|
|
153
|
+
const changePage = (
|
|
154
|
+
_: MouseEvent<HTMLButtonElement> | null,
|
|
155
|
+
value: number
|
|
156
|
+
): void => {
|
|
127
157
|
onPaginate?.(value);
|
|
128
158
|
};
|
|
129
159
|
|
|
130
|
-
const labelDisplayedRows = (
|
|
131
|
-
|
|
160
|
+
const labelDisplayedRows = useCallback(
|
|
161
|
+
({
|
|
162
|
+
from,
|
|
163
|
+
to,
|
|
164
|
+
count
|
|
165
|
+
}: {
|
|
166
|
+
count: number;
|
|
167
|
+
from: number;
|
|
168
|
+
to: number;
|
|
169
|
+
}): ReactNode => {
|
|
170
|
+
const range = `${from}-${to} ${t(labelOf)} `;
|
|
171
|
+
|
|
172
|
+
if (!approximateTotalRows) {
|
|
173
|
+
return `${range}${count}`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (isApproximateCountLoading) {
|
|
177
|
+
return (
|
|
178
|
+
<span
|
|
179
|
+
style={{ alignItems: 'center', display: 'inline-flex', gap: 4 }}
|
|
180
|
+
>
|
|
181
|
+
{range}
|
|
182
|
+
<CircularProgress size={10} />
|
|
183
|
+
<span>{t(labelComputingExactCount)}</span>
|
|
184
|
+
</span>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const approximateLabel = (
|
|
189
|
+
<button
|
|
190
|
+
onClick={onApproximateCountClick}
|
|
191
|
+
style={{
|
|
192
|
+
background: 'none',
|
|
193
|
+
border: 'none',
|
|
194
|
+
color: 'inherit',
|
|
195
|
+
cursor: onApproximateCountClick ? 'pointer' : 'default',
|
|
196
|
+
font: 'inherit',
|
|
197
|
+
fontWeight: 600,
|
|
198
|
+
padding: 0,
|
|
199
|
+
textDecoration: onApproximateCountClick
|
|
200
|
+
? 'underline dotted'
|
|
201
|
+
: 'none'
|
|
202
|
+
}}
|
|
203
|
+
type="button"
|
|
204
|
+
>
|
|
205
|
+
{t(labelApproximateCount)}
|
|
206
|
+
</button>
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<span>
|
|
211
|
+
{range}
|
|
212
|
+
{onApproximateCountClick ? (
|
|
213
|
+
<Tooltip title={t(labelApproximateCountTooltip)}>
|
|
214
|
+
{approximateLabel}
|
|
215
|
+
</Tooltip>
|
|
216
|
+
) : (
|
|
217
|
+
approximateLabel
|
|
218
|
+
)}
|
|
219
|
+
</span>
|
|
220
|
+
);
|
|
221
|
+
},
|
|
222
|
+
[
|
|
223
|
+
approximateTotalRows,
|
|
224
|
+
isApproximateCountLoading,
|
|
225
|
+
onApproximateCountClick,
|
|
226
|
+
t
|
|
227
|
+
]
|
|
228
|
+
);
|
|
132
229
|
|
|
133
230
|
return useMemoComponent({
|
|
134
231
|
Component: (
|
|
@@ -223,6 +320,8 @@ const MemoListingActionBar = ({
|
|
|
223
320
|
),
|
|
224
321
|
columnConfiguration,
|
|
225
322
|
customPaginationClassName,
|
|
323
|
+
approximateTotalRows,
|
|
324
|
+
isApproximateCountLoading,
|
|
226
325
|
...actionsBarMemoProps
|
|
227
326
|
]
|
|
228
327
|
});
|
|
@@ -245,7 +344,10 @@ const ListingActionBar = ({
|
|
|
245
344
|
widthToMoveTablePagination,
|
|
246
345
|
customPaginationClassName,
|
|
247
346
|
listingVariant,
|
|
248
|
-
viewerModeConfiguration
|
|
347
|
+
viewerModeConfiguration,
|
|
348
|
+
approximateTotalRows,
|
|
349
|
+
onApproximateCountClick,
|
|
350
|
+
isApproximateCountLoading
|
|
249
351
|
}: Props): JSX.Element | null => {
|
|
250
352
|
if (
|
|
251
353
|
not(paginated) &&
|
|
@@ -259,13 +361,16 @@ const ListingActionBar = ({
|
|
|
259
361
|
<MemoListingActionBar
|
|
260
362
|
actions={actions}
|
|
261
363
|
actionsBarMemoProps={actionsBarMemoProps}
|
|
364
|
+
approximateTotalRows={approximateTotalRows}
|
|
262
365
|
columnConfiguration={columnConfiguration}
|
|
263
366
|
columns={columns}
|
|
264
367
|
currentPage={currentPage}
|
|
265
368
|
customPaginationClassName={customPaginationClassName}
|
|
369
|
+
isApproximateCountLoading={isApproximateCountLoading}
|
|
266
370
|
limit={limit}
|
|
267
371
|
listingVariant={listingVariant}
|
|
268
372
|
moveTablePagination={moveTablePagination}
|
|
373
|
+
onApproximateCountClick={onApproximateCountClick}
|
|
269
374
|
paginated={paginated}
|
|
270
375
|
totalRows={totalRows}
|
|
271
376
|
viewerModeConfiguration={viewerModeConfiguration}
|
package/src/Listing/index.tsx
CHANGED
|
@@ -134,6 +134,9 @@ export interface Props<TRow> {
|
|
|
134
134
|
labelExpand: string;
|
|
135
135
|
};
|
|
136
136
|
totalRows?: number;
|
|
137
|
+
approximateTotalRows?: boolean;
|
|
138
|
+
onApproximateCountClick?: () => void;
|
|
139
|
+
isApproximateCountLoading?: boolean;
|
|
137
140
|
viewerModeConfiguration?: ViewerModeConfiguration;
|
|
138
141
|
widthToMoveTablePagination?: number;
|
|
139
142
|
isActionBarVisible: boolean;
|
|
@@ -198,7 +201,10 @@ const Listing = <
|
|
|
198
201
|
labelExpand: 'Expand'
|
|
199
202
|
},
|
|
200
203
|
isActionBarVisible = true,
|
|
201
|
-
labelNoResultFound = defaultLabelNoResultFound
|
|
204
|
+
labelNoResultFound = defaultLabelNoResultFound,
|
|
205
|
+
approximateTotalRows = false,
|
|
206
|
+
onApproximateCountClick,
|
|
207
|
+
isApproximateCountLoading = false
|
|
202
208
|
}: Props<TRow>): JSX.Element => {
|
|
203
209
|
const currentVisibleColumns = getVisibleColumns({
|
|
204
210
|
columnConfiguration,
|
|
@@ -527,13 +533,16 @@ const Listing = <
|
|
|
527
533
|
<ListingActionBar
|
|
528
534
|
actions={actions}
|
|
529
535
|
actionsBarMemoProps={actionsBarMemoProps}
|
|
536
|
+
approximateTotalRows={approximateTotalRows}
|
|
530
537
|
columnConfiguration={columnConfiguration}
|
|
531
538
|
columns={columns}
|
|
532
539
|
currentPage={currentPage}
|
|
533
540
|
customPaginationClassName={customPaginationClassName}
|
|
541
|
+
isApproximateCountLoading={isApproximateCountLoading}
|
|
534
542
|
limit={limit}
|
|
535
543
|
listingVariant={listingVariant}
|
|
536
544
|
moveTablePagination={moveTablePagination}
|
|
545
|
+
onApproximateCountClick={onApproximateCountClick}
|
|
537
546
|
paginated={paginated}
|
|
538
547
|
totalRows={totalRows}
|
|
539
548
|
viewerModeConfiguration={viewerModeConfiguration}
|
|
@@ -748,20 +757,26 @@ export const MemoizedListing = <TRow extends { id: string | number }>({
|
|
|
748
757
|
widthToMoveTablePagination,
|
|
749
758
|
listingVariant,
|
|
750
759
|
labelNoResultFound,
|
|
760
|
+
approximateTotalRows,
|
|
761
|
+
onApproximateCountClick,
|
|
762
|
+
isApproximateCountLoading,
|
|
751
763
|
...props
|
|
752
764
|
}: MemoizedListingProps<TRow>): JSX.Element =>
|
|
753
765
|
useMemoComponent({
|
|
754
766
|
Component: (
|
|
755
767
|
<Listing
|
|
768
|
+
approximateTotalRows={approximateTotalRows}
|
|
756
769
|
checkable={checkable}
|
|
757
770
|
columnConfiguration={columnConfiguration}
|
|
758
771
|
columns={columns}
|
|
759
772
|
currentPage={currentPage}
|
|
760
773
|
innerScrollDisabled={innerScrollDisabled}
|
|
774
|
+
isApproximateCountLoading={isApproximateCountLoading}
|
|
761
775
|
limit={limit}
|
|
762
776
|
listingVariant={listingVariant}
|
|
763
777
|
loading={loading}
|
|
764
778
|
moveTablePagination={moveTablePagination}
|
|
779
|
+
onApproximateCountClick={onApproximateCountClick}
|
|
765
780
|
paginated={paginated}
|
|
766
781
|
rowColorConditions={rowColorConditions}
|
|
767
782
|
rows={rows}
|
|
@@ -794,7 +809,9 @@ export const MemoizedListing = <TRow extends { id: string | number }>({
|
|
|
794
809
|
sortField,
|
|
795
810
|
innerScrollDisabled,
|
|
796
811
|
listingVariant,
|
|
797
|
-
labelNoResultFound
|
|
812
|
+
labelNoResultFound,
|
|
813
|
+
approximateTotalRows,
|
|
814
|
+
isApproximateCountLoading
|
|
798
815
|
]
|
|
799
816
|
});
|
|
800
817
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export const labelTo = 'to';
|
|
2
2
|
export const labelNoResultFound = 'No result found';
|
|
3
3
|
export const labelOf = 'of';
|
|
4
|
+
export const labelApproximateCount = '1,000+';
|
|
5
|
+
export const labelApproximateCountTooltip =
|
|
6
|
+
'More than 1,000 resources match your search. Click to continue.';
|
|
7
|
+
export const labelComputingExactCount = 'Loading...';
|
|
4
8
|
export const labelRowsPerPage = 'Rows per page';
|
|
5
9
|
export const labelFirstPage = 'First page';
|
|
6
10
|
export const labelLastPage = 'Last page';
|