diff --git a/app/actions/definitions/apiKeys.tsx b/app/actions/definitions/apiKeys.tsx
index 1c830ba944..7bf478ced2 100644
--- a/app/actions/definitions/apiKeys.tsx
+++ b/app/actions/definitions/apiKeys.tsx
@@ -27,8 +27,8 @@ export const createApiKey = createAction({
export const revokeApiKeyFactory = ({ apiKey }: { apiKey: ApiKey }) =>
createActionV2({
- name: ({ t, isContextMenu }) =>
- isContextMenu
+ name: ({ t, isMenu }) =>
+ isMenu
? apiKey.isExpired
? t("Delete")
: `${t("Revoke")}…`
diff --git a/app/actions/definitions/collections.tsx b/app/actions/definitions/collections.tsx
index fdd2252dae..06039e0c34 100644
--- a/app/actions/definitions/collections.tsx
+++ b/app/actions/definitions/collections.tsx
@@ -81,8 +81,7 @@ export const createCollection = createAction({
});
export const editCollection = createActionV2({
- name: ({ t, isContextMenu }) =>
- isContextMenu ? `${t("Edit")}…` : t("Edit collection"),
+ name: ({ t, isMenu }) => (isMenu ? `${t("Edit")}…` : t("Edit collection")),
analyticsName: "Edit collection",
section: ActiveCollectionSection,
icon: ,
@@ -107,8 +106,8 @@ export const editCollection = createActionV2({
});
export const editCollectionPermissions = createActionV2({
- name: ({ t, isContextMenu }) =>
- isContextMenu ? `${t("Permissions")}…` : t("Collection permissions"),
+ name: ({ t, isMenu }) =>
+ isMenu ? `${t("Permissions")}…` : t("Collection permissions"),
analyticsName: "Collection permissions",
section: ActiveCollectionSection,
icon: ,
diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx
index e83d7f8f8b..9bdb5dae8d 100644
--- a/app/actions/definitions/documents.tsx
+++ b/app/actions/definitions/documents.tsx
@@ -384,8 +384,8 @@ export const subscribeDocument = createActionV2({
analyticsName: "Subscribe to document",
section: ActiveDocumentSection,
icon: ,
- tooltip: ({ activeCollectionId, isContextMenu, stores, t }) => {
- if (!isContextMenu || !activeCollectionId) {
+ tooltip: ({ activeCollectionId, isMenu, stores, t }) => {
+ if (!isMenu || !activeCollectionId) {
return undefined;
}
@@ -393,8 +393,8 @@ export const subscribeDocument = createActionV2({
? t("Subscription inherited from collection")
: undefined;
},
- disabled: ({ activeCollectionId, isContextMenu, stores }) => {
- if (!isContextMenu || !activeCollectionId) {
+ disabled: ({ activeCollectionId, isMenu, stores }) => {
+ if (!isMenu || !activeCollectionId) {
return false;
}
@@ -430,8 +430,8 @@ export const unsubscribeDocument = createActionV2({
analyticsName: "Unsubscribe from document",
section: ActiveDocumentSection,
icon: ,
- tooltip: ({ activeCollectionId, isContextMenu, stores, t }) => {
- if (!isContextMenu || !activeCollectionId) {
+ tooltip: ({ activeCollectionId, isMenu, stores, t }) => {
+ if (!isMenu || !activeCollectionId) {
return undefined;
}
@@ -439,8 +439,8 @@ export const unsubscribeDocument = createActionV2({
? t("Subscription inherited from collection")
: undefined;
},
- disabled: ({ activeCollectionId, isContextMenu, stores }) => {
- if (!isContextMenu || !activeCollectionId) {
+ disabled: ({ activeCollectionId, isMenu, stores }) => {
+ if (!isMenu || !activeCollectionId) {
return false;
}
@@ -571,8 +571,7 @@ export const downloadDocumentAsMarkdown = createActionV2({
});
export const downloadDocument = createActionV2WithChildren({
- name: ({ t, isContextMenu }) =>
- isContextMenu ? t("Download") : t("Download document"),
+ name: ({ t, isMenu }) => (isMenu ? t("Download") : t("Download document")),
analyticsName: "Download document",
section: ActiveDocumentSection,
icon: ,
@@ -678,8 +677,7 @@ export const copyDocument = createActionV2WithChildren({
});
export const duplicateDocument = createActionV2({
- name: ({ t, isContextMenu }) =>
- isContextMenu ? t("Duplicate") : t("Duplicate document"),
+ name: ({ t, isMenu }) => (isMenu ? t("Duplicate") : t("Duplicate document")),
analyticsName: "Duplicate document",
section: ActiveDocumentSection,
icon: ,
@@ -829,8 +827,7 @@ export const searchInDocument = createInternalLinkActionV2({
});
export const printDocument = createActionV2({
- name: ({ t, isContextMenu }) =>
- isContextMenu ? t("Print") : t("Print document"),
+ name: ({ t, isMenu }) => (isMenu ? t("Print") : t("Print document")),
analyticsName: "Print document",
section: ActiveDocumentSection,
icon: ,
diff --git a/app/actions/definitions/navigation.tsx b/app/actions/definitions/navigation.tsx
index 569464076a..8b737016f8 100644
--- a/app/actions/definitions/navigation.tsx
+++ b/app/actions/definitions/navigation.tsx
@@ -131,8 +131,8 @@ export const navigateToTemplateSettings = createAction({
});
export const navigateToNotificationSettings = createInternalLinkActionV2({
- name: ({ t, isContextMenu }) =>
- isContextMenu ? t("Notification settings") : t("Notifications"),
+ name: ({ t, isMenu }) =>
+ isMenu ? t("Notification settings") : t("Notifications"),
analyticsName: "Navigate to notification settings",
section: NavigationSection,
iconInContextMenu: false,
diff --git a/app/actions/definitions/settings.tsx b/app/actions/definitions/settings.tsx
index 4637f609db..dfb8a3c2dc 100644
--- a/app/actions/definitions/settings.tsx
+++ b/app/actions/definitions/settings.tsx
@@ -37,8 +37,7 @@ export const changeToSystemTheme = createActionV2({
});
export const changeTheme = createActionV2WithChildren({
- name: ({ t, isContextMenu }) =>
- isContextMenu ? t("Appearance") : t("Change theme"),
+ name: ({ t, isMenu }) => (isMenu ? t("Appearance") : t("Change theme")),
analyticsName: "Change theme",
placeholder: ({ t }) => t("Change theme to"),
icon: ({ stores }) =>
diff --git a/app/components/ActionButton.tsx b/app/components/ActionButton.tsx
index 7b9371f091..d5468ea05f 100644
--- a/app/components/ActionButton.tsx
+++ b/app/components/ActionButton.tsx
@@ -3,12 +3,8 @@ import * as React from "react";
import Tooltip, { Props as TooltipProps } from "~/components/Tooltip";
import { performAction, performActionV2, resolve } from "~/actions";
import useIsMounted from "~/hooks/useIsMounted";
-import {
- Action,
- ActionContext,
- ActionV2Variant,
- ActionV2WithChildren,
-} from "~/types";
+import { Action, ActionV2Variant, ActionV2WithChildren } from "~/types";
+import useActionContext from "~/hooks/useActionContext";
export type Props = React.HTMLAttributes & {
/** Show the button in a disabled state */
@@ -17,8 +13,6 @@ export type Props = React.HTMLAttributes & {
hideOnActionDisabled?: boolean;
/** Action to use on button */
action?: Action | Exclude;
- /** Context of action, must be provided with action */
- context?: ActionContext;
/** If tooltip props are provided the button will be wrapped in a tooltip */
tooltip?: Omit;
};
@@ -28,22 +22,20 @@ export type Props = React.HTMLAttributes & {
*/
const ActionButton = React.forwardRef(
function _ActionButton(
- { action, context, tooltip, hideOnActionDisabled, ...rest }: Props,
+ { action, tooltip, hideOnActionDisabled, ...rest }: Props,
ref: React.Ref
) {
+ const actionContext = useActionContext({
+ isButton: true,
+ });
const isMounted = useIsMounted();
const [executing, setExecuting] = React.useState(false);
const disabled = rest.disabled;
- if (action && !context) {
- throw new Error("Context must be provided with action");
- }
- if (!context || !action) {
+ if (!actionContext || !action) {
return ;
}
- const actionContext = { ...context, isButton: true };
-
if (
action.visible &&
!resolve(action.visible, actionContext) &&
diff --git a/app/components/Breadcrumb.tsx b/app/components/Breadcrumb.tsx
index f46916d98e..bf38147847 100644
--- a/app/components/Breadcrumb.tsx
+++ b/app/components/Breadcrumb.tsx
@@ -25,7 +25,7 @@ function Breadcrumb(
{ actions, highlightFirstItem, children, max = 2 }: Props,
ref: React.RefObject | null
) {
- const actionContext = useActionContext({ isContextMenu: true });
+ const actionContext = useActionContext({ isMenu: true });
const visibleActions = useComputed(
() =>
diff --git a/app/components/ContextMenu/Template.tsx b/app/components/ContextMenu/Template.tsx
index 59debadf81..7bc390f4fc 100644
--- a/app/components/ContextMenu/Template.tsx
+++ b/app/components/ContextMenu/Template.tsx
@@ -104,7 +104,7 @@ export function filterTemplateItems(items: TMenuItem[]): TMenuItem[] {
function Template({ items, actions, context, showIcons, ...menu }: Props) {
const ctx = useActionContext({
- isContextMenu: true,
+ isMenu: true,
});
const templateItems = actions
diff --git a/app/components/DocumentListItem.tsx b/app/components/DocumentListItem.tsx
index 4511953e2b..9d69a4b7a0 100644
--- a/app/components/DocumentListItem.tsx
+++ b/app/components/DocumentListItem.tsx
@@ -25,7 +25,7 @@ import { useLocationSidebarContext } from "~/hooks/useLocationSidebarContext";
import DocumentMenu from "~/menus/DocumentMenu";
import { documentPath } from "~/utils/routeHelpers";
import { determineSidebarContext } from "./Sidebar/components/SidebarContext";
-import useActionContext from "~/hooks/useActionContext";
+import { ActionContextProvider } from "~/hooks/useActionContext";
import { useDocumentMenuAction } from "~/hooks/useDocumentMenuAction";
import { ContextMenu } from "./Menu/ContextMenu";
import useStores from "~/hooks/useStores";
@@ -94,97 +94,99 @@ function DocumentListItem(
currentContext: locationSidebarContext,
});
- const actionContext = useActionContext({
- isContextMenu: true,
- activeDocumentId: document.id,
- activeCollectionId:
- !isShared && document.collectionId ? document.collectionId : undefined,
- });
-
const contextMenuAction = useDocumentMenuAction({ document });
return (
-
-
-
-
- {document.icon && (
- <>
-
-
- >
- )}
-
- {document.isBadgedNew && document.createdBy?.id !== user.id && (
- {t("New")}
- )}
- {document.isDraft && showDraft && (
-
- {t("Draft")}
-
- )}
- {canStar && (
-
-
-
- )}
- {document.isTemplate && showTemplate && (
- {t("Template")}
- )}
-
+
+
+
+ {document.icon && (
+ <>
+
+
+ >
+ )}
+
+ {document.isBadgedNew && document.createdBy?.id !== user.id && (
+ {t("New")}
+ )}
+ {document.isDraft && showDraft && (
+
+ {t("Draft")}
+
+ )}
+ {canStar && (
+
+
+
+ )}
+ {document.isTemplate && showTemplate && (
+ {t("Template")}
+ )}
+
- {!queryIsInTitle && (
-
+ )}
+
- )}
-
-
-
-
-
-
-
+
+
+
+
+
+
+
);
}
diff --git a/app/components/Menu/ContextMenu.tsx b/app/components/Menu/ContextMenu.tsx
index 6894a0e884..d99a76ff8c 100644
--- a/app/components/Menu/ContextMenu.tsx
+++ b/app/components/Menu/ContextMenu.tsx
@@ -2,7 +2,7 @@ import * as React from "react";
import { actionV2ToMenuItem } from "~/actions";
import useActionContext from "~/hooks/useActionContext";
import useMobile from "~/hooks/useMobile";
-import { ActionContext, ActionV2Variant, ActionV2WithChildren } from "~/types";
+import { ActionV2Variant, ActionV2WithChildren } from "~/types";
import { toMenuItems } from "./transformer";
import { observer } from "mobx-react";
import { useComputed } from "~/hooks/useComputed";
@@ -12,8 +12,6 @@ import { MenuProvider } from "~/components/primitives/Menu/MenuContext";
type Props = {
/** Root action with children representing the menu items */
action: ActionV2WithChildren;
- /** Action context to use - new context will be created if not provided */
- context?: ActionContext;
/** Trigger for the menu */
children: React.ReactNode;
/** ARIA label for the menu */
@@ -25,15 +23,12 @@ type Props = {
};
export const ContextMenu = observer(
- ({ action, children, ariaLabel, context, onOpen, onClose }: Props) => {
+ ({ action, children, ariaLabel, onOpen, onClose }: Props) => {
const isMobile = useMobile();
const contentRef = React.useRef>(null);
-
- const actionContext =
- context ??
- useActionContext({
- isContextMenu: true,
- });
+ const actionContext = useActionContext({
+ isMenu: true,
+ });
const menuItems = useComputed(() => {
if (!open) {
diff --git a/app/components/Menu/DropdownMenu.tsx b/app/components/Menu/DropdownMenu.tsx
index 196a657649..930339eff4 100644
--- a/app/components/Menu/DropdownMenu.tsx
+++ b/app/components/Menu/DropdownMenu.tsx
@@ -14,7 +14,6 @@ import { actionV2ToMenuItem } from "~/actions";
import useActionContext from "~/hooks/useActionContext";
import useMobile from "~/hooks/useMobile";
import {
- ActionContext,
ActionV2Variant,
ActionV2WithChildren,
MenuItem,
@@ -27,8 +26,6 @@ import { useComputed } from "~/hooks/useComputed";
type Props = {
/** Root action with children representing the menu items */
action: ActionV2WithChildren;
- /** Action context to use - new context will be created if not provided */
- context?: ActionContext;
/** Trigger for the menu */
children: React.ReactNode;
/** Alignment w.r.t trigger - defaults to start */
@@ -49,7 +46,6 @@ export const DropdownMenu = observer(
(
{
action,
- context,
children,
align = "start",
ariaLabel,
@@ -64,12 +60,9 @@ export const DropdownMenu = observer(
const isMobile = useMobile();
const contentRef =
React.useRef>(null);
-
- const actionContext =
- context ??
- useActionContext({
- isContextMenu: true,
- });
+ const actionContext = useActionContext({
+ isMenu: true,
+ });
const menuItems = useComputed(() => {
if (!open) {
diff --git a/app/components/Notifications/Notifications.tsx b/app/components/Notifications/Notifications.tsx
index 617aff9bb7..11bc5c9bb6 100644
--- a/app/components/Notifications/Notifications.tsx
+++ b/app/components/Notifications/Notifications.tsx
@@ -6,7 +6,6 @@ import styled from "styled-components";
import { s, hover } from "@shared/styles";
import Notification from "~/models/Notification";
import { markNotificationsAsRead } from "~/actions/definitions/notifications";
-import useActionContext from "~/hooks/useActionContext";
import useStores from "~/hooks/useStores";
import NotificationMenu from "~/menus/NotificationMenu";
import Desktop from "~/utils/Desktop";
@@ -32,7 +31,6 @@ function Notifications(
{ onRequestClose }: Props,
ref: React.RefObject
) {
- const context = useActionContext();
const { notifications } = useStores();
const { t } = useTranslation();
const isEmpty = notifications.active.length === 0;
@@ -69,7 +67,6 @@ function Notifications(