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

mendersoftware / gui / 1213056175

14 Mar 2024 09:12AM UTC coverage: 83.598% (-16.4%) from 99.964%
1213056175

Pull #4355

gitlab-ci

mineralsfree
fix: Change minimal increment to 1 day, previous units updated automatically

Ticket: MEN-6831
Changelog: None

Signed-off-by: Mikita Pilinka <mikita.pilinka@northern.tech>
Pull Request #4355: MEN-6831: Change minimal increment to 1 day, previous units updated automatically

4439 of 6330 branches covered (70.13%)

3 of 5 new or added lines in 2 files covered. (60.0%)

1633 existing lines in 162 files now uncovered.

8410 of 10060 relevant lines covered (83.6%)

140.64 hits per line

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

97.22
/src/js/selectors/index.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 { createSelector } from '@reduxjs/toolkit';
15

16
import { defaultReports } from '../actions/deviceActions';
17
import { mapUserRolesToUiPermissions } from '../actions/userActions';
18
import { PLANS } from '../constants/appConstants';
19
import { DEPLOYMENT_STATES } from '../constants/deploymentConstants';
20
import {
21
  ALL_DEVICES,
22
  ATTRIBUTE_SCOPES,
23
  DEVICE_ISSUE_OPTIONS,
24
  DEVICE_LIST_MAXIMUM_LENGTH,
25
  DEVICE_ONLINE_CUTOFF,
26
  DEVICE_STATES,
27
  EXTERNAL_PROVIDER,
28
  UNGROUPED_GROUP
29
} from '../constants/deviceConstants';
30
import { READ_STATES, rolesByName, twoFAStates, uiPermissionsById } from '../constants/userConstants';
31
import { attributeDuplicateFilter, duplicateFilter, getDemoDeviceAddress as getDemoDeviceAddressHelper, versionCompare } from '../helpers';
32
import { onboardingSteps } from '../utils/onboardingmanager';
33

34
const getAppDocsVersion = state => state.app.docsVersion;
1,839✔
35
export const getFeatures = state => state.app.features;
19,481✔
36
export const getTooltipsById = state => state.users.tooltips.byId;
3,538✔
37
export const getRolesById = state => state.users.rolesById;
2,225✔
38
export const getOrganization = state => state.organization.organization;
8,150✔
39
export const getAcceptedDevices = state => state.devices.byStatus.accepted;
5,417✔
40
export const getCurrentSession = state => state.users.currentSession;
3,339✔
41
const getDevicesByStatus = state => state.devices.byStatus;
1,838✔
42
export const getDevicesById = state => state.devices.byId;
10,481✔
43
export const getDeviceReports = state => state.devices.reports;
1,671✔
44
export const getGroupsById = state => state.devices.groups.byId;
2,234✔
45
const getSelectedGroup = state => state.devices.groups.selectedGroup;
183✔
46
const getSearchedDevices = state => state.app.searchState.deviceIds;
1,559✔
47
const getListedDevices = state => state.devices.deviceList.deviceIds;
183✔
48
const getFilteringAttributes = state => state.devices.filteringAttributes;
1,714✔
49
export const getDeviceFilters = state => state.devices.filters || [];
226!
50
const getFilteringAttributesFromConfig = state => state.devices.filteringAttributesConfig.attributes;
1,648✔
51
export const getSortedFilteringAttributes = createSelector([getFilteringAttributes], filteringAttributes => ({
183✔
52
  ...filteringAttributes,
53
  identityAttributes: [...filteringAttributes.identityAttributes, 'id']
54
}));
55
export const getDeviceLimit = state => state.devices.limit;
1,699✔
56
const getDevicesList = state => Object.values(state.devices.byId);
183✔
57
const getOnboarding = state => state.onboarding;
2,061✔
58
export const getGlobalSettings = state => state.users.globalSettings;
4,255✔
59
const getIssueCountsByType = state => state.monitor.issueCounts.byType;
1,673✔
60
const getSelectedReleaseId = state => state.releases.selectedRelease;
183✔
61
export const getReleasesById = state => state.releases.byId;
1,064✔
62
export const getReleaseTags = state => state.releases.tags;
287✔
63
export const getReleaseListState = state => state.releases.releasesList;
531✔
64
const getListedReleases = state => state.releases.releasesList.releaseIds;
183✔
65
export const getUpdateTypes = state => state.releases.updateTypes;
183✔
66
export const getExternalIntegrations = state => state.organization.externalDeviceIntegrations;
183✔
67
const getDeploymentsById = state => state.deployments.byId;
2,195✔
68
export const getDeploymentsByStatus = state => state.deployments.byStatus;
2,051✔
69
const getSelectedDeploymentDeviceIds = state => state.deployments.selectedDeviceIds;
183✔
70
export const getDeploymentsSelectionState = state => state.deployments.selectionState;
983✔
71
export const getFullVersionInformation = state => state.app.versionInformation;
1,616✔
72
const getCurrentUserId = state => state.users.currentUser;
3,874✔
73
const getUsersById = state => state.users.byId;
2,226✔
74
export const getCurrentUser = createSelector([getUsersById, getCurrentUserId], (usersById, userId) => usersById[userId] ?? {});
183✔
75
export const getUserSettings = state => state.users.userSettings;
10,711✔
76
export const getSsoConfig = ({ organization: { ssoConfigs = [] } }) => ssoConfigs[0];
183!
77

