• 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

61.36
/src/js/components/devices/group-management/group-definition.js
1
// Copyright 2020 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, { useState } from 'react';
15

16
import { Autocomplete, FormHelperText, TextField } from '@mui/material';
17
import { createFilterOptions } from '@mui/material/useAutocomplete';
18

19
import validator from 'validator';
20

21
import { UNGROUPED_GROUP } from '../../../constants/deviceConstants';
22
import { fullyDecodeURI } from '../../../helpers';
23
import DocsLink from '../../common/docslink';
24
import InfoText from '../../common/infotext';
25

26
const filter = createFilterOptions();
6✔
27

28
export const validateGroupName = (encodedName, groups = [], selectedDevices = [], isCreationDynamic) => {
6!
29
  const name = fullyDecodeURI(encodedName);
5✔
30
  let invalid = false;
5✔
31
  let errortext = null;
5✔
32
  const isModification = name.length && groups.some(group => decodeURIComponent(group) === name);
5✔
33
  if (!name && !isModification) {
5✔
34
    invalid = true;
2✔
35
  } else if (!validator.isWhitelisted(name, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.')) {
3✔
36
    invalid = true;
1✔
37
    errortext = 'Valid characters are a-z, A-Z, 0-9, ., _ and -';
1✔
38
  } else if (selectedDevices.length && selectedDevices.every(({ group }) => group === name)) {
2✔
39
    invalid = true;
1✔
40
    errortext = `${name} is the same group the selected devices are already in`;
1✔
41
  } else if (isModification && isCreationDynamic) {
1!
42
    invalid = true;
1✔
43
    errortext = 'A group with the same name already exists';
1✔
44
  } else if (name === UNGROUPED_GROUP.name) {
×
45
    invalid = true;
×
46
    errortext = `A group with the name ${name} is created automatically`;
×
47
  }
48
  return { errortext, invalid, isModification, name };
5✔
49
};
50

51
const GroupOption = (props, option) => <li {...props}>{option.title}</li>;
6✔
52

53
export const GroupDefinition = ({ isCreationDynamic, groups, newGroup, onInputChange, selectedDevices, selectedGroup }) => {
6✔
54
  const [errortext, setErrorText] = useState('');
2✔
55

56
  const validateName = encodedName => {
2✔
57
    const { errortext: error, invalid, isModification, name } = validateGroupName(encodedName, groups, selectedDevices, isCreationDynamic);
×
58
    setErrorText(error);
×
59
    onInputChange(invalid, name, isModification);
×
60
  };
61

62
  const filteredGroups = groups
2✔
63
    .filter(group => group !== selectedGroup)
1✔
64
    .map(group => ({
1✔
65
      value: group,
66
      title: group
67
    }));
68
  return (
2✔
69
    <>
70
      <Autocomplete
71
        id="group-creation-selection"
72
        autoSelect
73
        freeSolo
74
        filterSelectedOptions
75
        filterOptions={(options, params) => {
76
          const filtered = filter(options, params);
×
77
          if (
×
78
            params.inputValue !== '' &&
×
79
            !groups.some(group => decodeURIComponent(group) === params.inputValue) &&
×
80
            (filtered.length !== 1 || (filtered.length === 1 && filtered[0].title !== params.inputValue))
81
          ) {
82
            filtered.push({
×
83
              inputValue: params.inputValue,
84
              title: `Create "${params.inputValue}" group`
85
            });
86
          }
87
          return filtered;
×
88
        }}
89
        getOptionLabel={option => {
90
          if (typeof option === 'string') {
×
91
            return option;
×
92
          }
93
          if (option.inputValue) {
×
94
            return option.inputValue;
×
95
          }
96
          return option.title;
×
97
        }}
98
        handleHomeEndKeys
99
        inputValue={newGroup}
100
        options={filteredGroups}
101
        onInputChange={(e, newValue) => validateName(newValue)}
×
102
        renderInput={params => <TextField {...params} label="Select a group, or type to create new" InputProps={{ ...params.InputProps }} />}
4✔
103
        renderOption={GroupOption}
104
      />
105
      <FormHelperText>{errortext}</FormHelperText>
106
      {isCreationDynamic && (
3✔
107
        <InfoText>
108
          Note: individual devices can&apos;t be added to dynamic groups.
109
          <br />
110
          <DocsLink path="overview/device-group" title="Learn more about static vs. dynamic groups" />
111
        </InfoText>
112
      )}
113
    </>
114
  );
115
};
116

117
export default GroupDefinition;
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