• 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.87
/frontend/src/js/common-ui/AsyncAutocomplete.tsx
1
// Copyright 2021 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 { useEffect, useState } from 'react';
2✔
15

2✔
16
import { Autocomplete, TextField, useTheme } from '@mui/material';
2✔
17

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

2✔
21
import Loader from './Loader';
2✔
22

2✔
23
export const AsyncAutocomplete = ({
17✔
24
  id,
2✔
25
  initialValue,
2✔
26
  isLoading,
2✔
27
  label,
2✔
28
  placeholder,
2✔
29
  styles,
2✔
30
  selectionAttribute,
2✔
31
  labelAttribute,
2✔
32
  onChange,
2✔
33
  onChangeSelection,
2✔
34
  options
2✔
35
}) => {
2✔
36
  const theme = useTheme();
127✔
37
  const [open, setOpen] = useState(false);
127✔
38
  const [inputValue, setInputValue] = useState(initialValue);
127✔
39
  const loading = open && isLoading;
127✔
40

2✔
41
  const debouncedValue = useDebounce(inputValue, TIMEOUTS.debounceShort);
127✔
42

2✔
43
  useEffect(() => {
127✔
44
    if (debouncedValue === undefined) {
16✔
45
      return;
8✔
46
    }
2✔
47
    const selection = options.find(option => option[selectionAttribute] === debouncedValue);
18✔
48
    if (selection) {
10!
49
      onChangeSelection(selection);
10✔
50
    } else {
2✔
51
      onChange(debouncedValue);
2✔
52
    }
2✔
53
    // eslint-disable-next-line react-hooks/exhaustive-deps
2✔
54
  }, [debouncedValue, JSON.stringify(options), onChange, onChangeSelection, selectionAttribute]);
2✔
55

2✔
56
  const onInputChange = (e, value, reason) => {
127✔
57
    if (reason === 'clear') {
4!
58
      setInputValue('');
2✔
59
      return onChangeSelection();
2✔
60
    } else if ((reason === 'reset' && !e) || reason === 'blur') {
4!
61
      return;
2✔
62
    }
2✔
63
    setInputValue(value);
4✔
64
  };
2✔
65

2✔
66
  return (
127✔
67
    <Autocomplete
2✔
68
      autoHighlight
2✔
69
      freeSolo
2✔
70
      getOptionLabel={option => option[labelAttribute]}
1,286✔
UNCOV
71
      isOptionEqualToValue={(option, value) => option[selectionAttribute] === value[selectionAttribute]}
2✔
72
      id={id}
2✔
73
      inputValue={inputValue || ''}
2✔
74
      loading={loading}
2✔
75
      onClose={() => setOpen(false)}
4✔
76
      onInputChange={onInputChange}
2✔
77
      onOpen={() => setOpen(true)}
4✔
78
      open={open}
2✔
79
      openOnFocus
2✔
80
      options={options}
2✔
81
      renderInput={params => (
2✔
82
        <TextField
132✔
83
          {...params}
2✔
84
          label={label}
2✔
85
          placeholder={placeholder}
2✔
86
          style={styles.textField}
2✔
87
          slotProps={{
2✔
88
            input: {
2✔
89
              ...params.InputProps,
2✔
90
              endAdornment: (
2✔
91
                <>
2✔
92
                  {loading && <Loader show small table style={{ marginTop: theme.spacing(-4) }} />}
2!
93
                  {params.InputProps.endAdornment}
2✔
94
                </>
2✔
95
              )
2✔
96
            }
2✔
97
          }}
2✔
98
        />
2✔
99
      )}
2✔
100
    />
2✔
101
  );
2✔
102
};
2✔
103

2✔
104
export default AsyncAutocomplete;
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