78
export const getVersionInformation = createSelector([getFullVersionInformation, getFeatures], ({ Integration, ...remainder }, { isHosted }) =>
183✔
79
  isHosted && Integration !== 'next' ? remainder : { ...remainder, Integration }
14!
80
);
81
export const getIsPreview = createSelector([getFullVersionInformation], ({ Integration }) => versionCompare(Integration, 'next') > -1);
183✔
82

83
export const getShowHelptips = createSelector([getTooltipsById], tooltips =>
183✔
84
  Object.values(tooltips).reduce((accu, { readState }) => accu || readState === READ_STATES.unread, false)
3!
85
);
86

87
export const getMappedDeploymentSelection = createSelector(
183✔
88
  [getDeploymentsSelectionState, (_, deploymentsState) => deploymentsState, getDeploymentsById],
499✔
89
  (selectionState, deploymentsState, deploymentsById) => {
90
    const { selection = [] } = selectionState[deploymentsState] ?? {};
271!
91
    return selection.reduce((accu, id) => {
271✔
92
      if (deploymentsById[id]) {
423!
93
        accu.push(deploymentsById[id]);
423✔
94
      }
95
      return accu;
423✔
96
    }, []);
97
  }
98
);
99

100
export const getDeploymentRelease = createSelector(
183✔
101
  [getDeploymentsById, getDeploymentsSelectionState, getReleasesById],
102
  (deploymentsById, { selectedId }, releasesById) => {
103
    const deployment = deploymentsById[selectedId] || {};
3✔
104
    return deployment.artifact_name && releasesById[deployment.artifact_name] ? releasesById[deployment.artifact_name] : { device_types_compatible: [] };
3✔
105
  }
106
);
107

108
export const getSelectedDeploymentData = createSelector(
183✔
109
  [getDeploymentsById, getDeploymentsSelectionState, getDevicesById, getSelectedDeploymentDeviceIds],
110
  (deploymentsById, { selectedId }, devicesById, selectedDeviceIds) => {
111
    const deployment = deploymentsById[selectedId] ?? {};
3✔
112
    const { devices = {} } = deployment;
3✔
113
    return {
3✔
114
      deployment,
115
      selectedDevices: selectedDeviceIds.map(deviceId => ({ ...devicesById[deviceId], ...devices[deviceId] }))
1✔
116
    };
117
  }
118
);
119

120
export const getHas2FA = createSelector(
183✔
121
  [getCurrentUser],
122
  currentUser => currentUser.hasOwnProperty('tfa_status') && currentUser.tfa_status === twoFAStates.enabled
5✔
123
);
124

125
export const getDemoDeviceAddress = createSelector([getDevicesList, getOnboarding], (devices, { approach, demoArtifactPort }) => {
183✔
126
  const demoDeviceAddress = `http://${getDemoDeviceAddressHelper(devices, approach)}`;
11✔
127
  return demoArtifactPort ? `${demoDeviceAddress}:${demoArtifactPort}` : demoDeviceAddress;
11!
128
});
129

