• 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

82.0
/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 { createRole, editRole, getRoles, removeRole } from '../../actions/userActions';
23
import { UNGROUPED_GROUP } from '../../constants/deviceConstants';
24
import { emptyRole, rolesById } from '../../constants/userConstants';
25
import { getFeatures } from '../../selectors';
26
import DetailsTable from '../common/detailstable';
27
import RoleDefinition from './roledefinition';
28

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

43
export const RoleManagement = () => {
5✔
44
  const [adding, setAdding] = useState(false);
6✔
45
  const [editing, setEditing] = useState(false);
6✔
46
  const [role, setRole] = useState({ ...emptyRole });
6✔
47
  const dispatch = useDispatch();
6✔
48
  const features = useSelector(getFeatures);
6✔
49
  const groups = useSelector(state => {
6✔
50
    // eslint-disable-next-line no-unused-vars
51
    const { [UNGROUPED_GROUP.id]: ungrouped, ...groups } = state.devices.groups.byId;
6✔
52
    return groups;
6✔
53
  });
54
  const releaseTags = useSelector(state => state.releases.releaseTags.reduce((accu, key) => ({ ...accu, [key]: key }), {}));
6✔
55
  const roles = useSelector(state => Object.entries(state.users.rolesById).map(([id, role]) => ({ id, ...role })));
36✔
56

57
  useEffect(() => {
6✔
58
    if (Object.keys(groups).length) {
2!
59
      return;
2✔
60
    }
UNCOV
61
    dispatch(getDynamicGroups());
×
UNCOV
62
    dispatch(getGroups());
×
UNCOV
63
    dispatch(getRoles());
×
64
  }, []);
65

66
  const addRole = () => {
6✔
UNCOV
67
    setAdding(true);
×
UNCOV
68
    setEditing(false);
×
UNCOV
69
    setRole({ ...emptyRole });
×
70
  };
71

72
  const onEditRole = editedRole => {
6✔
73
    setAdding(false);
2✔
74
    setEditing(true);
2✔
75
    setRole(editedRole);
2✔
76
  };
77

78
  const onCancel = () => {
6✔
79
    setAdding(false);
2✔
80
    setEditing(false);
2✔
81
  };
82

83
  const onSubmit = submittedRole => {
6✔
84
    if (adding) {
1!
UNCOV
85
      dispatch(createRole(submittedRole));
×
86
    } else {
87
      dispatch(editRole(submittedRole));
1✔
88
    }
89
    onCancel();
1✔
90
  };
91

92
  const items = useMemo(
6✔
93
    () =>
94
      Object.keys(rolesById)
2✔
95
        .reverse()
96
        .reduce((accu, key) => {
97
          const index = accu.findIndex(({ id }) => id === key);
50✔
98
          accu = [accu[index], ...accu.filter((item, itemIndex) => index !== itemIndex)];
60✔
99
          return accu;
10✔
100
        }, roles),
101
    [JSON.stringify(roles)]
102
  );
103

104
  return (
6✔
105
    <div>
106
      <h2 style={{ marginLeft: 20 }}>Roles</h2>
107
      <DetailsTable columns={columns} items={items} onItemClick={onEditRole} />
108
      <Chip color="primary" icon={<AddIcon />} label="Add a role" onClick={addRole} />
109
      <RoleDefinition
110
        adding={adding}
111
        editing={editing}
112
        features={features}
113
        onCancel={onCancel}
114
        onSubmit={onSubmit}
115
        removeRole={name => dispatch(removeRole(name))}
1✔
116
        selectedRole={role}
117
        stateGroups={groups}
118
        stateReleaseTags={releaseTags}
119
      />
120
    </div>
121
  );
122
};
123

124
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