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

mendersoftware / gui / 897326496

pending completion
897326496

Pull #3752

gitlab-ci

mzedel
chore(e2e): made use of shared timeout & login checking values to remove code duplication

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3752: chore(e2e-tests): slightly simplified log in test + separated log out test

4395 of 6392 branches covered (68.76%)

8060 of 9780 relevant lines covered (82.41%)

126.17 hits per line

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

78.72
/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 { connect } 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 = ({ createRole, editRole, features, getDynamicGroups, getGroups, getRoles, groups, releaseTags, removeRole, roles }) => {
5✔
44
  const [adding, setAdding] = useState(false);
6✔
45
  const [editing, setEditing] = useState(false);
6✔
46
  const [role, setRole] = useState({ ...emptyRole });
6✔
47

48
  useEffect(() => {
6✔
49
    if (!Object.keys(groups).length) {
2!
50
      getDynamicGroups();
×
51
      getGroups();
×
52
      getRoles();
×
53
    }
54
  }, []);
55

56
  const addRole = () => {
6✔
57
    setAdding(true);
×
58
    setEditing(false);
×
59
    setRole({ ...emptyRole });
×
60
  };
61

62
  const onEditRole = editedRole => {
6✔
63
    setAdding(false);
2✔
64
    setEditing(true);
2✔
65
    setRole(editedRole);
2✔
66
  };
67

68
  const onCancel = () => {
6✔
69
    setAdding(false);
2✔
70
    setEditing(false);
2✔
71
  };
72

73
  const onSubmit = submittedRole => {
6✔
74
    if (adding) {
1!
75
      createRole(submittedRole);
×
76
    } else {
77
      editRole(submittedRole);
1✔
78
    }
79
    onCancel();
1✔
80
  };
81

82
  const items = useMemo(
6✔
83
    () =>
84
      Object.keys(rolesById)
2✔
85
        .reverse()
86
        .reduce((accu, key) => {
87
          const index = accu.findIndex(({ id }) => id === key);
50✔
88
          accu = [accu[index], ...accu.filter((item, itemIndex) => index !== itemIndex)];
60✔
89
          return accu;
10✔
90
        }, roles),
91
    [JSON.stringify(roles)]
92
  );
93

94
  return (
6✔
95
    <div>
96
      <h2 style={{ marginLeft: 20 }}>Roles</h2>
97
      <DetailsTable columns={columns} items={items} onItemClick={onEditRole} />
98
      <Chip color="primary" icon={<AddIcon />} label="Add a role" onClick={addRole} />
99
      <RoleDefinition
100
        adding={adding}
101
        editing={editing}
102
        features={features}
103
        onCancel={onCancel}
104
        onSubmit={onSubmit}
105
        removeRole={removeRole}
106
        selectedRole={role}
107
        stateGroups={groups}
108
        stateReleaseTags={releaseTags}
109
      />
110
    </div>
111
  );
112
};
113

114
const actionCreators = { createRole, editRole, getDynamicGroups, getGroups, getRoles, removeRole };
5✔
115

116
const mapStateToProps = state => {
5✔
117
  // eslint-disable-next-line no-unused-vars
118
  const { [UNGROUPED_GROUP.id]: ungrouped, ...groups } = state.devices.groups.byId;
1✔
119
  return {
1✔
120
    features: getFeatures(state),
121
    groups,
122
    releaseTags: state.releases.releaseTags.reduce((accu, key) => ({ ...accu, [key]: key }), {}),
×
123
    roles: Object.entries(state.users.rolesById).map(([id, role]) => ({ id, ...role }))
6✔
124
  };
125
};
126

127
export default connect(mapStateToProps, actionCreators)(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