• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-server / 10423

11 Nov 2025 04:53PM UTC coverage: 74.435% (-0.1%) from 74.562%
10423

push

gitlab-ci

web-flow
Merge pull request #1071 from mendersoftware/dependabot/npm_and_yarn/frontend/main/development-dependencies-92732187be

3868 of 5393 branches covered (71.72%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 2 files covered. (100.0%)

176 existing lines in 95 files now uncovered.

64605 of 86597 relevant lines covered (74.6%)

7.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.2
/frontend/src/js/common-ui/Pagination.tsx
1
// Copyright 2019 Northern.tech AS
2✔
2
//
2✔
3
//    Licensed under the Apache License, Version 2.0 (the "License");
2✔
4
//    you may not use this file except in compliance with the License.
2✔
5
//    You may obtain a copy of the License at
2✔
6
//
2✔
7
//        http://www.apache.org/licenses/LICENSE-2.0
2✔
8
//
2✔
9
//    Unless required by applicable law or agreed to in writing, software
2✔
10
//    distributed under the License is distributed on an "AS IS" BASIS,
2✔
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2✔
12
//    See the License for the specific language governing permissions and
2✔
13
//    limitations under the License.
2✔
14
import { memo, useEffect, useState } from 'react';
2✔
15

2✔
16
import { KeyboardArrowLeft, KeyboardArrowRight } from '@mui/icons-material';
2✔
17
import { IconButton, TablePagination } from '@mui/material';
2✔
18

2✔
19
import { DEVICE_LIST_DEFAULTS, DEVICE_LIST_MAXIMUM_LENGTH, TIMEOUTS } from '@northern.tech/store/constants';
2✔
20
import { useDebounce } from '@northern.tech/utils/debouncehook';
2✔
21

2✔
22
import MenderTooltip from './helptips/MenderTooltip';
2✔
23

2✔
24
const defaultRowsPerPageOptions = [10, 20, DEVICE_LIST_MAXIMUM_LENGTH];
32✔
25
const { perPage: defaultPerPage } = DEVICE_LIST_DEFAULTS;
32✔
26
const paginationIndex = 1;
32✔
27
const paginationLimit = 10000;
32✔
28

2✔
29
const MaybeWrapper = ({ children, disabled }) =>
32✔
30
  disabled ? (
55✔
31
    <MenderTooltip arrow placement="top" title="Please refine your filter criteria first in order to proceed.">
2✔
32
      <div>{children}</div>
2✔
33
    </MenderTooltip>
2✔
34
  ) : (
2✔
35
    <div>{children}</div>
2✔
36
  );
2✔
37

2✔
38
export const TablePaginationActions = ({ count, page = 0, onPageChange, rowsPerPage = defaultPerPage, showCountInfo = true }) => {
32✔
39
  const [pageNo, setPageNo] = useState(page + paginationIndex);
55✔
40

2✔
41
  useEffect(() => {
55✔
42
    setPageNo(page + paginationIndex);
49✔
43
  }, [page, rowsPerPage, count]);
2✔
44

2✔
45
  const debouncedPage = useDebounce(pageNo, TIMEOUTS.debounceShort);
55✔
46

2✔
47
  useEffect(() => {
55✔
48
    const newPage = Math.min(Math.max(paginationIndex, debouncedPage), Math.max(paginationIndex, Math.ceil(count / rowsPerPage)));
52✔
49
    if (newPage !== page + paginationIndex) {
52✔
50
      onPageChange(newPage);
5✔
51
    }
2✔
52
  }, [count, debouncedPage, onPageChange, page, rowsPerPage]);
2✔
53

2✔
54
  const pages = Math.ceil(count / rowsPerPage);
55✔
55

2✔
56
  const isAtPaginationLimit = pageNo >= paginationLimit / rowsPerPage;
55✔
57
  return (
55✔
58
    <div className="flexbox center-aligned">
2✔
59
      {showCountInfo && <div>{`${(pageNo - paginationIndex) * rowsPerPage + 1}-${Math.min(pageNo * rowsPerPage, count)} of ${count}`}</div>}
2✔
60
      <IconButton onClick={() => setPageNo(pageNo - 1)} disabled={pageNo === paginationIndex} size="large" aria-label="prev">
3✔
61
        <KeyboardArrowLeft />
2✔
62
      </IconButton>
2✔
63
      <MaybeWrapper disabled={isAtPaginationLimit}>
2✔
64
        <IconButton onClick={() => setPageNo(pageNo + 1)} disabled={pageNo >= pages || isAtPaginationLimit} size="large" aria-label="next">
4✔
65
          <KeyboardArrowRight />
2✔
66
        </IconButton>
2✔
67
      </MaybeWrapper>
2✔
68
    </div>
2✔
69
  );
2✔
70
};
2✔
71

2✔
72
const Pagination = props => {
32✔
73
  const { className, onChangeRowsPerPage, onChangePage, page = 0, rowsPerPageOptions = defaultRowsPerPageOptions, showCountInfo, ...remainingProps } = props;
45✔
74
  // this is required due to the MUI tablepagination being 0-indexed, whereas we work with 1-indexed apis
2✔
75
  // running it without adjustment will lead to warnings from MUI
2✔
76
  const propsPage = Math.max(page - paginationIndex, 0);
45✔
77
  return (
45✔
78
    <TablePagination
2✔
79
      className={`flexbox margin-top ${className || ''}`}
2✔
80
      classes={{ spacer: 'flexbox no-basis' }}
2✔
81
      component="div"
2✔
82
      labelDisplayedRows={() => ''}
45✔
83
      labelRowsPerPage="Rows"
2✔
84
      slotProps={{ select: { name: 'pagination' } }}
2✔
85
      rowsPerPageOptions={rowsPerPageOptions}
2✔
UNCOV
86
      onRowsPerPageChange={e => onChangeRowsPerPage(e.target.value)}
2✔
87
      page={propsPage}
2✔
88
      onPageChange={onChangePage}
2✔
89
      ActionsComponent={actionProps => <TablePaginationActions {...actionProps} showCountInfo={showCountInfo} />}
45✔
90
      {...remainingProps}
2✔
91
    />
2✔
92
  );
2✔
93
};
2✔
94

2✔
95
export const areEqual = (prevProps, nextProps) => {
32✔
96
  if (prevProps.page !== nextProps.page || prevProps.rowsPerPage !== nextProps.rowsPerPage || prevProps.disabled !== nextProps.disabled) {
187!
97
    return false;
2✔
98
  }
2✔
99

2✔
100
  const pageStart = (prevProps.page - 1) * prevProps.rowsPerPage;
187✔
101
  const pageEnd = pageStart + prevProps.rowsPerPage;
187✔
102

2✔
103
  return Math.min(prevProps.count, pageEnd) === Math.min(nextProps.count, pageEnd);
187✔
104
};
2✔
105
export default memo(Pagination, areEqual);
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc