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

mendersoftware / gui / 1057188406

01 Nov 2023 04:24AM UTC coverage: 82.824% (-17.1%) from 99.964%
1057188406

Pull #4134

gitlab-ci

web-flow
chore: Bump uuid from 9.0.0 to 9.0.1

Bumps [uuid](https://github.com/uuidjs/uuid) from 9.0.0 to 9.0.1.
- [Changelog](https://github.com/uuidjs/uuid/blob/main/CHANGELOG.md)
- [Commits](https://github.com/uuidjs/uuid/compare/v9.0.0...v9.0.1)

---
updated-dependencies:
- dependency-name: uuid
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #4134: chore: Bump uuid from 9.0.0 to 9.0.1

4349 of 6284 branches covered (0.0%)

8313 of 10037 relevant lines covered (82.82%)

200.97 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 => ({
22✔
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;
3✔
46
const ResultTitle = ({ onClick, term, total }) => {
3✔
47
  const content = `${total ? total : 'No'} ${pluralize('device', total)} found for "${term}"`;
1!
48
  let props = { className: 'bold' };
1✔
49
  let style = {};
1✔
50
  if (!total) {
1!
51
    props = { className: 'info' };
1✔
52
    style = { width: `calc(100% - ${leftNavOffset}px)` };
1✔
53
  }
54
  return (
1✔
55
    <div className={`flexbox ${total ? 'center-aligned' : 'centered'}`} style={style}>
1!
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 }) => {
3!
67
  const navigate = useNavigate();
1,107✔
68
  const dispatch = useDispatch();
1,107✔
69

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

76
  const { classes } = useStyles();
1,107✔
77

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

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

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

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

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

100
  const onDeviceSelect = device => {
1,107✔
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 => {
1,107✔
107
    dispatch(setSearchState({ page }));
×
108
  };
109

110
  const onSortChange = attribute => {
1,107✔
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 = () => {
1,107✔
120
    dispatch(setSearchState({ searchTerm: '' }));
×
121
    onToggleSearchResult();
×
122
  };
123

124
  return (
1,107✔
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 && (
1,107!
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