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

mendersoftware / gui / 1091795320

01 Dec 2023 04:32AM UTC coverage: 82.784% (-17.2%) from 99.964%
1091795320

Pull #4229

gitlab-ci

web-flow
chore: Bump node from 21.1.0-alpine to 21.2.0-alpine

Bumps node from 21.1.0-alpine to 21.2.0-alpine.

---
updated-dependencies:
- dependency-name: node
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #4229: chore: Bump node from 21.1.0-alpine to 21.2.0-alpine

4316 of 6292 branches covered (0.0%)

8333 of 10066 relevant lines covered (82.78%)

188.98 hits per line

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

86.21
/src/js/components/common/chipselect.js
1
// Copyright 2023 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
import { Controller, useFormContext } from 'react-hook-form';
16

17
import { Autocomplete, TextField } from '@mui/material';
18

19
import { duplicateFilter, unionizeStrings } from '../../helpers';
20

21
export const ChipSelect = ({ className = '', name, disabled = false, inputRef, label = '', options = [], placeholder = '' }) => {
9!
22
  const [value, setValue] = useState('');
166✔
23

24
  const { control, getValues } = useFormContext();
166✔
25

26
  // to allow device types to automatically be selected on entered ',' we have to filter the input and transform any completed device types (followed by a ',')
27
  // while also checking for duplicates and allowing complete resets of the input
28
  const onTextInputChange = (inputValue, reason, setCurrentSelection) => {
166✔
29
    const value = inputValue || '';
18✔
30
    if (reason === 'clear') {
18!
31
      setValue('');
×
32
      return setCurrentSelection([]);
×
33
    } else if (reason === 'reset') {
18!
34
      return setValue('');
×
35
    }
36
    const lastIndex = value.lastIndexOf(',');
18✔
37
    const possibleSelection = value.substring(0, lastIndex).split(',').filter(duplicateFilter);
18✔
38
    const currentValue = value.substring(lastIndex + 1);
18✔
39
    const selection = getValues(name);
18✔
40
    const nextSelection = unionizeStrings(selection, possibleSelection);
18✔
41
    setValue(currentValue);
18✔
42
    setCurrentSelection(nextSelection);
18✔
43
  };
44

45
  const onTextInputLeave = (value, setCurrentSelection) => {
166✔
46
    const selection = getValues(name);
1✔
47
    const nextSelection = unionizeStrings(selection, [value]);
1✔
48
    setCurrentSelection(nextSelection);
1✔
49
    setValue('');
1✔
50
  };
51

52
  return (
166✔
53
    <Controller
54
      control={control}
55
      name={name}
56
      render={({ field: { onChange: formOnChange, value: currentSelection, ref, ...props } }) => (
57
        <Autocomplete
180✔
58
          id={`${name}-chip-select`}
59
          value={currentSelection}
60
          className={className}
61
          filterSelectedOptions
62
          freeSolo={true}
63
          includeInputInList={true}
64
          multiple
65
          // allow edits to the textinput without deleting existing device types by ignoring backspace
66
          onChange={(e, value) => (e.key !== 'Backspace' ? formOnChange(value) : null)}
×
67
          onInputChange={(e, v, reason) => onTextInputChange(null, reason, formOnChange)}
9✔
68
          options={options}
69
          readOnly={disabled}
70
          ref={ref}
71
          renderInput={params => (
72
            <TextField
183✔
73
              {...params}
74
              fullWidth
75
              inputProps={{ ...params.inputProps, value }}
76
              InputProps={{ ...params.InputProps, disableUnderline: disabled }}
77
              key={`${name}-input`}
78
              label={label}
79
              onBlur={e => onTextInputLeave(e.target.value, formOnChange)}
1✔
80
              onChange={e => onTextInputChange(e.target.value, 'input', formOnChange)}
9✔
81
              placeholder={currentSelection.length ? '' : placeholder}
183✔
82
              inputRef={inputRef}
83
            />
84
          )}
85
          {...props}
86
        />
87
      )}
88
    />
89
  );
90
};
91

92
export default ChipSelect;
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