diff --git a/app/actions/index.ts b/app/actions/index.ts index f880096c2d..2c83d80e8f 100644 --- a/app/actions/index.ts +++ b/app/actions/index.ts @@ -23,7 +23,7 @@ import Analytics from "~/utils/Analytics"; import history from "~/utils/history"; import { Action as KbarAction } from "kbar"; -function resolve(value: any, context: ActionContext): T { +export function resolve(value: any, context: ActionContext): T { return typeof value === "function" ? value(context) : value; } @@ -375,14 +375,6 @@ export function actionV2ToKBar( case "action": case "internal_link": case "external_link": { - const perform = - action.variant === "action" - ? () => performActionV2(action, context) - : action.variant === "internal_link" - ? () => - history.push(resolve(action.to, context)) - : () => window.open(action.url, action.target); - return [ { id: action.id, @@ -392,7 +384,7 @@ export function actionV2ToKBar( shortcut: action.shortcut, icon, priority, - perform, + perform: () => performActionV2(action, context), }, ]; } @@ -430,10 +422,17 @@ export function actionV2ToKBar( } export async function performActionV2( - action: ActionV2, + action: Exclude, context: ActionContext ) { - const result = action.perform(context); + const perform = + action.variant === "action" + ? () => action.perform(context) + : action.variant === "internal_link" + ? () => history.push(resolve(action.to, context)) + : () => window.open(action.url, action.target); + + const result = perform(); if (result instanceof Promise) { return result.catch((err: Error) => { diff --git a/app/components/ActionButton.tsx b/app/components/ActionButton.tsx index 91495ac8be..d04a33439e 100644 --- a/app/components/ActionButton.tsx +++ b/app/components/ActionButton.tsx @@ -1,9 +1,14 @@ /* oxlint-disable react/prop-types */ import * as React from "react"; import Tooltip, { Props as TooltipProps } from "~/components/Tooltip"; -import { performAction } from "~/actions"; +import { performAction, performActionV2, resolve } from "~/actions"; import useIsMounted from "~/hooks/useIsMounted"; -import { Action, ActionContext } from "~/types"; +import { + Action, + ActionContext, + ActionV2Variant, + ActionV2WithChildren, +} from "~/types"; export type Props = React.HTMLAttributes & { /** Show the button in a disabled state */ @@ -11,7 +16,7 @@ export type Props = React.HTMLAttributes & { /** Hide the button entirely if action is not applicable */ hideOnActionDisabled?: boolean; /** Action to use on button */ - action?: Action; + 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 */ @@ -40,8 +45,8 @@ const ActionButton = React.forwardRef( const actionContext = { ...context, isButton: true }; if ( - action?.visible && - !action.visible(actionContext) && + action.visible && + !resolve(action.visible, actionContext) && hideOnActionDisabled ) { return null; @@ -63,7 +68,10 @@ const ActionButton = React.forwardRef( ? (ev) => { ev.preventDefault(); ev.stopPropagation(); - const response = performAction(action, actionContext); + const response = + "variant" in action + ? performActionV2(action, actionContext) + : performAction(action, actionContext); if (response?.finally) { setExecuting(true); void response.finally( diff --git a/app/components/Menu/DropdownMenu.tsx b/app/components/Menu/DropdownMenu.tsx index 9635a5513b..12b65a380d 100644 --- a/app/components/Menu/DropdownMenu.tsx +++ b/app/components/Menu/DropdownMenu.tsx @@ -69,11 +69,6 @@ export const DropdownMenu = observer(function DropdownMenu({ [onOpen, onClose] ); - const handleCloseAutoFocus = React.useCallback((ev: Event) => { - ev.preventDefault(); - ev.stopPropagation(); - }, []); - const enablePointerEvents = React.useCallback(() => { if (contentRef.current) { contentRef.current.style.pointerEvents = "auto"; @@ -112,7 +107,6 @@ export const DropdownMenu = observer(function DropdownMenu({ aria-label={ariaLabel} onAnimationStart={disablePointerEvents} onAnimationEnd={enablePointerEvents} - onCloseAutoFocus={handleCloseAutoFocus} > {content} diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 66c201393a..7106b733a2 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -27,6 +27,9 @@ "Restore": "Restore", "Collection restored": "Collection restored", "Delete collection": "Delete collection", + "Export": "Export", + "Export collection": "Export collection", + "New document": "New document", "New template": "New template", "Delete comment": "Delete comment", "Mark as resolved": "Mark as resolved", @@ -42,7 +45,6 @@ "Debug logging disabled": "Debug logging disabled", "Development": "Development", "Open document": "Open document", - "New document": "New document", "New draft": "New draft", "New from template": "New from template", "New nested document": "New nested document", @@ -269,7 +271,6 @@ "A ZIP file containing the images, and documents in the Markdown format.": "A ZIP file containing the images, and documents in the Markdown format.", "A ZIP file containing the images, and documents as HTML files.": "A ZIP file containing the images, and documents as HTML files.", "Structured data that can be used to transfer data to another compatible {{ appName }} instance.": "Structured data that can be used to transfer data to another compatible {{ appName }} instance.", - "Export": "Export", "Exporting the collection {{collectionName}} may take some time.": "Exporting the collection {{collectionName}} may take some time.", "You will receive an email when it's complete.": "You will receive an email when it's complete.", "Include attachments": "Include attachments", @@ -552,13 +553,12 @@ "API key": "API key", "Show path to document": "Show path to document", "Path to document": "Path to document", - "Group member options": "Group member options", - "Export collection": "Export collection", - "Rename": "Rename", "Sort in sidebar": "Sort in sidebar", "A-Z sort": "A-Z sort", "Z-A sort": "Z-A sort", "Manual sort": "Manual sort", + "Rename": "Rename", + "Collection menu": "Collection menu", "Comment options": "Comment options", "Show document menu": "Show document menu", "{{ documentName }} restored": "{{ documentName }} restored", @@ -568,13 +568,13 @@ "Apply template": "Apply template", "Enable embeds": "Enable embeds", "File": "File", + "Group member options": "Group member options", "Group members": "Group members", "Edit group": "Edit group", "Delete group": "Delete group", "Group options": "Group options", "Cancel": "Cancel", "Import menu options": "Import menu options", - "Member options": "Member options", "New document in {{ collectionName }}": "New document in {{ collectionName }}", "New child document": "New child document", "Save in workspace": "Save in workspace", @@ -619,7 +619,6 @@ "Custom": "Custom", "No expiration": "No expiration", "The document archive is empty at the moment.": "The document archive is empty at the moment.", - "Collection menu": "Collection menu", "Drop documents to import": "Drop documents to import", "{{ collectionName }} doesn’t contain any\n documents yet.": "{{ collectionName }} doesn’t contain any\n documents yet.", "{{ usersCount }} users and {{ groupsCount }} groups with access": "{{ usersCount }} user and {{ groupsCount }} groups with access",