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

mendersoftware / gui / 1113439055

19 Dec 2023 09:01PM UTC coverage: 82.752% (-17.2%) from 99.964%
1113439055

Pull #4258

gitlab-ci

mender-test-bot
chore: Types update

Signed-off-by: Mender Test Bot <mender@northern.tech>
Pull Request #4258: chore: Types update

4326 of 6319 branches covered (0.0%)

8348 of 10088 relevant lines covered (82.75%)

189.39 hits per line

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

77.78
/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 { HELPTOOLTIPS, MenderHelpTooltip } from '../../../helptips/helptooltips';
29
import { DeviceLimitWarning } from '../../dialogs/preauth-dialog';
30
import Confirm from './../../../common/confirm';
31
import Authsetlist from './authsetlist';
32

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

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

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

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

97
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