130
export const getDeviceReportsForUser = createSelector(
183✔
131
  [getUserSettings, getCurrentUserId, getGlobalSettings, getDevicesById],
132
  ({ reports }, currentUserId, globalSettings, devicesById) => {
133
    return reports || globalSettings[`${currentUserId}-reports`] || (Object.keys(devicesById).length ? defaultReports : []);
45✔
134
  }
135
);
136

137
const listItemMapper = (byId, ids, { defaultObject = {}, cutOffSize = DEVICE_LIST_MAXIMUM_LENGTH }) => {
183✔
138
  return ids.slice(0, cutOffSize).reduce((accu, id) => {
1,664✔
139
    if (id && byId[id]) {
981!
140
      accu.push({ ...defaultObject, ...byId[id] });
981✔
141
    }
142
    return accu;
981✔
143
  }, []);
144
};
145

146
const listTypeDeviceIdMap = {
183✔
147
  deviceList: getListedDevices,
148
  search: getSearchedDevices
149
};
150
const getDeviceMappingDefaults = () => ({ defaultObject: { auth_sets: [] }, cutOffSize: DEVICE_LIST_MAXIMUM_LENGTH });
1,606✔
151
export const getMappedDevicesList = createSelector(
183✔
152
  [getDevicesById, (state, listType) => listTypeDeviceIdMap[listType](state), getDeviceMappingDefaults],
1,606✔
153
  listItemMapper
154
);
155

156
export const getDeviceCountsByStatus = createSelector([getDevicesByStatus], byStatus =>
183✔
157
  Object.values(DEVICE_STATES).reduce((accu, state) => {
604✔
158
    accu[state] = byStatus[state].total || 0;
2,416✔
159
    return accu;
2,416✔
160
  }, {})
161
);
162

163
export const getDeviceById = createSelector([getDevicesById, (_, deviceId) => deviceId], (devicesById, deviceId = '') => devicesById[deviceId] ?? {});
2,081✔
164

165
export const getDeviceConfigDeployment = createSelector([getDeviceById, getDeploymentsById], (device, deploymentsById) => {
183✔
166
  const { config = {} } = device;
13✔
167
  const { deployment_id: configDeploymentId } = config;
13✔
168
  const deviceConfigDeployment = deploymentsById[configDeploymentId] || {};
13✔
169
  return { device, deviceConfigDeployment };
13✔
170
});
171

172
export const getSelectedGroupInfo = createSelector(
183✔
173
  [getAcceptedDevices, getGroupsById, getSelectedGroup],
174
  ({ total: acceptedDeviceTotal }, groupsById, selectedGroup) => {
175
    let groupCount = acceptedDeviceTotal;
10✔
176
    let groupFilters = [];
10✔
177
    if (selectedGroup && groupsById[selectedGroup]) {
10✔
178
      groupCount = groupsById[selectedGroup].total;
4✔
179
      groupFilters = groupsById[selectedGroup].filters || [];
4!
180
    }
181
    return { groupCount, selectedGroup, groupFilters };
10✔
182
  }
183
);
184

185
const defaultIdAttribute = Object.freeze({ attribute: 'id', scope: ATTRIBUTE_SCOPES.identity });
183✔
186
export const getIdAttribute = createSelector([getGlobalSettings], ({ id_attribute = { ...defaultIdAttribute } }) => id_attribute);
183✔
187

188
export const getLimitMaxed = createSelector([getAcceptedDevices, getDeviceLimit], ({ total: acceptedDevices = 0 }, deviceLimit) =>
183!
189
  Boolean(deviceLimit && deviceLimit <= acceptedDevices)
10✔
190
);
191

