• 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

95.71
/frontend/src/js/common-ui/DetailsTable.tsx
1
// Copyright 2022 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
// material ui
2✔
15
import { Sort as SortIcon } from '@mui/icons-material';
2✔
16
import { Checkbox, Table, TableBody, TableCell, TableHead, TableRow } from '@mui/material';
2✔
17
import { makeStyles } from 'tss-react/mui';
2✔
18

2✔
19
import { SORTING_OPTIONS } from '@northern.tech/store/constants';
2✔
20

2✔
21
const useStyles = makeStyles()(() => ({
30✔
22
  header: {
2✔
23
    '.columnHeader': {
2✔
24
      display: 'table-cell'
2✔
25
    },
2✔
26
    '.columnHeader .sortIcon': {
2✔
27
      marginBottom: -6
2✔
28
    },
2✔
29
    '.nonSortable': { cursor: 'initial' }
2✔
30
  }
2✔
31
}));
2✔
32

2✔
33
export const DetailsTable = ({
17✔
34
  className = '',
2✔
35
  columns,
2✔
36
  items,
2✔
37
  onChangeSorting,
2✔
38
  onItemClick,
2✔
39
  sort = {},
2✔
40
  style = {},
2✔
41
  tableRef,
2✔
42
  onRowSelected = undefined,
2✔
43
  selectedRows = []
2✔
44
}) => {
2✔
45
  const { classes } = useStyles();
137✔
46

2✔
47
  const onRowSelection = selectedRow => {
137✔
48
    const updatedSelection = [...selectedRows];
2✔
49
    const selectedIndex = updatedSelection.indexOf(selectedRow);
2✔
50
    if (selectedIndex === -1) {
2!
51
      updatedSelection.push(selectedRow);
2✔
52
    } else {
2✔
53
      updatedSelection.splice(selectedIndex, 1);
2✔
54
    }
2✔
55
    onRowSelected(updatedSelection);
2✔
56
  };
2✔
57

2✔
58
  const onSelectAllClick = () => {
137✔
59
    let newSelectedRows = Array.from({ length: items.length }, (_, index) => index);
3✔
60
    if (selectedRows.length && selectedRows.length <= items.length) {
3!
61
      newSelectedRows = [];
2✔
62
    }
2✔
63
    onRowSelected(newSelectedRows);
3✔
64
  };
2✔
65

2✔
66
  return (
137✔
67
    <Table className={`margin-bottom ${className}`} style={style} ref={tableRef}>
2✔
68
      <TableHead className={classes.header}>
2✔
69
        <TableRow>
2✔
70
          {onRowSelected !== undefined && (
2✔
71
            <TableCell>
2✔
72
              <Checkbox indeterminate={false} checked={selectedRows.length === items.length} onChange={onSelectAllClick} />
2✔
73
            </TableCell>
2✔
74
          )}
2✔
75
          {columns.map(({ extras, key, renderTitle, sortable, title, cellProps = {} }) => (
2✔
76
            <TableCell
733✔
77
              key={key}
2✔
78
              className={`columnHeader ${sortable ? '' : 'nonSortable'}`}
2✔
UNCOV
79
              onClick={() => (sortable ? onChangeSorting(key) : null)}
2!
80
              {...cellProps}
2✔
81
            >
2✔
82
              {renderTitle ? renderTitle(extras) : title}
2✔
83
              {sortable && <SortIcon className={`sortIcon ${sort.key === key ? 'selected' : ''} ${(sort.direction === SORTING_OPTIONS.desc).toString()}`} />}
2✔
84
            </TableCell>
2✔
85
          ))}
2✔
86
        </TableRow>
2✔
87
      </TableHead>
2✔
88
      <TableBody>
2✔
89
        {items.map((item, index) => (
2✔
90
          <TableRow className={onItemClick ? 'clickable' : ''} hover key={item.id || index}>
889✔
91
            {onRowSelected !== undefined && (
2✔
92
              <TableCell>
2✔
UNCOV
93
                <Checkbox checked={selectedRows.includes(index)} onChange={() => onRowSelection(index)} />
2✔
94
              </TableCell>
2✔
95
            )}
2✔
96
            {columns.map(column => (
2✔
97
              <TableCell className="relative" key={column.key} onClick={() => (onItemClick ? onItemClick(item) : null)}>
3,678✔
98
                {column.render(item, column.extras)}
2✔
99
              </TableCell>
2✔
100
            ))}
2✔
101
          </TableRow>
2✔
102
        ))}
2✔
103
      </TableBody>
2✔
104
    </Table>
2✔
105
  );
2✔
106
};
2✔
107

2✔
108
export default DetailsTable;
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