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

mendersoftware / gui / 1235064739

01 Apr 2024 05:03AM UTC coverage: 83.603% (-16.4%) from 99.964%
1235064739

Pull #4368

gitlab-ci

web-flow
chore: Bump the development-dependencies group with 18 updates

Bumps the development-dependencies group with 18 updates:

| Package | From | To |
| --- | --- | --- |
| [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) | `7.24.0` | `7.24.3` |
| [@babel/eslint-parser](https://github.com/babel/babel/tree/HEAD/eslint/babel-eslint-parser) | `7.23.10` | `7.24.1` |
| [@babel/plugin-transform-runtime](https://github.com/babel/babel/tree/HEAD/packages/babel-plugin-transform-runtime) | `7.24.0` | `7.24.3` |
| [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) | `7.24.0` | `7.24.3` |
| [@babel/preset-react](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-react) | `7.23.3` | `7.24.1` |
| [@testing-library/react](https://github.com/testing-library/react-testing-library) | `14.2.1` | `14.2.2` |
| [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) | `7.1.0` | `7.4.0` |
| [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) | `7.1.0` | `7.4.0` |
| [autoprefixer](https://github.com/postcss/autoprefixer) | `10.4.17` | `10.4.19` |
| [core-js](https://github.com/zloirock/core-js/tree/HEAD/packages/core-js) | `3.36.0` | `3.36.1` |
| [esbuild-loader](https://github.com/privatenumber/esbuild-loader) | `4.0.3` | `4.1.0` |
| [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) | `7.33.2` | `7.34.1` |
| [eslint-plugin-sonarjs](https://github.com/SonarSource/eslint-plugin-sonarjs) | `0.24.0` | `0.25.0` |
| [eslint-webpack-plugin](https://github.com/webpack-contrib/eslint-webpack-plugin) | `4.0.1` | `4.1.0` |
| [msw](https://github.com/mswjs/msw) | `2.2.2` | `2.2.13` |
| [postcss](https://github.com/postcss/postcss) | `8.4.35` | `8.4.38` |
| [webpack](https://github.com/webpack/webpack) | `5.90.3` | `5.91.0` |
| [yarn](https://github.com/yarnpkg/yarn) | ... (continued)
Pull Request #4368: chore: Bump the development-dependencies group with 18 updates

4434 of 6325 branches covered (70.1%)

8408 of 10057 relevant lines covered (83.6%)

140.68 hits per line

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

72.34
/src/js/components/search-result.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, { useEffect, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16
import { useNavigate } from 'react-router-dom';
17

18
import { Close as CloseIcon } from '@mui/icons-material';
19
// material ui
20
import { ClickAwayListener, Drawer, IconButton, Typography } from '@mui/material';
21
import { makeStyles } from 'tss-react/mui';
22

23
import pluralize from 'pluralize';
24

25
import { setSearchState } from '../actions/appActions';
26
import { setDeviceListState } from '../actions/deviceActions';
27
import { SORTING_OPTIONS, TIMEOUTS } from '../constants/appConstants';
28
import { getIdAttribute, getMappedDevicesList, getUserSettings } from '../selectors';
29
import { getHeaders } from './devices/authorized-devices';
30
import { routes } from './devices/base-devices';
31
import Devicelist from './devices/devicelist';
32

33
const useStyles = makeStyles()(theme => ({
11✔
34
  drawerOffset: {
35
    top: theme.mixins.toolbar.minHeight + 1,
36
    left: 200
37
  },
38
  paper: {
39
    maxWidth: '100vw',
40
    minHeight: '20vh',
41
    boxShadow: 'none'
42
  }
43
}));
44

45
const leftNavOffset = 500;
2✔
46
const ResultTitle = ({ onClick, term, total }) => {
2✔
47
  const content = `${total ? total : 'No'} ${pluralize('device', total)} found for "${term}"`;
2!
48
  let props = { className: 'bold' };
2✔
49
  let style = {};
2✔
50
  if (!total) {
2!
51
    props = { className: 'info' };
2✔
52
    style = { width: `calc(100% - ${leftNavOffset}px)` };
2✔
53
  }
54
  return (
2✔
55
    <div className={`flexbox ${total ? 'center-aligned' : 'centered'}`} style={style}>
2!
56
      <Typography variant="body2" {...props}>
57
        {content}
58
      </Typography>
59
      <a className="margin-left-large" onClick={onClick}>
60
        clear search
61
      </a>
62
    </div>
63
  );
64
};
65

66
export const SearchResult = ({ onToggleSearchResult, open = true }) => {
2!
67
  const navigate = useNavigate();
22✔
68
  const dispatch = useDispatch();
22✔
69

70
  const { columnSelection } = useSelector(getUserSettings);
22✔
71
  const customColumnSizes = useSelector(state => state.users.customColumns);
1,580✔
72
  const devices = useSelector(state => getMappedDevicesList(state, 'search'));
1,580✔
73
  const idAttribute = useSelector(getIdAttribute);
22✔
74
  const searchState = useSelector(state => state.app.searchState);
1,580✔
75

76
  const { classes } = useStyles();
22✔
77

78
  const [columnHeaders, setColumnHeaders] = useState(getHeaders(columnSelection, routes.devices.defaultHeaders, idAttribute));
22✔
79

80
  const { isSearching, searchTerm, searchTotal, sort = {} } = searchState;
22!
81
  const { direction: sortDown = SORTING_OPTIONS.desc, key: sortCol } = sort;
22✔
82

83
  useEffect(() => {
22✔
84
    const columnHeaders = getHeaders(columnSelection, routes.devices.defaultHeaders, idAttribute);
6✔
85
    setColumnHeaders(columnHeaders);
6✔
86
  }, [columnSelection, idAttribute, idAttribute.attribute]);
87

88
  useEffect(() => {
22✔
89
    if (!open && isSearching) {
9!
90
      onToggleSearchResult();
×
91
    }
92
  }, [open, isSearching, onToggleSearchResult]);
93

94
  useEffect(() => {
22✔
95
    if (open && !searchTerm) {
9!
96
      onToggleSearchResult();
×
97
    }
98
  }, [onToggleSearchResult, open, searchTerm]);
99

100
  const onDeviceSelect = device => {
22✔
101
    dispatch(setDeviceListState({ selectedId: device.id }));
×
102
    onToggleSearchResult();
×
103
    setTimeout(() => navigate(`/devices/${device.status}?id=${device.id}`), TIMEOUTS.debounceShort);
×
104
  };
105

106
  const handlePageChange = page => {
22✔
107
    dispatch(setSearchState({ page }));
×
108
  };
109

110
  const onSortChange = attribute => {
22✔
111
    let changedSortCol = attribute.name;
×
112
    let changedSortDown = sortDown === SORTING_OPTIONS.desc ? SORTING_OPTIONS.asc : SORTING_OPTIONS.desc;
×
113
    if (changedSortCol !== sortCol) {
×
114
      changedSortDown = SORTING_OPTIONS.desc;
×
115
    }
116
    dispatch(setSearchState({ page: 1, sort: { direction: changedSortDown, key: changedSortCol, scope: attribute.scope } }));
×
117
  };
118

119
  const onClearClick = () => {
22✔
120
    dispatch(setSearchState({ searchTerm: '' }));
×
121
    onToggleSearchResult();
×
122
  };
123

124
  return (
22✔
125
    <ClickAwayListener onClickAway={onToggleSearchResult}>
126
      <Drawer
127
        anchor="top"
128
        classes={classes}
129
        disableEnforceFocus
130
        open={open}
131
        ModalProps={{ className: classes.drawerOffset, BackdropProps: { className: classes.drawerOffset } }}
132
        PaperProps={{ className: `${classes.drawerOffset} ${classes.paper}` }}
133
        SlideProps={{ direction: 'left' }}
134
      >
135
        <div className="flexbox center-aligned margin-bottom-small space-between">
136
          <ResultTitle onClick={onClearClick} term={searchTerm} total={searchTotal} />
137
          <IconButton onClick={onToggleSearchResult} aria-label="close" size="large">
138
            <CloseIcon />
139
          </IconButton>
140
        </div>
141
        {!!searchTotal && (
22!
142
          <Devicelist
143
            columnHeaders={columnHeaders}
144
            customColumnSizes={customColumnSizes}
145
            deviceListState={{ perPage: 10, sort: {} }}
146
            devices={devices}
147
            idAttribute={idAttribute}
148
            onSort={onSortChange}
149
            PaginationProps={{ rowsPerPageOptions: [10] }}
150
            pageTotal={searchTotal}
151
            onPageChange={handlePageChange}
152
            pageLoading={isSearching}
153
            onExpandClick={onDeviceSelect}
154
          />
155
        )}
156
      </Drawer>
157
    </ClickAwayListener>
158
  );
159
};
160

161
export default SearchResult;
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