192
export const getFilterAttributes = createSelector(
183✔
193
  [getGlobalSettings, getFilteringAttributes],
194
  ({ previousFilters }, { identityAttributes, inventoryAttributes, systemAttributes, tagAttributes }) => {
195
    const deviceNameAttribute = { key: 'name', value: 'Name', scope: ATTRIBUTE_SCOPES.tags, category: ATTRIBUTE_SCOPES.tags, priority: 1 };
3✔
196
    const deviceIdAttribute = { key: 'id', value: 'Device ID', scope: ATTRIBUTE_SCOPES.identity, category: ATTRIBUTE_SCOPES.identity, priority: 1 };
3✔
197
    const checkInAttribute = { key: 'check_in_time', value: 'Latest activity', scope: ATTRIBUTE_SCOPES.system, category: ATTRIBUTE_SCOPES.system, priority: 4 };
3✔
198
    const updateAttribute = { ...checkInAttribute, key: 'updated_ts', value: 'Last inventory update' };
3✔
199
    const firstRequestAttribute = { key: 'created_ts', value: 'First request', scope: ATTRIBUTE_SCOPES.system, category: ATTRIBUTE_SCOPES.system, priority: 4 };
3✔
200
    const attributes = [
3✔
UNCOV
201
      ...previousFilters.map(item => ({
×
202
        ...item,
203
        value: deviceIdAttribute.key === item.key ? deviceIdAttribute.value : item.key,
×
204
        category: 'recently used',
205
        priority: 0
206
      })),
207
      deviceNameAttribute,
208
      deviceIdAttribute,
209
      ...identityAttributes.map(item => ({ key: item, value: item, scope: ATTRIBUTE_SCOPES.identity, category: ATTRIBUTE_SCOPES.identity, priority: 1 })),
3✔
210
      ...inventoryAttributes.map(item => ({ key: item, value: item, scope: ATTRIBUTE_SCOPES.inventory, category: ATTRIBUTE_SCOPES.inventory, priority: 2 })),
3✔
UNCOV
211
      ...tagAttributes.map(item => ({ key: item, value: item, scope: ATTRIBUTE_SCOPES.tags, category: ATTRIBUTE_SCOPES.tags, priority: 3 })),
×
212
      checkInAttribute,
213
      updateAttribute,
214
      firstRequestAttribute,
UNCOV
215
      ...systemAttributes.map(item => ({ key: item, value: item, scope: ATTRIBUTE_SCOPES.system, category: ATTRIBUTE_SCOPES.system, priority: 4 }))
×
216
    ];
217
    return attributeDuplicateFilter(attributes, 'key');
3✔
218
  }
219
);
220

221
const getFilteringAttributesLimit = state => state.devices.filteringAttributesLimit;
183✔
222

223
export const getDeviceIdentityAttributes = createSelector(
183✔
224
  [getFilteringAttributes, getFilteringAttributesLimit],
225
  ({ identityAttributes }, filteringAttributesLimit) => {
226
    // limit the selection of the available attribute to AVAILABLE_ATTRIBUTE_LIMIT
227
    const attributes = identityAttributes.slice(0, filteringAttributesLimit);
2✔
228
    return attributes.reduce(
2✔
229
      (accu, value) => {
230
        accu.push({ value, label: value, scope: 'identity' });
3✔
231
        return accu;
3✔
232
      },
233
      [
234
        { value: 'name', label: 'Name', scope: 'tags' },
235
        { value: 'id', label: 'Device ID', scope: 'identity' }
236
      ]
237
    );
238
  }
239
);
240

241
// eslint-disable-next-line no-unused-vars
242
export const getGroupsByIdWithoutUngrouped = createSelector([getGroupsById], ({ [UNGROUPED_GROUP.id]: ungrouped, ...groups }) => groups);
183✔
243

244
export const getGroups = createSelector([getGroupsById], groupsById => {
183✔
245
  const groupNames = Object.keys(groupsById).sort();
14✔
246
  const groupedGroups = Object.entries(groupsById)
14✔
247
    .sort((a, b) => a[0].localeCompare(b[0]))
43✔
248
    .reduce(
249
      (accu, [groupname, group]) => {
250
        const name = groupname === UNGROUPED_GROUP.id ? UNGROUPED_GROUP.name : groupname;
37✔
251
        const groupItem = { ...group, groupId: name, name: groupname };
37✔
252
        if (group.filters.length > 0) {
37✔
253
          if (groupname !== UNGROUPED_GROUP.id) {
24✔
254
            accu.dynamic.push(groupItem);
13✔
255
          } else {
256
            accu.ungrouped.push(groupItem);
11✔
257
          }
258
        } else {
259
          accu.static.push(groupItem);
13✔
260
        }
261
        return accu;
37✔
262
      },
263
      { dynamic: [], static: [], ungrouped: [] }
264
    );
265
  return { groupNames, ...groupedGroups };
14✔
266
});
267

