chore: Combine 'pin' menu items into submenu
fix: Submenu should not appear when all items are not visible
This commit is contained in:
@@ -150,10 +150,11 @@ export const duplicateDocument = createAction({
|
|||||||
* Pin a document to a collection. Pinned documents will be displayed at the top
|
* Pin a document to a collection. Pinned documents will be displayed at the top
|
||||||
* of the collection for all collection members to see.
|
* of the collection for all collection members to see.
|
||||||
*/
|
*/
|
||||||
export const pinDocument = createAction({
|
export const pinDocumentToCollection = createAction({
|
||||||
name: ({ t }) => t("Pin to collection"),
|
name: ({ t }) => t("Pin to collection"),
|
||||||
section: DocumentSection,
|
section: DocumentSection,
|
||||||
icon: <PinIcon />,
|
icon: <PinIcon />,
|
||||||
|
iconInContextMenu: false,
|
||||||
visible: ({ activeCollectionId, activeDocumentId, stores }) => {
|
visible: ({ activeCollectionId, activeDocumentId, stores }) => {
|
||||||
if (!activeDocumentId || !activeCollectionId) {
|
if (!activeDocumentId || !activeCollectionId) {
|
||||||
return false;
|
return false;
|
||||||
@@ -188,6 +189,7 @@ export const pinDocumentToHome = createAction({
|
|||||||
name: ({ t }) => t("Pin to home"),
|
name: ({ t }) => t("Pin to home"),
|
||||||
section: DocumentSection,
|
section: DocumentSection,
|
||||||
icon: <PinIcon />,
|
icon: <PinIcon />,
|
||||||
|
iconInContextMenu: false,
|
||||||
visible: ({ activeDocumentId, currentTeamId, stores }) => {
|
visible: ({ activeDocumentId, currentTeamId, stores }) => {
|
||||||
if (!currentTeamId || !activeDocumentId) {
|
if (!currentTeamId || !activeDocumentId) {
|
||||||
return false;
|
return false;
|
||||||
@@ -214,6 +216,13 @@ export const pinDocumentToHome = createAction({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const pinDocument = createAction({
|
||||||
|
name: ({ t }) => t("Pin"),
|
||||||
|
section: DocumentSection,
|
||||||
|
icon: <PinIcon />,
|
||||||
|
children: [pinDocumentToCollection, pinDocumentToHome],
|
||||||
|
});
|
||||||
|
|
||||||
export const printDocument = createAction({
|
export const printDocument = createAction({
|
||||||
name: ({ t, isContextMenu }) =>
|
name: ({ t, isContextMenu }) =>
|
||||||
isContextMenu ? t("Print") : t("Print document"),
|
isContextMenu ? t("Print") : t("Print document"),
|
||||||
@@ -319,6 +328,6 @@ export const rootDocumentActions = [
|
|||||||
unstarDocument,
|
unstarDocument,
|
||||||
duplicateDocument,
|
duplicateDocument,
|
||||||
printDocument,
|
printDocument,
|
||||||
pinDocument,
|
pinDocumentToCollection,
|
||||||
pinDocumentToHome,
|
pinDocumentToHome,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -41,14 +41,17 @@ export function actionToMenuItem(
|
|||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
if (resolvedChildren) {
|
if (resolvedChildren) {
|
||||||
|
const items = resolvedChildren
|
||||||
|
.map((a) => actionToMenuItem(a, context))
|
||||||
|
.filter(Boolean)
|
||||||
|
.filter((a) => a.visible);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
title,
|
title,
|
||||||
icon,
|
icon,
|
||||||
items: resolvedChildren
|
items,
|
||||||
.map((a) => actionToMenuItem(a, context))
|
visible: visible && items.length > 0,
|
||||||
.filter((a) => !!a),
|
|
||||||
visible,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,10 +40,7 @@ import Flex from "~/components/Flex";
|
|||||||
import Modal from "~/components/Modal";
|
import Modal from "~/components/Modal";
|
||||||
import Switch from "~/components/Switch";
|
import Switch from "~/components/Switch";
|
||||||
import { actionToMenuItem } from "~/actions";
|
import { actionToMenuItem } from "~/actions";
|
||||||
import {
|
import { pinDocument } from "~/actions/definitions/documents";
|
||||||
pinDocument,
|
|
||||||
pinDocumentToHome,
|
|
||||||
} from "~/actions/definitions/documents";
|
|
||||||
import useActionContext from "~/hooks/useActionContext";
|
import useActionContext from "~/hooks/useActionContext";
|
||||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||||
import usePolicy from "~/hooks/usePolicy";
|
import usePolicy from "~/hooks/usePolicy";
|
||||||
@@ -329,7 +326,6 @@ function DocumentMenu({
|
|||||||
visible: !document.isStarred && !!can.star,
|
visible: !document.isStarred && !!can.star,
|
||||||
icon: <StarredIcon />,
|
icon: <StarredIcon />,
|
||||||
},
|
},
|
||||||
actionToMenuItem(pinDocumentToHome, context),
|
|
||||||
actionToMenuItem(pinDocument, context),
|
actionToMenuItem(pinDocument, context),
|
||||||
{
|
{
|
||||||
type: "separator",
|
type: "separator",
|
||||||
|
|||||||
Reference in New Issue
Block a user