• 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

91.38
/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 { currentArtifact, 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;
57!
42
  // eslint-disable-next-line no-unused-vars
43
  const { status, ...remainingIds } = identity_data;
57✔
44
  const nonIdKey = Object.keys(remainingIds)[0];
57✔
45
  if (!idAttribute || idAttribute === 'id' || idAttribute === 'Device ID') {
57✔
46
    return id;
55✔
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] || '-';
183!
64
export const DeviceSoftware = ({ device }) => (
183✔
65
  <AttributeRenderer content={getDeviceSoftwareText(device.attributes)} textContent={getDeviceSoftwareText(device.attributes)} />
17✔
66
);
67

68
export const getDeviceArtifactText = (attributes = {}) => attributes.artifact_name || '-';
183!
69
export const DeviceArtifact = ({ device }) => (
183✔
70
  <AttributeRenderer content={getDeviceArtifactText(device.attributes)} textContent={getDeviceArtifactText(device.attributes)} />
×
71
);
72

73
export const getDeviceTypeText = (attributes = {}) => (attributes.device_type?.length ? attributes.device_type.join(',') : '-');
183!
74
export const DeviceTypes = ({ device }) => (
183✔
75
  <AttributeRenderer content={getDeviceTypeText(device.attributes)} textContent={getDeviceTypeText(device.attributes)} />
17✔
76
);
77

78
export const RelativeDeviceTime = ({ device }) => (
183✔
79
  <div>
17✔
80
    <ApproximateRelativeDate updateTime={device.updated_ts} />
81
  </div>
82
);
83

84
export const DeviceCreationTime = ({ device }) =>
183✔
85
  device.created_ts ? (
1!
86
    <div>
87
      <Time value={device.created_ts} />
88
    </div>
89
  ) : (
90
    '-'
91
  );
92

93
export const DeviceStatusRenderer = ({ device }) => (
183✔
94
  <div>
17✔
95
    <DeviceStatus device={device} />
96
  </div>
97
);
98

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

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

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

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

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

194
const baseDevicesRoute = '/devices';
183✔
195

196
const acceptedDevicesRoute = {
183✔
197
  key: DEVICE_STATES.accepted,
198
  groupRestricted: false,
199
  route: `${baseDevicesRoute}/${DEVICE_STATES.accepted}`,
200
  title: () => DEVICE_STATES.accepted,
23✔
201
  emptyState: AcceptedEmptyState,
202
  defaultHeaders: [defaultHeaders.deviceType, defaultHeaders.currentSoftware, defaultHeaders.lastCheckIn]
203
};
204

205
export const routes = {
183✔
206
  allDevices: {
207
    ...acceptedDevicesRoute,
208
    route: baseDevicesRoute,
209
    key: 'any',
210
    title: () => 'any'
23✔
211
  },
212
  devices: acceptedDevicesRoute,
213
  [DEVICE_STATES.accepted]: acceptedDevicesRoute,
214
  [DEVICE_STATES.pending]: {
215
    key: DEVICE_STATES.pending,
216
    groupRestricted: true,
217
    route: `${baseDevicesRoute}/${DEVICE_STATES.pending}`,
218
    title: count => `${DEVICE_STATES.pending}${count ? ` (${count})` : ''}`,
23!
219
    emptyState: PendingEmptyState,
220
    defaultHeaders: [defaultHeaders.deviceCreationTime, defaultHeaders.lastCheckIn]
221
  },
222
  [DEVICE_STATES.preauth]: {
223
    key: DEVICE_STATES.preauth,
224
    groupRestricted: true,
225
    route: `${baseDevicesRoute}/${DEVICE_STATES.preauth}`,
226
    title: () => DEVICE_STATES.preauth,
23✔
227
    emptyState: PreauthorizedEmptyState,
228
    defaultHeaders: [
229
      {
230
        ...defaultHeaders.deviceCreationTime,
231
        title: 'Date added'
232
      }
233
    ]
234
  },
235
  [DEVICE_STATES.rejected]: {
236
    key: DEVICE_STATES.rejected,
237
    groupRestricted: true,
238
    route: `${baseDevicesRoute}/${DEVICE_STATES.rejected}`,
239
    title: () => DEVICE_STATES.rejected,
23✔
240
    emptyState: RejectedEmptyState,
241
    defaultHeaders: [defaultHeaders.deviceCreationTime, defaultHeaders.lastCheckIn]
242
  }
243
};
244

245
export const sortingAlternatives = Object.values(routes)
183✔
246
  .reduce((accu, item) => [...accu, ...item.defaultHeaders], [])
1,098✔
247
  .reduce((accu, item) => {
248
    if (item.attribute.alternative) {
2,562!
249
      accu[item.attribute.name] = item.attribute.alternative;
×
250
      accu[item.attribute.alternative] = item.attribute.name;
×
251
    }
252
    return accu;
2,562✔
253
  }, {});
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