268
export const getDeviceTwinIntegrations = createSelector([getExternalIntegrations], integrations =>
183✔
269
  integrations.filter(integration => integration.id && EXTERNAL_PROVIDER[integration.provider]?.deviceTwin)
4✔
270
);
271

272
export const getOfflineThresholdSettings = createSelector([getGlobalSettings], ({ offlineThreshold }) => ({
183✔
273
  interval: offlineThreshold?.interval || DEVICE_ONLINE_CUTOFF.interval,
26✔
274
  intervalUnit: offlineThreshold?.intervalUnit || DEVICE_ONLINE_CUTOFF.intervalName
26✔
275
}));
276

277
export const getOnboardingState = createSelector([getOnboarding, getUserSettings], ({ complete, progress, showTips, ...remainder }, { onboarding = {} }) => ({
183!
278
  ...remainder,
279
  ...onboarding,
280
  complete: onboarding.complete || complete,
187✔
281
  progress:
282
    Object.keys(onboardingSteps).findIndex(step => step === progress) > Object.keys(onboardingSteps).findIndex(step => step === onboarding.progress)
1,502✔
283
      ? progress
284
      : onboarding.progress,
285
  showTips: !onboarding.showTips ? onboarding.showTips : showTips
94✔
286
}));
287

288
export const getTooltipsState = createSelector([getTooltipsById, getUserSettings], (byId, { tooltips = {} }) =>
183✔
289
  Object.entries(byId).reduce(
61✔
290
    (accu, [id, value]) => {
UNCOV
291
      accu[id] = { ...accu[id], ...value };
×
UNCOV
292
      return accu;
×
293
    },
294
    { ...tooltips }
295
  )
296
);
297

298
export const getDocsVersion = createSelector([getAppDocsVersion, getFeatures], (appDocsVersion, { isHosted }) => {
183✔
299
  // if hosted, use latest docs version
300
  const docsVersion = appDocsVersion ? `${appDocsVersion}/` : 'development/';
41!
301
  return isHosted ? '' : docsVersion;
41✔
302
});
303

304
export const getIsEnterprise = createSelector(
183✔
305
  [getOrganization, getFeatures],
306
  ({ plan = PLANS.os.id }, { isEnterprise, isHosted }) => isEnterprise || (isHosted && plan === PLANS.enterprise.id)
77✔
307
);
308

309
export const getAttributesList = createSelector(
183✔
310
  [getFilteringAttributes, getFilteringAttributesFromConfig],
311
  ({ identityAttributes = [], inventoryAttributes = [] }, { identity = [], inventory = [] }) =>
28!
312
    [...identityAttributes, ...inventoryAttributes, ...identity, ...inventory].filter(duplicateFilter)
14✔
313
);
314

315
export const getRolesList = createSelector([getRolesById], rolesById => Object.entries(rolesById).map(([id, role]) => ({ id, ...role })));
183✔
316

317
export const getUserRoles = createSelector(
183✔
318
  [getCurrentUser, getRolesById, getIsEnterprise, getFeatures, getOrganization],
319
  (currentUser, rolesById, isEnterprise, { isHosted, hasMultitenancy }, { plan = PLANS.os.id }) => {
8✔
320
    const isAdmin = currentUser.roles?.length
71✔
321
      ? currentUser.roles.some(role => role === rolesByName.admin)
67✔
322
      : !(hasMultitenancy || isEnterprise || (isHosted && plan !== PLANS.os.id));
8!
323
    const uiPermissions = isAdmin
71✔
324
      ? mapUserRolesToUiPermissions([rolesByName.admin], rolesById)
325
      : mapUserRolesToUiPermissions(currentUser.roles || [], rolesById);
4✔
326
    return { isAdmin, uiPermissions };
71✔
327
  }
328
);
329

330
const hasPermission = (thing, permission) => Object.values(thing).some(permissions => permissions.includes(permission));
341✔
331

