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

mendersoftware / gui / 1091795320

01 Dec 2023 04:32AM UTC coverage: 82.784% (-17.2%) from 99.964%
1091795320

Pull #4229

gitlab-ci

web-flow
chore: Bump node from 21.1.0-alpine to 21.2.0-alpine

Bumps node from 21.1.0-alpine to 21.2.0-alpine.

---
updated-dependencies:
- dependency-name: node
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #4229: chore: Bump node from 21.1.0-alpine to 21.2.0-alpine

4316 of 6292 branches covered (0.0%)

8333 of 10066 relevant lines covered (82.78%)

188.98 hits per line

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

96.36
/src/js/components/devices/base-devices.js
1
// Copyright 2020 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 from 'react';
15
import { Link } from 'react-router-dom';
16

17
import pluralize from 'pluralize';
18

19
import preauthImage from '../../../assets/img/preauthorize.png';
20
import { DEVICE_STATES } from '../../constants/deviceConstants';
21
import { rootfsImageVersion } from '../../constants/releaseConstants';
22
import Time, { ApproximateRelativeDate } from '../common/time';
23
import DeviceStatus from './device-status';
24

25
const propertyNameMap = {
183✔
26
  inventory: 'attributes',
27
  identity: 'identity_data',
28
  system: 'system',
29
  monitor: 'monitor',
30
  tags: 'tags'
31
};
32

33
export const defaultTextRender = ({ column, device }) => {
183✔
34
  const propertyName = propertyNameMap[column.attribute.scope] ?? column.attribute.scope;
4!
35
  const accessorTarget = device[propertyName] ?? device;
4!
36
  const attributeValue = accessorTarget[column.attribute.name] || accessorTarget[column.attribute.alternative] || device[column.attribute.name];
4✔
37
  return typeof attributeValue === 'object' ? JSON.stringify(attributeValue) : attributeValue;
4!
38
};
39

40
export const getDeviceIdentityText = ({ device = {}, idAttribute }) => {
183!
41
  const { id = '', identity_data = {}, tags = {} } = device;
61!
42
  // eslint-disable-next-line no-unused-vars
43
  const { status, ...remainingIds } = identity_data;
61✔
44
  const nonIdKey = Object.keys(remainingIds)[0];
61✔
45
  if (!idAttribute || idAttribute === 'id' || idAttribute === 'Device ID') {
61✔
46
    return id;
59✔
47
  } else if (idAttribute === 'name') {
2!
48
    return tags[idAttribute] ?? `${id.substring(0, 6)}...`;
×
49
  }
50
  return identity_data[idAttribute] ?? identity_data[nonIdKey] ?? id;
2!
51
};
52

53
const AttributeRenderer = ({ content, textContent }) => (
183✔
54
  <div title={textContent}>
35✔
55
    <div className="text-overflow">{content}</div>
56
  </div>
57
);
58

59
export const DefaultAttributeRenderer = ({ column, device, idAttribute }) => (
183✔
60
  <AttributeRenderer content={column.textRender({ device, column, idAttribute })} textContent={column.textRender({ device, column, idAttribute })} />
1✔
61
);
62

63
export const getDeviceSoftwareText = (attributes = {}) => attributes[rootfsImageVersion] || attributes.artifact_name || '-';
183!
64
export const DeviceSoftware = ({ device }) => (
183✔
65
  <AttributeRenderer content={getDeviceSoftwareText(device.attributes)} textContent={getDeviceSoftwareText(device.attributes)} />
17✔
66
);
67

68
export const getDeviceTypeText = (attributes = {}) => (attributes.device_type?.length ? attributes.device_type.join(',') : '-');
183!
69
export const DeviceTypes = ({ device }) => (
183✔
70
  <AttributeRenderer content={getDeviceTypeText(device.attributes)} textContent={getDeviceTypeText(device.attributes)} />
17✔
71
);
72

73
export const RelativeDeviceTime = ({ device }) => (
183✔
74
  <div>
17✔
75
    <ApproximateRelativeDate updateTime={device.updated_ts} />
76
  </div>
77
);
78

79
export const DeviceCreationTime = ({ device }) =>
183✔
80
  device.created_ts ? (
1!
81
    <div>
82
      <Time value={device.created_ts} />
83
    </div>
84
  ) : (
85
    '-'
86
  );
87

88
export const DeviceStatusRenderer = ({ device }) => (
183✔
89
  <div>
17✔
90
    <DeviceStatus device={device} />
91
  </div>
92
);
93

94
export const AcceptedEmptyState = ({ allCount }) => (
183✔
95
  <div className="dashboard-placeholder">
4✔
96
    <p>No devices found</p>
97
    {!allCount && (
7✔
98
      <>
99
        <p>No devices have been authorized to connect to the Mender server yet.</p>
100
        <p>
101
          Visit the <Link to="/help/get-started">Help section</Link> to learn how to connect devices to the Mender server.
102
        </p>
103
      </>
104
    )}
105
  </div>
106
);
107

108
export const PreauthorizedEmptyState = ({ canManageDevices, limitMaxed, onClick }) => (
183✔
109
  <div className="dashboard-placeholder">
1✔
110
    <p>There are no preauthorized devices.</p>
111
    {canManageDevices && (
1!
112
      <p>
113
        {limitMaxed ? 'Preauthorize devices' : <a onClick={onClick}>Preauthorize devices</a>} so that when they come online, they will connect to the server
×
114
        immediately
115
      </p>
116
    )}
117
    <img src={preauthImage} alt="preauthorize" />
118
  </div>
119
);
120

