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

mendersoftware / gui / 1015445845

25 Sep 2023 09:43AM UTC coverage: 82.537% (-17.4%) from 99.964%
1015445845

Pull #4028

gitlab-ci

mzedel
chore: aligned release retrieval with v2 api models

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #4028: MEN-6455

4355 of 6315 branches covered (0.0%)

184 of 206 new or added lines in 19 files covered. (89.32%)

1724 existing lines in 164 files now uncovered.

8323 of 10084 relevant lines covered (82.54%)

208.49 hits per line

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

94.29
/src/js/components/dashboard/devices.js
1
// Copyright 2019 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, { useCallback, useEffect, useRef } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16
import { useNavigate } from 'react-router-dom';
17

18
import { getDeviceCount } from '../../actions/deviceActions';
19
import { getIssueCountsByType } from '../../actions/monitorActions';
20
import { advanceOnboarding } from '../../actions/onboardingActions';
21
import { setShowConnectingDialog } from '../../actions/userActions';
22
import { DEVICE_STATES } from '../../constants/deviceConstants';
23
import { onboardingSteps } from '../../constants/onboardingConstants';
24
import { getAcceptedDevices, getAvailableIssueOptionsByType, getDeviceCountsByStatus, getOnboardingState, getUserCapabilities } from '../../selectors';
25
import { getOnboardingComponentFor } from '../../utils/onboardingmanager';
26
import useWindowSize from '../../utils/resizehook';
27
import AcceptedDevices from './widgets/accepteddevices';
28
import ActionableDevices from './widgets/actionabledevices';
29
import PendingDevices from './widgets/pendingdevices';
30
import RedirectionWidget from './widgets/redirectionwidget';
31

32
export const Devices = ({ clickHandle }) => {
5✔
33
  // eslint-disable-next-line no-unused-vars
34
  const size = useWindowSize();
446✔
35
  const anchor = useRef();
446✔
36
  const pendingsRef = useRef();
446✔
37
  const navigate = useNavigate();
446✔
38
  const dispatch = useDispatch();
446✔
39
  const { total: acceptedDevicesCount } = useSelector(getAcceptedDevices);
446✔
40
  const availableIssueOptions = useSelector(getAvailableIssueOptionsByType);
446✔
41
  const { canManageDevices } = useSelector(getUserCapabilities);
446✔
42
  const onboardingState = useSelector(getOnboardingState);
446✔
43
  const { pending: pendingDevicesCount } = useSelector(getDeviceCountsByStatus);
446✔
44

45
  const refreshDevices = useCallback(() => {
446✔
46
    const issueRequests = Object.keys(availableIssueOptions).map(key => dispatch(getIssueCountsByType(key, { filters: [], selectedIssues: [key] })));
16✔
47
    return Promise.all([dispatch(getDeviceCount(DEVICE_STATES.accepted)), dispatch(getDeviceCount(DEVICE_STATES.pending)), ...issueRequests]);
16✔
48
    // eslint-disable-next-line react-hooks/exhaustive-deps
49
  }, [JSON.stringify(availableIssueOptions), dispatch]);
50

51
  const showDismissHelptipsDialog = useSelector(state => !state.onboarding.complete && state.onboarding.showTipsDialog);
1,573✔
52
  const showDeviceConnectionDialog = useSelector(state => state.users.showConnectDeviceDialog);
1,573✔
53
  const showsDialog = showDismissHelptipsDialog || showDeviceConnectionDialog;
446✔
54

55
  useEffect(() => {
446✔
56
    // on render the store might not be updated so we resort to the API and let all later request go through the store
57
    // to be in sync with the rest of the UI
58
    refreshDevices();
8✔
59
  }, [refreshDevices]);
60

61
  useEffect(() => {
446✔
62
    refreshDevices();
8✔
63
    // eslint-disable-next-line react-hooks/exhaustive-deps
64
  }, [JSON.stringify(availableIssueOptions), refreshDevices]);
65

66
  const onConnectClick = () => {
446✔
UNCOV
67
    dispatch(setShowConnectingDialog(true));
×
UNCOV
68
    navigate('/devices/accepted');
×
69
  };
70

71
  let onboardingComponent = null;
446✔
72
  if (anchor.current && !showsDialog) {
446✔
73
    const element = anchor.current.children[anchor.current.children.length - 1];
437✔
74
    const deviceConnectionAnchor = { left: element.offsetLeft + element.offsetWidth / 2, top: element.offsetTop + element.offsetHeight - 50 };
437✔
75
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.DASHBOARD_ONBOARDING_START, onboardingState, { anchor: deviceConnectionAnchor });
437✔
76
    if (pendingsRef.current) {
437✔
77
      const element = pendingsRef.current.lastChild;
1✔
78
      const pendingsAnchor = {
1✔
79
        left: pendingsRef.current.offsetLeft + element.offsetWidth / 2,
80
        top: pendingsRef.current.offsetTop + element.offsetHeight
81
      };
82
      onboardingComponent = getOnboardingComponentFor(onboardingSteps.DASHBOARD_ONBOARDING_PENDINGS, onboardingState, { anchor: pendingsAnchor });
1✔
83
    }
84
  }
85
  return (
446✔
86
    <>
87
      <div className="dashboard" ref={anchor}>
88
        <AcceptedDevices devicesCount={acceptedDevicesCount} onClick={clickHandle} />
89
        {!!acceptedDevicesCount && <ActionableDevices issues={availableIssueOptions} onClick={clickHandle} />}
884✔
90
        {!!pendingDevicesCount && !acceptedDevicesCount && (
885✔
91
          <PendingDevices
92
            advanceOnboarding={step => dispatch(advanceOnboarding(step))}
1✔
93
            innerRef={pendingsRef}
94
            isActive={pendingDevicesCount > 0}
95
            onboardingState={onboardingState}
96
            onClick={clickHandle}
97
            pendingDevicesCount={pendingDevicesCount}
98
          />
99
        )}
100
        {canManageDevices && (
697✔
101
          <RedirectionWidget content={acceptedDevicesCount || pendingDevicesCount ? '+ connect more devices' : 'Connect a device'} onClick={onConnectClick} />
507✔
102
        )}
103
      </div>
104
      {onboardingComponent}
105
    </>
106
  );
107
};
108

109
export default Devices;
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