From e2c5fda61066bb72294b2e301db3e94b5d8f6c78 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 22 Apr 2023 10:00:09 -0400 Subject: [PATCH] fix: Do not copy edit path from headers chore: Rename url -> path in routeHelpers closes #5229 --- app/actions/definitions/documents.tsx | 8 +++--- app/actions/definitions/revisions.tsx | 7 +++-- app/components/DocumentBreadcrumb.tsx | 17 +++++++---- app/components/DocumentTemplatizeDialog.tsx | 4 +-- app/components/EventListItem.tsx | 6 ++-- app/menus/DocumentMenu.tsx | 4 +-- app/scenes/Collection.tsx | 28 +++++++++---------- app/scenes/Document/components/Document.tsx | 14 +++++----- .../Document/components/DocumentMeta.tsx | 10 ++++--- app/scenes/Document/components/Editor.tsx | 8 +++--- app/scenes/Document/components/Header.tsx | 4 +-- app/scenes/Document/components/History.tsx | 4 +-- app/scenes/Document/components/Insights.tsx | 4 +-- .../Document/components/RevisionViewer.tsx | 4 +-- app/scenes/DocumentDelete.tsx | 6 ++-- app/scenes/DocumentNew.tsx | 4 +-- app/stores/CollectionsStore.ts | 6 ++-- app/utils/routeHelpers.ts | 23 ++++++++------- shared/editor/nodes/Heading.ts | 10 +++---- 19 files changed, 91 insertions(+), 80 deletions(-) diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index b8d53177f..fe69dfa71 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -37,8 +37,8 @@ import { DocumentSection } from "~/actions/sections"; import env from "~/env"; import history from "~/utils/history"; import { - documentInsightsUrl, - documentHistoryUrl, + documentInsightsPath, + documentHistoryPath, homePath, newDocumentPath, searchPath, @@ -749,7 +749,7 @@ export const openDocumentHistory = createAction({ if (!document) { return; } - history.push(documentHistoryUrl(document)); + history.push(documentHistoryPath(document)); }, }); @@ -770,7 +770,7 @@ export const openDocumentInsights = createAction({ if (!document) { return; } - history.push(documentInsightsUrl(document)); + history.push(documentInsightsPath(document)); }, }); diff --git a/app/actions/definitions/revisions.tsx b/app/actions/definitions/revisions.tsx index 55f1ba1cd..4ecb1bc03 100644 --- a/app/actions/definitions/revisions.tsx +++ b/app/actions/definitions/revisions.tsx @@ -6,7 +6,10 @@ import stores from "~/stores"; import { createAction } from "~/actions"; import { RevisionSection } from "~/actions/sections"; import history from "~/utils/history"; -import { documentHistoryUrl, matchDocumentHistory } from "~/utils/routeHelpers"; +import { + documentHistoryPath, + matchDocumentHistory, +} from "~/utils/routeHelpers"; export const restoreRevision = createAction({ name: ({ t }) => t("Restore revision"), @@ -57,7 +60,7 @@ export const copyLinkToRevision = createAction({ return; } - const url = `${window.location.origin}${documentHistoryUrl( + const url = `${window.location.origin}${documentHistoryPath( document, revisionId )}`; diff --git a/app/components/DocumentBreadcrumb.tsx b/app/components/DocumentBreadcrumb.tsx index 952ef2c1b..61dc2f7cd 100644 --- a/app/components/DocumentBreadcrumb.tsx +++ b/app/components/DocumentBreadcrumb.tsx @@ -9,7 +9,12 @@ import Breadcrumb from "~/components/Breadcrumb"; import CollectionIcon from "~/components/Icons/CollectionIcon"; import useStores from "~/hooks/useStores"; import { MenuInternalLink } from "~/types"; -import { collectionUrl } from "~/utils/routeHelpers"; +import { + archivePath, + collectionPath, + templatesPath, + trashPath, +} from "~/utils/routeHelpers"; type Props = { document: Document; @@ -24,7 +29,7 @@ function useCategory(document: Document): MenuInternalLink | null { type: "route", icon: , title: t("Trash"), - to: "/trash", + to: trashPath(), }; } @@ -33,7 +38,7 @@ function useCategory(document: Document): MenuInternalLink | null { type: "route", icon: , title: t("Archive"), - to: "/archive", + to: archivePath(), }; } @@ -42,7 +47,7 @@ function useCategory(document: Document): MenuInternalLink | null { type: "route", icon: , title: t("Templates"), - to: "/templates", + to: templatesPath(), }; } @@ -66,14 +71,14 @@ const DocumentBreadcrumb: React.FC = ({ type: "route", title: collection.name, icon: , - to: collectionUrl(collection.url), + to: collectionPath(collection.url), }; } else if (document.collectionId && !collection) { collectionNode = { type: "route", title: t("Deleted Collection"), icon: undefined, - to: collectionUrl("deleted-collection"), + to: collectionPath("deleted-collection"), }; } diff --git a/app/components/DocumentTemplatizeDialog.tsx b/app/components/DocumentTemplatizeDialog.tsx index ad643f974..d83338de6 100644 --- a/app/components/DocumentTemplatizeDialog.tsx +++ b/app/components/DocumentTemplatizeDialog.tsx @@ -6,7 +6,7 @@ import { useHistory } from "react-router-dom"; import ConfirmationDialog from "~/components/ConfirmationDialog"; import useStores from "~/hooks/useStores"; import useToasts from "~/hooks/useToasts"; -import { documentUrl } from "~/utils/routeHelpers"; +import { documentPath } from "~/utils/routeHelpers"; type Props = { documentId: string; @@ -23,7 +23,7 @@ function DocumentTemplatizeDialog({ documentId }: Props) { const handleSubmit = React.useCallback(async () => { const template = await document?.templatize(); if (template) { - history.push(documentUrl(template)); + history.push(documentPath(template)); showToast(t("Template created, go ahead and customize it"), { type: "info", }); diff --git a/app/components/EventListItem.tsx b/app/components/EventListItem.tsx index 713b518ec..90c9eface 100644 --- a/app/components/EventListItem.tsx +++ b/app/components/EventListItem.tsx @@ -26,7 +26,7 @@ import Time from "~/components/Time"; import useStores from "~/hooks/useStores"; import RevisionMenu from "~/menus/RevisionMenu"; import Logger from "~/utils/Logger"; -import { documentHistoryUrl } from "~/utils/routeHelpers"; +import { documentHistoryPath } from "~/utils/routeHelpers"; type Props = { document: Document; @@ -62,7 +62,7 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => { icon = ; meta = t("{{userName}} edited", opts); to = { - pathname: documentHistoryUrl(document, event.modelId || ""), + pathname: documentHistoryPath(document, event.modelId || ""), state: { retainScrollPosition: true }, }; break; @@ -71,7 +71,7 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => { icon = ; meta = t("Latest"); to = { - pathname: documentHistoryUrl(document), + pathname: documentHistoryPath(document), state: { retainScrollPosition: true }, }; break; diff --git a/app/menus/DocumentMenu.tsx b/app/menus/DocumentMenu.tsx index 0ad7f37cb..2af249b69 100644 --- a/app/menus/DocumentMenu.tsx +++ b/app/menus/DocumentMenu.tsx @@ -47,7 +47,7 @@ import useRequest from "~/hooks/useRequest"; import useStores from "~/hooks/useStores"; import useToasts from "~/hooks/useToasts"; import { MenuItem } from "~/types"; -import { editDocumentUrl, newDocumentPath } from "~/utils/routeHelpers"; +import { documentEditPath, newDocumentPath } from "~/utils/routeHelpers"; type Props = { document: Document; @@ -260,7 +260,7 @@ function DocumentMenu({ { type: "route", title: t("Edit"), - to: editDocumentUrl(document), + to: documentEditPath(document), visible: !!can.update && !team.seamlessEditing, icon: , }, diff --git a/app/scenes/Collection.tsx b/app/scenes/Collection.tsx index 344b6d7de..f795eb4d3 100644 --- a/app/scenes/Collection.tsx +++ b/app/scenes/Collection.tsx @@ -34,7 +34,7 @@ import useCommandBarActions from "~/hooks/useCommandBarActions"; import useLastVisitedPath from "~/hooks/useLastVisitedPath"; import usePolicy from "~/hooks/usePolicy"; import useStores from "~/hooks/useStores"; -import { collectionUrl, updateCollectionUrl } from "~/utils/routeHelpers"; +import { collectionPath, updateCollectionPath } from "~/utils/routeHelpers"; import Actions from "./Collection/Actions"; import DropToImport from "./Collection/DropToImport"; import Empty from "./Collection/Empty"; @@ -63,7 +63,7 @@ function CollectionScene() { React.useEffect(() => { if (collection?.name) { - const canonicalUrl = updateCollectionUrl(match.url, collection); + const canonicalUrl = updateCollectionPath(match.url, collection); if (match.url !== canonicalUrl) { history.replace(canonicalUrl, history.location.state); @@ -179,24 +179,24 @@ function CollectionScene() { /> - + {t("Documents")} - + {t("Recently updated")} - + {t("Recently published")} - + {t("Least recently updated")} - + {t("A–Z")} - + - + - - + + - + - + - + { const { document, abilities } = this.props; if (abilities.update) { - this.props.history.push(editDocumentUrl(document)); + this.props.history.push(documentEditPath(document)); } }; @@ -228,7 +228,7 @@ class DocumentScene extends React.Component { if (location.pathname.endsWith("history")) { this.props.history.push(document.url); } else { - this.props.history.push(documentHistoryUrl(document)); + this.props.history.push(documentHistoryPath(document)); } }; @@ -307,7 +307,7 @@ class DocumentScene extends React.Component { this.props.history.push(savedDocument.url); this.props.ui.setActiveDocument(savedDocument); } else if (document.isNew) { - this.props.history.push(editDocumentUrl(savedDocument)); + this.props.history.push(documentEditPath(savedDocument)); this.props.ui.setActiveDocument(savedDocument); } } catch (err) { @@ -399,7 +399,7 @@ class DocumentScene extends React.Component { const canonicalUrl = shareId ? this.props.match.url - : updateDocumentUrl(this.props.match.url, document); + : updateDocumentPath(this.props.match.url, document); return ( diff --git a/app/scenes/Document/components/DocumentMeta.tsx b/app/scenes/Document/components/DocumentMeta.tsx index 71e4e282b..f535fd809 100644 --- a/app/scenes/Document/components/DocumentMeta.tsx +++ b/app/scenes/Document/components/DocumentMeta.tsx @@ -10,7 +10,7 @@ import Document from "~/models/Document"; import DocumentMeta from "~/components/DocumentMeta"; import Fade from "~/components/Fade"; import useStores from "~/hooks/useStores"; -import { documentUrl, documentInsightsUrl } from "~/utils/routeHelpers"; +import { documentPath, documentInsightsPath } from "~/utils/routeHelpers"; type Props = { /* The document to display meta data for */ @@ -32,7 +32,7 @@ function TitleDocumentMeta({ to, isDraft, document, ...rest }: Props) { const Wrapper = viewsLoadedOnMount.current ? React.Fragment : Fade; - const insightsUrl = documentInsightsUrl(document); + const insightsPath = documentInsightsPath(document); const commentsCount = comments.inDocument(document.id).length; return ( @@ -41,7 +41,9 @@ function TitleDocumentMeta({ to, isDraft, document, ...rest }: Props) {  •  {t("Viewed by")}{" "} {onlyYou @@ -56,7 +58,7 @@ function TitleDocumentMeta({ to, isDraft, document, ...rest }: Props) { <>  •  ui.toggleComments(document.id)} > diff --git a/app/scenes/Document/components/Editor.tsx b/app/scenes/Document/components/Editor.tsx index f85edbf29..22df28a38 100644 --- a/app/scenes/Document/components/Editor.tsx +++ b/app/scenes/Document/components/Editor.tsx @@ -15,8 +15,8 @@ import useMobile from "~/hooks/useMobile"; import usePolicy from "~/hooks/usePolicy"; import useStores from "~/hooks/useStores"; import { - documentHistoryUrl, - documentUrl, + documentHistoryPath, + documentPath, matchDocumentHistory, } from "~/utils/routeHelpers"; import { useDocumentContext } from "../../../components/DocumentContext"; @@ -167,8 +167,8 @@ function DocumentEditor(props: Props, ref: React.RefObject) { document={document} to={ match.path === matchDocumentHistory - ? documentUrl(document) - : documentHistoryUrl(document) + ? documentPath(document) + : documentHistoryPath(document) } rtl={ titleRef.current?.getComputedDirection() === "rtl" ? true : false diff --git a/app/scenes/Document/components/Header.tsx b/app/scenes/Document/components/Header.tsx index e5ef1d9d2..61d4cdd92 100644 --- a/app/scenes/Document/components/Header.tsx +++ b/app/scenes/Document/components/Header.tsx @@ -32,7 +32,7 @@ import NewChildDocumentMenu from "~/menus/NewChildDocumentMenu"; import TableOfContentsMenu from "~/menus/TableOfContentsMenu"; import TemplatesMenu from "~/menus/TemplatesMenu"; import { metaDisplay } from "~/utils/keyboard"; -import { newDocumentPath, editDocumentUrl } from "~/utils/routeHelpers"; +import { newDocumentPath, documentEditPath } from "~/utils/routeHelpers"; import ObservingBanner from "./ObservingBanner"; import PublicBreadcrumb from "./PublicBreadcrumb"; import ShareButton from "./ShareButton"; @@ -133,7 +133,7 @@ function DocumentHeader({