@centreon/ui 26.12.11 → 26.12.12
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
|
@@ -82,6 +82,26 @@ const useStyles = makeStyles<StyleProps>()(
|
|
|
82
82
|
})
|
|
83
83
|
);
|
|
84
84
|
|
|
85
|
+
const defaultRowsPerPageOptions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
|
|
86
|
+
|
|
87
|
+
// The page size can be any number (the platform setting is free), so it is
|
|
88
|
+
// added to the options when missing, for the selector to show it. `Number`
|
|
89
|
+
// because `onLimitChange` is typed `string | number`, so a consumer may store a
|
|
90
|
+
// string limit.
|
|
91
|
+
const getRowsPerPageOptions = (limit: number | string): Array<number> => {
|
|
92
|
+
const rowsPerPage = Number(limit);
|
|
93
|
+
|
|
94
|
+
if (
|
|
95
|
+
!Number.isInteger(rowsPerPage) ||
|
|
96
|
+
rowsPerPage <= 0 ||
|
|
97
|
+
defaultRowsPerPageOptions.includes(rowsPerPage)
|
|
98
|
+
) {
|
|
99
|
+
return defaultRowsPerPageOptions;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return [...defaultRowsPerPageOptions, rowsPerPage].sort((a, b) => a - b);
|
|
103
|
+
};
|
|
104
|
+
|
|
85
105
|
type Props = Pick<
|
|
86
106
|
ListingProps<unknown>,
|
|
87
107
|
| 'actions'
|
|
@@ -287,7 +307,7 @@ const MemoListingActionBar = ({
|
|
|
287
307
|
onRowsPerPageChange={changeRowPerPage}
|
|
288
308
|
page={currentPage ?? 0}
|
|
289
309
|
rowsPerPage={limit ?? 10}
|
|
290
|
-
rowsPerPageOptions={
|
|
310
|
+
rowsPerPageOptions={getRowsPerPageOptions(limit ?? 10)}
|
|
291
311
|
SelectProps={{
|
|
292
312
|
id: labelRowsPerPage,
|
|
293
313
|
MenuProps: {
|
|
@@ -473,4 +473,100 @@ describe('Listing', () => {
|
|
|
473
473
|
});
|
|
474
474
|
expect(onRowClick).not.toHaveBeenCalled();
|
|
475
475
|
});
|
|
476
|
+
|
|
477
|
+
describe('Rows per page', () => {
|
|
478
|
+
const defaultOptions = [
|
|
479
|
+
'10',
|
|
480
|
+
'20',
|
|
481
|
+
'30',
|
|
482
|
+
'40',
|
|
483
|
+
'50',
|
|
484
|
+
'60',
|
|
485
|
+
'70',
|
|
486
|
+
'80',
|
|
487
|
+
'90',
|
|
488
|
+
'100'
|
|
489
|
+
];
|
|
490
|
+
|
|
491
|
+
const openRowsPerPage = async (limit: number): Promise<HTMLElement> => {
|
|
492
|
+
render(
|
|
493
|
+
<Listing
|
|
494
|
+
columns={defaultColumn}
|
|
495
|
+
currentPage={0}
|
|
496
|
+
limit={limit}
|
|
497
|
+
rows={listingWithSubItems3Rows}
|
|
498
|
+
totalRows={3}
|
|
499
|
+
/>
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
const rowsPerPage = within(
|
|
503
|
+
await screen.findByTestId('Listing Pagination')
|
|
504
|
+
).getByRole('combobox');
|
|
505
|
+
|
|
506
|
+
expect(rowsPerPage).toHaveTextContent(new RegExp(`^${limit}$`));
|
|
507
|
+
|
|
508
|
+
await userEvent.click(rowsPerPage);
|
|
509
|
+
|
|
510
|
+
return screen.findByRole('listbox');
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
const getOptionLabels = (listbox: HTMLElement): Array<string | null> =>
|
|
514
|
+
within(listbox)
|
|
515
|
+
.getAllByRole('option')
|
|
516
|
+
.map((option) => option.textContent);
|
|
517
|
+
|
|
518
|
+
it.each([
|
|
519
|
+
{
|
|
520
|
+
limit: 25,
|
|
521
|
+
options: [
|
|
522
|
+
'10',
|
|
523
|
+
'20',
|
|
524
|
+
'25',
|
|
525
|
+
'30',
|
|
526
|
+
'40',
|
|
527
|
+
'50',
|
|
528
|
+
'60',
|
|
529
|
+
'70',
|
|
530
|
+
'80',
|
|
531
|
+
'90',
|
|
532
|
+
'100'
|
|
533
|
+
]
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
limit: 150,
|
|
537
|
+
options: [
|
|
538
|
+
'10',
|
|
539
|
+
'20',
|
|
540
|
+
'30',
|
|
541
|
+
'40',
|
|
542
|
+
'50',
|
|
543
|
+
'60',
|
|
544
|
+
'70',
|
|
545
|
+
'80',
|
|
546
|
+
'90',
|
|
547
|
+
'100',
|
|
548
|
+
'150'
|
|
549
|
+
]
|
|
550
|
+
}
|
|
551
|
+
])(
|
|
552
|
+
'adds the page size $limit to the options when it is not one of them',
|
|
553
|
+
async ({ limit, options }) => {
|
|
554
|
+
const listbox = await openRowsPerPage(limit);
|
|
555
|
+
|
|
556
|
+
expect(getOptionLabels(listbox)).toEqual(options);
|
|
557
|
+
expect(
|
|
558
|
+
within(listbox).getByRole('option', { name: `${limit}` })
|
|
559
|
+
).toHaveAttribute('aria-selected', 'true');
|
|
560
|
+
}
|
|
561
|
+
);
|
|
562
|
+
|
|
563
|
+
it('keeps the default options when the page size is one of them', async () => {
|
|
564
|
+
const listbox = await openRowsPerPage(30);
|
|
565
|
+
|
|
566
|
+
expect(getOptionLabels(listbox)).toEqual(defaultOptions);
|
|
567
|
+
expect(
|
|
568
|
+
within(listbox).getByRole('option', { name: '30' })
|
|
569
|
+
).toHaveAttribute('aria-selected', 'true');
|
|
570
|
+
});
|
|
571
|
+
});
|
|
476
572
|
});
|