• 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

95.74
/src/js/components/deployments/deployment-report/devicelist.js
1
// Copyright 2017 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 { Link } from 'react-router-dom';
16

17
// material ui
18
import { Button, LinearProgress } from '@mui/material';
19
import { makeStyles } from 'tss-react/mui';
20

21
import DeltaIcon from '../../../../assets/img/deltaicon.svg';
22
import { canAccess as canShow } from '../../../constants/appConstants';
23
import { deploymentSubstates } from '../../../constants/deploymentConstants';
24
import { DEVICE_LIST_DEFAULTS } from '../../../constants/deviceConstants';
25
import { rootfsImageVersion as rootfsImageVersionAttribute } from '../../../constants/releaseConstants';
26
import { FileSize, formatTime } from '../../../helpers';
27
import { TwoColumns } from '../../common/configurationobject';
28
import DetailsTable from '../../common/detailstable';
29
import DeviceIdentityDisplay from '../../common/deviceidentity';
30
import Loader from '../../common/loader';
31
import MenderTooltip from '../../common/mendertooltip';
32
import Pagination from '../../common/pagination';
33
import { MaybeTime } from '../../common/time';
34

35
const useStyles = makeStyles()(() => ({
12✔
36
  table: { minHeight: '10vh', maxHeight: '40vh', overflowX: 'auto' }
37
}));
38

39
const { page: defaultPage } = DEVICE_LIST_DEFAULTS;
12✔
40

41
const stateTitleMap = {
12✔
42
  noartifact: 'No compatible artifact found',
43
  'already-installed': 'Already installed',
44
  'pause-before-installing': 'Paused before installing',
45
  'pause-before-rebooting': 'Paused before rebooting',
46
  'pause-before-committing': 'Paused before committing'
47
};
48

49
const determinedStateMap = {
12✔
50
  'noartifact': 0,
51
  'aborted': 100,
52
  'already-installed': 100,
53
  'failure': 100,
54
  'success': 100
55
};
56

57
const statusColorMap = {
12✔
58
  failure: 'secondary',
59
  aborted: 'secondary',
60
  default: 'primary'
61
};
62

63
const undefinedStates = [deploymentSubstates.pending, deploymentSubstates.decommissioned, deploymentSubstates.alreadyInstalled];
12✔
64

65
const deviceListColumns = [
12✔
66
  {
67
    key: 'idAttribute',
68
    title: 'id',
69
    renderTitle: ({ idAttribute }) => idAttribute,
7✔
70
    render: ({ device, idAttribute }) => (
71
      <Link style={{ fontWeight: 'initial', opacity: idAttribute === 'name' ? 0.6 : 1 }} to={`/devices?id=${device.id}`}>
5!
72
        <DeviceIdentityDisplay device={device} isEditable={false} />
73
      </Link>
74
    ),
75
    canShow
76
  },
77
  {
78
    key: 'device-type',
79
    title: 'Device Type',
80
    render: ({ device }) => {
81
      const { attributes = {} } = device;
5!
82
      const { device_type: deviceTypes = [] } = attributes;
5✔
83
      return deviceTypes.length ? deviceTypes.join(',') : '-';
5!
84
    },
85
    canShow
86
  },
87
  {
88
    key: 'current-software',
89
    title: 'Current software',
90
    render: ({ device: { attributes = {} }, userCapabilities: { canReadReleases } }) => {
×
91
      const { artifact_name, [rootfsImageVersionAttribute]: rootfsImageVersion } = attributes;
5✔
92
      const softwareName = rootfsImageVersion || artifact_name;
5✔
93
      const encodedArtifactName = encodeURIComponent(softwareName);
5✔
94
      return softwareName ? (
5!
95
        canReadReleases ? (
×
96
          <Link style={{ fontWeight: 'initial' }} to={`/releases/${encodedArtifactName}`}>
97
            {softwareName}
98
          </Link>
99
        ) : (
100
          softwareName
101
        )
102
      ) : (
103
        '-'
104
      );
105
    },
106
    canShow
107
  },
108
  { key: 'started', title: 'Started', render: ({ device: { created } }) => <MaybeTime value={formatTime(created)} />, sortable: false, canShow },
5✔
109
  { key: 'finished', title: 'Finished', render: ({ device: { finished } }) => <MaybeTime value={formatTime(finished)} />, sortable: false, canShow },
5✔
110
  {
111
    key: 'artifact_size',
112
    title: 'Artifact size',
113
    render: ({ device: { image = {} } }) => {
×
114
      const { size } = image;
5✔
115
      return <FileSize fileSize={size} />;
5✔
116
    },
117
    sortable: false,
118
    canShow
119
  },
120
  {
121
    key: 'delta',
122
    title: '',
123
    render: ({ device: { isDelta } }) =>
124
      isDelta ? (
5!
125
        <MenderTooltip placement="bottom" title="Device is enabled for delta updates">
126
          <DeltaIcon />
127
        </MenderTooltip>
128
      ) : (
129
        ''
130
      ),
131
    canShow
132
  },
133
  {
134
    key: 'attempts',
135
    title: 'Attempts',
136
    render: ({ device: { attempts, retries } }) => `${attempts || 1} / ${retries + 1}`,
×
137
    canShow: ({ deployment: { retries } }) => !!retries
7✔
138
  },
139
  {
140
    key: 'status',
141
    title: 'Deployment status',
142
    render: ({ device: { substate, status = '' } }) => {
×
143
      const statusTitle = stateTitleMap[status] || status;
5✔
144
      const progressColor = statusColorMap[statusTitle.toLowerCase()] ?? statusColorMap.default;
5✔
145
      const devicePercentage = determinedStateMap[status];
5✔
146
      return (
5✔
147
        <>
148
          {substate ? (
5!
149
            <div className="flexbox">
150
              <div className="capitalized-start" style={{ verticalAlign: 'top' }}>{`${statusTitle}: `}</div>
151
              <div className="substate">{substate}</div>
152
            </div>
153
          ) : (
154
            statusTitle
155
          )}
156
          {!undefinedStates.includes(status.toLowerCase()) && (
10✔
157
            <div style={{ position: 'absolute', bottom: 0, width: '100%' }}>
158
              <LinearProgress color={progressColor} value={devicePercentage} variant={devicePercentage !== undefined ? 'determinate' : 'indeterminate'} />
5!
159
            </div>
160
          )}
161
        </>
162
      );
163
    },
164
    canShow
165
  },
166
  {
167
    key: 'log',
168
    title: '',
169
    render: ({ device: { id, log }, viewLog }) => (log ? <Button onClick={() => viewLog(id)}>View log</Button> : null),
5!
170
    canShow
171
  }
172
];
173

