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

mendersoftware / gui / 913068613

pending completion
913068613

Pull #3803

gitlab-ci

web-flow
Merge pull request #3801 from mzedel/men-6383

MEN-6383 - device check in time
Pull Request #3803: staging alignment

4418 of 6435 branches covered (68.66%)

178 of 246 new or added lines in 27 files covered. (72.36%)

8352 of 10138 relevant lines covered (82.38%)

160.95 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 { 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, 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✔
55
    setLoading(auth_id);
×
56
    // call API to update authset
NEW
57
    const request = status === DEVICE_DISMISSAL_STATE ? dispatch(deleteAuthset(device_id, auth_id)) : dispatch(updateDeviceAuth(device_id, auth_id, status));
×
58
    // on finish, change "loading" back to null
NEW
59
    return request.finally(() => setLoading(null));
×
60
  };
61

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

94
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