121
export const PendingEmptyState = ({ filters }) => (
183✔
122
  <div className="dashboard-placeholder">
1✔
123
    <p>
124
      {filters.length
1!
125
        ? `There are no pending devices matching the selected ${pluralize('filters', filters.length)}`
126
        : 'There are no devices pending authorization'}
127
    </p>
128
    <p>
129
      Visit the <Link to="/help/get-started">Help section</Link> to learn how to connect devices to the Mender server.
130
    </p>
131
  </div>
132
);
133

134
export const RejectedEmptyState = ({ filters }) => (
183✔
135
  <div className="dashboard-placeholder">
1✔
136
    <p>{filters.length ? `There are no rejected devices matching the selected ${pluralize('filters', filters.length)}` : 'There are no rejected devices'}</p>
1!
137
  </div>
138
);
139

140
export const defaultHeaders = {
183✔
141
  currentSoftware: {
142
    title: 'Current software',
143
    attribute: { name: rootfsImageVersion, scope: 'inventory', alternative: 'artifact_name' },
144
    component: DeviceSoftware,
145
    sortable: true,
146
    textRender: getDeviceSoftwareText
147
  },
148
  deviceCreationTime: {
149
    title: 'First request',
150
    attribute: { name: 'created_ts', scope: 'system' },
151
    component: DeviceCreationTime,
152
    sortable: true
153
  },
154
  deviceId: {
155
    title: 'Device ID',
156
    attribute: { name: 'id', scope: 'identity' },
157
    sortable: true,
158
    textRender: ({ device }) => device.id
×
159
  },
160
  deviceStatus: {
161
    title: 'Status',
162
    attribute: { name: 'status', scope: 'identity' },
163
    component: DeviceStatusRenderer,
164
    sortable: true,
165
    textRender: defaultTextRender
166
  },
167
  deviceType: {
168
    title: 'Device type',
169
    attribute: { name: 'device_type', scope: 'inventory' },
170
    component: DeviceTypes,
171
    sortable: true,
172
    textRender: getDeviceTypeText
173
  },
174
  lastCheckIn: {
175
    title: 'Latest activity',
176
    attribute: { name: 'updated_ts', scope: 'system' },
177
    component: RelativeDeviceTime,
178
    sortable: true
179
  }
180
};
181

182
const baseDevicesRoute = '/devices';
183✔
183

184
const acceptedDevicesRoute = {
183✔
185
  key: DEVICE_STATES.accepted,
186
  groupRestricted: false,
187
  route: `${baseDevicesRoute}/${DEVICE_STATES.accepted}`,
188
  title: () => DEVICE_STATES.accepted,
23✔
189
  emptyState: AcceptedEmptyState,
190
  defaultHeaders: [defaultHeaders.deviceType, defaultHeaders.currentSoftware, defaultHeaders.lastCheckIn]
191
};
192

193
export const routes = {
183✔
194
  allDevices: {
195
    ...acceptedDevicesRoute,
196
    route: baseDevicesRoute,
197
    key: 'any',
198
    title: () => 'any'
23✔
199
  },
200
  devices: acceptedDevicesRoute,
201
  [DEVICE_STATES.accepted]: acceptedDevicesRoute,
202
  [DEVICE_STATES.pending]: {
203
    key: DEVICE_STATES.pending,
204
    groupRestricted: true,
205
    route: `${baseDevicesRoute}/${DEVICE_STATES.pending}`,
206
    title: count => `${DEVICE_STATES.pending}${count ? ` (${count})` : ''}`,
23!
207
    emptyState: PendingEmptyState,
208
    defaultHeaders: [defaultHeaders.deviceCreationTime, defaultHeaders.lastCheckIn]
209
  },
210
  [DEVICE_STATES.preauth]: {
211
    key: DEVICE_STATES.preauth,
212
    groupRestricted: true,
213
    route: `${baseDevicesRoute}/${DEVICE_STATES.preauth}`,
214
    title: () => DEVICE_STATES.preauth,
23✔
215
    emptyState: PreauthorizedEmptyState,
216
    defaultHeaders: [
217
      {
218
        ...defaultHeaders.deviceCreationTime,
219
        title: 'Date added'
220
      }
221
    ]
222
  },
223
  [DEVICE_STATES.rejected]: {
224
    key: DEVICE_STATES.rejected,
225
    groupRestricted: true,
226
    route: `${baseDevicesRoute}/${DEVICE_STATES.rejected}`,
227
    title: () => DEVICE_STATES.rejected,
23✔
228
    emptyState: RejectedEmptyState,
229
    defaultHeaders: [defaultHeaders.deviceCreationTime, defaultHeaders.lastCheckIn]
230
  }
231
};
232

233
export const sortingAlternatives = Object.values(routes)
183✔
234
  .reduce((accu, item) => [...accu, ...item.defaultHeaders], [])
1,098✔
235
  .reduce((accu, item) => {
236
    if (item.attribute.alternative) {
2,562✔
237
      accu[item.attribute.name] = item.attribute.alternative;
549✔
238
      accu[item.attribute.alternative] = item.attribute.name;
549✔
239
    }
240
    return accu;
2,562✔
241
  }, {});
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