From f84ca3b9c3f697aae29466cd21219b3dea48637b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 29 Jul 2026 19:12:24 -0400 Subject: [PATCH] Display model title in dialog header (#13196) * Display model title in dialogs * feedback --- app/actions/definitions/collections.tsx | 13 +-- app/actions/definitions/documents.tsx | 59 +++++++++---- app/components/DialogTitle.tsx | 84 +++++++++++++++++++ .../Sidebar/components/TrashLink.tsx | 12 ++- app/components/TemplatizeDialog/index.tsx | 14 +--- app/stores/DialogsStore.ts | 10 ++- shared/i18n/locales/en_US/translation.json | 4 +- 7 files changed, 157 insertions(+), 39 deletions(-) create mode 100644 app/components/DialogTitle.tsx diff --git a/app/actions/definitions/collections.tsx b/app/actions/definitions/collections.tsx index 0f8f082015..e37b92c8d8 100644 --- a/app/actions/definitions/collections.tsx +++ b/app/actions/definitions/collections.tsx @@ -27,6 +27,7 @@ import { CollectionEdit } from "~/components/Collection/CollectionEdit"; import { CollectionNew } from "~/components/Collection/CollectionNew"; import CollectionDeleteDialog from "~/components/CollectionDeleteDialog"; import ConfirmationDialog from "~/components/ConfirmationDialog"; +import { DialogTitle } from "~/components/DialogTitle"; import DynamicCollectionIcon from "~/components/Icons/CollectionIcon"; import { getHeaderExpandedKey } from "~/components/Sidebar/components/Header"; import { @@ -105,7 +106,7 @@ export const editCollection = createAction({ } stores.dialogs.openModal({ - title: t("Edit collection"), + title: , content: ( + ), content: ( , content: ( { @@ -477,7 +480,7 @@ export const deleteCollection = createAction({ } stores.dialogs.openModal({ - title: t("Delete collection"), + title: , content: ( , content: ( , content: , }); } @@ -686,7 +687,7 @@ export const shareDocument = createAction({ } stores.dialogs.openModal({ - title: t("Share this document"), + title: , content: ( , content: ( , content: ( t("Templatize"), + name: ({ t }) => `${t("Templatize")}…`, analyticsName: "Templatize document", section: ActiveDocumentSection, icon: , @@ -1194,10 +1195,14 @@ export const createTemplateFromDocument = createAction({ if (!activeDocumentId) { return; } + const document = stores.documents.get(activeDocumentId); + if (!document) { + return; + } event?.preventDefault(); event?.stopPropagation(); stores.dialogs.openModal({ - title: t("Create template"), + title: , content: , }); }, @@ -1255,9 +1260,14 @@ export const moveDocumentToCollection = createAction({ } stores.dialogs.openModal({ - title: t("Move {{ documentType }}", { - documentType: document.noun, - }), + title: ( + + ), content: , }); } @@ -1303,7 +1313,12 @@ export const archiveDocument = createAction({ } dialogs.openModal({ - title: t("Are you sure you want to archive this document?"), + title: ( + + ), content: ( { @@ -1431,9 +1446,14 @@ export const deleteDocument = createAction({ } stores.dialogs.openModal({ - title: t("Delete {{ documentName }}", { - documentName: document.noun, - }), + title: ( + + ), content: ( + ), content: ( , content: , }); }, diff --git a/app/components/DialogTitle.tsx b/app/components/DialogTitle.tsx new file mode 100644 index 0000000000..3e8f56f366 --- /dev/null +++ b/app/components/DialogTitle.tsx @@ -0,0 +1,84 @@ +import { observer } from "mobx-react"; +import { DocumentIcon } from "outline-icons"; +import type * as React from "react"; +import styled from "styled-components"; +import Icon from "@shared/components/Icon"; +import type Collection from "~/models/Collection"; +import Document from "~/models/Document"; +import CollectionIcon from "~/components/Icons/CollectionIcon"; +import Text from "~/components/Text"; +import useStores from "~/hooks/useStores"; + +type Props = { + /** The title of the dialog. */ + title: React.ReactNode; + /** The document or collection that the dialog acts upon. */ + model: Document | Collection; +}; + +/** + * Renders a dialog title, additionally showing the name and icon of the model + * being acted upon when it is not the one currently being viewed. + * + * @returns the dialog title, optionally subtitled with the model. + */ +export const DialogTitle = observer(function DialogTitle_({ + title, + model, +}: Props) { + const { ui } = useStores(); + const isDocument = model instanceof Document; + + if ( + isDocument + ? ui.activeDocumentId === model.id + : ui.activeCollectionId === model.id + ) { + return <>{title}; + } + + const icon = !isDocument ? ( + + ) : model.icon ? ( + + ) : ( + + ); + + return ( + + {title} + + {icon} + + {isDocument ? model.titleWithDefault : model.name} + + + + ); +}); + +const Wrapper = styled.span` + display: flex; + flex-direction: column; + min-width: 0; + overflow: hidden; + margin-top: -4px; + gap: 4px; +`; + +const Subject = styled(Text)` + display: flex; + align-items: center; + gap: 4px; + min-width: 0; + margin-left: -4px; + + > :first-child { + flex-shrink: 0; + } +`; diff --git a/app/components/Sidebar/components/TrashLink.tsx b/app/components/Sidebar/components/TrashLink.tsx index 0c726808ff..eb56a5cc65 100644 --- a/app/components/Sidebar/components/TrashLink.tsx +++ b/app/components/Sidebar/components/TrashLink.tsx @@ -3,6 +3,7 @@ import { TrashIcon } from "outline-icons"; import { useDrop } from "react-dnd"; import { useTranslation } from "react-i18next"; import DocumentDelete from "~/scenes/DocumentDelete"; +import { DialogTitle } from "~/components/DialogTitle"; import useStores from "~/hooks/useStores"; import { trashPath } from "~/utils/routeHelpers"; import type { DragObject } from "../hooks/useDragAndDrop"; @@ -21,9 +22,14 @@ function TrashLink() { } dialogs.openModal({ - title: t("Delete {{ documentName }}", { - documentName: document?.noun, - }), + title: ( + + ), content: (
- , - }} - /> + {t( + "Creating a template is a non-destructive action – we'll make a copy of the document and turn it into a template that can be used as a starting point for new documents." + )}
void; }; +type GuideDefinition = { + title: string; + content: React.ReactNode; + isOpen: boolean; +}; + export default class DialogsStore { @observable.shallow - guide: DialogDefinition; + guide: GuideDefinition; @observable.shallow modalStack = new Map(); diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 1cd14636f1..6f75e1da34 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -69,7 +69,7 @@ "Unpublish": "Unpublish", "Unpublished {{ documentName }}": "Unpublished {{ documentName }}", "Subscription inherited from collection": "Subscription inherited from collection", - "Share this document": "Share this document", + "Share document": "Share document", "Download": "Download", "Download document": "Download document", "Download as Markdown": "Download as Markdown", @@ -570,7 +570,7 @@ "Highlight some text and use the <1> control to add placeholders that can be filled out when creating new documents": "Highlight some text and use the <1> control to add placeholders that can be filled out when creating new documents", "You’re editing a template": "You’re editing a template", "Template created, go ahead and customize it": "Template created, go ahead and customize it", - "Creating a template from {{titleWithDefault}} is a non-destructive action – we'll make a copy of the document and turn it into a template that can be used as a starting point for new documents.": "Creating a template from {{titleWithDefault}} is a non-destructive action – we'll make a copy of the document and turn it into a template that can be used as a starting point for new documents.", + "Creating a template is a non-destructive action – we'll make a copy of the document and turn it into a template that can be used as a starting point for new documents.": "Creating a template is a non-destructive action – we'll make a copy of the document and turn it into a template that can be used as a starting point for new documents.", "Enable other members to use the template immediately": "Enable other members to use the template immediately", "Location": "Location", "Admins can manage the workspace and access billing.": "Admins can manage the workspace and access billing.",