fix: don't show duplicate entry when create is disabled (#3162)

This commit is contained in:
Erez Rokah
2020-01-28 14:28:33 -08:00
committed by GitHub
parent 22df7f7ae1
commit 06c045e4e6

View File

@ -29,6 +29,10 @@ const styles = {
align-items: center; align-items: center;
border: 0 solid ${colors.textFieldBorder}; border: 0 solid ${colors.textFieldBorder};
`, `,
publishedButton: css`
background-color: ${colorsRaw.tealLight};
color: ${colorsRaw.teal};
`,
}; };
const ToolbarContainer = styled.div` const ToolbarContainer = styled.div`
@ -140,9 +144,12 @@ const SaveButton = styled(ToolbarButton)`
${buttons.lightBlue}; ${buttons.lightBlue};
`; `;
const PublishedButton = styled(StyledDropdownButton)` const PublishedToolbarButton = styled(StyledDropdownButton)`
background-color: ${colorsRaw.tealLight}; ${styles.publishedButton}
color: ${colorsRaw.teal}; `;
const PublishedButton = styled(ToolbarButton)`
${styles.publishedButton}
`; `;
const PublishButton = styled(StyledDropdownButton)` const PublishButton = styled(StyledDropdownButton)`
@ -289,23 +296,33 @@ class EditorToolbar extends React.Component {
isNewEntry, isNewEntry,
t, t,
} = this.props; } = this.props;
const canCreate = collection.get('create');
if (!isNewEntry && !hasChanged) { if (!isNewEntry && !hasChanged) {
return ( return (
<> <>
{this.renderDeployPreviewControls(t('editor.editorToolbar.deployButtonLabel'))} {this.renderDeployPreviewControls(t('editor.editorToolbar.deployButtonLabel'))}
<ToolbarDropdown {canCreate ? (
dropdownTopOverlap="40px" <ToolbarDropdown
dropdownWidth="150px" dropdownTopOverlap="40px"
renderButton={() => ( dropdownWidth="150px"
<PublishedButton>{t('editor.editorToolbar.published')}</PublishedButton> renderButton={() => (
)} <PublishedToolbarButton>
> {t('editor.editorToolbar.published')}
<DropdownItem </PublishedToolbarButton>
label={t('editor.editorToolbar.duplicate')} )}
icon="add" >
onClick={onDuplicate} {
/> <DropdownItem
</ToolbarDropdown> label={t('editor.editorToolbar.duplicate')}
icon="add"
onClick={onDuplicate}
/>
}
</ToolbarDropdown>
) : (
<PublishedButton>{t('editor.editorToolbar.published')}</PublishedButton>
)}
</> </>
); );
} }
@ -328,7 +345,7 @@ class EditorToolbar extends React.Component {
iconDirection="right" iconDirection="right"
onClick={onPersist} onClick={onPersist}
/> />
{collection.get('create') ? ( {canCreate ? (
<> <>
<DropdownItem <DropdownItem
label={t('editor.editorToolbar.publishAndCreateNew')} label={t('editor.editorToolbar.publishAndCreateNew')}
@ -403,6 +420,8 @@ class EditorToolbar extends React.Component {
isPersisting, isPersisting,
t, t,
} = this.props; } = this.props;
const canCreate = collection.get('create');
if (currentStatus) { if (currentStatus) {
return ( return (
<> <>
@ -458,7 +477,7 @@ class EditorToolbar extends React.Component {
iconDirection="right" iconDirection="right"
onClick={onPublish} onClick={onPublish}
/> />
{collection.get('create') ? ( {canCreate ? (
<> <>
<DropdownItem <DropdownItem
label={t('editor.editorToolbar.publishAndCreateNew')} label={t('editor.editorToolbar.publishAndCreateNew')}
@ -489,11 +508,11 @@ class EditorToolbar extends React.Component {
dropdownTopOverlap="40px" dropdownTopOverlap="40px"
dropdownWidth="150px" dropdownWidth="150px"
renderButton={() => ( renderButton={() => (
<PublishedButton> <PublishedToolbarButton>
{isPersisting {isPersisting
? t('editor.editorToolbar.unpublishing') ? t('editor.editorToolbar.unpublishing')
: t('editor.editorToolbar.published')} : t('editor.editorToolbar.published')}
</PublishedButton> </PublishedToolbarButton>
)} )}
> >
<DropdownItem <DropdownItem
@ -502,11 +521,13 @@ class EditorToolbar extends React.Component {
iconDirection="right" iconDirection="right"
onClick={unPublish} onClick={unPublish}
/> />
<DropdownItem {canCreate && (
label={t('editor.editorToolbar.duplicate')} <DropdownItem
icon="add" label={t('editor.editorToolbar.duplicate')}
onClick={onDuplicate} icon="add"
/> onClick={onDuplicate}
/>
)}
</ToolbarDropdown> </ToolbarDropdown>
</> </>
); );