Hide save bar if no action is available (#735)
This commit is contained in:
parent
7cd3409bb3
commit
287a2eb8ed
3 changed files with 47 additions and 44 deletions
|
@ -136,7 +136,7 @@ const AttributePage: React.FC<AttributePageProps> = ({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form initial={initialForm} onSubmit={handleSubmit}>
|
<Form initial={initialForm} onSubmit={handleSubmit}>
|
||||||
{({ change, data, submit }) => {
|
{({ change, data, hasChanged, submit }) => {
|
||||||
const changeMetadata = makeMetadataChangeHandler(change);
|
const changeMetadata = makeMetadataChangeHandler(change);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -185,7 +185,7 @@ const AttributePage: React.FC<AttributePageProps> = ({
|
||||||
</div>
|
</div>
|
||||||
</Grid>
|
</Grid>
|
||||||
<SaveButtonBar
|
<SaveButtonBar
|
||||||
disabled={disabled}
|
disabled={disabled || !hasChanged}
|
||||||
state={saveButtonBarState}
|
state={saveButtonBarState}
|
||||||
onCancel={onBack}
|
onCancel={onBack}
|
||||||
onSave={submit}
|
onSave={submit}
|
||||||
|
|
|
@ -80,55 +80,58 @@ export const SaveButtonBar: React.FC<SaveButtonBarProps> = props => {
|
||||||
const scrollPosition = useWindowScroll();
|
const scrollPosition = useWindowScroll();
|
||||||
const scrolledToBottom =
|
const scrolledToBottom =
|
||||||
scrollPosition.y + window.innerHeight >= document.body.scrollHeight;
|
scrollPosition.y + window.innerHeight >= document.body.scrollHeight;
|
||||||
|
const shouldDisplay = onDelete || !disabled;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppActionContext.Consumer>
|
<AppActionContext.Consumer>
|
||||||
{anchor =>
|
{anchor =>
|
||||||
anchor ? (
|
anchor ? (
|
||||||
<Portal container={anchor.current}>
|
<Portal container={anchor.current}>
|
||||||
<div className={classes.root} {...rest}>
|
{shouldDisplay && (
|
||||||
<Container>
|
<div className={classes.root} {...rest}>
|
||||||
<Card elevation={scrolledToBottom ? 0 : 16}>
|
<Container>
|
||||||
<CardContent className={classes.content}>
|
<Card elevation={scrolledToBottom ? 0 : 16}>
|
||||||
{!!onDelete && (
|
<CardContent className={classes.content}>
|
||||||
|
{!!onDelete && (
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
onClick={onDelete}
|
||||||
|
className={classes.deleteButton}
|
||||||
|
data-test="button-bar-delete"
|
||||||
|
>
|
||||||
|
{labels && labels.delete
|
||||||
|
? labels.delete
|
||||||
|
: intl.formatMessage(buttonMessages.delete)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<div className={classes.spacer} />
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
className={classes.cancelButton}
|
||||||
onClick={onDelete}
|
variant="text"
|
||||||
className={classes.deleteButton}
|
onClick={onCancel}
|
||||||
data-test="button-bar-delete"
|
data-test="button-bar-cancel"
|
||||||
>
|
>
|
||||||
{labels && labels.delete
|
{maybe(
|
||||||
? labels.delete
|
() => labels.cancel,
|
||||||
: intl.formatMessage(buttonMessages.delete)}
|
intl.formatMessage(buttonMessages.back)
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
<ConfirmButton
|
||||||
<div className={classes.spacer} />
|
disabled={disabled}
|
||||||
<Button
|
onClick={onSave}
|
||||||
className={classes.cancelButton}
|
transitionState={state}
|
||||||
variant="text"
|
data-test="button-bar-confirm"
|
||||||
onClick={onCancel}
|
>
|
||||||
data-test="button-bar-cancel"
|
{maybe(
|
||||||
>
|
() => labels.save,
|
||||||
{maybe(
|
intl.formatMessage(buttonMessages.save)
|
||||||
() => labels.cancel,
|
)}
|
||||||
intl.formatMessage(buttonMessages.back)
|
</ConfirmButton>
|
||||||
)}
|
</CardContent>
|
||||||
</Button>
|
</Card>
|
||||||
<ConfirmButton
|
</Container>
|
||||||
disabled={disabled}
|
</div>
|
||||||
onClick={onSave}
|
)}
|
||||||
transitionState={state}
|
|
||||||
data-test="button-bar-confirm"
|
|
||||||
>
|
|
||||||
{maybe(
|
|
||||||
() => labels.save,
|
|
||||||
intl.formatMessage(buttonMessages.save)
|
|
||||||
)}
|
|
||||||
</ConfirmButton>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</Container>
|
|
||||||
</div>
|
|
||||||
</Portal>
|
</Portal>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ const CountryListPage: React.FC<CountryListPageProps> = ({
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Form initial={initialForm} onSubmit={onSubmit}>
|
<Form initial={initialForm} onSubmit={onSubmit}>
|
||||||
{({ change, data, submit }) => (
|
{({ change, data, hasChanged, submit }) => (
|
||||||
<>
|
<>
|
||||||
<Container>
|
<Container>
|
||||||
<AppHeader onBack={onBack}>
|
<AppHeader onBack={onBack}>
|
||||||
|
@ -77,7 +77,7 @@ const CountryListPage: React.FC<CountryListPageProps> = ({
|
||||||
</Grid>
|
</Grid>
|
||||||
</Container>
|
</Container>
|
||||||
<SaveButtonBar
|
<SaveButtonBar
|
||||||
disabled={disabled}
|
disabled={disabled || !hasChanged}
|
||||||
state={saveButtonBarState}
|
state={saveButtonBarState}
|
||||||
onCancel={onBack}
|
onCancel={onBack}
|
||||||
onSave={submit}
|
onSave={submit}
|
||||||
|
|
Loading…
Reference in a new issue