Skip to content

Commit

Permalink
Merge pull request #27 from jtomasek/fix-history
Browse files Browse the repository at this point in the history
Fix new cluster modal redirect
  • Loading branch information
rawagner authored Jun 23, 2020
2 parents 27c235e + 648ed61 commit a9cad41
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/api/axiosClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const getDefaultClient = () => {
return applyCaseMiddleware(client);
};

export let client: AxiosInstance = getDefaultClient();
let client: AxiosInstance = getDefaultClient();

export const setClient = (axiosInstance: AxiosInstance) => {
client = applyCaseMiddleware(axiosInstance);
};

export { client };
3 changes: 2 additions & 1 deletion src/api/clusters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
Credentials,
} from './types';
import { client } from './axiosClient';
export const getClusters = (): AxiosPromise<Cluster[]> => client.get('clusters');

export const getClusters = (): AxiosPromise<Cluster[]> => client.get('/clusters');

export const getCluster = (id: string): AxiosPromise<Cluster> => client.get(`/clusters/${id}`);

Expand Down
7 changes: 5 additions & 2 deletions src/components/clusters/Clusters.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { RouteComponentProps } from 'react-router-dom';
import {
PageSectionVariants,
TextContent,
Expand All @@ -26,7 +27,9 @@ import alertsReducer, {
removeAlert,
} from '../../features/alerts/alertsSlice';

const Clusters: React.FC = () => {
type ClustersProps = RouteComponentProps;

const Clusters: React.FC<ClustersProps> = ({ history }) => {
const { LOADING, EMPTY, ERROR, RELOADING } = ResourceUIState;
const [isModalOpen, setIsModalOpen] = React.useState(false);
const [alerts, dispatchAlertsAction] = React.useReducer(alertsReducer, []);
Expand Down Expand Up @@ -124,7 +127,7 @@ const Clusters: React.FC = () => {
return (
<>
{body}
{isModalOpen && <NewClusterModal closeModal={closeModal} />}
{isModalOpen && <NewClusterModal closeModal={closeModal} history={history} />}
</>
);
};
Expand Down
9 changes: 4 additions & 5 deletions src/components/clusters/newClusterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
ModalBoxFooter,
ModalVariant,
} from '@patternfly/react-core';
import { History } from 'history';
import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator';
import * as Yup from 'yup';
// import history from '../../history';
import { LoadingState } from '../ui/uiState';
import { postCluster, getClusters } from '../../api/clusters';
import { Formik, FormikHelpers } from 'formik';
Expand Down Expand Up @@ -47,9 +47,10 @@ export const NewClusterModalButton: React.FC<NewClusterModalButtonProps> = ({

type NewClusterModalProps = {
closeModal: () => void;
history: History;
};

export const NewClusterModal: React.FC<NewClusterModalProps> = ({ closeModal }) => {
export const NewClusterModal: React.FC<NewClusterModalProps> = ({ closeModal, history }) => {
const nameInputRef = React.useCallback((node) => {
if (node !== null) {
node.focus();
Expand Down Expand Up @@ -84,9 +85,7 @@ export const NewClusterModal: React.FC<NewClusterModalProps> = ({ closeModal })

try {
const { data } = await postCluster(values);
console.info(`Fix navigation to /clusters/${data.id}`);
// TODO(mlibra): Fix navigation, history is not available in the library
// history.push(`/clusters/${data.id}`);
history.push(`/clusters/${data.id}`);
} catch (e) {
handleApiError<ClusterCreateParams>(e, () =>
formikActions.setStatus({
Expand Down
25 changes: 13 additions & 12 deletions src/components/ui/AlertsSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ type AlertsSectionProps = {
onClose: (alert: AlertProps) => void;
};

const AlertsSection: React.FC<AlertsSectionProps> = ({ alerts, onClose }) => (
<PageSection padding={{ default: 'noPadding' }}>
<AlertGroup className="alerts-section">
{alerts.map((alert) => (
// eslint-disable-next-line react/jsx-key
<Alert actionClose={<AlertActionCloseButton onClose={() => onClose(alert)} />} {...alert}>
{alert.message}
</Alert>
))}
</AlertGroup>
</PageSection>
);
const AlertsSection: React.FC<AlertsSectionProps> = ({ alerts, onClose }) =>
alerts.length ? (
<PageSection padding={{ default: 'noPadding' }}>
<AlertGroup className="alerts-section">
{alerts.map((alert) => (
// eslint-disable-next-line react/jsx-key
<Alert actionClose={<AlertActionCloseButton onClose={() => onClose(alert)} />} {...alert}>
{alert.message}
</Alert>
))}
</AlertGroup>
</PageSection>
) : null;

export default AlertsSection;

0 comments on commit a9cad41

Please sign in to comment.