• 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

93.75
/src/js/components/common/forms/filters.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, { useEffect, useState } from 'react';
15
import { FormProvider, useForm } from 'react-hook-form';
16

17
import { makeStyles } from 'tss-react/mui';
18

19
import { TIMEOUTS } from '../../../constants/appConstants';
20
import { useDebounce } from '../../../utils/debouncehook';
21

22
const useStyles = makeStyles()(theme => ({
4✔
23
  filters: {
24
    backgroundColor: theme.palette.background.lightgrey,
25
    columnGap: theme.spacing(2),
26
    display: 'flex',
27
    flexWrap: 'wrap',
28
    padding: `10px ${theme.spacing(3)} ${theme.spacing(3)}`,
29
    rowGap: theme.spacing(2),
30
    '.filter-item': {
31
      display: 'grid'
32
    },
33
    '.filter-item > div': {
34
      alignSelf: 'end'
35
    }
36
  },
37
  filterReset: { right: theme.spacing(3) }
38
}));
39

40
export const Filters = ({ className = '', defaultValues, filters = [], initialValues, onChange }) => {
4!
41
  const { classes } = useStyles();
51✔
42
  const [values, setValues] = useState(initialValues);
51✔
43

44
  const methods = useForm({ mode: 'onChange', defaultValues });
51✔
45
  const { formState, reset, watch, setValue } = methods;
51✔
46
  const { isDirty } = formState;
51✔
47

48
  useEffect(() => {
51✔
49
    Object.entries(initialValues).map(([key, value]) => setValue(key, value));
27✔
50
    // eslint-disable-next-line react-hooks/exhaustive-deps
51
  }, [JSON.stringify(initialValues), setValue]);
52

53
  watch(setValues);
51✔
54
  const debouncedValues = useDebounce(values, TIMEOUTS.default);
51✔
55

56
  useEffect(() => {
51✔
57
    onChange(debouncedValues);
10✔
58
    // eslint-disable-next-line react-hooks/exhaustive-deps
59
  }, [JSON.stringify(debouncedValues), onChange]);
60

61
  return (
51✔
62
    <FormProvider {...methods}>
63
      <form className={`margin-bottom relative margin-top ${classes.filters} ${className}`} noValidate>
64
        {filters.map(({ key, title, Component, componentProps }) => (
65
          <div className="filter-item" key={key}>
153✔
66
            <h5 className="margin-top-small margin-bottom-none muted">{title}</h5>
67
            <Component name={key} {...componentProps} />
68
          </div>
69
        ))}
70
        {isDirty && (
57✔
NEW
71
          <span className={`link absolute ${classes.filterReset}`} onClick={() => reset()}>
×
72
            Clear filter
73
          </span>
74
        )}
75
      </form>
76
    </FormProvider>
77
  );
78
};
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