Address PR feedback.

This commit is contained in:
Kia Lam
2019-03-13 15:59:42 -04:00
parent 21156d1409
commit 0495214f47
4 changed files with 23 additions and 26 deletions

View File

@@ -114,7 +114,6 @@ describe('<AccessList />', () => {
}); });
test('getTeamRoles returns empty array if dataset is missing team_id attribute', (done) => { test('getTeamRoles returns empty array if dataset is missing team_id attribute', (done) => {
const wrapper = mount( const wrapper = mount(
<I18nProvider> <I18nProvider>
<MemoryRouter> <MemoryRouter>
@@ -140,7 +139,7 @@ describe('<AccessList />', () => {
test('test handleWarning, confirmDelete, and removeRole methods for Alert component', (done) => { test('test handleWarning, confirmDelete, and removeRole methods for Alert component', (done) => {
const handleWarning = jest.spyOn(AccessList.prototype, 'handleWarning'); const handleWarning = jest.spyOn(AccessList.prototype, 'handleWarning');
const confirmDelete = jest.spyOn(AccessList.prototype, 'confirmDelete'); const confirmDelete = jest.spyOn(AccessList.prototype, 'confirmDelete');
const removeRole = jest.spyOn(AccessList.prototype, 'removeRole'); const removeRole = jest.spyOn(AccessList.prototype, 'removeAccessRole');
const wrapper = mount( const wrapper = mount(
<I18nProvider> <I18nProvider>
<MemoryRouter> <MemoryRouter>
@@ -182,19 +181,13 @@ describe('<AccessList />', () => {
</MemoryRouter> </MemoryRouter>
</I18nProvider> </I18nProvider>
).find('AccessList'); ).find('AccessList');
expect(wrapper.state().warningMsg).not.toBeDefined;
expect(wrapper.state().warningTitle).not.toBeDefined;
expect(wrapper.state().deleteType).not.toBeDefined;
expect(wrapper.state().deleteRoleId).not.toBeDefined;
expect(wrapper.state().deleteResourceId).not.toBeDefined;
setImmediate(() => { setImmediate(() => {
const expected = [ const expected = [
{ {
deleteType: 'users' deleteType: 'users'
}, },
{ {
deleteRoleId: mockData[0].summary_fields.foo[0].role.id deleteRoleId: mockData[0].summary_fields.foo[0].role.id
}, },
{ {
@@ -208,10 +201,10 @@ describe('<AccessList />', () => {
expect(wrapper.state().warningTitle).not.toBe(null); expect(wrapper.state().warningTitle).not.toBe(null);
expect(wrapper.state().warningMsg).not.toBe(null); expect(wrapper.state().warningMsg).not.toBe(null);
expected.forEach(criteria => { expected.forEach(criteria => {
for (const prop in criteria) { Object.keys(criteria).forEach(key => {
expect(wrapper.state()[prop]).toEqual(criteria[prop]); expect(wrapper.state()[key]).toEqual(criteria[key]);
} });
}) });
done(); done();
}); });
}); });

View File

@@ -275,3 +275,10 @@
.at-u-textRight { .at-u-textRight {
text-align: right; text-align: right;
} }
.awx-c-chip {
padding: 3px 0;
height: 24px;
margin-right: 10px;
margin-bottom: 10px;
}

View File

@@ -116,7 +116,7 @@ class AccessList extends React.Component {
this.onCompact = this.onCompact.bind(this); this.onCompact = this.onCompact.bind(this);
this.onSort = this.onSort.bind(this); this.onSort = this.onSort.bind(this);
this.getQueryParams = this.getQueryParams.bind(this); this.getQueryParams = this.getQueryParams.bind(this);
this.removeRole = this.removeRole.bind(this); this.removeAccessRole = this.removeAccessRole.bind(this);
this.handleWarning = this.handleWarning.bind(this); this.handleWarning = this.handleWarning.bind(this);
this.hideWarning = this.hideWarning.bind(this); this.hideWarning = this.hideWarning.bind(this);
this.confirmDelete = this.confirmDelete.bind(this); this.confirmDelete = this.confirmDelete.bind(this);
@@ -225,8 +225,8 @@ class AccessList extends React.Component {
} }
}); });
result.teamRoles = teamRoles || []; result.teamRoles = teamRoles;
result.userRoles = userRoles || []; result.userRoles = userRoles;
}); });
this.setState(stateToUpdate); this.setState(stateToUpdate);
} catch (error) { } catch (error) {
@@ -234,10 +234,14 @@ class AccessList extends React.Component {
} }
} }
async removeRole (roleId, resourceId, type) { async removeAccessRole (roleId, resourceId, type) {
const { removeRole } = this.props; const { removeRole } = this.props;
const url = `/api/v2/${type}/${resourceId}/roles/`; const url = `/api/v2/${type}/${resourceId}/roles/`;
await removeRole(url, roleId); try {
await removeRole(url, roleId);
} catch (error) {
this.setState({ error });
}
const queryParams = this.getQueryParams(); const queryParams = this.getQueryParams();
try { try {
this.fetchOrgAccessList(queryParams); this.fetchOrgAccessList(queryParams);
@@ -280,7 +284,7 @@ class AccessList extends React.Component {
confirmDelete () { confirmDelete () {
const { deleteType, deleteResourceId, deleteRoleId } = this.state; const { deleteType, deleteResourceId, deleteRoleId } = this.state;
this.removeRole(deleteRoleId, deleteResourceId, deleteType); this.removeAccessRole(deleteRoleId, deleteResourceId, deleteType);
} }
render () { render () {

View File

@@ -8,10 +8,3 @@
display: none; display: none;
} }
} }
.awx-c-chip {
padding: 3px 0;
height: 24px;
margin-right: 10px;
margin-bottom: 10px;
}