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

mendersoftware / gui / 901187442

pending completion
901187442

Pull #3795

gitlab-ci

mzedel
feat: increased chances of adopting our intended navigation patterns instead of unsupported browser navigation

Ticket: None
Changelog: None
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3795: feat: increased chances of adopting our intended navigation patterns instead of unsupported browser navigation

4389 of 6365 branches covered (68.96%)

5 of 5 new or added lines in 1 file covered. (100.0%)

1729 existing lines in 165 files now uncovered.

8274 of 10019 relevant lines covered (82.58%)

144.86 hits per line

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

55.56
/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 { DEVICE_DISMISSAL_STATE, DEVICE_STATES } from '../../../../constants/deviceConstants';
25
import { getAcceptedDevices, getDeviceLimit, getLimitMaxed, getUserCapabilities } from '../../../../selectors';
26
import { DeviceLimitWarning } from '../../dialogs/preauth-dialog';
27
import Confirm from './../../../common/confirm';
28
import Authsetlist from './authsetlist';
29

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

43
export const Authsets = ({ decommission, device, deviceListRefresh, showHelptips }) => {
12✔
44
  const [confirmDecommission, setConfirmDecomission] = useState(false);
3✔
45
  const [loading, setLoading] = useState(false);
3✔
46
  const dispatch = useDispatch();
3✔
47
  const { total: acceptedDevices = 0 } = useSelector(getAcceptedDevices);
3!
48
  const deviceLimit = useSelector(getDeviceLimit);
3✔
49
  const limitMaxed = useSelector(getLimitMaxed);
3✔
50
  const userCapabilities = useSelector(getUserCapabilities);
3✔
51

52
  const { auth_sets = [], status = DEVICE_STATES.accepted } = device;
3!
53

54
  const updateDeviceAuthStatus = (device_id, auth_id, status) => {
3✔
UNCOV
55
    setLoading(auth_id);
×
UNCOV
56
    const postUpdateSteps = () => {
×
UNCOV
57
      deviceListRefresh();
×
UNCOV
58
      setLoading(null);
×
59
    };
60

UNCOV
61
    if (status === DEVICE_DISMISSAL_STATE) {
×
UNCOV
62
      return (
×
63
        dispatch(deleteAuthset(device_id, auth_id))
64
          // on finish, change "loading" back to null
65
          .finally(postUpdateSteps)
66
      );
67
    } else {
68
      // call API to update authset
UNCOV
69
      return (
×
70
        dispatch(updateDeviceAuth(device_id, auth_id, status))
71
          // on finish, change "loading" back to null
72
          .finally(postUpdateSteps)
73
      );
74
    }
75
  };
76

77
  const { canManageDevices } = userCapabilities;
3✔
78
  const { classes } = useStyles();
3✔
79
  return (
3✔
80
    <div className={classes.wrapper}>
81
      <div className="margin-bottom-small">
82
        {status === DEVICE_STATES.pending ? `Authorization ${pluralize('request', auth_sets.length)}` : 'Authorization sets'}
3!
83
      </div>
84
      <Authsetlist
85
        limitMaxed={limitMaxed}
86
        total={auth_sets.length}
87
        confirm={updateDeviceAuthStatus}
88
        loading={loading}
89
        device={device}
90
        showHelptips={showHelptips}
91
        userCapabilities={userCapabilities}
92
      />
93
      {limitMaxed && <DeviceLimitWarning acceptedDevices={acceptedDevices} deviceLimit={deviceLimit} hasContactInfo />}
3!
94
      {![DEVICE_STATES.preauth, DEVICE_STATES.pending].includes(device.status) && canManageDevices && (
9✔
95
        <div className={`flexbox ${classes.decommission}`}>
96
          {confirmDecommission ? (
3!
UNCOV
97
            <Confirm action={() => decommission(device.id)} cancel={() => setConfirmDecomission(false)} type="decommissioning" />
×
98
          ) : (
99
            <Button color="secondary" onClick={setConfirmDecomission}>
100
              Decommission device
101
            </Button>
102
          )}
103
        </div>
104
      )}
105
    </div>
106
  );
107
};
108

109
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