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

mendersoftware / gui / 1057188406

01 Nov 2023 04:24AM UTC coverage: 82.824% (-17.1%) from 99.964%
1057188406

Pull #4134

gitlab-ci

web-flow
chore: Bump uuid from 9.0.0 to 9.0.1

Bumps [uuid](https://github.com/uuidjs/uuid) from 9.0.0 to 9.0.1.
- [Changelog](https://github.com/uuidjs/uuid/blob/main/CHANGELOG.md)
- [Commits](https://github.com/uuidjs/uuid/compare/v9.0.0...v9.0.1)

---
updated-dependencies:
- dependency-name: uuid
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #4134: chore: Bump uuid from 9.0.0 to 9.0.1

4349 of 6284 branches covered (0.0%)

8313 of 10037 relevant lines covered (82.82%)

200.97 hits per line

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

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

16
// material ui
17
import { Checkbox, MenuItem, Select } from '@mui/material';
18
import { makeStyles } from 'tss-react/mui';
19

20
import { DEVICE_ISSUE_OPTIONS } from '../../../constants/deviceConstants';
21

22
const menuProps = {
10✔
23
  anchorOrigin: {
24
    vertical: 'bottom',
25
    horizontal: 'left'
26
  },
27
  transformOrigin: {
28
    vertical: 'top',
29
    horizontal: 'left'
30
  }
31
};
32

33
const useStyles = makeStyles()(theme => ({
10✔
34
  menuItem: { paddingLeft: theme.spacing(), paddingRight: theme.spacing(3) }
35
}));
36

37
const groupOptions = (options = [], selection = []) => {
10!
38
  const things = options.reduce((accu, value) => {
3✔
39
    const { issueCategory, key } = DEVICE_ISSUE_OPTIONS[value.key];
7✔
40
    const nestedValue = { ...value, level: 0, checked: selection.includes(key) };
7✔
41
    if (issueCategory) {
7✔
42
      nestedValue.level = 1;
6✔
43
      let categoryItem = { ...DEVICE_ISSUE_OPTIONS[issueCategory], count: nestedValue.count, checked: nestedValue.checked };
6✔
44
      let existingItems = [];
6✔
45
      if (Array.isArray(accu[issueCategory])) {
6✔
46
        categoryItem = {
3✔
47
          ...accu[issueCategory][0],
48
          count: accu[issueCategory][0].count + nestedValue.count,
49
          checked: accu[issueCategory][0].checked && nestedValue.checked
4✔
50
        };
51
        existingItems = accu[issueCategory].slice(1);
3✔
52
      }
53
      accu[issueCategory] = [categoryItem, ...existingItems, nestedValue];
6✔
54
    } else {
55
      accu[key] = nestedValue;
1✔
56
    }
57
    return accu;
7✔
58
  }, {});
59
  return Object.values(things).flat();
3✔
60
};
61

62
const Selection = ({ selected = [], options = [] }) => {
10!
63
  const { classes } = useStyles();
22✔
64
  let content = 'all';
22✔
65
  if (selected.length) {
22✔
66
    const { titles, sum } = selected.reduce(
18✔
67
      (accu, issue) => {
68
        accu.titles.push(DEVICE_ISSUE_OPTIONS[issue].title);
34✔
69
        accu.sum += options.find(option => option.key === issue)?.count || 0;
88✔
70
        return accu;
34✔
71
      },
72
      { titles: [], sum: 0 }
73
    );
74
    content = `${titles.join(', ')} (${sum})`;
18✔
75
  }
76
  return (
22✔
77
    <MenuItem className={classes.menuItem} size="small" value="">
78
      {content}
79
    </MenuItem>
80
  );
81
};
82

83
const DeviceIssuesSelection = ({ onChange, options, selection }) => {
10✔
84
  const [open, setOpen] = useState(false);
20✔
85

86
  const handleClose = () => {
20✔
87
    setOpen(false);
1✔
88
  };
89

90
  const handleOpen = e => {
20✔
91
    if (e && e.target.closest('input')?.hasOwnProperty('checked')) {
1!
92
      return;
×
93
    }
94
    setOpen(true);
1✔
95
  };
96

97
  // eslint-disable-next-line react-hooks/exhaustive-deps
98
  const groupedOptions = useMemo(() => groupOptions(options, selection), [options.join(''), selection.join('')]);
20✔
99

100
  const onSelectionChange = useCallback(
20✔
101
    ({ target: { value: newSelection } }, { props: { value: clickedItem } }) => {
102
      const issue = DEVICE_ISSUE_OPTIONS[clickedItem];
1✔
103
      let categoryItems = [];
1✔
104
      if (issue.isCategory) {
1!
105
        categoryItems = options.reduce(
1✔
106
          (collector, option) => (DEVICE_ISSUE_OPTIONS[option.key].issueCategory === clickedItem ? [...collector, option.key] : collector),
2!
107
          categoryItems
108
        );
109
      }
110

111
      let selectedOptions = newSelection;
1✔
112
      if (categoryItems.length && categoryItems.every(item => selection.includes(item))) {
1!
113
        selectedOptions = selectedOptions.filter(option => !(categoryItems.includes(option) || option === clickedItem));
×
114
      } else {
115
        selectedOptions = [...newSelection, ...categoryItems].filter(option => (issue.isCategory ? option !== clickedItem : true));
3!
116
      }
117
      onChange({ target: { value: [...new Set(selectedOptions)] } });
1✔
118
    },
119
    [onChange, options, selection]
120
  );
121

122
  return (
20✔
123
    <div className="flexbox center-aligned margin-left">
124
      <div>Show:</div>
125
      <Select
126
        disableUnderline
127
        displayEmpty
128
        MenuProps={menuProps}
129
        multiple
130
        size="small"
131
        open={open}
132
        onClose={handleClose}
133
        onOpen={handleOpen}
134
        onChange={onSelectionChange}
135
        renderValue={selected => <Selection selected={selected} options={groupedOptions} />}
22✔
136
        value={selection}
137
        SelectDisplayProps={{ style: { padding: 0 } }}
138
      >
139
        {groupedOptions.map(({ checked, count, key, title, level = 0 }) => (
20✔
140
          <MenuItem key={key} value={key} size="small">
61✔
141
            <Checkbox checked={checked} style={{ marginLeft: 8 * (level + 1) }} size="small" />
142
            {title} ({count})
143
          </MenuItem>
144
        ))}
145
      </Select>
146
    </div>
147
  );
148
};
149

150
export default DeviceIssuesSelection;
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