fix: Do not copy edit path from headers
chore: Rename url -> path in routeHelpers closes #5229
This commit is contained in:
@@ -37,8 +37,8 @@ import { DocumentSection } from "~/actions/sections";
|
|||||||
import env from "~/env";
|
import env from "~/env";
|
||||||
import history from "~/utils/history";
|
import history from "~/utils/history";
|
||||||
import {
|
import {
|
||||||
documentInsightsUrl,
|
documentInsightsPath,
|
||||||
documentHistoryUrl,
|
documentHistoryPath,
|
||||||
homePath,
|
homePath,
|
||||||
newDocumentPath,
|
newDocumentPath,
|
||||||
searchPath,
|
searchPath,
|
||||||
@@ -749,7 +749,7 @@ export const openDocumentHistory = createAction({
|
|||||||
if (!document) {
|
if (!document) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
history.push(documentHistoryUrl(document));
|
history.push(documentHistoryPath(document));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -770,7 +770,7 @@ export const openDocumentInsights = createAction({
|
|||||||
if (!document) {
|
if (!document) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
history.push(documentInsightsUrl(document));
|
history.push(documentInsightsPath(document));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import stores from "~/stores";
|
|||||||
import { createAction } from "~/actions";
|
import { createAction } from "~/actions";
|
||||||
import { RevisionSection } from "~/actions/sections";
|
import { RevisionSection } from "~/actions/sections";
|
||||||
import history from "~/utils/history";
|
import history from "~/utils/history";
|
||||||
import { documentHistoryUrl, matchDocumentHistory } from "~/utils/routeHelpers";
|
import {
|
||||||
|
documentHistoryPath,
|
||||||
|
matchDocumentHistory,
|
||||||
|
} from "~/utils/routeHelpers";
|
||||||
|
|
||||||
export const restoreRevision = createAction({
|
export const restoreRevision = createAction({
|
||||||
name: ({ t }) => t("Restore revision"),
|
name: ({ t }) => t("Restore revision"),
|
||||||
@@ -57,7 +60,7 @@ export const copyLinkToRevision = createAction({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${window.location.origin}${documentHistoryUrl(
|
const url = `${window.location.origin}${documentHistoryPath(
|
||||||
document,
|
document,
|
||||||
revisionId
|
revisionId
|
||||||
)}`;
|
)}`;
|
||||||
|
|||||||
@@ -9,7 +9,12 @@ import Breadcrumb from "~/components/Breadcrumb";
|
|||||||
import CollectionIcon from "~/components/Icons/CollectionIcon";
|
import CollectionIcon from "~/components/Icons/CollectionIcon";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import { MenuInternalLink } from "~/types";
|
import { MenuInternalLink } from "~/types";
|
||||||
import { collectionUrl } from "~/utils/routeHelpers";
|
import {
|
||||||
|
archivePath,
|
||||||
|
collectionPath,
|
||||||
|
templatesPath,
|
||||||
|
trashPath,
|
||||||
|
} from "~/utils/routeHelpers";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
document: Document;
|
document: Document;
|
||||||
@@ -24,7 +29,7 @@ function useCategory(document: Document): MenuInternalLink | null {
|
|||||||
type: "route",
|
type: "route",
|
||||||
icon: <TrashIcon />,
|
icon: <TrashIcon />,
|
||||||
title: t("Trash"),
|
title: t("Trash"),
|
||||||
to: "/trash",
|
to: trashPath(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +38,7 @@ function useCategory(document: Document): MenuInternalLink | null {
|
|||||||
type: "route",
|
type: "route",
|
||||||
icon: <ArchiveIcon />,
|
icon: <ArchiveIcon />,
|
||||||
title: t("Archive"),
|
title: t("Archive"),
|
||||||
to: "/archive",
|
to: archivePath(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +47,7 @@ function useCategory(document: Document): MenuInternalLink | null {
|
|||||||
type: "route",
|
type: "route",
|
||||||
icon: <ShapesIcon />,
|
icon: <ShapesIcon />,
|
||||||
title: t("Templates"),
|
title: t("Templates"),
|
||||||
to: "/templates",
|
to: templatesPath(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,14 +71,14 @@ const DocumentBreadcrumb: React.FC<Props> = ({
|
|||||||
type: "route",
|
type: "route",
|
||||||
title: collection.name,
|
title: collection.name,
|
||||||
icon: <CollectionIcon collection={collection} expanded />,
|
icon: <CollectionIcon collection={collection} expanded />,
|
||||||
to: collectionUrl(collection.url),
|
to: collectionPath(collection.url),
|
||||||
};
|
};
|
||||||
} else if (document.collectionId && !collection) {
|
} else if (document.collectionId && !collection) {
|
||||||
collectionNode = {
|
collectionNode = {
|
||||||
type: "route",
|
type: "route",
|
||||||
title: t("Deleted Collection"),
|
title: t("Deleted Collection"),
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
to: collectionUrl("deleted-collection"),
|
to: collectionPath("deleted-collection"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { useHistory } from "react-router-dom";
|
|||||||
import ConfirmationDialog from "~/components/ConfirmationDialog";
|
import ConfirmationDialog from "~/components/ConfirmationDialog";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import useToasts from "~/hooks/useToasts";
|
import useToasts from "~/hooks/useToasts";
|
||||||
import { documentUrl } from "~/utils/routeHelpers";
|
import { documentPath } from "~/utils/routeHelpers";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
documentId: string;
|
documentId: string;
|
||||||
@@ -23,7 +23,7 @@ function DocumentTemplatizeDialog({ documentId }: Props) {
|
|||||||
const handleSubmit = React.useCallback(async () => {
|
const handleSubmit = React.useCallback(async () => {
|
||||||
const template = await document?.templatize();
|
const template = await document?.templatize();
|
||||||
if (template) {
|
if (template) {
|
||||||
history.push(documentUrl(template));
|
history.push(documentPath(template));
|
||||||
showToast(t("Template created, go ahead and customize it"), {
|
showToast(t("Template created, go ahead and customize it"), {
|
||||||
type: "info",
|
type: "info",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import Time from "~/components/Time";
|
|||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import RevisionMenu from "~/menus/RevisionMenu";
|
import RevisionMenu from "~/menus/RevisionMenu";
|
||||||
import Logger from "~/utils/Logger";
|
import Logger from "~/utils/Logger";
|
||||||
import { documentHistoryUrl } from "~/utils/routeHelpers";
|
import { documentHistoryPath } from "~/utils/routeHelpers";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
document: Document;
|
document: Document;
|
||||||
@@ -62,7 +62,7 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
|||||||
icon = <EditIcon size={16} />;
|
icon = <EditIcon size={16} />;
|
||||||
meta = t("{{userName}} edited", opts);
|
meta = t("{{userName}} edited", opts);
|
||||||
to = {
|
to = {
|
||||||
pathname: documentHistoryUrl(document, event.modelId || ""),
|
pathname: documentHistoryPath(document, event.modelId || ""),
|
||||||
state: { retainScrollPosition: true },
|
state: { retainScrollPosition: true },
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
@@ -71,7 +71,7 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
|||||||
icon = <LightningIcon size={16} />;
|
icon = <LightningIcon size={16} />;
|
||||||
meta = t("Latest");
|
meta = t("Latest");
|
||||||
to = {
|
to = {
|
||||||
pathname: documentHistoryUrl(document),
|
pathname: documentHistoryPath(document),
|
||||||
state: { retainScrollPosition: true },
|
state: { retainScrollPosition: true },
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ import useRequest from "~/hooks/useRequest";
|
|||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import useToasts from "~/hooks/useToasts";
|
import useToasts from "~/hooks/useToasts";
|
||||||
import { MenuItem } from "~/types";
|
import { MenuItem } from "~/types";
|
||||||
import { editDocumentUrl, newDocumentPath } from "~/utils/routeHelpers";
|
import { documentEditPath, newDocumentPath } from "~/utils/routeHelpers";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
document: Document;
|
document: Document;
|
||||||
@@ -260,7 +260,7 @@ function DocumentMenu({
|
|||||||
{
|
{
|
||||||
type: "route",
|
type: "route",
|
||||||
title: t("Edit"),
|
title: t("Edit"),
|
||||||
to: editDocumentUrl(document),
|
to: documentEditPath(document),
|
||||||
visible: !!can.update && !team.seamlessEditing,
|
visible: !!can.update && !team.seamlessEditing,
|
||||||
icon: <EditIcon />,
|
icon: <EditIcon />,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import useCommandBarActions from "~/hooks/useCommandBarActions";
|
|||||||
import useLastVisitedPath from "~/hooks/useLastVisitedPath";
|
import useLastVisitedPath from "~/hooks/useLastVisitedPath";
|
||||||
import usePolicy from "~/hooks/usePolicy";
|
import usePolicy from "~/hooks/usePolicy";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import { collectionUrl, updateCollectionUrl } from "~/utils/routeHelpers";
|
import { collectionPath, updateCollectionPath } from "~/utils/routeHelpers";
|
||||||
import Actions from "./Collection/Actions";
|
import Actions from "./Collection/Actions";
|
||||||
import DropToImport from "./Collection/DropToImport";
|
import DropToImport from "./Collection/DropToImport";
|
||||||
import Empty from "./Collection/Empty";
|
import Empty from "./Collection/Empty";
|
||||||
@@ -63,7 +63,7 @@ function CollectionScene() {
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (collection?.name) {
|
if (collection?.name) {
|
||||||
const canonicalUrl = updateCollectionUrl(match.url, collection);
|
const canonicalUrl = updateCollectionPath(match.url, collection);
|
||||||
|
|
||||||
if (match.url !== canonicalUrl) {
|
if (match.url !== canonicalUrl) {
|
||||||
history.replace(canonicalUrl, history.location.state);
|
history.replace(canonicalUrl, history.location.state);
|
||||||
@@ -179,24 +179,24 @@ function CollectionScene() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<Tab to={collectionUrl(collection.url)} exact>
|
<Tab to={collectionPath(collection.url)} exact>
|
||||||
{t("Documents")}
|
{t("Documents")}
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab to={collectionUrl(collection.url, "updated")} exact>
|
<Tab to={collectionPath(collection.url, "updated")} exact>
|
||||||
{t("Recently updated")}
|
{t("Recently updated")}
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab to={collectionUrl(collection.url, "published")} exact>
|
<Tab to={collectionPath(collection.url, "published")} exact>
|
||||||
{t("Recently published")}
|
{t("Recently published")}
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab to={collectionUrl(collection.url, "old")} exact>
|
<Tab to={collectionPath(collection.url, "old")} exact>
|
||||||
{t("Least recently updated")}
|
{t("Least recently updated")}
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab to={collectionUrl(collection.url, "alphabetical")} exact>
|
<Tab to={collectionPath(collection.url, "alphabetical")} exact>
|
||||||
{t("A–Z")}
|
{t("A–Z")}
|
||||||
</Tab>
|
</Tab>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path={collectionUrl(collection.url, "alphabetical")}>
|
<Route path={collectionPath(collection.url, "alphabetical")}>
|
||||||
<PaginatedDocumentList
|
<PaginatedDocumentList
|
||||||
key="alphabetical"
|
key="alphabetical"
|
||||||
documents={documents.alphabeticalInCollection(
|
documents={documents.alphabeticalInCollection(
|
||||||
@@ -208,7 +208,7 @@ function CollectionScene() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path={collectionUrl(collection.url, "old")}>
|
<Route path={collectionPath(collection.url, "old")}>
|
||||||
<PaginatedDocumentList
|
<PaginatedDocumentList
|
||||||
key="old"
|
key="old"
|
||||||
documents={documents.leastRecentlyUpdatedInCollection(
|
documents={documents.leastRecentlyUpdatedInCollection(
|
||||||
@@ -220,10 +220,10 @@ function CollectionScene() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path={collectionUrl(collection.url, "recent")}>
|
<Route path={collectionPath(collection.url, "recent")}>
|
||||||
<Redirect to={collectionUrl(collection.url, "published")} />
|
<Redirect to={collectionPath(collection.url, "published")} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path={collectionUrl(collection.url, "published")}>
|
<Route path={collectionPath(collection.url, "published")}>
|
||||||
<PaginatedDocumentList
|
<PaginatedDocumentList
|
||||||
key="published"
|
key="published"
|
||||||
documents={documents.recentlyPublishedInCollection(
|
documents={documents.recentlyPublishedInCollection(
|
||||||
@@ -236,7 +236,7 @@ function CollectionScene() {
|
|||||||
showPublished
|
showPublished
|
||||||
/>
|
/>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path={collectionUrl(collection.url, "updated")}>
|
<Route path={collectionPath(collection.url, "updated")}>
|
||||||
<PaginatedDocumentList
|
<PaginatedDocumentList
|
||||||
key="updated"
|
key="updated"
|
||||||
documents={documents.recentlyUpdatedInCollection(
|
documents={documents.recentlyUpdatedInCollection(
|
||||||
@@ -248,7 +248,7 @@ function CollectionScene() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path={collectionUrl(collection.url)} exact>
|
<Route path={collectionPath(collection.url)} exact>
|
||||||
<PaginatedDocumentList
|
<PaginatedDocumentList
|
||||||
documents={documents.rootInCollection(collection.id)}
|
documents={documents.rootInCollection(collection.id)}
|
||||||
fetch={documents.fetchPage}
|
fetch={documents.fetchPage}
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ import { emojiToUrl } from "~/utils/emoji";
|
|||||||
import { isModKey } from "~/utils/keyboard";
|
import { isModKey } from "~/utils/keyboard";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
documentHistoryUrl,
|
documentHistoryPath,
|
||||||
editDocumentUrl,
|
documentEditPath,
|
||||||
updateDocumentUrl,
|
updateDocumentPath,
|
||||||
} from "~/utils/routeHelpers";
|
} from "~/utils/routeHelpers";
|
||||||
import Container from "./Container";
|
import Container from "./Container";
|
||||||
import Contents from "./Contents";
|
import Contents from "./Contents";
|
||||||
@@ -211,7 +211,7 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
const { document, abilities } = this.props;
|
const { document, abilities } = this.props;
|
||||||
|
|
||||||
if (abilities.update) {
|
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")) {
|
if (location.pathname.endsWith("history")) {
|
||||||
this.props.history.push(document.url);
|
this.props.history.push(document.url);
|
||||||
} else {
|
} 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.history.push(savedDocument.url);
|
||||||
this.props.ui.setActiveDocument(savedDocument);
|
this.props.ui.setActiveDocument(savedDocument);
|
||||||
} else if (document.isNew) {
|
} else if (document.isNew) {
|
||||||
this.props.history.push(editDocumentUrl(savedDocument));
|
this.props.history.push(documentEditPath(savedDocument));
|
||||||
this.props.ui.setActiveDocument(savedDocument);
|
this.props.ui.setActiveDocument(savedDocument);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -399,7 +399,7 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
|
|
||||||
const canonicalUrl = shareId
|
const canonicalUrl = shareId
|
||||||
? this.props.match.url
|
? this.props.match.url
|
||||||
: updateDocumentUrl(this.props.match.url, document);
|
: updateDocumentPath(this.props.match.url, document);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary showTitle>
|
<ErrorBoundary showTitle>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import Document from "~/models/Document";
|
|||||||
import DocumentMeta from "~/components/DocumentMeta";
|
import DocumentMeta from "~/components/DocumentMeta";
|
||||||
import Fade from "~/components/Fade";
|
import Fade from "~/components/Fade";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import { documentUrl, documentInsightsUrl } from "~/utils/routeHelpers";
|
import { documentPath, documentInsightsPath } from "~/utils/routeHelpers";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
/* The document to display meta data for */
|
/* 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 Wrapper = viewsLoadedOnMount.current ? React.Fragment : Fade;
|
||||||
|
|
||||||
const insightsUrl = documentInsightsUrl(document);
|
const insightsPath = documentInsightsPath(document);
|
||||||
const commentsCount = comments.inDocument(document.id).length;
|
const commentsCount = comments.inDocument(document.id).length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -41,7 +41,9 @@ function TitleDocumentMeta({ to, isDraft, document, ...rest }: Props) {
|
|||||||
<Wrapper>
|
<Wrapper>
|
||||||
•
|
•
|
||||||
<Link
|
<Link
|
||||||
to={match.url === insightsUrl ? documentUrl(document) : insightsUrl}
|
to={
|
||||||
|
match.url === insightsPath ? documentPath(document) : insightsPath
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{t("Viewed by")}{" "}
|
{t("Viewed by")}{" "}
|
||||||
{onlyYou
|
{onlyYou
|
||||||
@@ -56,7 +58,7 @@ function TitleDocumentMeta({ to, isDraft, document, ...rest }: Props) {
|
|||||||
<>
|
<>
|
||||||
•
|
•
|
||||||
<CommentLink
|
<CommentLink
|
||||||
to={documentUrl(document)}
|
to={documentPath(document)}
|
||||||
onClick={() => ui.toggleComments(document.id)}
|
onClick={() => ui.toggleComments(document.id)}
|
||||||
>
|
>
|
||||||
<CommentIcon size={18} />
|
<CommentIcon size={18} />
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import useMobile from "~/hooks/useMobile";
|
|||||||
import usePolicy from "~/hooks/usePolicy";
|
import usePolicy from "~/hooks/usePolicy";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import {
|
import {
|
||||||
documentHistoryUrl,
|
documentHistoryPath,
|
||||||
documentUrl,
|
documentPath,
|
||||||
matchDocumentHistory,
|
matchDocumentHistory,
|
||||||
} from "~/utils/routeHelpers";
|
} from "~/utils/routeHelpers";
|
||||||
import { useDocumentContext } from "../../../components/DocumentContext";
|
import { useDocumentContext } from "../../../components/DocumentContext";
|
||||||
@@ -167,8 +167,8 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
|||||||
document={document}
|
document={document}
|
||||||
to={
|
to={
|
||||||
match.path === matchDocumentHistory
|
match.path === matchDocumentHistory
|
||||||
? documentUrl(document)
|
? documentPath(document)
|
||||||
: documentHistoryUrl(document)
|
: documentHistoryPath(document)
|
||||||
}
|
}
|
||||||
rtl={
|
rtl={
|
||||||
titleRef.current?.getComputedDirection() === "rtl" ? true : false
|
titleRef.current?.getComputedDirection() === "rtl" ? true : false
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import NewChildDocumentMenu from "~/menus/NewChildDocumentMenu";
|
|||||||
import TableOfContentsMenu from "~/menus/TableOfContentsMenu";
|
import TableOfContentsMenu from "~/menus/TableOfContentsMenu";
|
||||||
import TemplatesMenu from "~/menus/TemplatesMenu";
|
import TemplatesMenu from "~/menus/TemplatesMenu";
|
||||||
import { metaDisplay } from "~/utils/keyboard";
|
import { metaDisplay } from "~/utils/keyboard";
|
||||||
import { newDocumentPath, editDocumentUrl } from "~/utils/routeHelpers";
|
import { newDocumentPath, documentEditPath } from "~/utils/routeHelpers";
|
||||||
import ObservingBanner from "./ObservingBanner";
|
import ObservingBanner from "./ObservingBanner";
|
||||||
import PublicBreadcrumb from "./PublicBreadcrumb";
|
import PublicBreadcrumb from "./PublicBreadcrumb";
|
||||||
import ShareButton from "./ShareButton";
|
import ShareButton from "./ShareButton";
|
||||||
@@ -133,7 +133,7 @@ function DocumentHeader({
|
|||||||
<Button
|
<Button
|
||||||
as={Link}
|
as={Link}
|
||||||
icon={<EditIcon />}
|
icon={<EditIcon />}
|
||||||
to={editDocumentUrl(document)}
|
to={documentEditPath(document)}
|
||||||
neutral
|
neutral
|
||||||
>
|
>
|
||||||
{t("Edit")}
|
{t("Edit")}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import Empty from "~/components/Empty";
|
|||||||
import PaginatedEventList from "~/components/PaginatedEventList";
|
import PaginatedEventList from "~/components/PaginatedEventList";
|
||||||
import useKeyDown from "~/hooks/useKeyDown";
|
import useKeyDown from "~/hooks/useKeyDown";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import { documentUrl } from "~/utils/routeHelpers";
|
import { documentPath } from "~/utils/routeHelpers";
|
||||||
import Sidebar from "./SidebarLayout";
|
import Sidebar from "./SidebarLayout";
|
||||||
|
|
||||||
const EMPTY_ARRAY: Event[] = [];
|
const EMPTY_ARRAY: Event[] = [];
|
||||||
@@ -26,7 +26,7 @@ function History() {
|
|||||||
|
|
||||||
const onCloseHistory = () => {
|
const onCloseHistory = () => {
|
||||||
if (document) {
|
if (document) {
|
||||||
history.push(documentUrl(document));
|
history.push(documentPath(document));
|
||||||
} else {
|
} else {
|
||||||
history.goBack();
|
history.goBack();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import Time from "~/components/Time";
|
|||||||
import useKeyDown from "~/hooks/useKeyDown";
|
import useKeyDown from "~/hooks/useKeyDown";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import useTextSelection from "~/hooks/useTextSelection";
|
import useTextSelection from "~/hooks/useTextSelection";
|
||||||
import { documentUrl } from "~/utils/routeHelpers";
|
import { documentPath } from "~/utils/routeHelpers";
|
||||||
import Sidebar from "./SidebarLayout";
|
import Sidebar from "./SidebarLayout";
|
||||||
|
|
||||||
function Insights() {
|
function Insights() {
|
||||||
@@ -34,7 +34,7 @@ function Insights() {
|
|||||||
|
|
||||||
const onCloseInsights = () => {
|
const onCloseInsights = () => {
|
||||||
if (document) {
|
if (document) {
|
||||||
history.push(documentUrl(document));
|
history.push(documentPath(document));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import Document from "~/models/Document";
|
|||||||
import Revision from "~/models/Revision";
|
import Revision from "~/models/Revision";
|
||||||
import { Props as EditorProps } from "~/components/Editor";
|
import { Props as EditorProps } from "~/components/Editor";
|
||||||
import Flex from "~/components/Flex";
|
import Flex from "~/components/Flex";
|
||||||
import { documentUrl } from "~/utils/routeHelpers";
|
import { documentPath } from "~/utils/routeHelpers";
|
||||||
import { Meta as DocumentMeta } from "./DocumentMeta";
|
import { Meta as DocumentMeta } from "./DocumentMeta";
|
||||||
|
|
||||||
type Props = Omit<EditorProps, "extensions"> & {
|
type Props = Omit<EditorProps, "extensions"> & {
|
||||||
@@ -28,7 +28,7 @@ function RevisionViewer(props: Props) {
|
|||||||
{!shareId && (
|
{!shareId && (
|
||||||
<DocumentMeta
|
<DocumentMeta
|
||||||
document={document}
|
document={document}
|
||||||
to={documentUrl(document)}
|
to={documentPath(document)}
|
||||||
rtl={revision.rtl}
|
rtl={revision.rtl}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import Flex from "~/components/Flex";
|
|||||||
import Text from "~/components/Text";
|
import Text from "~/components/Text";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import useToasts from "~/hooks/useToasts";
|
import useToasts from "~/hooks/useToasts";
|
||||||
import { collectionUrl, documentUrl } from "~/utils/routeHelpers";
|
import { collectionPath, documentPath } from "~/utils/routeHelpers";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
document: Document;
|
document: Document;
|
||||||
@@ -43,14 +43,14 @@ function DocumentDelete({ document, onSubmit }: Props) {
|
|||||||
const parent = documents.get(document.parentDocumentId);
|
const parent = documents.get(document.parentDocumentId);
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
history.push(documentUrl(parent));
|
history.push(documentPath(parent));
|
||||||
onSubmit();
|
onSubmit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, redirect to the collection home
|
// otherwise, redirect to the collection home
|
||||||
history.push(collectionUrl(collection?.url || "/"));
|
history.push(collectionPath(collection?.url || "/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit();
|
onSubmit();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import Flex from "~/components/Flex";
|
|||||||
import PlaceholderDocument from "~/components/PlaceholderDocument";
|
import PlaceholderDocument from "~/components/PlaceholderDocument";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import useToasts from "~/hooks/useToasts";
|
import useToasts from "~/hooks/useToasts";
|
||||||
import { editDocumentUrl } from "~/utils/routeHelpers";
|
import { documentEditPath } from "~/utils/routeHelpers";
|
||||||
|
|
||||||
function DocumentNew() {
|
function DocumentNew() {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -37,7 +37,7 @@ function DocumentNew() {
|
|||||||
title: "",
|
title: "",
|
||||||
text: "",
|
text: "",
|
||||||
});
|
});
|
||||||
history.replace(editDocumentUrl(document), location.state);
|
history.replace(documentEditPath(document), location.state);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showToast(t("Couldn’t create the document, try again?"), {
|
showToast(t("Couldn’t create the document, try again?"), {
|
||||||
type: "error",
|
type: "error",
|
||||||
|
|||||||
@@ -199,8 +199,10 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
|||||||
return this.pathsToDocuments.find((path) => path.id === documentId);
|
return this.pathsToDocuments.find((path) => path.id === documentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
titleForDocument(documentUrl: string): string | undefined {
|
titleForDocument(documentPath: string): string | undefined {
|
||||||
const path = this.pathsToDocuments.find((path) => path.url === documentUrl);
|
const path = this.pathsToDocuments.find(
|
||||||
|
(path) => path.url === documentPath
|
||||||
|
);
|
||||||
if (path) {
|
if (path) {
|
||||||
return path.title;
|
return path.title;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,17 +44,17 @@ export function groupSettingsPath(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function commentPath(document: Document, comment: Comment): string {
|
export function commentPath(document: Document, comment: Comment): string {
|
||||||
return `${documentUrl(document)}?commentId=${comment.id}`;
|
return `${documentPath(document)}?commentId=${comment.id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function collectionUrl(url: string, section?: string): string {
|
export function collectionPath(url: string, section?: string): string {
|
||||||
if (section) {
|
if (section) {
|
||||||
return `${url}/${section}`;
|
return `${url}/${section}`;
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateCollectionUrl(
|
export function updateCollectionPath(
|
||||||
oldUrl: string,
|
oldUrl: string,
|
||||||
collection: Collection
|
collection: Collection
|
||||||
): string {
|
): string {
|
||||||
@@ -65,19 +65,22 @@ export function updateCollectionUrl(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function documentUrl(doc: Document): string {
|
export function documentPath(doc: Document): string {
|
||||||
return doc.url;
|
return doc.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function editDocumentUrl(doc: Document): string {
|
export function documentEditPath(doc: Document): string {
|
||||||
return `${doc.url}/edit`;
|
return `${doc.url}/edit`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function documentInsightsUrl(doc: Document): string {
|
export function documentInsightsPath(doc: Document): string {
|
||||||
return `${doc.url}/insights`;
|
return `${doc.url}/insights`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function documentHistoryUrl(doc: Document, revisionId?: string): string {
|
export function documentHistoryPath(
|
||||||
|
doc: Document,
|
||||||
|
revisionId?: string
|
||||||
|
): string {
|
||||||
let base = `${doc.url}/history`;
|
let base = `${doc.url}/history`;
|
||||||
if (revisionId) {
|
if (revisionId) {
|
||||||
base += `/${revisionId}`;
|
base += `/${revisionId}`;
|
||||||
@@ -89,7 +92,7 @@ export function documentHistoryUrl(doc: Document, revisionId?: string): string {
|
|||||||
* Replace full url's document part with the new one in case
|
* Replace full url's document part with the new one in case
|
||||||
* the document slug has been updated
|
* the document slug has been updated
|
||||||
*/
|
*/
|
||||||
export function updateDocumentUrl(oldUrl: string, document: Document): string {
|
export function updateDocumentPath(oldUrl: string, document: Document): string {
|
||||||
// Update url to match the current one
|
// Update url to match the current one
|
||||||
return oldUrl.replace(
|
return oldUrl.replace(
|
||||||
new RegExp("/doc/([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})"),
|
new RegExp("/doc/([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})"),
|
||||||
@@ -132,10 +135,6 @@ export function sharedDocumentPath(shareId: string, docPath?: string) {
|
|||||||
return docPath ? `/s/${shareId}${docPath}` : `/s/${shareId}`;
|
return docPath ? `/s/${shareId}${docPath}` : `/s/${shareId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function notFoundUrl(): string {
|
|
||||||
return "/404";
|
|
||||||
}
|
|
||||||
|
|
||||||
export function urlify(path: string): string {
|
export function urlify(path: string): string {
|
||||||
return `${window.location.host}${path}`;
|
return `${window.location.host}${path}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,9 +58,7 @@ export default class Heading extends Node {
|
|||||||
anchor.innerText = "#";
|
anchor.innerText = "#";
|
||||||
anchor.type = "button";
|
anchor.type = "button";
|
||||||
anchor.className = "heading-anchor";
|
anchor.className = "heading-anchor";
|
||||||
anchor.addEventListener("click", (event) =>
|
anchor.addEventListener("click", this.handleCopyLink);
|
||||||
this.handleCopyLink(event)
|
|
||||||
);
|
|
||||||
|
|
||||||
fold = document.createElement("button");
|
fold = document.createElement("button");
|
||||||
fold.innerText = "";
|
fold.innerText = "";
|
||||||
@@ -181,8 +179,10 @@ export default class Heading extends Node {
|
|||||||
|
|
||||||
// the existing url might contain a hash already, lets make sure to remove
|
// the existing url might contain a hash already, lets make sure to remove
|
||||||
// that rather than appending another one.
|
// that rather than appending another one.
|
||||||
const urlWithoutHash = window.location.href.split("#")[0];
|
const normalizedUrl = window.location.href
|
||||||
copy(urlWithoutHash + hash);
|
.split("#")[0]
|
||||||
|
.replace("/edit", "");
|
||||||
|
copy(normalizedUrl + hash);
|
||||||
|
|
||||||
this.options.onShowToast(this.options.dictionary.linkCopied);
|
this.options.onShowToast(this.options.dictionary.linkCopied);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user