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

mendersoftware / gui / 1350829378

27 Jun 2024 01:46PM UTC coverage: 83.494% (-16.5%) from 99.965%
1350829378

Pull #4465

gitlab-ci

mzedel
chore: test fixes

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #4465: MEN-7169 - feat: added multi sorting capabilities to devices view

4506 of 6430 branches covered (70.08%)

81 of 100 new or added lines in 14 files covered. (81.0%)

1661 existing lines in 163 files now uncovered.

8574 of 10269 relevant lines covered (83.49%)

160.6 hits per line

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

84.09
/src/js/components/settings/roles.js
1
// Copyright 2020 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, { useEffect, useMemo, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
// material ui
18
import { Add as AddIcon, ArrowRightAlt as ArrowRightAltIcon } from '@mui/icons-material';
19
import { Chip } from '@mui/material';
20

21
import { getDynamicGroups, getGroups } from '../../actions/deviceActions';
22
import { getExistingReleaseTags } from '../../actions/releaseActions.js';
23
import { createRole, editRole, getRoles, removeRole } from '../../actions/userActions';
24
import { BENEFITS } from '../../constants/appConstants';
25
import { emptyRole, rolesById } from '../../constants/userConstants';
26
import { getGroupsByIdWithoutUngrouped, getIsEnterprise, getReleaseTagsById, getRolesList } from '../../selectors';
27
import DetailsTable from '../common/detailstable';
28
import { DocsTooltip } from '../common/docslink';
29
import EnterpriseNotification from '../common/enterpriseNotification';
30
import { InfoHintContainer } from '../common/info-hint';
31
import RoleDefinition from './roledefinition';
32

33
const columns = [
4✔
34
  { key: 'name', title: 'Role', render: ({ name }) => name },
67✔
35
  { key: 'description', title: 'Description', render: ({ description }) => description || '-' },
67✔
36
  {
37
    key: 'manage',
38
    title: 'Manage',
39
    render: () => (
40
      <div className="bold flexbox center-aligned link-color margin-right-small uppercased" style={{ whiteSpace: 'nowrap' }}>
67✔
41
        view details <ArrowRightAltIcon />
42
      </div>
43
    )
44
  }
45
];
46

47
export const RoleManagement = () => {
4✔
48
  const [adding, setAdding] = useState(false);
8✔
49
  const [editing, setEditing] = useState(false);
8✔
50
  const [role, setRole] = useState({ ...emptyRole });
8✔
51
  const dispatch = useDispatch();
8✔
52
  const groups = useSelector(getGroupsByIdWithoutUngrouped);
8✔
53
  const releaseTags = useSelector(getReleaseTagsById);
8✔
54
  const roles = useSelector(getRolesList);
8✔
55
  const isEnterprise = useSelector(getIsEnterprise);
8✔
56

57
  useEffect(() => {
8✔
58
    dispatch(getExistingReleaseTags());
2✔
59
  }, [dispatch]);
60

61
  useEffect(() => {
8✔
62
    if (Object.keys(groups).length) {
2!
63
      return;
2✔
64
    }
UNCOV
65
    dispatch(getDynamicGroups());
×
UNCOV
66
    dispatch(getGroups());
×
UNCOV
67
    dispatch(getRoles());
×
68
    // eslint-disable-next-line react-hooks/exhaustive-deps
69
  }, [dispatch, JSON.stringify(groups)]);
70

71
  const addRole = () => {
8✔
UNCOV
72
    setAdding(true);
×
UNCOV
73
    setEditing(false);
×
UNCOV
74
    setRole({ ...emptyRole });
×
75
  };
76

77
  const onEditRole = editedRole => {
8✔
78
    setAdding(false);
2✔
79
    setEditing(true);
2✔
80
    setRole(editedRole);
2✔
81
  };
82

83
  const onCancel = () => {
8✔
84
    setAdding(false);
2✔
85
    setEditing(false);
2✔
86
  };
87

88
  const onSubmit = submittedRole => {
8✔
89
    if (adding) {
1!
UNCOV
90
      dispatch(createRole(submittedRole));
×
91
    } else {
92
      dispatch(editRole(submittedRole));
1✔
93
    }
94
    onCancel();
1✔
95
  };
96

97
  const items = useMemo(
8✔
98
    () =>
99
      Object.keys(rolesById)
4✔
100
        .reverse()
101
        .reduce((accu, key) => {
102
          const index = accu.findIndex(({ id }) => id === key);
100✔
103
          accu = [accu[index], ...accu.filter((item, itemIndex) => index !== itemIndex)];
185✔
104
          return accu;
20✔
105
        }, roles),
106
    // eslint-disable-next-line react-hooks/exhaustive-deps
107
    [JSON.stringify(roles)]
108
  );
109

110
  return (
8✔
111
    <div>
112
      <div className="flexbox center-aligned">
113
        <h2 style={{ marginLeft: 20 }}>Roles</h2>
114
        <InfoHintContainer>
115
          <EnterpriseNotification id={BENEFITS.rbac.id} />
116
          <DocsTooltip />
117
        </InfoHintContainer>
118
      </div>
119
      <DetailsTable columns={columns} items={items} onItemClick={onEditRole} />
120
      <Chip color="primary" icon={<AddIcon />} label="Add a role" onClick={addRole} disabled={!isEnterprise} />
121
      <RoleDefinition
122
        adding={adding}
123
        editing={editing}
124
        onCancel={onCancel}
125
        onSubmit={onSubmit}
126
        removeRole={name => dispatch(removeRole(name))}
1✔
127
        selectedRole={role}
128
        stateGroups={groups}
129
        stateReleaseTags={releaseTags}
130
      />
131
    </div>
132
  );
133
};
134

135
export default RoleManagement;
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