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