update route group params

This commit is contained in:
Jake McDermott
2019-01-03 09:40:48 -05:00
parent 3e201d3ca0
commit dce50fe18b
6 changed files with 46 additions and 45 deletions

View File

@@ -17,7 +17,7 @@ describe('<App />', () => {
<App <App
routeGroups={[ routeGroups={[
{ {
title: 'Group One', groupTitle: 'Group One',
groupId: 'group_one', groupId: 'group_one',
routes: [ routes: [
{ title: 'Foo', path: '/foo' }, { title: 'Foo', path: '/foo' },
@@ -25,7 +25,7 @@ describe('<App />', () => {
], ],
}, },
{ {
title: 'Group Two', groupTitle: 'Group Two',
groupId: 'group_two', groupId: 'group_two',
routes: [ routes: [
{ title: 'Fiz', path: '/fiz' }, { title: 'Fiz', path: '/fiz' },
@@ -77,19 +77,13 @@ describe('<App />', () => {
expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP); expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP);
}); });
test('logout button click triggers expected callback', async (done) => { test('onLogout makes expected call to api client', async (done) => {
const logout = jest.fn(() => Promise.resolve()); const logout = jest.fn(() => Promise.resolve());
const api = { logout }; const api = { logout };
const appWrapper = mount( const appWrapper = shallow(<App api={api} />);
<HashRouter>
<I18nProvider>
<App api={api} />
</I18nProvider>
</HashRouter>
);
appWrapper.find('button[id="button-logout"]').simulate('click'); appWrapper.instance().onLogout();
await asyncFlush(); await asyncFlush();
expect(api.logout).toHaveBeenCalledTimes(1); expect(api.logout).toHaveBeenCalledTimes(1);
@@ -106,6 +100,6 @@ describe('<App />', () => {
</I18nProvider> </I18nProvider>
</HashRouter> </HashRouter>
); );
expect(api.get).toHaveBeenCalledTimes(1); expect(getConfig).toHaveBeenCalledTimes(1);
}); });
}); });

View File

@@ -12,7 +12,7 @@ describe('NavExpandableGroup', () => {
<Nav aria-label="Test Navigation"> <Nav aria-label="Test Navigation">
<NavExpandableGroup <NavExpandableGroup
groupId="test" groupId="test"
title="Test" groupTitle="Test"
routes={[ routes={[
{ path: '/foo', title: 'Foo' }, { path: '/foo', title: 'Foo' },
{ path: '/bar', title: 'Bar' }, { path: '/bar', title: 'Bar' },
@@ -45,7 +45,7 @@ describe('NavExpandableGroup', () => {
<Nav aria-label="Test Navigation"> <Nav aria-label="Test Navigation">
<NavExpandableGroup <NavExpandableGroup
groupId="test" groupId="test"
title="Test" groupTitle="Test"
routes={[ routes={[
{ path: '/foo', title: 'Foo' }, { path: '/foo', title: 'Foo' },
{ path: '/bar', title: 'Bar' }, { path: '/bar', title: 'Bar' },

View File

@@ -126,10 +126,12 @@ class App extends Component {
nav={( nav={(
<Nav aria-label={navLabel}> <Nav aria-label={navLabel}>
<NavList> <NavList>
{routeGroups.map(params => ( {routeGroups.map(({ groupId, groupTitle, routes }) => (
<NavExpandableGroup <NavExpandableGroup
key={params.groupId} key={groupId}
{...params} groupId={groupId}
groupTitle={groupTitle}
routes={routes}
/> />
))} ))}
</NavList> </NavList>

View File

@@ -25,7 +25,7 @@ class NavExpandableGroup extends Component {
}; };
render () { render () {
const { routes, groupId, staticContext, ...rest } = this.props; const { groupId, groupTitle, routes } = this.props;
const isActive = this.isActiveGroup(); const isActive = this.isActiveGroup();
return ( return (
@@ -33,7 +33,7 @@ class NavExpandableGroup extends Component {
isActive={isActive} isActive={isActive}
isExpanded={isActive} isExpanded={isActive}
groupId={groupId} groupId={groupId}
{...rest} title={groupTitle}
> >
{routes.map(({ path, title }) => ( {routes.map(({ path, title }) => (
<NavItem <NavItem

View File

@@ -111,7 +111,7 @@ export async function main (render, api) {
navLabel={i18n._(t`Primary Navigation`)} navLabel={i18n._(t`Primary Navigation`)}
routeGroups={[ routeGroups={[
{ {
title: i18n._(t`Views`), groupTitle: i18n._(t`Views`),
groupId: 'views_group', groupId: 'views_group',
routes: [ routes: [
{ {
@@ -137,7 +137,7 @@ export async function main (render, api) {
], ],
}, },
{ {
title: i18n._(t`Resources`), groupTitle: i18n._(t`Resources`),
groupId: 'resources_group', groupId: 'resources_group',
routes: [ routes: [
{ {
@@ -168,7 +168,7 @@ export async function main (render, api) {
], ],
}, },
{ {
title: i18n._(t`Access`), groupTitle: i18n._(t`Access`),
groupId: 'access_group', groupId: 'access_group',
routes: [ routes: [
{ {
@@ -189,7 +189,7 @@ export async function main (render, api) {
], ],
}, },
{ {
title: i18n._(t`Administration`), groupTitle: i18n._(t`Administration`),
groupId: 'administration_group', groupId: 'administration_group',
routes: [ routes: [
{ {
@@ -220,7 +220,7 @@ export async function main (render, api) {
], ],
}, },
{ {
title: i18n._(t`Settings`), groupTitle: i18n._(t`Settings`),
groupId: 'settings_group', groupId: 'settings_group',
routes: [ routes: [
{ {

View File

@@ -1,5 +1,4 @@
import React, { Fragment } from 'react'; import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router-dom'; import { withRouter } from 'react-router-dom';
import { Trans } from '@lingui/macro'; import { Trans } from '@lingui/macro';
import { import {
@@ -18,10 +17,8 @@ import {
CardBody, CardBody,
} from '@patternfly/react-core'; } from '@patternfly/react-core';
import { ConfigContext } from '../../../context'; import AnsibleSelect from '../../../components/AnsibleSelect';
import { API_ORGANIZATIONS } from '../../../endpoints';
import api from '../../../api';
import AnsibleSelect from '../../../components/AnsibleSelect'
const { light } = PageSectionVariants; const { light } = PageSectionVariants;
class OrganizationAdd extends React.Component { class OrganizationAdd extends React.Component {
@@ -40,6 +37,8 @@ class OrganizationAdd extends React.Component {
description: '', description: '',
instanceGroups: '', instanceGroups: '',
custom_virtualenv: '', custom_virtualenv: '',
custom_virtualenvs: [],
hideAnsibleSelect: true,
error:'', error:'',
}; };
@@ -61,7 +60,8 @@ class OrganizationAdd extends React.Component {
async onSubmit() { async onSubmit() {
const data = Object.assign({}, { ...this.state }); const data = Object.assign({}, { ...this.state });
await api.post(API_ORGANIZATIONS, data); await api.createOrganization(data);
this.resetForm(); this.resetForm();
} }
@@ -69,10 +69,22 @@ class OrganizationAdd extends React.Component {
this.props.history.push('/organizations'); this.props.history.push('/organizations');
} }
async componentDidMount() {
try {
const { data } = await api.getConfig();
this.setState({ custom_virtualenvs: [...data.custom_virtualenvs] });
if (this.state.custom_virtualenvs.length > 1) {
// Show dropdown if we have more than one ansible environment
this.setState({ hideAnsibleSelect: !this.state.hideAnsibleSelect });
}
} catch (error) {
this.setState({ error })
}
}
render() { render() {
const { name } = this.state; const { name } = this.state;
const enabled = name.length > 0; // TODO: add better form validation const enabled = name.length > 0; // TODO: add better form validation
return ( return (
<Fragment> <Fragment>
<PageSection variant={light} className="pf-m-condensed"> <PageSection variant={light} className="pf-m-condensed">
@@ -116,16 +128,13 @@ class OrganizationAdd extends React.Component {
onChange={this.handleChange} onChange={this.handleChange}
/> />
</FormGroup> </FormGroup>
<ConfigContext.Consumer> <AnsibleSelect
{({ custom_virtualenvs }) => labelName="Ansible Environment"
<AnsibleSelect selected={this.state.custom_virtualenv}
labelName="Ansible Environment" selectChange={this.onSelectChange}
selected={this.state.custom_virtualenv} data={this.state.custom_virtualenvs}
selectChange={this.onSelectChange} hidden={this.state.hideAnsibleSelect}
data={custom_virtualenvs} />
/>
}
</ConfigContext.Consumer>
</Gallery> </Gallery>
<ActionGroup className="at-align-right"> <ActionGroup className="at-align-right">
<Toolbar> <Toolbar>
@@ -146,8 +155,4 @@ class OrganizationAdd extends React.Component {
} }
} }
OrganizationAdd.contextTypes = {
custom_virtualenvs: PropTypes.array,
};
export default withRouter(OrganizationAdd); export default withRouter(OrganizationAdd);