fix(structure): add action names to column icon tooltips

This commit is contained in:
zipg authored and GitHub committed 2026-09-22 01:10:59 +08:00
1 parent 529267cded
commit 3156f36fac
8 files changed
+37 -6

No files matched your search

@@ -761,14 +761,30 @@ describe("TableStructureEditor action column", () => {
expect(copyTooltip?.getAttribute("delay-duration")).toBe("500");
expect(deleteTooltip?.getAttribute("delay-duration")).toBe("500");
expect(root.querySelector("[data-add-column-shortcut-content]")?.textContent).toBe("Shift+Enter");
expect(root.querySelector("[data-copy-column-shortcut-content]")?.textContent).toBe("⌘/Ctrl+D");
expect(root.querySelector("[data-delete-column-shortcut-content]")?.textContent?.trim()).toBe("⌘/Ctrl+Del");
// The add control already renders its label, so that hint stays a bare shortcut.
expect(root.querySelector("[data-add-column-shortcut-content]")?.textContent).not.toContain("structureEditor.addColumn");
expect(root.querySelector("[data-copy-column-shortcut-content]")?.textContent).not.toContain("structureEditor.copyColumn");
// The icon-only copy/delete controls must name the action next to the shortcut (#9870).
expect(root.querySelector("[data-copy-column-shortcut-content]")?.textContent).toBe("structureEditor.copyColumn⌘/Ctrl+D");
expect(root.querySelector("[data-delete-column-shortcut-content]")?.textContent).toBe("structureEditor.drop⌘/Ctrl+Del");
expect(copyTooltip?.querySelector("button")?.hasAttribute("title")).toBe(false);
expect(deleteTooltip?.querySelector("button")?.hasAttribute("title")).toBe(false);
});
it("names the delete control after the action it currently performs", async () => {
const root = await mountEditor("dameng");
const persistedDelete = root.querySelector<HTMLButtonElement>('button[aria-label="structureEditor.drop"]');
if (!persistedDelete) throw new Error("Missing delete button for the persisted column");
persistedDelete.click();
await vi.waitFor(() => expect(root.querySelector("[data-delete-column-shortcut-content]")?.textContent).toBe("structureEditor.restore⌘/Ctrl+Del"));
buttonWithText(root, "structureEditor.addColumn").click();
await vi.waitFor(() => expect(root.querySelector('[data-column-row-index="1"]')).not.toBeNull());
const addedRow = root.querySelector('[data-column-row-index="1"]');
expect(addedRow?.querySelector('button[aria-label="structureEditor.remove"]')).not.toBeNull();
expect(addedRow?.querySelector("[data-delete-column-shortcut-content]")?.textContent).toBe("structureEditor.remove⌘/Ctrl+Del");
});
it("adds a field below the focused input on Shift+Enter", async () => {
const root = await mountEditor("dameng");
const sourceInput = root.querySelector<HTMLInputElement>('[data-column-row-index="0"] [data-column-name-input]');
@@ -3774,6 +3774,17 @@ function columnContextMenuItems(column: EditableStructureColumn): ContextMenuIte
];
}
/**
* The delete control is icon-only and swaps between three actions, so its
* tooltip has to name the action instead of only showing the shortcut (#9870).
*/
function deleteColumnActionLabel(column: EditableStructureColumn): string {
if (!column.original) {
return t("structureEditor.remove");
}
return column.markedForDrop ? t("structureEditor.restore") : t("structureEditor.drop");
}
function isColumnNameDisabled(column: EditableStructureColumn): boolean {
return column.markedForDrop || (!!column.original && !structureCapabilities.value.renameColumn);
}
@@ -5031,7 +5042,10 @@ watch(
<Copy :class="structureIconClass" />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom" class="font-mono font-medium" data-copy-column-shortcut-content>⌘/Ctrl+D</TooltipContent>
<TooltipContent side="bottom" data-copy-column-shortcut-content>
<span>{{ t("structureEditor.copyColumn") }}</span>
<span data-slot="kbd" class="font-mono font-medium opacity-70">⌘/Ctrl+D</span>
</TooltipContent>
</Tooltip>
<Tooltip :delay-duration="FIELD_SHORTCUT_TOOLTIP_DELAY_MS" data-delete-column-shortcut-tooltip>
<TooltipTrigger as-child>
@@ -5043,8 +5057,9 @@ watch(
<X :class="structureIconClass" />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom" class="font-mono font-medium" data-delete-column-shortcut-content>
{{ column.markedForDrop ? t("structureEditor.restore") : "⌘/Ctrl+Del" }}
<TooltipContent side="bottom" data-delete-column-shortcut-content>
<span>{{ deleteColumnActionLabel(column) }}</span>
<span data-slot="kbd" class="font-mono font-medium opacity-70">⌘/Ctrl+Del</span>
</TooltipContent>
</Tooltip>
</div>