332
export const getUserCapabilities = createSelector([getUserRoles], ({ uiPermissions }) => {
183✔
333
  const canManageReleases = hasPermission(uiPermissions.releases, uiPermissionsById.manage.value);
67✔
334
  const canReadReleases = canManageReleases || hasPermission(uiPermissions.releases, uiPermissionsById.read.value);
67✔
335
  const canUploadReleases = canManageReleases || hasPermission(uiPermissions.releases, uiPermissionsById.upload.value);
67✔
336

337
  const canAuditlog = uiPermissions.auditlog.includes(uiPermissionsById.read.value);
67✔
338

339
  const canReadUsers = uiPermissions.userManagement.includes(uiPermissionsById.read.value);
67✔
340
  const canManageUsers = uiPermissions.userManagement.includes(uiPermissionsById.manage.value);
67✔
341

342
  const canReadDevices = hasPermission(uiPermissions.groups, uiPermissionsById.read.value);
67✔
343
  const canWriteDevices = Object.values(uiPermissions.groups).some(
67✔
344
    groupPermissions => groupPermissions.includes(uiPermissionsById.read.value) && groupPermissions.length > 1
65✔
345
  );
346
  const canTroubleshoot = hasPermission(uiPermissions.groups, uiPermissionsById.connect.value);
67✔
347
  const canManageDevices = hasPermission(uiPermissions.groups, uiPermissionsById.manage.value);
67✔
348
  const canConfigure = hasPermission(uiPermissions.groups, uiPermissionsById.configure.value);
67✔
349

350
  const canDeploy = uiPermissions.deployments.includes(uiPermissionsById.deploy.value) || hasPermission(uiPermissions.groups, uiPermissionsById.deploy.value);
67✔
351
  const canReadDeployments = uiPermissions.deployments.includes(uiPermissionsById.read.value);
67✔
352

353
  return {
67✔
354
    canAuditlog,
355
    canConfigure,
356
    canDeploy,
357
    canManageDevices,
358
    canManageReleases,
359
    canManageUsers,
360
    canReadDeployments,
361
    canReadDevices,
362
    canReadReleases,
363
    canReadUsers,
364
    canTroubleshoot,
365
    canUploadReleases,
366
    canWriteDevices,
367
    groupsPermissions: uiPermissions.groups,
368
    releasesPermissions: uiPermissions.releases
369
  };
370
});
371

372
export const getTenantCapabilities = createSelector(
183✔
373
  [getFeatures, getOrganization, getIsEnterprise],
374
  (
375
    { hasAuditlogs: isAuditlogEnabled, hasDeviceConfig: isDeviceConfigEnabled, hasDeviceConnect: isDeviceConnectEnabled, hasMonitor: isMonitorEnabled },
376
    { addons = [], plan = PLANS.os.id },
10✔
377
    isEnterprise
378
  ) => {
379
    const canDelta = isEnterprise || plan === PLANS.professional.id;
48✔
380
    const hasAuditlogs = isAuditlogEnabled && isEnterprise;
48✔
381
    const hasDeviceConfig = isDeviceConfigEnabled && (!isEnterprise || addons.some(addon => addon.name === 'configure' && Boolean(addon.enabled)));
48✔
382
    const hasDeviceConnect = isDeviceConnectEnabled && (!isEnterprise || addons.some(addon => addon.name === 'troubleshoot' && Boolean(addon.enabled)));
48✔
383
    const hasMonitor = isMonitorEnabled && addons.some(addon => addon.name === 'monitor' && Boolean(addon.enabled));
48✔
384
    return {
48✔
385
      canDelta,
386
      canRetry: canDelta,
387
      canSchedule: canDelta,
388
      hasAuditlogs,
389
      hasDeviceConfig,
390
      hasDeviceConnect,
391
      hasFullFiltering: canDelta,
392
      hasMonitor,
393
      isEnterprise,
394
      plan
395
    };
396
  }
397
);
398

