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

mendersoftware / gui / 919001084

pending completion
919001084

Pull #3839

gitlab-ci

mzedel
revert: "chore: bump node from 20.2.0-alpine to 20.3.1-alpine"

This reverts commit cbfcd7663.

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3839: Combined PRs

4399 of 6397 branches covered (68.77%)

8302 of 10074 relevant lines covered (82.41%)

162.96 hits per line

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

92.73
/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, { useEffect, useRef, useState } 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 {
25
  getAcceptedDevices,
26
  getAvailableIssueOptionsByType,
27
  getDeviceCountsByStatus,
28
  getOnboardingState,
29
  getShowHelptips,
30
  getUserCapabilities
31
} from '../../selectors';
32
import { getOnboardingComponentFor } from '../../utils/onboardingmanager';
33
import useWindowSize from '../../utils/resizehook';
34
import AcceptedDevices from './widgets/accepteddevices';
35
import ActionableDevices from './widgets/actionabledevices';
36
import PendingDevices from './widgets/pendingdevices';
37
import RedirectionWidget from './widgets/redirectionwidget';
38

39
export const Devices = ({ clickHandle }) => {
5✔
40
  const [loading, setLoading] = useState(false);
591✔
41
  // eslint-disable-next-line no-unused-vars
42
  const size = useWindowSize();
591✔
43
  const anchor = useRef();
591✔
44
  const pendingsRef = useRef();
591✔
45
  const navigate = useNavigate();
591✔
46
  const dispatch = useDispatch();
591✔
47
  const { total: acceptedDevicesCount } = useSelector(getAcceptedDevices);
591✔
48
  const availableIssueOptions = useSelector(getAvailableIssueOptionsByType);
591✔
49
  const { canManageDevices } = useSelector(getUserCapabilities);
591✔
50
  const onboardingState = useSelector(getOnboardingState);
591✔
51
  const { pending: pendingDevicesCount } = useSelector(getDeviceCountsByStatus);
591✔
52
  const showHelptips = useSelector(getShowHelptips);
591✔
53

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

60
  useEffect(() => {
591✔
61
    refreshDevices();
9✔
62
  }, [JSON.stringify(availableIssueOptions)]);
63

64
  const refreshDevices = () => {
591✔
65
    if (loading) {
18!
66
      return;
×
67
    }
68
    const issueRequests = Object.keys(availableIssueOptions).map(key => dispatch(getIssueCountsByType(key, { filters: [], selectedIssues: [key] })));
18✔
69
    setLoading(true);
18✔
70
    return Promise.all([dispatch(getDeviceCount(DEVICE_STATES.accepted)), dispatch(getDeviceCount(DEVICE_STATES.pending)), ...issueRequests]).finally(() =>
18✔
71
      setLoading(false)
16✔
72
    );
73
  };
74

75
  const onConnectClick = () => {
591✔
76
    dispatch(setShowConnectingDialog(true));
×
77
    navigate('/devices/accepted');
×
78
  };
79

80
  let onboardingComponent = null;
591✔
81
  if (anchor.current) {
591✔
82
    const element = anchor.current.children[anchor.current.children.length - 1];
580✔
83
    const deviceConnectionAnchor = { left: element.offsetLeft + element.offsetWidth / 2, top: element.offsetTop + element.offsetHeight - 50 };
580✔
84
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.DASHBOARD_ONBOARDING_START, onboardingState, { anchor: deviceConnectionAnchor });
580✔
85
    if (pendingsRef.current) {
580✔
86
      const element = pendingsRef.current.lastChild;
1✔
87
      const pendingsAnchor = {
1✔
88
        left: pendingsRef.current.offsetLeft + element.offsetWidth / 2,
89
        top: pendingsRef.current.offsetTop + element.offsetHeight
90
      };
91
      onboardingComponent = getOnboardingComponentFor(onboardingSteps.DASHBOARD_ONBOARDING_PENDINGS, onboardingState, { anchor: pendingsAnchor });
1✔
92
    }
93
  }
94
  return (
591✔
95
    <>
96
      <div className="dashboard" ref={anchor}>
97
        <AcceptedDevices devicesCount={acceptedDevicesCount} onClick={clickHandle} />
98
        {!!acceptedDevicesCount && <ActionableDevices issues={availableIssueOptions} />}
1,174✔
99
        {!!pendingDevicesCount && !acceptedDevicesCount && (
1,175✔
100
          <PendingDevices
101
            advanceOnboarding={step => dispatch(advanceOnboarding(step))}
1✔
102
            innerRef={pendingsRef}
103
            isActive={pendingDevicesCount > 0}
104
            onboardingState={onboardingState}
105
            onClick={clickHandle}
106
            pendingDevicesCount={pendingDevicesCount}
107
            showHelptips={showHelptips}
108
          />
109
        )}
110
        {canManageDevices && (
684✔
111
          <RedirectionWidget content={acceptedDevicesCount || pendingDevicesCount ? '+ connect more devices' : 'Connect a device'} onClick={onConnectClick} />
191✔
112
        )}
113
      </div>
114
      {onboardingComponent}
115
    </>
116
  );
117
};
118

119
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