feat: duplicate a document as draft (#6782)
* feat: duplicate a document as draft * review * Default `publish` toggle to match current document Ensures duplicating a draft does not publish it. --------- Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@@ -19,9 +19,17 @@ function DuplicateDialog({ document, onSubmit }: Props) {
|
||||
const defaultTitle = t(`Copy of {{ documentName }}`, {
|
||||
documentName: document.title,
|
||||
});
|
||||
const [publish, setPublish] = React.useState<boolean>(!!document.publishedAt);
|
||||
const [recursive, setRecursive] = React.useState<boolean>(true);
|
||||
const [title, setTitle] = React.useState<string>(defaultTitle);
|
||||
|
||||
const handlePublishChange = React.useCallback(
|
||||
(ev: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setPublish(ev.target.checked);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const handleRecursiveChange = React.useCallback(
|
||||
(ev: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setRecursive(ev.target.checked);
|
||||
@@ -38,6 +46,7 @@ function DuplicateDialog({ document, onSubmit }: Props) {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const result = await document.duplicate({
|
||||
publish,
|
||||
recursive,
|
||||
title,
|
||||
});
|
||||
@@ -56,15 +65,26 @@ function DuplicateDialog({ document, onSubmit }: Props) {
|
||||
defaultValue={defaultTitle}
|
||||
/>
|
||||
{document.publishedAt && !document.isTemplate && (
|
||||
<Text size="small">
|
||||
<Switch
|
||||
name="recursive"
|
||||
label={t("Include nested documents")}
|
||||
labelPosition="right"
|
||||
checked={recursive}
|
||||
onChange={handleRecursiveChange}
|
||||
/>
|
||||
</Text>
|
||||
<>
|
||||
<Text size="small">
|
||||
<Switch
|
||||
name="publish"
|
||||
label={t("Published")}
|
||||
labelPosition="right"
|
||||
checked={publish}
|
||||
onChange={handlePublishChange}
|
||||
/>
|
||||
</Text>
|
||||
<Text size="small">
|
||||
<Switch
|
||||
name="recursive"
|
||||
label={t("Include nested documents")}
|
||||
labelPosition="right"
|
||||
checked={recursive}
|
||||
onChange={handleRecursiveChange}
|
||||
/>
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
</ConfirmationDialog>
|
||||
);
|
||||
|
||||
@@ -509,8 +509,11 @@ export default class Document extends ParanoidModel {
|
||||
move = (collectionId: string, parentDocumentId?: string | undefined) =>
|
||||
this.store.move(this.id, collectionId, parentDocumentId);
|
||||
|
||||
duplicate = (options?: { title?: string; recursive?: boolean }) =>
|
||||
this.store.duplicate(this, options);
|
||||
duplicate = (options?: {
|
||||
title?: string;
|
||||
publish?: boolean;
|
||||
recursive?: boolean;
|
||||
}) => this.store.duplicate(this, options);
|
||||
|
||||
@computed
|
||||
get pinned(): boolean {
|
||||
|
||||
@@ -567,6 +567,7 @@ export default class DocumentsStore extends Store<Document> {
|
||||
document: Document,
|
||||
options?: {
|
||||
title?: string;
|
||||
publish?: boolean;
|
||||
recursive?: boolean;
|
||||
}
|
||||
): Promise<Document[]> => {
|
||||
|
||||
Reference in New Issue
Block a user