399
export const getAvailableIssueOptionsByType = createSelector(
183✔
400
  [getFeatures, getTenantCapabilities, getIssueCountsByType],
401
  ({ hasReporting }, { hasFullFiltering, hasMonitor }, issueCounts) =>
402
    Object.values(DEVICE_ISSUE_OPTIONS).reduce((accu, { isCategory, key, needsFullFiltering, needsMonitor, needsReporting, title }) => {
15✔
403
      if (isCategory || (needsReporting && !hasReporting) || (needsFullFiltering && !hasFullFiltering) || (needsMonitor && !hasMonitor)) {
90✔
404
        return accu;
84✔
405
      }
406
      accu[key] = { count: issueCounts[key].filtered, key, title };
6✔
407
      return accu;
6✔
408
    }, {})
409
);
410

411
export const getDeviceTypes = createSelector([getAcceptedDevices, getDevicesById], ({ deviceIds = [] }, devicesById) =>
183!
412
  Object.keys(
1✔
413
    deviceIds.slice(0, 200).reduce((accu, item) => {
414
      const { device_type: deviceTypes = [] } = devicesById[item] ? devicesById[item].attributes : {};
2!
415
      accu = deviceTypes.reduce((deviceTypeAccu, deviceType) => {
2✔
416
        if (deviceType.length > 1) {
2!
417
          deviceTypeAccu[deviceType] = deviceTypeAccu[deviceType] ? deviceTypeAccu[deviceType] + 1 : 1;
2!
418
        }
419
        return deviceTypeAccu;
2✔
420
      }, accu);
421
      return accu;
2✔
422
    }, {})
423
  )
424
);
425

426
export const getGroupNames = createSelector([getGroupsById, getUserRoles, (_, options = {}) => options], (groupsById, { uiPermissions }, { staticOnly }) => {
197✔
427
  // eslint-disable-next-line no-unused-vars
428
  const { [UNGROUPED_GROUP.id]: ungrouped, ...groups } = groupsById;
193✔
429
  if (staticOnly) {
193!
UNCOV
430
    return Object.keys(uiPermissions.groups).sort();
×
431
  }
432
  return Object.keys(
193✔
433
    Object.entries(groups).reduce((accu, [groupName, group]) => {
434
      if (group.filter || uiPermissions.groups[ALL_DEVICES]) {
386!
435
        accu[groupName] = group;
386✔
436
      }
437
      return accu;
386✔
438
    }, uiPermissions.groups)
439
  ).sort();
440
});
441

442
const getReleaseMappingDefaults = () => ({});
183✔
443
export const getReleasesList = createSelector([getReleasesById, getListedReleases, getReleaseMappingDefaults], listItemMapper);
183✔
444

445
export const getReleaseTagsById = createSelector([getReleaseTags], releaseTags => releaseTags.reduce((accu, key) => ({ ...accu, [key]: key }), {}));
183✔
446
export const getHasReleases = createSelector(
183✔
447
  [getReleaseListState, getReleasesById],
448
  ({ searchTotal, total }, byId) => !!(Object.keys(byId).length || total || searchTotal)
53!
449
);
450

451
export const getSelectedRelease = createSelector([getReleasesById, getSelectedReleaseId], (byId, id) => byId[id] ?? {});
183✔
452

453
const relevantDeploymentStates = [DEPLOYMENT_STATES.pending, DEPLOYMENT_STATES.inprogress, DEPLOYMENT_STATES.finished];
183✔
454
export const DEPLOYMENT_CUTOFF = 3;
183✔
455
export const getRecentDeployments = createSelector([getDeploymentsById, getDeploymentsByStatus], (deploymentsById, deploymentsByStatus) =>
183✔
456
  Object.entries(deploymentsByStatus).reduce(
603✔
457
    (accu, [state, byStatus]) => {
458
      if (!relevantDeploymentStates.includes(state) || !byStatus.deploymentIds.length) {
2,412✔
459
        return accu;
615✔
460
      }
461
      accu[state] = byStatus.deploymentIds
1,797✔
462
        .reduce((accu, id) => {
463
          if (deploymentsById[id]) {
3,537✔
464
            accu.push(deploymentsById[id]);
3,534✔
465
          }
466
          return accu;
3,537✔
467
        }, [])
468
        .slice(0, DEPLOYMENT_CUTOFF);
469
      accu.total += byStatus.total;
1,797✔
470
      return accu;
1,797✔
471
    },
472
    { total: 0 }
473
  )
474
);
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