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

mendersoftware / gui / 947088195

pending completion
947088195

Pull #2661

gitlab-ci

mzedel
chore: improved device filter scrolling behaviour

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #2661: chore: added lint rules for hooks usage

4411 of 6415 branches covered (68.76%)

297 of 440 new or added lines in 62 files covered. (67.5%)

1617 existing lines in 163 files now uncovered.

8311 of 10087 relevant lines covered (82.39%)

192.12 hits per line

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

95.83
/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 {
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
  // eslint-disable-next-line no-unused-vars
41
  const size = useWindowSize();
476✔
42
  const anchor = useRef();
476✔
43
  const pendingsRef = useRef();
476✔
44
  const navigate = useNavigate();
476✔
45
  const dispatch = useDispatch();
476✔
46
  const { total: acceptedDevicesCount } = useSelector(getAcceptedDevices);
476✔
47
  const availableIssueOptions = useSelector(getAvailableIssueOptionsByType);
476✔
48
  const { canManageDevices } = useSelector(getUserCapabilities);
476✔
49
  const onboardingState = useSelector(getOnboardingState);
476✔
50
  const { pending: pendingDevicesCount } = useSelector(getDeviceCountsByStatus);
476✔
51
  const showHelptips = useSelector(getShowHelptips);
476✔
52

53
  const refreshDevices = useCallback(() => {
476✔
54
    const issueRequests = Object.keys(availableIssueOptions).map(key => dispatch(getIssueCountsByType(key, { filters: [], selectedIssues: [key] })));
18✔
55
    return Promise.all([dispatch(getDeviceCount(DEVICE_STATES.accepted)), dispatch(getDeviceCount(DEVICE_STATES.pending)), ...issueRequests]);
18✔
56
    // eslint-disable-next-line react-hooks/exhaustive-deps
57
  }, [JSON.stringify(availableIssueOptions), dispatch]);
58

59
  useEffect(() => {
476✔
60
    // on render the store might not be updated so we resort to the API and let all later request go through the store
61
    // to be in sync with the rest of the UI
62
    refreshDevices();
9✔
63
  }, [refreshDevices]);
64

65
  useEffect(() => {
476✔
66
    refreshDevices();
9✔
67
    // eslint-disable-next-line react-hooks/exhaustive-deps
68
  }, [JSON.stringify(availableIssueOptions), refreshDevices]);
69

70
  const onConnectClick = () => {
476✔
UNCOV
71
    dispatch(setShowConnectingDialog(true));
×
UNCOV
72
    navigate('/devices/accepted');
×
73
  };
74

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

114
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