mirror of
https://github.com/outline/outline.git
synced 2026-11-26 07:33:19 +03:00
feat: Show a single new document action outside the sidebar
This commit is contained in:
9 files changed
+58
-28
No files matched your search
@@ -447,14 +447,24 @@ export const createNewDocument = createActionWithChildren({
|
||||
children: [createDocumentBefore, createDocumentAfter, createNestedDocument],
|
||||
});
|
||||
|
||||
export const createNewDocumentInAlphabeticalCollection =
|
||||
createInternalLinkAction({
|
||||
/**
|
||||
* Creates the action that opens a new document nested inside the active
|
||||
* document.
|
||||
*
|
||||
* @param visible - additional visibility check for the action.
|
||||
* @returns the action.
|
||||
*/
|
||||
function newNestedDocumentAction(
|
||||
visible: (context: ActionContext) => boolean = () => true
|
||||
) {
|
||||
return createInternalLinkAction({
|
||||
name: ({ t }) => t("New document"),
|
||||
analyticsName: "New document",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <NewDocumentIcon />,
|
||||
keywords: "create",
|
||||
visible: ({ currentTeamId, activeDocumentId, stores }) => {
|
||||
visible: (context) => {
|
||||
const { currentTeamId, activeDocumentId, stores } = context;
|
||||
if (!activeDocumentId || !currentTeamId) {
|
||||
return false;
|
||||
}
|
||||
@@ -464,7 +474,7 @@ export const createNewDocumentInAlphabeticalCollection =
|
||||
if (!stores.policies.abilities(activeDocumentId).createChildDocument) {
|
||||
return false;
|
||||
}
|
||||
return isAlphabeticallySorted(stores, activeDocumentId);
|
||||
return visible(context);
|
||||
},
|
||||
to: ({ activeDocumentId, sidebarContext }) => {
|
||||
const [pathname, search] =
|
||||
@@ -477,6 +487,16 @@ export const createNewDocumentInAlphabeticalCollection =
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export const createNewDocumentInAlphabeticalCollection =
|
||||
newNestedDocumentAction(
|
||||
({ activeDocumentId, stores }) =>
|
||||
!!activeDocumentId && isAlphabeticallySorted(stores, activeDocumentId)
|
||||
);
|
||||
|
||||
/** A single action to create a nested document, for menus outside the sidebar. */
|
||||
export const createNewNestedDocument = newNestedDocumentAction();
|
||||
|
||||
export const starDocument = createAction({
|
||||
name: ({ t }) => t("Star"),
|
||||
|
||||
@@ -108,13 +108,13 @@ const CollectionLink: React.FC<Props> = ({
|
||||
const contextMenuAction = useCollectionMenuAction({
|
||||
collectionId: collection.id,
|
||||
onRename: handleRename,
|
||||
showLinkActions: true,
|
||||
isSidebar: true,
|
||||
});
|
||||
|
||||
const menu = !isDraggingAnyCollection ? (
|
||||
<CollectionMenu
|
||||
collection={collection}
|
||||
showLinkActions
|
||||
isSidebar
|
||||
onRename={handleRename}
|
||||
onOpen={handleMenuOpen}
|
||||
onClose={handleMenuClose}
|
||||
|
||||
@@ -248,13 +248,13 @@ const DocumentLink = observer(function DocumentLink({
|
||||
const contextMenuAction = useDocumentMenuAction({
|
||||
documentId: node.id,
|
||||
onRename: handleRename,
|
||||
showLinkActions: true,
|
||||
isSidebar: true,
|
||||
});
|
||||
|
||||
const menu = document ? (
|
||||
<DocumentMenu
|
||||
document={document}
|
||||
showLinkActions
|
||||
isSidebar
|
||||
onRename={handleRename}
|
||||
onOpen={handleMenuOpen}
|
||||
onClose={handleMenuClose}
|
||||
|
||||
@@ -265,6 +265,7 @@ function SharedWithMeLink({ membership, depth = 0 }: Props) {
|
||||
const menu = !isDragging ? (
|
||||
<DocumentMenu
|
||||
document={document}
|
||||
isSidebar
|
||||
onOpen={handleMenuOpen}
|
||||
onClose={handleMenuClose}
|
||||
/>
|
||||
|
||||
@@ -186,6 +186,7 @@ const StarredDocumentLink = observer(function StarredDocumentLink({
|
||||
const contextMenuAction = useDocumentMenuAction({
|
||||
documentId: document.id,
|
||||
onRename: handleRename,
|
||||
isSidebar: true,
|
||||
});
|
||||
|
||||
const isActive = React.useCallback(
|
||||
@@ -206,6 +207,7 @@ const StarredDocumentLink = observer(function StarredDocumentLink({
|
||||
const menu = (
|
||||
<DocumentMenu
|
||||
document={document}
|
||||
isSidebar
|
||||
onRename={handleRename}
|
||||
onOpen={handleMenuOpen}
|
||||
onClose={handleMenuClose}
|
||||
@@ -329,11 +331,13 @@ const StarredCollectionLink = observer(function StarredCollectionLink({
|
||||
const contextMenuAction = useCollectionMenuAction({
|
||||
collectionId: collection.id,
|
||||
onRename: handleRename,
|
||||
isSidebar: true,
|
||||
});
|
||||
|
||||
const menu = !isDraggingAnyStar ? (
|
||||
<CollectionMenu
|
||||
collection={collection}
|
||||
isSidebar
|
||||
onRename={handleRename}
|
||||
onOpen={handleMenuOpen}
|
||||
onClose={handleMenuClose}
|
||||
|
||||
@@ -29,20 +29,20 @@ type Props = {
|
||||
collectionId: string;
|
||||
/** Invoked when the "Rename" menu item is clicked */
|
||||
onRename?: () => void;
|
||||
/** Whether to include the action that adds a link, used in the sidebar */
|
||||
showLinkActions?: boolean;
|
||||
/** Whether the menu is shown in the sidebar, where links can be added */
|
||||
isSidebar?: boolean;
|
||||
};
|
||||
|
||||
export function useCollectionMenuAction({
|
||||
collectionId,
|
||||
onRename,
|
||||
showLinkActions = false,
|
||||
isSidebar = false,
|
||||
}: Props) {
|
||||
const actions = useMemo(
|
||||
() => [
|
||||
// Actions that add to the tree of the collection, not change it.
|
||||
createDocument,
|
||||
...(showLinkActions ? [addLinkToCollection] : []),
|
||||
...(isSidebar ? [addLinkToCollection] : []),
|
||||
importDocument,
|
||||
ActionSeparator,
|
||||
restoreCollection,
|
||||
@@ -68,7 +68,7 @@ export function useCollectionMenuAction({
|
||||
ActionSeparator,
|
||||
deleteCollection,
|
||||
],
|
||||
[collectionId, onRename, showLinkActions]
|
||||
[collectionId, onRename, isSidebar]
|
||||
);
|
||||
|
||||
return useMenuAction(actions);
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
shareDocument,
|
||||
createNewDocument,
|
||||
createNewDocumentInAlphabeticalCollection,
|
||||
createNewNestedDocument,
|
||||
importDocument,
|
||||
createTemplateFromDocument,
|
||||
duplicateDocument,
|
||||
@@ -54,8 +55,8 @@ type Props = {
|
||||
onRename?: () => void;
|
||||
/** Callback when a template is selected to apply its content to the document */
|
||||
onSelectTemplate?: (template: Template) => void;
|
||||
/** Whether to include the actions that add links around the document, used in the sidebar */
|
||||
showLinkActions?: boolean;
|
||||
/** Whether the menu is shown in the sidebar, where items can be added around the document */
|
||||
isSidebar?: boolean;
|
||||
};
|
||||
|
||||
export function useDocumentMenuAction({
|
||||
@@ -64,7 +65,7 @@ export function useDocumentMenuAction({
|
||||
onFindAndReplace,
|
||||
onRename,
|
||||
onSelectTemplate,
|
||||
showLinkActions = false,
|
||||
isSidebar = false,
|
||||
}: Props) {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useMobile();
|
||||
@@ -78,9 +79,13 @@ export function useDocumentMenuAction({
|
||||
() =>
|
||||
createRootMenuAction([
|
||||
// Actions that add to the tree around the document, not change it.
|
||||
createNewDocument,
|
||||
createNewDocumentInAlphabeticalCollection,
|
||||
...(showLinkActions ? [addLinkToDocument] : []),
|
||||
...(isSidebar
|
||||
? [
|
||||
createNewDocument,
|
||||
createNewDocumentInAlphabeticalCollection,
|
||||
addLinkToDocument,
|
||||
]
|
||||
: [createNewNestedDocument]),
|
||||
importDocument,
|
||||
ActionSeparator,
|
||||
restoreDocument,
|
||||
@@ -132,7 +137,7 @@ export function useDocumentMenuAction({
|
||||
t,
|
||||
isMobile,
|
||||
isViewing,
|
||||
showLinkActions,
|
||||
isSidebar,
|
||||
templateMenuActions,
|
||||
documentId,
|
||||
onFindAndReplace,
|
||||
|
||||
@@ -17,8 +17,8 @@ type Props = {
|
||||
onRename?: () => void;
|
||||
onOpen?: () => void;
|
||||
onClose?: () => void;
|
||||
/** Whether to include the action that adds a link, used in the sidebar */
|
||||
showLinkActions?: boolean;
|
||||
/** Whether the menu is shown in the sidebar, where links can be added */
|
||||
isSidebar?: boolean;
|
||||
};
|
||||
|
||||
function CollectionMenu({
|
||||
@@ -28,7 +28,7 @@ function CollectionMenu({
|
||||
onRename,
|
||||
onOpen,
|
||||
onClose,
|
||||
showLinkActions,
|
||||
isSidebar,
|
||||
}: Props) {
|
||||
const { subscriptions } = useStores();
|
||||
const { t } = useTranslation();
|
||||
@@ -53,7 +53,7 @@ function CollectionMenu({
|
||||
const rootAction = useCollectionMenuAction({
|
||||
collectionId: collection.id,
|
||||
onRename,
|
||||
showLinkActions,
|
||||
isSidebar,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -47,8 +47,8 @@ type Props = {
|
||||
onOpen?: () => void;
|
||||
/** Invoked when menu is closed */
|
||||
onClose?: () => void;
|
||||
/** Whether to include the actions that add links around the document, used in the sidebar */
|
||||
showLinkActions?: boolean;
|
||||
/** Whether the menu is shown in the sidebar, where items can be added around the document */
|
||||
isSidebar?: boolean;
|
||||
};
|
||||
|
||||
function DocumentMenu({
|
||||
@@ -62,7 +62,7 @@ function DocumentMenu({
|
||||
onOpen,
|
||||
onClose,
|
||||
onFindAndReplace,
|
||||
showLinkActions,
|
||||
isSidebar,
|
||||
}: Props) {
|
||||
const { t } = useTranslation();
|
||||
const user = useCurrentUser();
|
||||
@@ -133,7 +133,7 @@ function DocumentMenu({
|
||||
const rootAction = useDocumentMenuAction({
|
||||
documentId: document.id,
|
||||
isViewing: showDisplayOptions,
|
||||
showLinkActions,
|
||||
isSidebar,
|
||||
onFindAndReplace,
|
||||
onRename,
|
||||
onSelectTemplate,
|
||||
|
||||
Reference in new issue
Block a user