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

mendersoftware / gui / 1015445845

25 Sep 2023 09:43AM UTC coverage: 82.537% (-17.4%) from 99.964%
1015445845

Pull #4028

gitlab-ci

mzedel
chore: aligned release retrieval with v2 api models

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #4028: MEN-6455

4355 of 6315 branches covered (0.0%)

184 of 206 new or added lines in 19 files covered. (89.32%)

1724 existing lines in 164 files now uncovered.

8323 of 10084 relevant lines covered (82.54%)

208.49 hits per line

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

88.46
/src/js/components/common/search.js
1
// Copyright 2022 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, useEffect } from 'react';
15
import { Controller, FormProvider, useForm, useFormContext } from 'react-hook-form';
16

17
import { Search as SearchIcon } from '@mui/icons-material';
18
import { InputAdornment, TextField } from '@mui/material';
19
import { makeStyles } from 'tss-react/mui';
20

21
import { TIMEOUTS } from '../../constants/appConstants';
22
import { useDebounce } from '../../utils/debouncehook';
23
import Loader from './loader';
24

25
const useStyles = makeStyles()(() => ({
28✔
26
  root: {
27
    input: {
28
      fontSize: '13px'
29
    }
30
  }
31
}));
32

33
const endAdornment = (
34
  <InputAdornment position="end">
6✔
35
    <Loader show small style={{ marginTop: -10 }} />
36
  </InputAdornment>
37
);
38

39
const startAdornment = (
40
  <InputAdornment position="start">
6✔
41
    <SearchIcon color="disabled" fontSize="small" />
42
  </InputAdornment>
43
);
44

45
// due to search not working reliably for single letter searches, only start at 2
46
const MINIMUM_SEARCH_LENGTH = 2;
6✔
47

48
export const ControlledSearch = ({ isSearching, name = 'search', onSearch, placeholder = 'Search devices', style = {} }) => {
6✔
49
  const { classes } = useStyles();
476✔
50
  const { control, watch } = useFormContext();
476✔
51

52
  const searchValue = watch('search', '');
476✔
53

54
  const debouncedSearchTerm = useDebounce(searchValue, TIMEOUTS.debounceDefault);
476✔
55

56
  useEffect(() => {
476✔
57
    if (debouncedSearchTerm.length < MINIMUM_SEARCH_LENGTH) {
10!
58
      return;
10✔
59
    }
UNCOV
60
    onSearch(debouncedSearchTerm);
×
61
  }, [debouncedSearchTerm, onSearch]);
62

63
  const onTriggerSearch = useCallback(
476✔
64
    ({ key }) => {
65
      if (key === 'Enter' && (!debouncedSearchTerm || debouncedSearchTerm.length >= MINIMUM_SEARCH_LENGTH)) {
2!
NEW
66
        onSearch(debouncedSearchTerm);
×
67
      }
68
    },
69
    [debouncedSearchTerm, onSearch]
70
  );
71

72
  const adornments = isSearching ? { startAdornment, endAdornment } : { startAdornment };
476✔
73
  return (
476✔
74
    <Controller
75
      name={name}
76
      control={control}
77
      render={({ field }) => (
78
        <TextField
476✔
79
          className={classes.root}
80
          InputProps={adornments}
81
          onKeyPress={onTriggerSearch}
82
          placeholder={placeholder}
83
          size="small"
84
          style={style}
85
          {...field}
86
        />
87
      )}
88
    />
89
  );
90
};
91

92
ControlledSearch.displayName = 'ConnectedSearch';
6✔
93

94
const Search = props => {
6✔
95
  const { searchTerm, onSearch, trigger } = props;
425✔
96
  const methods = useForm({ mode: 'onChange', defaultValues: { search: searchTerm ?? '' } });
425!
97
  const { handleSubmit } = methods;
425✔
98
  return (
425✔
99
    <FormProvider {...methods}>
NEW
100
      <form noValidate onSubmit={handleSubmit(({ search }) => onSearch(search, !trigger))}>
×
101
        <ControlledSearch {...props} />
102
        <input className="hidden" type="submit" />
103
      </form>
104
    </FormProvider>
105
  );
106
};
107

108
export default Search;
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