fix: Do not copy edit path from headers

chore: Rename url -> path in routeHelpers
closes #5229
This commit is contained in:
Tom Moor
2023-04-22 10:00:09 -04:00
parent 4b5680a16e
commit e2c5fda610
19 changed files with 91 additions and 80 deletions

View File

@@ -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() {
/>
<Tabs>
<Tab to={collectionUrl(collection.url)} exact>
<Tab to={collectionPath(collection.url)} exact>
{t("Documents")}
</Tab>
<Tab to={collectionUrl(collection.url, "updated")} exact>
<Tab to={collectionPath(collection.url, "updated")} exact>
{t("Recently updated")}
</Tab>
<Tab to={collectionUrl(collection.url, "published")} exact>
<Tab to={collectionPath(collection.url, "published")} exact>
{t("Recently published")}
</Tab>
<Tab to={collectionUrl(collection.url, "old")} exact>
<Tab to={collectionPath(collection.url, "old")} exact>
{t("Least recently updated")}
</Tab>
<Tab to={collectionUrl(collection.url, "alphabetical")} exact>
<Tab to={collectionPath(collection.url, "alphabetical")} exact>
{t("AZ")}
</Tab>
</Tabs>
<Switch>
<Route path={collectionUrl(collection.url, "alphabetical")}>
<Route path={collectionPath(collection.url, "alphabetical")}>
<PaginatedDocumentList
key="alphabetical"
documents={documents.alphabeticalInCollection(
@@ -208,7 +208,7 @@ function CollectionScene() {
}}
/>
</Route>
<Route path={collectionUrl(collection.url, "old")}>
<Route path={collectionPath(collection.url, "old")}>
<PaginatedDocumentList
key="old"
documents={documents.leastRecentlyUpdatedInCollection(
@@ -220,10 +220,10 @@ function CollectionScene() {
}}
/>
</Route>
<Route path={collectionUrl(collection.url, "recent")}>
<Redirect to={collectionUrl(collection.url, "published")} />
<Route path={collectionPath(collection.url, "recent")}>
<Redirect to={collectionPath(collection.url, "published")} />
</Route>
<Route path={collectionUrl(collection.url, "published")}>
<Route path={collectionPath(collection.url, "published")}>
<PaginatedDocumentList
key="published"
documents={documents.recentlyPublishedInCollection(
@@ -236,7 +236,7 @@ function CollectionScene() {
showPublished
/>
</Route>
<Route path={collectionUrl(collection.url, "updated")}>
<Route path={collectionPath(collection.url, "updated")}>
<PaginatedDocumentList
key="updated"
documents={documents.recentlyUpdatedInCollection(
@@ -248,7 +248,7 @@ function CollectionScene() {
}}
/>
</Route>
<Route path={collectionUrl(collection.url)} exact>
<Route path={collectionPath(collection.url)} exact>
<PaginatedDocumentList
documents={documents.rootInCollection(collection.id)}
fetch={documents.fetchPage}

View File

@@ -39,9 +39,9 @@ import { emojiToUrl } from "~/utils/emoji";
import { isModKey } from "~/utils/keyboard";
import {
documentHistoryUrl,
editDocumentUrl,
updateDocumentUrl,
documentHistoryPath,
documentEditPath,
updateDocumentPath,
} from "~/utils/routeHelpers";
import Container from "./Container";
import Contents from "./Contents";
@@ -211,7 +211,7 @@ class DocumentScene extends React.Component<Props> {
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<Props> {
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<Props> {
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<Props> {
const canonicalUrl = shareId
? this.props.match.url
: updateDocumentUrl(this.props.match.url, document);
: updateDocumentPath(this.props.match.url, document);
return (
<ErrorBoundary showTitle>

View File

@@ -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) {
<Wrapper>
&nbsp;&nbsp;
<Link
to={match.url === insightsUrl ? documentUrl(document) : insightsUrl}
to={
match.url === insightsPath ? documentPath(document) : insightsPath
}
>
{t("Viewed by")}{" "}
{onlyYou
@@ -56,7 +58,7 @@ function TitleDocumentMeta({ to, isDraft, document, ...rest }: Props) {
<>
&nbsp;&nbsp;
<CommentLink
to={documentUrl(document)}
to={documentPath(document)}
onClick={() => ui.toggleComments(document.id)}
>
<CommentIcon size={18} />

View File

@@ -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<any>) {
document={document}
to={
match.path === matchDocumentHistory
? documentUrl(document)
: documentHistoryUrl(document)
? documentPath(document)
: documentHistoryPath(document)
}
rtl={
titleRef.current?.getComputedDirection() === "rtl" ? true : false

View File

@@ -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({
<Button
as={Link}
icon={<EditIcon />}
to={editDocumentUrl(document)}
to={documentEditPath(document)}
neutral
>
{t("Edit")}

View File

@@ -8,7 +8,7 @@ import Empty from "~/components/Empty";
import PaginatedEventList from "~/components/PaginatedEventList";
import useKeyDown from "~/hooks/useKeyDown";
import useStores from "~/hooks/useStores";
import { documentUrl } from "~/utils/routeHelpers";
import { documentPath } from "~/utils/routeHelpers";
import Sidebar from "./SidebarLayout";
const EMPTY_ARRAY: Event[] = [];
@@ -26,7 +26,7 @@ function History() {
const onCloseHistory = () => {
if (document) {
history.push(documentUrl(document));
history.push(documentPath(document));
} else {
history.goBack();
}

View File

@@ -17,7 +17,7 @@ import Time from "~/components/Time";
import useKeyDown from "~/hooks/useKeyDown";
import useStores from "~/hooks/useStores";
import useTextSelection from "~/hooks/useTextSelection";
import { documentUrl } from "~/utils/routeHelpers";
import { documentPath } from "~/utils/routeHelpers";
import Sidebar from "./SidebarLayout";
function Insights() {
@@ -34,7 +34,7 @@ function Insights() {
const onCloseInsights = () => {
if (document) {
history.push(documentUrl(document));
history.push(documentPath(document));
}
};

View File

@@ -5,7 +5,7 @@ import Document from "~/models/Document";
import Revision from "~/models/Revision";
import { Props as EditorProps } from "~/components/Editor";
import Flex from "~/components/Flex";
import { documentUrl } from "~/utils/routeHelpers";
import { documentPath } from "~/utils/routeHelpers";
import { Meta as DocumentMeta } from "./DocumentMeta";
type Props = Omit<EditorProps, "extensions"> & {
@@ -28,7 +28,7 @@ function RevisionViewer(props: Props) {
{!shareId && (
<DocumentMeta
document={document}
to={documentUrl(document)}
to={documentPath(document)}
rtl={revision.rtl}
/>
)}

View File

@@ -8,7 +8,7 @@ import Flex from "~/components/Flex";
import Text from "~/components/Text";
import useStores from "~/hooks/useStores";
import useToasts from "~/hooks/useToasts";
import { collectionUrl, documentUrl } from "~/utils/routeHelpers";
import { collectionPath, documentPath } from "~/utils/routeHelpers";
type Props = {
document: Document;
@@ -43,14 +43,14 @@ function DocumentDelete({ document, onSubmit }: Props) {
const parent = documents.get(document.parentDocumentId);
if (parent) {
history.push(documentUrl(parent));
history.push(documentPath(parent));
onSubmit();
return;
}
}
// otherwise, redirect to the collection home
history.push(collectionUrl(collection?.url || "/"));
history.push(collectionPath(collection?.url || "/"));
}
onSubmit();

View File

@@ -9,7 +9,7 @@ import Flex from "~/components/Flex";
import PlaceholderDocument from "~/components/PlaceholderDocument";
import useStores from "~/hooks/useStores";
import useToasts from "~/hooks/useToasts";
import { editDocumentUrl } from "~/utils/routeHelpers";
import { documentEditPath } from "~/utils/routeHelpers";
function DocumentNew() {
const history = useHistory();
@@ -37,7 +37,7 @@ function DocumentNew() {
title: "",
text: "",
});
history.replace(editDocumentUrl(document), location.state);
history.replace(documentEditPath(document), location.state);
} catch (err) {
showToast(t("Couldnt create the document, try again?"), {
type: "error",