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

mendersoftware / gui / 1081664682

22 Nov 2023 02:11PM UTC coverage: 82.798% (-17.2%) from 99.964%
1081664682

Pull #4214

gitlab-ci

tranchitella
fix: Fixed the infinite page redirects when the back button is pressed

Remove the location and navigate from the useLocationParams.setValue callback
dependencies as they change the set function that is presented in other
useEffect dependencies. This happens when the back button is clicked, which
leads to the location changing infinitely.

Changelog: Title
Ticket: MEN-6847
Ticket: MEN-6796

Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
Signed-off-by: Fabio Tranchitella <fabio.tranchitella@northern.tech>
Pull Request #4214: fix: Fixed the infinite page redirects when the back button is pressed

4319 of 6292 branches covered (0.0%)

8332 of 10063 relevant lines covered (82.8%)

191.0 hits per line

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

87.5
/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 = {
4✔
28
  create: 'createUser',
29
  edit: 'editUser',
30
  remove: 'removeUser'
31
};
32

33
const DeleteUserDialog = ({ dismiss, open, submit, user }) => (
4✔
34
  <Dialog open={open}>
18✔
35
    <DialogTitle>Delete user?</DialogTitle>
36
    <DialogContent style={{ overflow: 'hidden' }}>
37
      Are you sure you want to delete the user with email{' '}
38
      <b>
39
        <i>{user.email}</i>
40
      </b>
41
      ?
42
    </DialogContent>
43
    <DialogActions>
44
      <Button style={{ marginRight: 10 }} onClick={dismiss}>
45
        Cancel
46
      </Button>
47
      <Button variant="contained" color="primary" onClick={() => submit(user, 'remove', user.id)}>
×
48
        Delete user
49
      </Button>
50
    </DialogActions>
51
  </Dialog>
52
);
53

54
export const UserManagement = () => {
4✔
55
  const [showCreate, setShowCreate] = useState(false);
19✔
56
  const [removeDialog, setRemoveDialog] = useState(false);
18✔
57
  const [user, setUser] = useState({});
18✔
58
  const dispatch = useDispatch();
18✔
59

60
  const { canManageUsers } = useSelector(getUserCapabilities);
18✔
61
  const { isHosted } = useSelector(getFeatures);
18✔
62
  const isEnterprise = useSelector(getIsEnterprise);
18✔
63
  const currentUser = useSelector(getCurrentUser);
18✔
64
  const roles = useSelector(getRolesById);
18✔
65
  const users = useSelector(state => Object.values(state.users.byId));
32✔
66
  const props = {
18✔
67
    canManageUsers,
68
    createUser: userData => dispatch(createUser(userData)),
1✔
69
    currentUser,
70
    editUser: (id, userData) => dispatch(editUser(id, userData)),
1✔
71
    isEnterprise,
72
    isHosted,
73
    removeUser: id => dispatch(removeUser(id)),
×
74
    roles,
75
    users
76
  };
77

78
  useEffect(() => {
18✔
79
    dispatch(getUserList());
4✔
80
  }, [dispatch]);
81

82
  useEffect(() => {
18✔
83
    dispatch(getUserList());
6✔
84
  }, [currentUser.id, dispatch, users.length]);
85

86
  const openEdit = user => {
18✔
87
    setUser(user);
3✔
88
    setRemoveDialog(false);
3✔
89
    dispatch(setSnackbar(''));
3✔
90
  };
91

92
  const openRemove = () => {
18✔
93
    dispatch(setSnackbar(''));
1✔
94
    setRemoveDialog(true);
1✔
95
  };
96

97
  const dialogDismiss = () => {
18✔
98
    setUser({});
3✔
99
    setShowCreate(false);
3✔
100
    setRemoveDialog(false);
3✔
101
  };
102

103
  const submit = (userData, type, id, passwordResetEmail) => {
18✔
104
    if (userData) {
2!
105
      let request = null;
2✔
106
      if (id) {
2✔
107
        request = props[actions[type]](id, userData);
1✔
108
      } else {
109
        request = props[actions[type]](userData);
1✔
110
      }
111
      return request.then(() => {
2✔
112
        if (passwordResetEmail) {
2!
113
          dispatch(passwordResetStart(passwordResetEmail));
×
114
        }
115
        dialogDismiss();
2✔
116
      });
117
    }
118
    if (passwordResetEmail) {
×
119
      dispatch(passwordResetStart(passwordResetEmail));
×
120
    }
121
    return dialogDismiss();
×
122
  };
123

124
  return (
18✔
125
    <div>
126
      <div className="flexbox centered space-between" style={{ marginLeft: '20px' }}>
127
        <h2>Users</h2>
128
        <Button variant="contained" color="primary" onClick={setShowCreate}>
129
          Create new user
130
        </Button>
131
      </div>
132

133
      <UserList {...props} editUser={openEdit} />
134
      {showCreate && <UserForm {...props} closeDialog={dialogDismiss} submit={submit} />}
26✔
135
      <UserDefinition
136
        currentUser={currentUser}
137
        isEnterprise={isEnterprise}
138
        onRemove={openRemove}
139
        onCancel={dialogDismiss}
140
        onSubmit={submit}
141
        roles={roles}
142
        selectedUser={user}
143
      />
144
      <DeleteUserDialog dismiss={dialogDismiss} open={removeDialog} submit={submit} user={user} />
145
    </div>
146
  );
147
};
148

149
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