174
const ValueFileSize = ({ value, ...props }) => <FileSize fileSize={value} {...props} />;
12✔
175

176
export const DeploymentDeviceList = ({ deployment, getDeploymentDevices, idAttribute, selectedDevices, userCapabilities, viewLog }) => {
12✔
177
  const [currentPage, setCurrentPage] = useState(defaultPage);
7✔
178
  const [isLoading, setIsLoading] = useState(false);
7✔
179
  const [perPage, setPerPage] = useState(10);
7✔
180
  const { device_count = 0, totalDeviceCount: totalDevices, statistics = {} } = deployment;
7!
181
  const totalSize = statistics.total_size ?? 0;
7!
182
  const totalDeviceCount = totalDevices ?? device_count;
7✔
183
  const { classes } = useStyles();
7✔
184

185
  useEffect(() => {
7✔
186
    setCurrentPage(defaultPage);
3✔
187
  }, [perPage]);
188

189
  useEffect(() => {
7✔
190
    if (!deployment.id) {
3!
191
      return;
×
192
    }
193
    setIsLoading(true);
3✔
194
    getDeploymentDevices(deployment.id, { page: currentPage, perPage }).then(() => setIsLoading(false));
3✔
195
    // eslint-disable-next-line react-hooks/exhaustive-deps
196
  }, [currentPage, deployment.id, deployment.status, getDeploymentDevices, JSON.stringify(statistics.status), perPage]);
197

198
  const columns = deviceListColumns.reduce((accu, column) => (column.canShow({ deployment }) ? [...accu, { ...column, extras: { idAttribute } }] : accu), []);
70✔
199
  const items = selectedDevices.map(device => ({ device, id: device.id, idAttribute, userCapabilities, viewLog }));
7✔
200
  return (
7✔
201
    <>
202
      <DetailsTable className={classes.table} columns={columns} items={items} />
203
      <div className="flexbox space-between center-aligned margin-top">
204
        <div className="flexbox">
205
          <Pagination
206
            className="margin-top-none"
207
            count={totalDeviceCount}
208
            rowsPerPage={perPage}
209
            onChangePage={setCurrentPage}
210
            onChangeRowsPerPage={setPerPage}
211
            page={currentPage}
212
          />
213
          <Loader show={isLoading} small />
214
        </div>
215
        <TwoColumns chipLikeKey={false} compact items={{ 'Total download size': totalSize }} ValueComponent={ValueFileSize} />
216
      </div>
217
    </>
218
  );
219
};
220

221
export default DeploymentDeviceList;
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