fix(search): Find Action hides actions that cannot run (#4327)

Find Action only checked an action's when clause, not its enabled() check, so Annotate with Git Blame on an untracked file, Show Current Revision, or Set NULL with no data grid focused were listed as enabled and did nothing. Matching now uses isActionEnabled, the same check menus and shortcuts use. When Include disabled actions is unchecked, unavailable actions are hidden, also from the recent list. The database cell actions are enabled only while a grid has focus (a popup opened from the grid keeps the grid it captured). An empty Actions tab says Nothing found.

Closes #4223
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-18 23:41:40 +08:00
1 джерело 262b91d89a
коміт 3de76f1a63
8 files changed
+155 -20

No files matched your search

+29 -1
Переглянути файл
@@ -1,5 +1,6 @@
import { installKeyboardDispatcher, useKeymap } from "@/platform/keymap";
import { registerActions } from "@/platform/actions";
import { executeAction, getAction, isActionEnabled, registerActions } from "@/platform/actions";
import { getContext } from "@/platform/context";
import { act, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { useState } from "react";
@@ -699,6 +700,33 @@ describe("Set NULL / Set DEFAULT (issue #2331, phase 1)", () => {
{ name: "c", type: "text", default: "now()" },
];
it("keeps the invoking grid available to a popup using its captured focus context", async () => {
const onEdit = vi.fn();
render(
<>
<Grid columns={[columns[0]!]} rowCount={1} value={() => "old"} editable onEdit={onEdit} />
<div role="dialog">
<input aria-label="Action query" />
</div>
<button>Outside the grid</button>
</>,
);
fireEvent.mouseDown(screen.getByRole("gridcell"), { button: 0 });
const source = { ...getContext() };
const action = getAction("db.setCellNull")!;
expect(isActionEnabled(action, source)).toBe(true);
act(() => screen.getByLabelText("Action query").focus());
expect(isActionEnabled(action)).toBe(false);
expect(isActionEnabled(action, source)).toBe(true);
act(() => screen.getByRole("grid").focus());
await act(() => executeAction(action.id));
expect(onEdit).toHaveBeenCalledWith(0, 0, null);
act(() => screen.getByRole("button", { name: "Outside the grid" }).focus());
expect(isActionEnabled(action, source)).toBe(false);
});
it("sets NULL on the selection from the context menu and ⌘⌫, skipping NOT NULL columns", async () => {
const onEdit = vi.fn();
render(
+9 -3
Переглянути файл
@@ -1,5 +1,5 @@
import { registerActions, type ActionContext } from "@/platform/actions";
import { setContext } from "@/platform/context";
import { getContext, setContext } from "@/platform/context";
export type CellCopy = "tsv" | "csv" | "onerow" | "header" | "rowsTsv" | "rowsCsv";
@@ -26,7 +26,7 @@ let active: CellActions | null = null;
/** The focused grid (not while a text field in it has focus). */
export function activeCellGrid(): CellActions | null {
return active;
return getContext().dbCellGridFocus ? active : null;
}
const COPIES: Array<[CellCopy, string, string]> = [
@@ -53,12 +53,18 @@ export function installCellActions(): () => void {
const onFocus = (event: FocusEvent) => {
const target = event.target instanceof Element ? event.target : null;
const root = target?.closest("[data-db-cell-grid]");
// A popup can query the grid that opened it with its captured context.
if (!root && target?.closest("[data-popup], [role=dialog]")) {
setContext("dbCellGridFocus", false);
return;
}
active =
root && !target?.closest("input, textarea, select, [contenteditable='true']") ? (grids.get(root) ?? null) : null;
setContext("dbCellGridFocus", !!active);
};
document.addEventListener("focusin", onFocus);
const handle = ({ arg }: ActionContext) => (arg as CellActions | undefined) ?? active;
const handle = ({ arg, ctx }: ActionContext) =>
(arg as CellActions | undefined) ?? (ctx.dbCellGridFocus ? active : null);
const dispose = registerActions([
{
id: "db.toggleBooleanCell",