* Split permissions for reading documents from updating collection * fix: Admins should have collection read permission, tests * tsc * Add admin option to permission selector * Combine publish and create permissions, update -> createDocuments where appropriate * Plural -> singular * wip * Quick version of collection structure loading, will revisit * Remove documentIds method * stash * fixing tests to account for admin creation * Add self-hosted migration * fix: Allow groups to have admin permission * Prefetch collection documents * fix: Document explorer (move/publish) not working with async documents * fix: Cannot re-parent document to collection by drag and drop * fix: Cannot drag to import into collection item without admin permission * Remove unused isEditor getter
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import * as React from "react";
|
|
import { sortNavigationNodes } from "@shared/utils/collections";
|
|
import Collection from "~/models/Collection";
|
|
import Document from "~/models/Document";
|
|
|
|
export default function useCollectionDocuments(
|
|
collection: Collection | undefined,
|
|
activeDocument: Document | undefined
|
|
) {
|
|
return React.useMemo(() => {
|
|
if (!collection?.sortedDocuments) {
|
|
return undefined;
|
|
}
|
|
|
|
const insertDraftDocument =
|
|
activeDocument?.isActive &&
|
|
activeDocument?.isDraft &&
|
|
activeDocument?.collectionId === collection.id &&
|
|
!activeDocument?.parentDocumentId;
|
|
|
|
return insertDraftDocument
|
|
? sortNavigationNodes(
|
|
[activeDocument.asNavigationNode, ...collection.sortedDocuments],
|
|
collection.sort,
|
|
false
|
|
)
|
|
: collection.sortedDocuments;
|
|
}, [
|
|
activeDocument?.isActive,
|
|
activeDocument?.isDraft,
|
|
activeDocument?.collectionId,
|
|
activeDocument?.parentDocumentId,
|
|
activeDocument?.asNavigationNode,
|
|
collection,
|
|
collection?.sortedDocuments,
|
|
collection?.id,
|
|
collection?.sort,
|
|
]);
|
|
}
|