• 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

70.69
/src/js/components/settings/user-management/usermanagement.js
1
// Copyright 2017 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, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
// material ui
18
import { Button, Dialog, DialogActions, DialogContent, DialogTitle } from '@mui/material';
19

20
import { setSnackbar } from '../../../actions/appActions';
21
import { createUser, editUser, getUserList, passwordResetStart, removeUser } from '../../../actions/userActions';
22
import { getCurrentUser, getFeatures, getIsEnterprise, getRolesById, getUserCapabilities } from '../../../selectors';
23
import { UserDefinition } from './userdefinition';
24
import UserForm from './userform';
25
import UserList from './userlist';
26

27
const actions = {
5✔
28
  create: 'createUser',
29
  edit: 'editUser',
30
  remove: 'removeUser'
31
};
32

33
export const UserManagement = () => {
5✔
34
  const [showCreate, setShowCreate] = useState(false);
8✔
35
  const [removeDialog, setRemoveDialog] = useState(false);
8✔
36
  const [user, setUser] = useState({});
8✔
37
  const dispatch = useDispatch();
8✔
38

39
  const { canManageUsers } = useSelector(getUserCapabilities);
8✔
40
  const { isHosted } = useSelector(getFeatures);
8✔
41
  const isEnterprise = useSelector(getIsEnterprise);
8✔
42
  const currentUser = useSelector(getCurrentUser);
8✔
43
  const roles = useSelector(getRolesById);
8✔
44
  const users = useSelector(state => Object.values(state.users.byId));
8✔
45
  const props = {
8✔
46
    canManageUsers,
UNCOV
47
    createUser: userData => dispatch(createUser(userData)),
×
48
    currentUser,
49
    editUser: (id, userData) => dispatch(editUser(id, userData)),
1✔
50
    isEnterprise,
51
    isHosted,
UNCOV
52
    removeUser: id => dispatch(removeUser(id)),
×
53
    roles,
54
    users
55
  };
56

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

61
  useEffect(() => {
8✔
62
    dispatch(getUserList());
3✔
63
  }, [currentUser.id, users.length]);
64

65
  const openEdit = user => {
8✔
66
    setUser(user);
3✔
67
    setRemoveDialog(false);
3✔
68
    dispatch(setSnackbar(''));
3✔
69
  };
70

71
  const openRemove = () => {
8✔
72
    dispatch(setSnackbar(''));
1✔
73
    setRemoveDialog(true);
1✔
74
  };
75

76
  const dialogDismiss = () => {
8✔
77
    setUser({});
1✔
78
    setShowCreate(false);
1✔
79
    setRemoveDialog(false);
1✔
80
  };
81

82
  const submit = (userData, type, id, passwordResetEmail) => {
8✔
83
    if (userData) {
1!
84
      let request = null;
1✔
85
      if (id) {
1!
86
        request = props[actions[type]](id, userData);
1✔
87
      } else {
UNCOV
88
        request = props[actions[type]](userData);
×
89
      }
90
      return request.then(() => {
1✔
UNCOV
91
        if (passwordResetEmail) {
×
UNCOV
92
          dispatch(passwordResetStart(passwordResetEmail));
×
93
        }
UNCOV
94
        dialogDismiss();
×
95
      });
96
    }
UNCOV
97
    if (passwordResetEmail) {
×
UNCOV
98
      dispatch(passwordResetStart(passwordResetEmail));
×
99
    }
UNCOV
100
    return dialogDismiss();
×
101
  };
102

103
  return (
8✔
104
    <div>
105
      <div className="flexbox centered space-between" style={{ marginLeft: '20px' }}>
106
        <h2>Users</h2>
107
        <Button variant="contained" color="primary" onClick={setShowCreate}>
108
          Create new user
109
        </Button>
110
      </div>
111

112
      <UserList {...props} editUser={openEdit} />
113
      {showCreate && <UserForm {...props} closeDialog={dialogDismiss} submit={submit} />}
8!
114
      <UserDefinition
115
        currentUser={currentUser}
116
        isEnterprise={isEnterprise}
117
        onRemove={openRemove}
118
        onCancel={dialogDismiss}
119
        onSubmit={submit}
120
        roles={roles}
121
        selectedUser={user}
122
      />
123
      {removeDialog && (
9✔
124
        <Dialog open>
125
          <DialogTitle>Remove user?</DialogTitle>
126
          <DialogContent style={{ overflow: 'hidden' }}>
127
            Are you sure you want to remove the user with email{' '}
128
            <b>
129
              <i>{user.email}</i>
130
            </b>
131
            ?
132
          </DialogContent>
133
          <DialogActions>
134
            <Button style={{ marginRight: 10 }} onClick={dialogDismiss}>
135
              Cancel
136
            </Button>
UNCOV
137
            <Button variant="contained" color="primary" onClick={() => submit(user, 'remove', user.id)}>
×
138
              Remove user
139
            </Button>
140
          </DialogActions>
141
        </Dialog>
142
      )}
143
    </div>
144
  );
145
};
146

147
export default UserManagement;
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