Skip to content

Commit 7a4b073

Browse files
Fix PR issues
1 parent 48f185d commit 7a4b073

4 files changed

Lines changed: 15 additions & 29 deletions

File tree

app/javascript/components/selected-groups-list/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
44

55
const SelectedGroupsList = ({ groups }) => {
66
const selectedGroups = [];
7-
// console.log(groups);
7+
88
groups.sort();
99
if (groups) {
1010
groups.forEach((group) => {

app/javascript/components/user-form/helper.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const areGroupsEqual = (initialValues, selectedGroups = []) => {
2-
selectedGroups.sort();
3-
initialValues.groups.sort();
4-
if (selectedGroups.length !== initialValues.groups.length) {
2+
const selectedGroupsCopy = [...selectedGroups];
3+
selectedGroupsCopy.sort();
4+
const initialGroupValuesCopy = [...initialValues.groups];
5+
initialGroupValuesCopy.sort();
6+
if (selectedGroupsCopy.length !== initialGroupValuesCopy.length) {
57
return false;
68
}
7-
return selectedGroups.every((group, index) => group === initialValues.groups[index]);
9+
return selectedGroupsCopy.every((group, index) => group === initialGroupValuesCopy[index]);
810
};
911

1012
export const passwordValidation = (initialValues, id, editMode, values, setState, selectedGroups) => {

app/javascript/components/user-form/index.jsx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const UserForm = ({
1313
const [{
1414
initialValues, isLoading, editMode, groups, selectedGroups, // Use to populate the custom component
1515
}, setState] = useState({ isLoading: true });
16+
const url = '/ops';
1617

1718
useEffect(() => {
1819
if (id) {
@@ -86,23 +87,7 @@ const UserForm = ({
8687
if (values.email === undefined) {
8788
values.email = '';
8889
}
89-
const groupIds = new Set();
90-
const sortedGroupIds = [];
91-
const groupIdObjects = [];
92-
values.groups.forEach((group) => {
93-
if (group.value) {
94-
groupIds.add(group.value);
95-
} else {
96-
groupIds.add(group);
97-
}
98-
});
99-
groupIds.forEach((group) => {
100-
sortedGroupIds.push(group);
101-
});
102-
sortedGroupIds.sort();
103-
sortedGroupIds.forEach((group) => {
104-
groupIdObjects.push({ id: group });
105-
});
90+
const groupIdObjects = [...new Set(values.groups.map((g) => g.value || g))].sort().map((id) => ({ id }));
10691
if (id) {
10792
if (values.confirmPassword && values.confirmPassword === values.password) {
10893
API.post(`/api/users/${id}`,
@@ -116,7 +101,7 @@ const UserForm = ({
116101
miq_groups: groupIdObjects,
117102
},
118103
}).then(() => {
119-
miqRedirectBack(`User ${values.name} was saved`, 'success', '/ops/');
104+
miqRedirectBack(`User ${values.name} was saved`, 'success', url);
120105
});
121106
} else {
122107
API.post(`/api/users/${id}`,
@@ -129,7 +114,7 @@ const UserForm = ({
129114
miq_groups: groupIdObjects,
130115
},
131116
}).then(() => {
132-
miqRedirectBack(`User ${values.name} was saved`, 'success', '/ops/');
117+
miqRedirectBack(`User ${values.name} was saved`, 'success', url);
133118
});
134119
}
135120
miqSparkleOff();
@@ -141,14 +126,13 @@ const UserForm = ({
141126
email: values.email,
142127
miq_groups: groupIdObjects,
143128
}).then(() => {
144-
miqRedirectBack(`User ${values.name} was saved`, 'success', '/ops/');
129+
miqRedirectBack(`User ${values.name} was saved`, 'success', url);
145130
});
146131
miqSparkleOff();
147132
}
148133
};
149134

150135
const onCancel = () => {
151-
const url = '/ops/';
152136
let message = '';
153137
message = __('Add of new User was cancelled by the user');
154138
miqRedirectBack(message, 'success', url);
@@ -177,7 +161,7 @@ const UserForm = ({
177161
canReset={!!id}
178162
onReset={onFormReset}
179163
buttonsLabels={{
180-
submitLabel: id ? __('Submit') : __('Add'),
164+
submitLabel: id ? __('Save') : __('Add'),
181165
}}
182166
/>
183167
</div>

cypress/e2e/ui/Settings/application-settings.cy.js renamed to cypress/e2e/ui/Settings/Application-Settings/user.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
LABEL_CONFIG_KEYS,
44
BUTTON_CONFIG_KEYS,
55
FIELD_CONFIG_KEYS,
6-
} from '../../../support/commands/constants/command_constants';
7-
import { flashClassMap } from '../../../support/assertions/assertion_constants';
6+
} from '../../../../support/commands/constants/command_constants';
7+
import { flashClassMap } from '../../../../support/assertions/assertion_constants';
88

99
// Field values
1010
const EVM_GROUP_SUPER_ADMIN = 'EvmGroup-super_administrator';

0 commit comments

Comments
 (0)