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

mendersoftware / gui / 963002358

pending completion
963002358

Pull #3870

gitlab-ci

mzedel
chore: cleaned up left over onboarding tooltips & aligned with updated design

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

4348 of 6319 branches covered (68.81%)

95 of 122 new or added lines in 24 files covered. (77.87%)

1734 existing lines in 160 files now uncovered.

8174 of 9951 relevant lines covered (82.14%)

178.12 hits per line

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

62.5
/src/js/components/devices/device-details/authsets/authsets.js
1
// Copyright 2021 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, { useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
// material ui
18
import { Button } from '@mui/material';
19
import { makeStyles } from 'tss-react/mui';
20

21
import pluralize from 'pluralize';
22

23
import { deleteAuthset, updateDeviceAuth } from '../../../../actions/deviceActions';
24
import { advanceOnboarding } from '../../../../actions/onboardingActions';
25
import { DEVICE_DISMISSAL_STATE, DEVICE_STATES } from '../../../../constants/deviceConstants';
26
import { onboardingSteps } from '../../../../constants/onboardingConstants';
27
import { getAcceptedDevices, getDeviceLimit, getLimitMaxed, getUserCapabilities } from '../../../../selectors';
28
import { DeviceLimitWarning } from '../../dialogs/preauth-dialog';
29
import Confirm from './../../../common/confirm';
30
import Authsetlist from './authsetlist';
31

32
const useStyles = makeStyles()(theme => ({
12✔
33
  decommission: { justifyContent: 'flex-end', marginTop: theme.spacing(2) },
34
  wrapper: {
35
    backgroundColor: theme.palette.grey[400],
36
    borderColor: theme.palette.grey[500],
37
    borderStyle: 'solid',
38
    borderWidth: 1,
39
    marginBottom: theme.spacing(2),
40
    minWidth: 700,
41
    padding: theme.spacing(2)
42
  }
43
}));
44

45
export const Authsets = ({ decommission, device, listRef, showHelptips }) => {
12✔
46
  const [confirmDecommission, setConfirmDecomission] = useState(false);
3✔
47
  const [loading, setLoading] = useState(false);
3✔
48
  const dispatch = useDispatch();
3✔
49
  const { total: acceptedDevices = 0 } = useSelector(getAcceptedDevices);
3!
50
  const deviceLimit = useSelector(getDeviceLimit);
3✔
51
  const limitMaxed = useSelector(getLimitMaxed);
3✔
52
  const userCapabilities = useSelector(getUserCapabilities);
3✔
53
  const { classes } = useStyles();
3✔
54
  const { auth_sets = [], status = DEVICE_STATES.accepted } = device;
3!
55
  const { canManageDevices } = userCapabilities;
3✔
56

57
  const updateDeviceAuthStatus = (device_id, auth_id, status) => {
3✔
UNCOV
58
    setLoading(auth_id);
×
59
    // call API to update authset
UNCOV
60
    const request = status === DEVICE_DISMISSAL_STATE ? dispatch(deleteAuthset(device_id, auth_id)) : dispatch(updateDeviceAuth(device_id, auth_id, status));
×
61
    // on finish, change "loading" back to null
NEW
62
    return request.then(() => dispatch(advanceOnboarding(onboardingSteps.DEVICES_PENDING_ACCEPTING_ONBOARDING))).finally(() => setLoading(null));
×
63
  };
64

65
  return (
3✔
66
    <div className={classes.wrapper}>
67
      <div className="margin-bottom-small">
68
        {status === DEVICE_STATES.pending ? `Authorization ${pluralize('request', auth_sets.length)}` : 'Authorization sets'}
3!
69
      </div>
70
      <Authsetlist
71
        limitMaxed={limitMaxed}
72
        listRef={listRef}
73
        total={auth_sets.length}
74
        confirm={updateDeviceAuthStatus}
75
        loading={loading}
76
        device={device}
77
        showHelptips={showHelptips}
78
        userCapabilities={userCapabilities}
79
      />
80
      {limitMaxed && <DeviceLimitWarning acceptedDevices={acceptedDevices} deviceLimit={deviceLimit} hasContactInfo />}
3!
81
      {![DEVICE_STATES.preauth, DEVICE_STATES.pending].includes(device.status) && canManageDevices && (
9✔
82
        <div className={`flexbox ${classes.decommission}`}>
83
          {confirmDecommission ? (
3!
UNCOV
84
            <Confirm action={() => decommission(device.id)} cancel={() => setConfirmDecomission(false)} type="decommissioning" />
×
85
          ) : (
86
            <Button color="secondary" onClick={setConfirmDecomission}>
87
              Decommission device
88
            </Button>
89
          )}
90
        </div>
91
      )}
92
    </div>
93
  );
94
};
95

96
export default Authsets;
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