mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 10:57:36 -02:30
update api calls to utilized network context
This commit is contained in:
@@ -15,6 +15,8 @@ import {
|
|||||||
import { I18n } from '@lingui/react';
|
import { I18n } from '@lingui/react';
|
||||||
import { Trans, t } from '@lingui/macro';
|
import { Trans, t } from '@lingui/macro';
|
||||||
|
|
||||||
|
import { withNetwork } from '../../contexts/Network';
|
||||||
|
|
||||||
import CheckboxListItem from '../ListItem';
|
import CheckboxListItem from '../ListItem';
|
||||||
import DataListToolbar from '../DataListToolbar';
|
import DataListToolbar from '../DataListToolbar';
|
||||||
import SelectedList from '../SelectedList';
|
import SelectedList from '../SelectedList';
|
||||||
@@ -67,7 +69,7 @@ class Lookup extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getData () {
|
async getData () {
|
||||||
const { getItems } = this.props;
|
const { getItems, handleHttpError } = this.props;
|
||||||
const { page, page_size, sortedColumnKey, sortOrder } = this.state;
|
const { page, page_size, sortedColumnKey, sortOrder } = this.state;
|
||||||
|
|
||||||
this.setState({ error: false });
|
this.setState({ error: false });
|
||||||
@@ -92,7 +94,7 @@ class Lookup extends React.Component {
|
|||||||
|
|
||||||
this.setState(stateToUpdate);
|
this.setState(stateToUpdate);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ error: true });
|
handleHttpError(err) || this.setState({ error: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,4 +275,4 @@ Lookup.defaultProps = {
|
|||||||
name: null,
|
name: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Lookup;
|
export default withNetwork(Lookup);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import { CubesIcon } from '@patternfly/react-icons';
|
|||||||
import { I18n, i18nMark } from '@lingui/react';
|
import { I18n, i18nMark } from '@lingui/react';
|
||||||
import { Trans, t } from '@lingui/macro';
|
import { Trans, t } from '@lingui/macro';
|
||||||
|
|
||||||
|
import { withNetwork } from '../../contexts/Network';
|
||||||
|
|
||||||
import DataListToolbar from '../DataListToolbar';
|
import DataListToolbar from '../DataListToolbar';
|
||||||
import NotificationListItem from './NotificationListItem';
|
import NotificationListItem from './NotificationListItem';
|
||||||
import Pagination from '../Pagination';
|
import Pagination from '../Pagination';
|
||||||
@@ -117,58 +119,71 @@ class Notifications extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createError (id, isCurrentlyOn) {
|
async createError (id, isCurrentlyOn) {
|
||||||
const { onCreateError, match } = this.props;
|
const { onCreateError, match, handleHttpError } = this.props;
|
||||||
const postParams = { id };
|
const postParams = { id };
|
||||||
|
let errorHandled;
|
||||||
if (isCurrentlyOn) {
|
if (isCurrentlyOn) {
|
||||||
postParams.disassociate = true;
|
postParams.disassociate = true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await onCreateError(match.params.id, postParams);
|
await onCreateError(match.params.id, postParams);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ error: true });
|
errorHandled = handleHttpError(err);
|
||||||
|
if (!errorHandled) {
|
||||||
|
this.setState({ error: true });
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (isCurrentlyOn) {
|
if (!errorHandled) {
|
||||||
// Remove it from state
|
if (isCurrentlyOn) {
|
||||||
this.setState((prevState) => ({
|
// Remove it from state
|
||||||
errorTemplateIds: prevState.errorTemplateIds.filter((templateId) => templateId !== id)
|
this.setState((prevState) => ({
|
||||||
}));
|
errorTemplateIds: prevState.errorTemplateIds.filter((templateId) => templateId !== id)
|
||||||
} else {
|
}));
|
||||||
// Add it to state
|
} else {
|
||||||
this.setState(prevState => ({
|
// Add it to state
|
||||||
errorTemplateIds: [...prevState.errorTemplateIds, id]
|
this.setState(prevState => ({
|
||||||
}));
|
errorTemplateIds: [...prevState.errorTemplateIds, id]
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createSuccess (id, isCurrentlyOn) {
|
async createSuccess (id, isCurrentlyOn) {
|
||||||
const { onCreateSuccess, match } = this.props;
|
const { onCreateSuccess, match, handleHttpError } = this.props;
|
||||||
const postParams = { id };
|
const postParams = { id };
|
||||||
|
let errorHandled;
|
||||||
if (isCurrentlyOn) {
|
if (isCurrentlyOn) {
|
||||||
postParams.disassociate = true;
|
postParams.disassociate = true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await onCreateSuccess(match.params.id, postParams);
|
await onCreateSuccess(match.params.id, postParams);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ error: true });
|
errorHandled = handleHttpError(err);
|
||||||
|
if (!errorHandled) {
|
||||||
|
this.setState({ error: true });
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (isCurrentlyOn) {
|
if (!errorHandled) {
|
||||||
// Remove it from state
|
if (isCurrentlyOn) {
|
||||||
this.setState((prevState) => ({
|
// Remove it from state
|
||||||
successTemplateIds: prevState.successTemplateIds.filter((templateId) => templateId !== id)
|
this.setState((prevState) => ({
|
||||||
}));
|
successTemplateIds: prevState.successTemplateIds
|
||||||
} else {
|
.filter((templateId) => templateId !== id)
|
||||||
// Add it to state
|
}));
|
||||||
this.setState(prevState => ({
|
} else {
|
||||||
successTemplateIds: [...prevState.successTemplateIds, id]
|
// Add it to state
|
||||||
}));
|
this.setState(prevState => ({
|
||||||
|
successTemplateIds: [...prevState.successTemplateIds, id]
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async readNotifications (queryParams) {
|
async readNotifications (queryParams) {
|
||||||
const { noInitialResults } = this.state;
|
const { noInitialResults } = this.state;
|
||||||
const { onReadNotifications, onReadSuccess, onReadError, match } = this.props;
|
const { onReadNotifications, onReadSuccess, onReadError, match, handleHttpError } = this.props;
|
||||||
const { page, page_size, order_by } = queryParams;
|
const { page, page_size, order_by } = queryParams;
|
||||||
|
|
||||||
let sortOrder = 'ascending';
|
let sortOrder = 'ascending';
|
||||||
@@ -233,12 +248,11 @@ class Notifications extends Component {
|
|||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
successTemplateIds,
|
successTemplateIds,
|
||||||
errorTemplateIds
|
errorTemplateIds,
|
||||||
|
loading: false
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ error: true });
|
handleHttpError(err) || this.setState({ error: true, loading: false });
|
||||||
} finally {
|
|
||||||
this.setState({ loading: false });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,4 +343,4 @@ Notifications.propTypes = {
|
|||||||
onCreateSuccess: PropTypes.func.isRequired,
|
onCreateSuccess: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Notifications;
|
export default withNetwork(Notifications);
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import React, { Component, Fragment } from 'react';
|
import React, { Component, Fragment } from 'react';
|
||||||
import { Route, Switch } from 'react-router-dom';
|
import { Route, withRouter, Switch } from 'react-router-dom';
|
||||||
import { i18nMark } from '@lingui/react';
|
import { i18nMark } from '@lingui/react';
|
||||||
|
|
||||||
|
import { NetworkProvider } from '../../contexts/Network';
|
||||||
|
import { withRootDialog } from '../../contexts/RootDialog';
|
||||||
|
|
||||||
|
import Breadcrumbs from '../../components/Breadcrumbs/Breadcrumbs';
|
||||||
|
|
||||||
import OrganizationsList from './screens/OrganizationsList';
|
import OrganizationsList from './screens/OrganizationsList';
|
||||||
import OrganizationAdd from './screens/OrganizationAdd';
|
import OrganizationAdd from './screens/OrganizationAdd';
|
||||||
import Organization from './screens/Organization/Organization';
|
import Organization from './screens/Organization/Organization';
|
||||||
import Breadcrumbs from '../../components/Breadcrumbs/Breadcrumbs';
|
|
||||||
|
|
||||||
class Organizations extends Component {
|
class Organizations extends Component {
|
||||||
state = {
|
state = {
|
||||||
@@ -13,7 +17,7 @@ class Organizations extends Component {
|
|||||||
'/organizations': i18nMark('Organizations'),
|
'/organizations': i18nMark('Organizations'),
|
||||||
'/organizations/add': i18nMark('Create New Organization')
|
'/organizations/add': i18nMark('Create New Organization')
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
setBreadcrumbConfig = (organization) => {
|
setBreadcrumbConfig = (organization) => {
|
||||||
if (!organization) {
|
if (!organization) {
|
||||||
@@ -35,7 +39,7 @@ class Organizations extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { match, api, history, location } = this.props;
|
const { match, history, location, setRootDialogMessage } = this.props;
|
||||||
const { breadcrumbConfig } = this.state;
|
const { breadcrumbConfig } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -47,28 +51,34 @@ class Organizations extends Component {
|
|||||||
<Route
|
<Route
|
||||||
path={`${match.path}/add`}
|
path={`${match.path}/add`}
|
||||||
render={() => (
|
render={() => (
|
||||||
<OrganizationAdd
|
<OrganizationAdd />
|
||||||
api={api}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path={`${match.path}/:id`}
|
path={`${match.path}/:id`}
|
||||||
render={() => (
|
render={({ match: newRouteMatch }) => (
|
||||||
<Organization
|
<NetworkProvider
|
||||||
api={api}
|
handle404={() => {
|
||||||
history={history}
|
history.replace('/organizations');
|
||||||
location={location}
|
setRootDialogMessage({
|
||||||
setBreadcrumb={this.setBreadcrumbConfig}
|
title: '404',
|
||||||
/>
|
bodyText: `Cannot find organization with ID ${newRouteMatch.params.id}.`,
|
||||||
|
variant: 'warning'
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Organization
|
||||||
|
history={history}
|
||||||
|
location={location}
|
||||||
|
setBreadcrumb={this.setBreadcrumbConfig}
|
||||||
|
/>
|
||||||
|
</NetworkProvider>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path={`${match.path}`}
|
path={`${match.path}`}
|
||||||
render={() => (
|
render={() => (
|
||||||
<OrganizationsList
|
<OrganizationsList />
|
||||||
api={api}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Switch>
|
</Switch>
|
||||||
@@ -77,4 +87,4 @@ class Organizations extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Organizations;
|
export default withRootDialog(withRouter(Organizations));
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import { t } from '@lingui/macro';
|
|||||||
|
|
||||||
import Lookup from '../../../components/Lookup';
|
import Lookup from '../../../components/Lookup';
|
||||||
|
|
||||||
|
import { withNetwork } from '../../../contexts/Network';
|
||||||
|
|
||||||
const INSTANCE_GROUPS_LOOKUP_COLUMNS = [
|
const INSTANCE_GROUPS_LOOKUP_COLUMNS = [
|
||||||
{ name: i18nMark('Name'), key: 'name', isSortable: true },
|
{ name: i18nMark('Name'), key: 'name', isSortable: true },
|
||||||
{ name: i18nMark('Modified'), key: 'modified', isSortable: false, isNumeric: true },
|
{ name: i18nMark('Modified'), key: 'modified', isSortable: false, isNumeric: true },
|
||||||
@@ -69,9 +71,6 @@ class InstanceGroupsLookup extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstanceGroupsLookup.propTypes = {
|
InstanceGroupsLookup.propTypes = {
|
||||||
api: PropTypes.shape({
|
|
||||||
getInstanceGroups: PropTypes.func,
|
|
||||||
}).isRequired,
|
|
||||||
value: PropTypes.arrayOf(PropTypes.object).isRequired,
|
value: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
tooltip: PropTypes.string,
|
tooltip: PropTypes.string,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
@@ -81,4 +80,4 @@ InstanceGroupsLookup.defaultProps = {
|
|||||||
tooltip: '',
|
tooltip: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default InstanceGroupsLookup;
|
export default withNetwork(InstanceGroupsLookup);
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import {
|
|||||||
Link
|
Link
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
|
|
||||||
|
import { withNetwork } from '../../../contexts/Network';
|
||||||
|
|
||||||
import AlertModal from '../../../components/AlertModal';
|
import AlertModal from '../../../components/AlertModal';
|
||||||
import Pagination from '../../../components/Pagination';
|
import Pagination from '../../../components/Pagination';
|
||||||
import DataListToolbar from '../../../components/DataListToolbar';
|
import DataListToolbar from '../../../components/DataListToolbar';
|
||||||
@@ -238,20 +240,16 @@ class OrganizationAccessList extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async removeAccessRole (roleId, resourceId, type) {
|
async removeAccessRole (roleId, resourceId, type) {
|
||||||
const { removeRole } = this.props;
|
const { removeRole, handleHttpError } = this.props;
|
||||||
const url = `/api/v2/${type}/${resourceId}/roles/`;
|
const url = `/api/v2/${type}/${resourceId}/roles/`;
|
||||||
try {
|
try {
|
||||||
await removeRole(url, roleId);
|
await removeRole(url, roleId);
|
||||||
|
const queryParams = this.getQueryParams();
|
||||||
|
await this.fetchOrgAccessList(queryParams);
|
||||||
|
this.setState({ showWarning: false });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.setState({ error });
|
handleHttpError(error) || this.setState({ error });
|
||||||
}
|
}
|
||||||
const queryParams = this.getQueryParams();
|
|
||||||
try {
|
|
||||||
this.fetchOrgAccessList(queryParams);
|
|
||||||
} catch (error) {
|
|
||||||
this.setState({ error });
|
|
||||||
}
|
|
||||||
this.setState({ showWarning: false });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleWarning (roleName, roleId, resourceName, resourceId, type) {
|
handleWarning (roleName, roleId, resourceName, resourceId, type) {
|
||||||
@@ -432,4 +430,4 @@ OrganizationAccessList.propTypes = {
|
|||||||
removeRole: PropTypes.func.isRequired,
|
removeRole: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default OrganizationAccessList;
|
export default withNetwork(OrganizationAccessList);
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import {
|
|||||||
FormGroup,
|
FormGroup,
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
|
|
||||||
import { ConfigContext } from '../../../context';
|
import { Config } from '../../../contexts/Config';
|
||||||
|
import { withNetwork } from '../../../contexts/Network';
|
||||||
import FormRow from '../../../components/FormRow';
|
import FormRow from '../../../components/FormRow';
|
||||||
import FormField from '../../../components/FormField';
|
import FormField from '../../../components/FormField';
|
||||||
import FormActionGroup from '../../../components/FormActionGroup';
|
import FormActionGroup from '../../../components/FormActionGroup';
|
||||||
@@ -81,7 +82,7 @@ class OrganizationForm extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { api, organization, handleCancel } = this.props;
|
const { organization, handleCancel } = this.props;
|
||||||
const { instanceGroups, formIsValid, error } = this.state;
|
const { instanceGroups, formIsValid, error } = this.state;
|
||||||
const defaultVenv = '/venv/ansible/';
|
const defaultVenv = '/venv/ansible/';
|
||||||
|
|
||||||
@@ -112,7 +113,7 @@ class OrganizationForm extends Component {
|
|||||||
type="text"
|
type="text"
|
||||||
label={i18n._(t`Description`)}
|
label={i18n._(t`Description`)}
|
||||||
/>
|
/>
|
||||||
<ConfigContext.Consumer>
|
<Config>
|
||||||
{({ custom_virtualenvs }) => (
|
{({ custom_virtualenvs }) => (
|
||||||
custom_virtualenvs && custom_virtualenvs.length > 1 && (
|
custom_virtualenvs && custom_virtualenvs.length > 1 && (
|
||||||
<Field
|
<Field
|
||||||
@@ -133,10 +134,9 @@ class OrganizationForm extends Component {
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
</ConfigContext.Consumer>
|
</Config>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
<InstanceGroupsLookup
|
<InstanceGroupsLookup
|
||||||
api={api}
|
|
||||||
value={instanceGroups}
|
value={instanceGroups}
|
||||||
onChange={this.handleInstanceGroupsChange}
|
onChange={this.handleInstanceGroupsChange}
|
||||||
tooltip={i18n._(t`Select the Instance Groups for this Organization to run on.`)}
|
tooltip={i18n._(t`Select the Instance Groups for this Organization to run on.`)}
|
||||||
@@ -157,7 +157,6 @@ class OrganizationForm extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OrganizationForm.propTypes = {
|
OrganizationForm.propTypes = {
|
||||||
api: PropTypes.shape().isRequired,
|
|
||||||
organization: PropTypes.shape(),
|
organization: PropTypes.shape(),
|
||||||
handleSubmit: PropTypes.func.isRequired,
|
handleSubmit: PropTypes.func.isRequired,
|
||||||
handleCancel: PropTypes.func.isRequired,
|
handleCancel: PropTypes.func.isRequired,
|
||||||
@@ -175,4 +174,4 @@ OrganizationForm.contextTypes = {
|
|||||||
custom_virtualenvs: PropTypes.arrayOf(PropTypes.string)
|
custom_virtualenvs: PropTypes.arrayOf(PropTypes.string)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withRouter(OrganizationForm);
|
export default withNetwork(withRouter(OrganizationForm));
|
||||||
|
|||||||
@@ -13,13 +13,16 @@ import {
|
|||||||
PageSection
|
PageSection
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
|
|
||||||
|
import { withNetwork } from '../../../../contexts/Network';
|
||||||
|
|
||||||
|
import Tabs from '../../../../components/Tabs/Tabs';
|
||||||
|
import Tab from '../../../../components/Tabs/Tab';
|
||||||
|
|
||||||
import OrganizationAccess from './OrganizationAccess';
|
import OrganizationAccess from './OrganizationAccess';
|
||||||
import OrganizationDetail from './OrganizationDetail';
|
import OrganizationDetail from './OrganizationDetail';
|
||||||
import OrganizationEdit from './OrganizationEdit';
|
import OrganizationEdit from './OrganizationEdit';
|
||||||
import OrganizationNotifications from './OrganizationNotifications';
|
import OrganizationNotifications from './OrganizationNotifications';
|
||||||
import OrganizationTeams from './OrganizationTeams';
|
import OrganizationTeams from './OrganizationTeams';
|
||||||
import Tabs from '../../../../components/Tabs/Tabs';
|
|
||||||
import Tab from '../../../../components/Tabs/Tab';
|
|
||||||
|
|
||||||
class Organization extends Component {
|
class Organization extends Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
@@ -47,18 +50,18 @@ class Organization extends Component {
|
|||||||
|
|
||||||
async fetchOrganization () {
|
async fetchOrganization () {
|
||||||
const {
|
const {
|
||||||
api,
|
|
||||||
match,
|
match,
|
||||||
setBreadcrumb
|
setBreadcrumb,
|
||||||
|
api,
|
||||||
|
handleHttpError
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data } = await api.getOrganizationDetails(+match.params.id);
|
const { data } = await api.getOrganizationDetails(parseInt(match.params.id, 10));
|
||||||
this.setState({ organization: data });
|
|
||||||
setBreadcrumb(data);
|
setBreadcrumb(data);
|
||||||
|
this.setState({ organization: data, loading: false });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.setState({ error: true });
|
handleHttpError(error) || this.setState({ error: true, loading: false });
|
||||||
} finally {
|
|
||||||
this.setState({ loading: false });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +69,6 @@ class Organization extends Component {
|
|||||||
const {
|
const {
|
||||||
location,
|
location,
|
||||||
match,
|
match,
|
||||||
api,
|
|
||||||
history
|
history
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
@@ -125,7 +127,6 @@ class Organization extends Component {
|
|||||||
path="/organizations/:id/edit"
|
path="/organizations/:id/edit"
|
||||||
render={() => (
|
render={() => (
|
||||||
<OrganizationEdit
|
<OrganizationEdit
|
||||||
api={api}
|
|
||||||
match={match}
|
match={match}
|
||||||
organization={organization}
|
organization={organization}
|
||||||
/>
|
/>
|
||||||
@@ -137,7 +138,6 @@ class Organization extends Component {
|
|||||||
path="/organizations/:id/details"
|
path="/organizations/:id/details"
|
||||||
render={() => (
|
render={() => (
|
||||||
<OrganizationDetail
|
<OrganizationDetail
|
||||||
api={api}
|
|
||||||
match={match}
|
match={match}
|
||||||
organization={organization}
|
organization={organization}
|
||||||
/>
|
/>
|
||||||
@@ -148,7 +148,6 @@ class Organization extends Component {
|
|||||||
path="/organizations/:id/access"
|
path="/organizations/:id/access"
|
||||||
render={() => (
|
render={() => (
|
||||||
<OrganizationAccess
|
<OrganizationAccess
|
||||||
api={api}
|
|
||||||
match={match}
|
match={match}
|
||||||
location={location}
|
location={location}
|
||||||
history={history}
|
history={history}
|
||||||
@@ -160,7 +159,9 @@ class Organization extends Component {
|
|||||||
render={() => (
|
render={() => (
|
||||||
<OrganizationTeams
|
<OrganizationTeams
|
||||||
id={Number(match.params.id)}
|
id={Number(match.params.id)}
|
||||||
api={api}
|
match={match}
|
||||||
|
location={location}
|
||||||
|
history={history}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@@ -168,7 +169,6 @@ class Organization extends Component {
|
|||||||
path="/organizations/:id/notifications"
|
path="/organizations/:id/notifications"
|
||||||
render={() => (
|
render={() => (
|
||||||
<OrganizationNotifications
|
<OrganizationNotifications
|
||||||
api={api}
|
|
||||||
match={match}
|
match={match}
|
||||||
location={location}
|
location={location}
|
||||||
history={history}
|
history={history}
|
||||||
@@ -184,4 +184,4 @@ class Organization extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withRouter(Organization);
|
export default withNetwork(withRouter(Organization));
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { withNetwork } from '../../../../contexts/Network';
|
||||||
|
|
||||||
import OrganizationAccessList from '../../components/OrganizationAccessList';
|
import OrganizationAccessList from '../../components/OrganizationAccessList';
|
||||||
|
|
||||||
class OrganizationAccess extends React.Component {
|
class OrganizationAccess extends React.Component {
|
||||||
@@ -38,4 +41,4 @@ class OrganizationAccess extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default OrganizationAccess;
|
export default withNetwork(OrganizationAccess);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React, { Component } from 'react';
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { I18n } from '@lingui/react';
|
import { I18n } from '@lingui/react';
|
||||||
import { Trans, t } from '@lingui/macro';
|
import { Trans, t } from '@lingui/macro';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CardBody,
|
CardBody,
|
||||||
Button,
|
Button,
|
||||||
@@ -9,6 +10,9 @@ import {
|
|||||||
TextContent,
|
TextContent,
|
||||||
TextVariants,
|
TextVariants,
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
|
|
||||||
|
import { withNetwork } from '../../../../contexts/Network';
|
||||||
|
|
||||||
import BasicChip from '../../../../components/BasicChip/BasicChip';
|
import BasicChip from '../../../../components/BasicChip/BasicChip';
|
||||||
|
|
||||||
const detailWrapperStyle = {
|
const detailWrapperStyle = {
|
||||||
@@ -68,6 +72,7 @@ class OrganizationDetail extends Component {
|
|||||||
async loadInstanceGroups () {
|
async loadInstanceGroups () {
|
||||||
const {
|
const {
|
||||||
api,
|
api,
|
||||||
|
handleHttpError,
|
||||||
match
|
match
|
||||||
} = this.props;
|
} = this.props;
|
||||||
try {
|
try {
|
||||||
@@ -78,7 +83,7 @@ class OrganizationDetail extends Component {
|
|||||||
instanceGroups: [...data.results]
|
instanceGroups: [...data.results]
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ error: true });
|
handleHttpError(err) || this.setState({ error: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,4 +178,4 @@ class OrganizationDetail extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default OrganizationDetail;
|
export default withNetwork(OrganizationDetail);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import React, { Component } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { CardBody } from '@patternfly/react-core';
|
import { CardBody } from '@patternfly/react-core';
|
||||||
|
|
||||||
import OrganizationForm from '../../components/OrganizationForm';
|
import OrganizationForm from '../../components/OrganizationForm';
|
||||||
|
import { withNetwork } from '../../../../contexts/Network';
|
||||||
|
|
||||||
class OrganizationEdit extends Component {
|
class OrganizationEdit extends Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
@@ -20,14 +20,13 @@ class OrganizationEdit extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleSubmit (values, groupsToAssociate, groupsToDisassociate) {
|
async handleSubmit (values, groupsToAssociate, groupsToDisassociate) {
|
||||||
const { api, organization } = this.props;
|
const { api, organization, handleHttpError } = this.props;
|
||||||
try {
|
try {
|
||||||
await api.updateOrganizationDetails(organization.id, values);
|
await api.updateOrganizationDetails(organization.id, values);
|
||||||
await this.submitInstanceGroups(groupsToAssociate, groupsToDisassociate);
|
await this.submitInstanceGroups(groupsToAssociate, groupsToDisassociate);
|
||||||
} catch (err) {
|
|
||||||
this.setState({ error: err });
|
|
||||||
} finally {
|
|
||||||
this.handleSuccess();
|
this.handleSuccess();
|
||||||
|
} catch (err) {
|
||||||
|
handleHttpError(err) || this.setState({ error: err });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +41,7 @@ class OrganizationEdit extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async submitInstanceGroups (groupsToAssociate, groupsToDisassociate) {
|
async submitInstanceGroups (groupsToAssociate, groupsToDisassociate) {
|
||||||
const { api, organization } = this.props;
|
const { api, organization, handleHttpError } = this.props;
|
||||||
const url = organization.related.instance_groups;
|
const url = organization.related.instance_groups;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -53,18 +52,17 @@ class OrganizationEdit extends Component {
|
|||||||
await api.disassociate(url, id);
|
await api.disassociate(url, id);
|
||||||
}));
|
}));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ error: err });
|
handleHttpError(err) || this.setState({ error: err });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { api, organization } = this.props;
|
const { organization } = this.props;
|
||||||
const { error } = this.state;
|
const { error } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<OrganizationForm
|
<OrganizationForm
|
||||||
api={api}
|
|
||||||
organization={organization}
|
organization={organization}
|
||||||
handleSubmit={this.handleSubmit}
|
handleSubmit={this.handleSubmit}
|
||||||
handleCancel={this.handleCancel}
|
handleCancel={this.handleCancel}
|
||||||
@@ -76,7 +74,6 @@ class OrganizationEdit extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OrganizationEdit.propTypes = {
|
OrganizationEdit.propTypes = {
|
||||||
api: PropTypes.shape().isRequired,
|
|
||||||
organization: PropTypes.shape().isRequired,
|
organization: PropTypes.shape().isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -85,4 +82,4 @@ OrganizationEdit.contextTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export { OrganizationEdit as _OrganizationEdit };
|
export { OrganizationEdit as _OrganizationEdit };
|
||||||
export default withRouter(OrganizationEdit);
|
export default withNetwork(withRouter(OrganizationEdit));
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
|
import { withNetwork } from '../../../../contexts/Network';
|
||||||
|
|
||||||
import NotificationsList from '../../../../components/NotificationsList/Notifications.list';
|
import NotificationsList from '../../../../components/NotificationsList/Notifications.list';
|
||||||
|
|
||||||
class OrganizationNotifications extends Component {
|
class OrganizationNotifications extends Component {
|
||||||
@@ -60,4 +62,4 @@ class OrganizationNotifications extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default OrganizationNotifications;
|
export default withNetwork(OrganizationNotifications);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import OrganizationTeamsList from '../../components/OrganizationTeamsList';
|
import OrganizationTeamsList from '../../components/OrganizationTeamsList';
|
||||||
import { parseQueryString } from '../../../../qs';
|
import { parseQueryString } from '../../../../qs';
|
||||||
|
import { withNetwork } from '../../../../contexts/Network';
|
||||||
|
|
||||||
const DEFAULT_QUERY_PARAMS = {
|
const DEFAULT_QUERY_PARAMS = {
|
||||||
page: 1,
|
page: 1,
|
||||||
@@ -47,7 +48,7 @@ class OrganizationTeams extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async readOrganizationTeamsList () {
|
async readOrganizationTeamsList () {
|
||||||
const { api, id } = this.props;
|
const { api, handleHttpError, id } = this.props;
|
||||||
const params = this.getQueryParams();
|
const params = this.getQueryParams();
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
try {
|
try {
|
||||||
@@ -61,7 +62,7 @@ class OrganizationTeams extends React.Component {
|
|||||||
isInitialized: true,
|
isInitialized: true,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.setState({
|
handleHttpError(error) && this.setState({
|
||||||
error,
|
error,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isInitialized: true,
|
isInitialized: true,
|
||||||
@@ -94,9 +95,8 @@ class OrganizationTeams extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OrganizationTeams.propTypes = {
|
OrganizationTeams.propTypes = {
|
||||||
id: PropTypes.number.isRequired,
|
id: PropTypes.number.isRequired
|
||||||
api: PropTypes.shape().isRequired,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { OrganizationTeams as _OrganizationTeams };
|
export { OrganizationTeams as _OrganizationTeams };
|
||||||
export default withRouter(OrganizationTeams);
|
export default withNetwork(withRouter(OrganizationTeams));
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import {
|
|||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
import { TimesIcon } from '@patternfly/react-icons';
|
import { TimesIcon } from '@patternfly/react-icons';
|
||||||
|
|
||||||
|
import { withNetwork } from '../../../contexts/Network';
|
||||||
|
|
||||||
import OrganizationForm from '../components/OrganizationForm';
|
import OrganizationForm from '../components/OrganizationForm';
|
||||||
|
|
||||||
class OrganizationAdd extends React.Component {
|
class OrganizationAdd extends React.Component {
|
||||||
@@ -29,7 +31,7 @@ class OrganizationAdd extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleSubmit (values, groupsToAssociate) {
|
async handleSubmit (values, groupsToAssociate) {
|
||||||
const { api } = this.props;
|
const { api, handleHttpError } = this.props;
|
||||||
try {
|
try {
|
||||||
const { data: response } = await api.createOrganization(values);
|
const { data: response } = await api.createOrganization(values);
|
||||||
const instanceGroupsUrl = response.related.instance_groups;
|
const instanceGroupsUrl = response.related.instance_groups;
|
||||||
@@ -37,10 +39,9 @@ class OrganizationAdd extends React.Component {
|
|||||||
await Promise.all(groupsToAssociate.map(async id => {
|
await Promise.all(groupsToAssociate.map(async id => {
|
||||||
await api.associateInstanceGroup(instanceGroupsUrl, id);
|
await api.associateInstanceGroup(instanceGroupsUrl, id);
|
||||||
}));
|
}));
|
||||||
} catch (err) {
|
|
||||||
this.setState({ error: err });
|
|
||||||
} finally {
|
|
||||||
this.handleSuccess(response.id);
|
this.handleSuccess(response.id);
|
||||||
|
} catch (err) {
|
||||||
|
handleHttpError(err) || this.setState({ error: err });
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ error: err });
|
this.setState({ error: err });
|
||||||
@@ -58,7 +59,6 @@ class OrganizationAdd extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { api } = this.props;
|
|
||||||
const { error } = this.state;
|
const { error } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -82,7 +82,6 @@ class OrganizationAdd extends React.Component {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<OrganizationForm
|
<OrganizationForm
|
||||||
api={api}
|
|
||||||
handleSubmit={this.handleSubmit}
|
handleSubmit={this.handleSubmit}
|
||||||
handleCancel={this.handleCancel}
|
handleCancel={this.handleCancel}
|
||||||
/>
|
/>
|
||||||
@@ -105,4 +104,4 @@ OrganizationAdd.contextTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export { OrganizationAdd as _OrganizationAdd };
|
export { OrganizationAdd as _OrganizationAdd };
|
||||||
export default withRouter(OrganizationAdd);
|
export default withNetwork(withRouter(OrganizationAdd));
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ import {
|
|||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
|
|
||||||
import { CubesIcon } from '@patternfly/react-icons';
|
import { CubesIcon } from '@patternfly/react-icons';
|
||||||
|
|
||||||
|
import { withNetwork } from '../../../contexts/Network';
|
||||||
|
|
||||||
import DataListToolbar from '../../../components/DataListToolbar';
|
import DataListToolbar from '../../../components/DataListToolbar';
|
||||||
import OrganizationListItem from '../components/OrganizationListItem';
|
import OrganizationListItem from '../components/OrganizationListItem';
|
||||||
import Pagination from '../../../components/Pagination';
|
import Pagination from '../../../components/Pagination';
|
||||||
@@ -170,14 +173,21 @@ class OrganizationsList extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleOrgDelete (event) {
|
async handleOrgDelete (event) {
|
||||||
const { orgsToDelete } = this.state;
|
const { orgsToDelete, handleHttpError } = this.state;
|
||||||
const { api } = this.props;
|
const { api } = this.props;
|
||||||
|
let errorHandled;
|
||||||
|
|
||||||
orgsToDelete.forEach(async (org) => {
|
try {
|
||||||
await api.destroyOrganization(org.id);
|
await Promise.all(orgsToDelete.map(async (org) => api.destroyOrganization(org.id)));
|
||||||
|
this.handleClearOrgsToDelete();
|
||||||
|
} catch (err) {
|
||||||
|
errorHandled = handleHttpError(err);
|
||||||
|
} finally {
|
||||||
|
if (!errorHandled) {
|
||||||
const queryParams = this.getQueryParams();
|
const queryParams = this.getQueryParams();
|
||||||
this.fetchOrganizations(queryParams);
|
this.fetchOrganizations(queryParams);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +202,7 @@ class OrganizationsList extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchOrganizations (queryParams) {
|
async fetchOrganizations (queryParams) {
|
||||||
const { api } = this.props;
|
const { api, handleHttpError } = this.props;
|
||||||
const { page, page_size, order_by } = queryParams;
|
const { page, page_size, order_by } = queryParams;
|
||||||
|
|
||||||
let sortOrder = 'ascending';
|
let sortOrder = 'ascending';
|
||||||
@@ -220,6 +230,7 @@ class OrganizationsList extends Component {
|
|||||||
sortedColumnKey,
|
sortedColumnKey,
|
||||||
results,
|
results,
|
||||||
selected: [],
|
selected: [],
|
||||||
|
loading: false
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is in place to track whether or not the initial request
|
// This is in place to track whether or not the initial request
|
||||||
@@ -233,9 +244,7 @@ class OrganizationsList extends Component {
|
|||||||
this.setState(stateToUpdate);
|
this.setState(stateToUpdate);
|
||||||
this.updateUrl(queryParams);
|
this.updateUrl(queryParams);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ error: true });
|
handleHttpError(err) || this.setState({ error: true, loading: false });
|
||||||
} finally {
|
|
||||||
this.setState({ loading: false });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,8 +280,8 @@ class OrganizationsList extends Component {
|
|||||||
isOpen={isModalOpen}
|
isOpen={isModalOpen}
|
||||||
onClose={this.handleClearOrgsToDelete}
|
onClose={this.handleClearOrgsToDelete}
|
||||||
actions={[
|
actions={[
|
||||||
<Button variant="danger" aria-label="confirm-delete" onClick={this.handleOrgDelete}>Delete</Button>,
|
<Button variant="danger" key="delete" aria-label="confirm-delete" onClick={this.handleOrgDelete}>Delete</Button>,
|
||||||
<Button variant="secondary" aria-label="cancel-delete" onClick={this.handleClearOrgsToDelete}>Cancel</Button>
|
<Button variant="secondary" key="cancel" aria-label="cancel-delete" onClick={this.handleClearOrgsToDelete}>Cancel</Button>
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{warningMsg}
|
{warningMsg}
|
||||||
@@ -350,4 +359,4 @@ class OrganizationsList extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withRouter(OrganizationsList);
|
export default withNetwork(withRouter(OrganizationsList));
|
||||||
|
|||||||
Reference in New Issue
Block a user