Skip to content

Commit

Permalink
SHIBUI-1941 Modal if navigating away from form
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jun 9, 2021
1 parent 52f3f6c commit 9ee68ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ui/src/app/metadata/editor/MetadataEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function MetadataEditor ({ current }) {
const onChange = (changes) => {
dispatch(setFormDataAction(changes.formData));
dispatch(setFormErrorAction(changes.errors));
// setBlocking(true);
setBlocking(true);
};

function save(metadata) {
Expand All @@ -51,6 +51,7 @@ export function MetadataEditor ({ current }) {
};

const cancel = () => {
setBlocking(false);
gotoDetail();
};

Expand Down
12 changes: 10 additions & 2 deletions ui/src/app/metadata/wizard/MetadataProviderWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useMetadataFormDispatcher, setFormDataAction, setFormErrorAction, useMe
import { MetadataConfiguration } from '../component/MetadataConfiguration';
import { Configuration } from '../hoc/Configuration';
import { useMetadataEntity, useMetadataProviders } from '../hooks/api';
import { useHistory } from 'react-router';
import { Prompt, useHistory } from 'react-router';
import { removeNull } from '../../core/utility/remove_null';

import { useNotificationDispatcher, createNotificationAction, NotificationTypes } from '../../notifications/hoc/Notifications';
Expand Down Expand Up @@ -40,7 +40,7 @@ export function MetadataProviderWizard({onRestart}) {
const onChange = (changes) => {
formDispatch(setFormDataAction(changes.formData));
formDispatch(setFormErrorAction(changes.errors));
// console.log('change', changes);
setBlocking(true);
};

const onEditFromSummary = (idx) => {
Expand All @@ -67,8 +67,16 @@ export function MetadataProviderWizard({onRestart}) {
}
}

const [blocking, setBlocking] = React.useState(false);

return (
<>
<Prompt
when={blocking}
message={location =>
`message.unsaved-editor`
}
/>
<div className="row mb-4">
<div className="col-12">
<WizardNav onSave={save}
Expand Down
12 changes: 10 additions & 2 deletions ui/src/app/metadata/wizard/MetadataSourceWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useMetadataFormDispatcher, setFormDataAction, setFormErrorAction, useMe
import { MetadataConfiguration } from '../component/MetadataConfiguration';
import { Configuration } from '../hoc/Configuration';
import { useMetadataEntity, useMetadataSources } from '../hooks/api';
import { useHistory } from 'react-router';
import { Prompt, useHistory } from 'react-router';
import { removeNull } from '../../core/utility/remove_null';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
Expand Down Expand Up @@ -46,7 +46,7 @@ export function MetadataSourceWizard ({ onShowNav }) {
const onChange = (changes) => {
formDispatch(setFormDataAction(changes.formData));
formDispatch(setFormErrorAction(changes.errors));
// console.log('change', changes);
setBlocking(true);
};

const onEditFromSummary = (idx) => {
Expand All @@ -67,11 +67,19 @@ export function MetadataSourceWizard ({ onShowNav }) {
}
}

const [blocking, setBlocking] = React.useState(false);

const validator = definition.validator(data);
const warnings = definition.warnings && definition.warnings(metadata);

return (
<>
<Prompt
when={blocking}
message={location =>
`message.unsaved-editor`
}
/>
<div className="row mb-4">
<div className="col-12">
<WizardNav onSave={save} disabled={ errors.length > 0 || loading } saving={loading} />
Expand Down

0 comments on commit 9ee68ba

Please sign in to comment.