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

mendersoftware / gui / 1113439055

19 Dec 2023 09:01PM UTC coverage: 82.752% (-17.2%) from 99.964%
1113439055

Pull #4258

gitlab-ci

mender-test-bot
chore: Types update

Signed-off-by: Mender Test Bot <mender@northern.tech>
Pull Request #4258: chore: Types update

4326 of 6319 branches covered (0.0%)

8348 of 10088 relevant lines covered (82.75%)

189.39 hits per line

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

96.08
/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()(() => ({
11✔
36
  table: { minHeight: '10vh', maxHeight: '40vh', overflowX: 'auto' }
37
}));
38

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

41
const stateTitleMap = {
11✔
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 = {
11✔
50
  'noartifact': 0,
51
  'aborted': 100,
52
  'already-installed': 100,
53
  'failure': 100,
54
  'success': 100
55
};
56

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

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

65
const deviceListColumns = [
11✔
66
  {
67
    key: 'idAttribute',
68
    title: 'id',
69
    renderTitle: ({ idAttribute }) => idAttribute,
10✔
70
    render: ({ device, idAttribute }) => (
71
      <Link style={{ fontWeight: 'initial', opacity: idAttribute === 'name' ? 0.6 : 1 }} to={`/devices?id=${device.id}`}>
7!
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;
7!
82
      const { device_type: deviceTypes = [] } = attributes;
7✔
83
      return deviceTypes.length ? deviceTypes.join(',') : '-';
7!
84
    },
85
    canShow
86
  },
87
  {
88
    key: 'current-artifact',
89
    title: 'Current artifact',
90
    render: ({ device: { attributes = {} }, userCapabilities: { canReadReleases } }) => {
×
91
      const { artifact_name } = attributes;
7✔
92
      const softwareName = artifact_name;
7✔
93
      const encodedArtifactName = encodeURIComponent(softwareName);
7✔
94
      return softwareName ? (
7!
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
  {
109
    key: 'current-software',
110
    title: 'Current software',
111
    render: ({ device: { attributes = {} }, userCapabilities: { canReadReleases } }) => {
×
112
      const { [rootfsImageVersionAttribute]: rootfsImageVersion } = attributes;
7✔
113
      const softwareName = rootfsImageVersion;
7✔
114
      const encodedArtifactName = encodeURIComponent(softwareName);
7✔
115
      return softwareName ? (
7!
116
        canReadReleases ? (
×
117
          <Link style={{ fontWeight: 'initial' }} to={`/releases/${encodedArtifactName}`}>
118
            {softwareName}
119
          </Link>
120
        ) : (
121
          softwareName
122
        )
123
      ) : (
124
        '-'
125
      );
126
    },
127
    canShow
128
  },
129
  { key: 'started', title: 'Started', render: ({ device: { started } }) => <MaybeTime value={formatTime(started)} />, sortable: false, canShow },
7✔
130
  { key: 'finished', title: 'Finished', render: ({ device: { finished } }) => <MaybeTime value={formatTime(finished)} />, sortable: false, canShow },
7✔
131
  {
132
    key: 'artifact_size',
133
    title: 'Artifact size',
134
    render: ({ device: { image = {} } }) => {
×
135
      const { size } = image;
7✔
136
      return <FileSize fileSize={size} />;
7✔
137
    },
138
    sortable: false,
139
    canShow
140
  },
141
  {
142
    key: 'delta',
143
    title: '',
144
    render: ({ device: { isDelta } }) =>
145
      isDelta ? (
7!
146
        <MenderTooltip placement="bottom" title="Device is enabled for delta updates">
147
          <DeltaIcon />
148
        </MenderTooltip>
149
      ) : (
150
        ''
151
      ),
152
    canShow
153
  },
154
  {
155
    key: 'attempts',
156
    title: 'Attempts',
157
    render: ({ device: { attempts, retries } }) => `${attempts || 1} / ${retries + 1}`,
×
158
    canShow: ({ deployment: { retries } }) => !!retries
10✔
159
  },
160
  {
161
    key: 'status',
162
    title: 'Deployment status',
163
    render: ({ device: { substate, status = '' } }) => {
×
164
      const statusTitle = stateTitleMap[status] || status;
7✔
165
      const progressColor = statusColorMap[statusTitle.toLowerCase()] ?? statusColorMap.default;
7✔
166
      const devicePercentage = determinedStateMap[status];
7✔
167
      return (
7✔
168
        <>
169
          {substate ? (
7!
170
            <div className="flexbox">
171
              <div className="capitalized-start" style={{ verticalAlign: 'top' }}>{`${statusTitle}: `}</div>
172
              <div className="substate">{substate}</div>
173
            </div>
174
          ) : (
175
            statusTitle
176
          )}
177
          {!undefinedStates.includes(status.toLowerCase()) && (
14✔
178
            <div style={{ position: 'absolute', bottom: 0, width: '100%' }}>
179
              <LinearProgress color={progressColor} value={devicePercentage} variant={devicePercentage !== undefined ? 'determinate' : 'indeterminate'} />
7!
180
            </div>
181
          )}
182
        </>
183
      );
184
    },
185
    canShow
186
  },
187
  {
188
    key: 'log',
189
    title: '',
190
    render: ({ device: { id, log }, viewLog }) => (log ? <Button onClick={() => viewLog(id)}>View log</Button> : null),
7!
191
    canShow
192
  }
193
];
194

195
const ValueFileSize = ({ value, ...props }) => <FileSize fileSize={value} {...props} />;
11✔
196

197
export const DeploymentDeviceList = ({ deployment, getDeploymentDevices, idAttribute, selectedDevices, userCapabilities, viewLog }) => {
11✔
198
  const [currentPage, setCurrentPage] = useState(defaultPage);
10✔
199
  const [isLoading, setIsLoading] = useState(false);
10✔
200
  const [perPage, setPerPage] = useState(10);
10✔
201
  const { device_count = 0, totalDeviceCount: totalDevices, statistics = {} } = deployment;
10!
202
  const totalSize = statistics.total_size ?? 0;
10!
203
  const totalDeviceCount = totalDevices ?? device_count;
10✔
204
  const { classes } = useStyles();
10✔
205

206
  useEffect(() => {
10✔
207
    setCurrentPage(defaultPage);
3✔
208
  }, [perPage]);
209

210
  useEffect(() => {
10✔
211
    if (!deployment.id) {
3!
212
      return;
×
213
    }
214
    setIsLoading(true);
3✔
215
    getDeploymentDevices(deployment.id, { page: currentPage, perPage }).then(() => setIsLoading(false));
3✔
216
    // eslint-disable-next-line react-hooks/exhaustive-deps
217
  }, [currentPage, deployment.id, deployment.status, getDeploymentDevices, JSON.stringify(statistics.status), perPage]);
218

219
  const columns = deviceListColumns.reduce((accu, column) => (column.canShow({ deployment }) ? [...accu, { ...column, extras: { idAttribute } }] : accu), []);
110✔
220
  const items = selectedDevices.map(device => ({ device, id: device.id, idAttribute, userCapabilities, viewLog }));
10✔
221
  return (
10✔
222
    <>
223
      <DetailsTable className={classes.table} columns={columns} items={items} />
224
      <div className="flexbox space-between center-aligned margin-top">
225
        <div className="flexbox">
226
          <Pagination
227
            className="margin-top-none"
228
            count={totalDeviceCount}
229
            rowsPerPage={perPage}
230
            onChangePage={setCurrentPage}
231
            onChangeRowsPerPage={setPerPage}
232
            page={currentPage}
233
          />
234
          <Loader show={isLoading} small />
235
        </div>
236
        <TwoColumns chipLikeKey={false} compact items={{ 'Total download size': totalSize }} ValueComponent={ValueFileSize} />
237
      </div>
238
    </>
239
  );
240
};
241

242
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