• 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

90.91
/src/js/reducers/userReducer.js
1
// Copyright 2019 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 * as UserConstants from '../constants/userConstants';
15

16
export const initialState = {
183✔
17
  byId: {},
18
  currentUser: null,
19
  customColumns: [],
20
  currentSession: {
21
    // { token: window.localStorage.getItem('JWT'), expiresAt: '2023-01-01T00:15:00.000Z' | undefined }, // expiresAt depending on the stay logged in setting
22
  },
23
  qrCode: null,
24
  globalSettings: {
25
    id_attribute: undefined,
26
    previousFilters: [],
27
    previousPhases: [],
28
    retries: 0
29
  },
30
  permissionSetsById: {
31
    ...UserConstants.defaultPermissionSets
32
  },
33
  rolesById: {
34
    ...UserConstants.rolesById
35
  },
36
  tooltips: {
37
    byId: {
38
      // <id>: { readState: <read|unread> } // this object is getting enhanced by the tooltip texts in the app constants
39
    }
40
  },
41
  userSettings: {
42
    columnSelection: [],
43
    onboarding: {}
44
  }
45
};
46

47
const userReducer = (state = initialState, action) => {
183✔
48
  switch (action.type) {
2,559!
49
    case UserConstants.RECEIVED_QR_CODE:
50
      return {
3✔
51
        ...state,
52
        qrCode: action.value
53
      };
54
    case UserConstants.SUCCESSFULLY_LOGGED_IN:
55
      return {
6✔
56
        ...state,
57
        currentSession: action.value
58
      };
59
    case UserConstants.RECEIVED_USER_LIST:
60
      return {
13✔
61
        ...state,
62
        byId: { ...action.users }
63
      };
64
    case UserConstants.RECEIVED_ACTIVATION_CODE:
65
      return {
2✔
66
        ...state,
67
        activationCode: action.code
68
      };
69
    case UserConstants.RECEIVED_USER:
70
      return {
5✔
71
        ...state,
72
        byId: {
73
          ...state.byId,
74
          [action.user.id]: {
75
            ...action.user
76
          }
77
        },
78
        currentUser: action.user.id
79
      };
80
    case UserConstants.CREATED_USER:
81
      // the new user gets a 0 as id, since this will be overwritten by the retrieved userlist anyway + there is no way to know the id before
82
      return {
3✔
83
        ...state,
84
        byId: {
85
          ...state.byId,
86
          0: action.user
87
        }
88
      };
89
    case UserConstants.REMOVED_USER: {
90
      // eslint-disable-next-line no-unused-vars
91
      const { [action.userId]: removedUser, ...byId } = state.byId;
2✔
92
      return {
2✔
93
        ...state,
94
        byId,
95
        currentUser: state.currentUser === action.userId ? null : state.currentUser
2!
96
      };
97
    }
98
    case UserConstants.UPDATED_USER:
99
      return {
13✔
100
        ...state,
101
        byId: {
102
          ...state.byId,
103
          [action.userId]: {
104
            ...state.byId[action.userId],
105
            ...action.user
106
          }
107
        }
108
      };
109
    case UserConstants.RECEIVED_PERMISSION_SETS:
110
      return {
1✔
111
        ...state,
112
        permissionSetsById: action.value
113
      };
114
    case UserConstants.RECEIVED_ROLES:
115
    case UserConstants.REMOVED_ROLE:
116
      return {
6✔
117
        ...state,
118
        rolesById: action.value
119
      };
120
    case UserConstants.CREATED_ROLE:
121
    case UserConstants.UPDATED_ROLE:
122
      return {
4✔
123
        ...state,
124
        rolesById: {
125
          ...state.rolesById,
126
          [action.roleId]: {
127
            ...state.rolesById[action.roleId],
128
            ...action.role
129
          }
130
        }
131
      };
132
    case UserConstants.SET_CUSTOM_COLUMNS:
133
      return {
6✔
134
        ...state,
135
        customColumns: action.value
136
      };
137
    case UserConstants.SET_GLOBAL_SETTINGS:
138
      return {
6✔
139
        ...state,
140
        settingsInitialized: true,
141
        globalSettings: {
142
          ...state.globalSettings,
143
          ...action.settings
144
        }
145
      };
146
    case UserConstants.SET_USER_SETTINGS:
147
      return {
20✔
148
        ...state,
149
        userSettingsInitialized: true,
150
        userSettings: {
151
          ...state.userSettings,
152
          ...action.settings
153
        }
154
      };
155
    case UserConstants.SET_SHOW_CONNECT_DEVICE:
156
      return {
2✔
157
        ...state,
158
        showConnectDeviceDialog: action.show
159
      };
160
    case UserConstants.SET_TOOLTIP_STATE:
161
      return {
×
162
        ...state,
163
        tooltips: {
164
          ...state.tooltips,
165
          byId: {
166
            ...state.tooltips.byId,
167
            [action.id]: action.value
168
          }
169
        }
170
      };
171
    case UserConstants.SET_TOOLTIPS_STATE:
172
      return {
×
173
        ...state,
174
        tooltips: {
175
          ...state.tooltips,
176
          byId: action.value
177
        }
178
      };
179
    default:
180
      return state;
2,467✔
181
  }
182
};
183

184
export default userReducer;
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