chore: Deprecate collection.url on client

This commit is contained in:
Tom Moor
2024-01-31 20:08:01 -05:00
parent 4800b60825
commit 7417514e7c
11 changed files with 32 additions and 24 deletions

View File

@@ -34,11 +34,11 @@ export const openCollection = createAction({
return collections.map((collection) => ({
// Note: using url which includes the slug rather than id here to bust
// cache if the collection is renamed
id: collection.url,
id: collection.path,
name: collection.name,
icon: <ColorCollectionIcon collection={collection} />,
section: CollectionSection,
perform: () => history.push(collection.url),
perform: () => history.push(collection.path),
}));
},
});

View File

@@ -79,7 +79,7 @@ const DocumentBreadcrumb: React.FC<Props> = ({
type: "route",
title: collection.name,
icon: <CollectionIcon collection={collection} expanded />,
to: collectionPath(collection.url),
to: collectionPath(collection.path),
};
} else if (document.isCollectionDeleted) {
collectionNode = {

View File

@@ -54,7 +54,7 @@ const CollectionLink: React.FC<Props> = ({
await collection.save({
name,
});
history.replace(collection.url, history.location.state);
history.replace(collection.path, history.location.state);
},
[collection, history]
);
@@ -133,7 +133,7 @@ const CollectionLink: React.FC<Props> = ({
<DropToImport collectionId={collection.id}>
<SidebarLink
to={{
pathname: collection.url,
pathname: collection.path,
state: { starred: inStarredSection },
}}
expanded={expanded}

View File

@@ -65,7 +65,7 @@ export default function useCollectionTrees(): NavigationNode[] {
const collectionNode: NavigationNode = {
id: collection.id,
title: collection.name,
url: collection.url,
url: collection.path,
type: NavigationNodeType.Collection,
children: collection.documents
? sortNavigationNodes(collection.documents, collection.sort, true)

View File

@@ -65,6 +65,9 @@ export default class Collection extends ParanoidModel {
@observable
documents?: NavigationNode[];
/**
* @deprecated Use path instead.
*/
@observable
url: string;
@@ -139,6 +142,11 @@ export default class Collection extends ParanoidModel {
return (this.name ? this.name[0] : "?").toUpperCase();
}
@computed
get path() {
return this.url;
}
fetchDocuments = async (options?: { force: boolean }) => {
if (this.isFetching) {
return;

View File

@@ -166,7 +166,7 @@ class Notification extends Model {
const collection = this.collectionId
? this.store.rootStore.collections.get(this.collectionId)
: undefined;
return collection ? collectionPath(collection.url) : "";
return collection ? collectionPath(collection.path) : "";
}
case NotificationEventType.AddUserToDocument:
case NotificationEventType.MentionedInDocument: {

View File

@@ -179,27 +179,27 @@ function CollectionScene() {
<Documents>
<Tabs>
<Tab to={collectionPath(collection.url)} exact>
<Tab to={collectionPath(collection.path)} exact>
{t("Documents")}
</Tab>
<Tab to={collectionPath(collection.url, "updated")} exact>
<Tab to={collectionPath(collection.path, "updated")} exact>
{t("Recently updated")}
</Tab>
<Tab to={collectionPath(collection.url, "published")} exact>
<Tab to={collectionPath(collection.path, "published")} exact>
{t("Recently published")}
</Tab>
<Tab to={collectionPath(collection.url, "old")} exact>
<Tab to={collectionPath(collection.path, "old")} exact>
{t("Least recently updated")}
</Tab>
<Tab
to={collectionPath(collection.url, "alphabetical")}
to={collectionPath(collection.path, "alphabetical")}
exact
>
{t("AZ")}
</Tab>
</Tabs>
<Switch>
<Route path={collectionPath(collection.url, "alphabetical")}>
<Route path={collectionPath(collection.path, "alphabetical")}>
<PaginatedDocumentList
key="alphabetical"
documents={documents.alphabeticalInCollection(
@@ -211,7 +211,7 @@ function CollectionScene() {
}}
/>
</Route>
<Route path={collectionPath(collection.url, "old")}>
<Route path={collectionPath(collection.path, "old")}>
<PaginatedDocumentList
key="old"
documents={documents.leastRecentlyUpdatedInCollection(
@@ -223,12 +223,12 @@ function CollectionScene() {
}}
/>
</Route>
<Route path={collectionPath(collection.url, "recent")}>
<Route path={collectionPath(collection.path, "recent")}>
<Redirect
to={collectionPath(collection.url, "published")}
to={collectionPath(collection.path, "published")}
/>
</Route>
<Route path={collectionPath(collection.url, "published")}>
<Route path={collectionPath(collection.path, "published")}>
<PaginatedDocumentList
key="published"
documents={documents.recentlyPublishedInCollection(
@@ -241,7 +241,7 @@ function CollectionScene() {
showPublished
/>
</Route>
<Route path={collectionPath(collection.url, "updated")}>
<Route path={collectionPath(collection.path, "updated")}>
<PaginatedDocumentList
key="updated"
documents={documents.recentlyUpdatedInCollection(
@@ -253,7 +253,7 @@ function CollectionScene() {
}}
/>
</Route>
<Route path={collectionPath(collection.url)} exact>
<Route path={collectionPath(collection.path)} exact>
<PaginatedDocumentList
documents={documents.rootInCollection(collection.id)}
fetch={documents.fetchPage}

View File

@@ -65,7 +65,7 @@ class CollectionNew extends React.Component<Props> {
try {
await collection.save();
this.props.onSubmit();
history.push(collection.url);
history.push(collection.path);
} catch (err) {
toast.error(err.message);
} finally {

View File

@@ -51,7 +51,7 @@ function DocumentDelete({ document, onSubmit }: Props) {
}
// otherwise, redirect to the collection home
history.push(collectionPath(collection?.url || "/"));
history.push(collectionPath(collection?.path || "/"));
}
onSubmit();

View File

@@ -121,13 +121,13 @@ export default class CollectionsStore extends Store<Collection> {
if (this.isLoaded) {
this.data.forEach((collection) => {
const { id, name, url } = collection;
const { id, name, path } = collection;
const node = {
type: DocumentPathItemType.Collection,
id,
collectionId: id,
title: name,
url,
url: path,
};
results.push([node]);

View File

@@ -42,7 +42,7 @@ export function updateCollectionPath(
// Update url to match the current one
return oldUrl.replace(
new RegExp("/collection/[0-9a-zA-Z-_~]*"),
collection.url
collection.path
);
}