Skip to content

Commit 2ae26b7

Browse files
Update
1 parent e8f2dfe commit 2ae26b7

File tree

4 files changed

+57
-19
lines changed

4 files changed

+57
-19
lines changed

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable jsx-a11y/label-has-associated-control */
12
import React, { useState } from 'react';
23
import PropTypes from 'prop-types';
34
import { prepareProps } from '@data-driven-forms/carbon-component-mapper';
@@ -9,15 +10,31 @@ const SelectedGroupsList = (props) => {
910
initialValues, options, id, titleText, label, placeholder,
1011
...rest
1112
} = useFieldApi(prepareProps(props));
12-
13+
const items = [
14+
<i className="ff ff-group" />,
15+
<p className="group-name">
16+
Item 1
17+
</p>,
18+
<br />,
19+
<i className="ff ff-group" />,
20+
<p className="group-name">
21+
Item 2
22+
</p>,
23+
<br />,
24+
<i className="ff ff-group" />,
25+
<p className="group-name">
26+
Item 3
27+
</p>,
28+
<br />,
29+
];
1330
return (
1431
<div>
15-
<h2 className="selected-groups-label">
32+
<label id="selected-groups-label">
1633
{__('Selected Groups')}
17-
</h2>
18-
<UnorderedList>
19-
<ListItem>Test</ListItem>
20-
</UnorderedList>
34+
</label>
35+
<div id="selected-groups">
36+
{items}
37+
</div>
2138
</div>
2239
);
2340
};

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,37 @@ import { passwordValidation } from './helper';
99

1010
const UserForm = ({ id, data, disabled }) => {
1111
const [{
12-
initialValues, isLoading, editMode, groups,
12+
initialValues, isLoading, editMode, groups, selectedGroups, // Use to populate the new custom component
1313
}, setState] = useState({ isLoading: true });
1414

1515
useEffect(() => {
1616
if (id) {
17-
Promise.all([API.get('/api/groups?&expand=resources')]).then((apiResult) => {
18-
console.log(apiResult);
19-
});
17+
Promise.all([API.get('/api/groups?&expand=resources')])
18+
.then((apiResult) => ({ result: apiResult.success ? 'success' : 'error', data: apiResult }))
19+
.catch((apiResult) => ({ result: 'error', data: apiResult }));
20+
2021
API.get('/api/groups?&expand=resources').then(({ resources }) => {
21-
const temp = [];
22+
const availableGroups = [];
2223
resources.forEach((group) => {
23-
temp.push({ label: group.description, value: group.id });
24+
availableGroups.push({ label: group.description, value: group.id });
2425
});
25-
return temp;
26-
}).then((groups) => {
26+
return availableGroups;
27+
}).then((availableGroups) => {
2728
API.get(`/api/users/${id}`).then((values) => {
2829
values.groups = [values.current_group_id];
2930
setState({
3031
initialValues: values,
3132
isLoading: false,
3233
editMode: false,
33-
groups,
34+
groups: availableGroups,
3435
});
3536
});
3637
});
3738
} else {
3839
API.get('/api/groups?&expand=resources').then(({ resources }) => {
39-
const temp = [];
40+
const availableGroups = [];
4041
resources.forEach((group) => {
41-
temp.push({ label: group.description, value: group.id });
42+
availableGroups.push({ label: group.description, value: group.id });
4243
});
4344
const values = {};
4445
if (data.name) {
@@ -54,7 +55,8 @@ const UserForm = ({ id, data, disabled }) => {
5455
initialValues: values,
5556
isLoading: false,
5657
editMode: false,
57-
groups: temp,
58+
groups: availableGroups,
59+
selectedGroups: [],
5860
});
5961
});
6062
}
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
.selected-groups-label {
1+
#selected-groups-label {
2+
display: inline-flex;
23
font-family: inherit;
34
font-size: 0.75rem;
45
letter-spacing: 0.32px;
56
color: #525252;
67
font-weight: 400;
78
line-height: 1rem;
89
}
10+
11+
#selected-groups {
12+
padding-left: 3rem;
13+
display: inline-table;
14+
}
15+
16+
.group-name {
17+
display: inline-flex;
18+
font-family: "Open Sans", Helvetica, Arial, sans-serif;
19+
font-size: 12px;
20+
line-height: 1.67;
21+
color: #363636;
22+
padding-left: 2px;
23+
margin-bottom: 0px;
24+
}

app/views/ops/_rbac_user_details.html.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
= render :partial => "layouts/flash_msg"
33
- url = url_for_only_path(:action => 'rbac_user_field_changed', :id => (@edit[:user_id] || "new"))
44
- disabled = @edit && @edit[:new][:userid] == "admin"
5+
#user_info
6+
%h3
7+
= _("User Information")
58
= react('UserForm', {:id => (@edit[:user_id]), :data => @record.dup, :disabled => disabled})
69

710
- change_stored_password ||= _("Change")

0 commit comments

Comments
 (0)