Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Restore Image bar back button

Bittia7a4e9add9d9
diff --git a/src/components/WorkspaceBackNavigation.integration.test.tsx b/src/components/WorkspaceBackNavigation.integration.test.tsx
index 1431bb7..c49f19b 100644
--- a/src/components/WorkspaceBackNavigation.integration.test.tsx
+++ b/src/components/WorkspaceBackNavigation.integration.test.tsx
@@ -37,7 +37,7 @@ it("uses application Back and Alt+Left for scenes, clears the action on tab swit
expect(screen.getByRole("dialog")).toBeInTheDocument(); expect(onBack).not.toHaveBeenCalled();
});
-it("uses application Back to show parent images, then restores the project back action", () => {
+it.each(["local", "global"])("uses %s Back to show parent images, then restores the project back action", (action) => {
let config = createEmptyImage(project());
const root = config.imageScene!.outputAssetId!;
config = createEmptyImage(config, undefined, root);
@@ -46,14 +46,16 @@ it("uses application Back to show parent images, then restores the project back
render(<ProjectWorkspace project={{ folderPath: "D:/Images", config }} initialView="editor" onBack={onBack} onSave={async () => {}} />);
const bar = screen.getByLabelText("Generated images");
expect(bar.querySelector(`[data-image-asset="${child}"]`)).toBeInTheDocument();
- expect(within(bar).queryByRole("button", { name: "Back to all images" })).not.toBeInTheDocument();
- fireEvent.click(screen.getByRole("button", { name: "Back to all images" }));
+ const localBack = within(bar).getByRole("button", { name: "Back to all images" });
+ const globalBack = screen.getAllByRole("button", { name: "Back to all images" }).find((button) => !bar.contains(button))!;
+ expect(globalBack).toBeInTheDocument();
+ fireEvent.click(action === "local" ? localBack : globalBack);
expect(bar.querySelector(`[data-image-asset="${child}"]`)).not.toBeInTheDocument();
expect(bar.querySelector(`[data-image-asset="${root}"]`)).toHaveAttribute("aria-pressed", "true");
expect(onBack).not.toHaveBeenCalled();
// Opening the family again registers the keyboard action too.
fireEvent.click(bar.querySelector(`[data-image-asset="${root}"]`)!);
- expect(screen.getByRole("button", { name: "Back to all images" })).toBeInTheDocument();
+ expect(screen.getAllByRole("button", { name: "Back to all images" })).toHaveLength(2);
fireEvent.keyDown(document.body, { key: "ArrowLeft", code: "ArrowLeft", altKey: true });
expect(bar.querySelector(`[data-image-asset="${child}"]`)).not.toBeInTheDocument();
expect(screen.getByRole("button", { name: "Back to project library" })).toBeInTheDocument();
diff --git a/src/components/workspace/ImageBar.tsx b/src/components/workspace/ImageBar.tsx
index 9d4253d..544d1d0 100644
--- a/src/components/workspace/ImageBar.tsx
+++ b/src/components/workspace/ImageBar.tsx
@@ -17,8 +17,7 @@ import "../../styles/image-editor.css";
An image regenerated or edited from another joins that image's family. The
bar lists the primary images; while an image with a family is selected it
shows just that family — the primary first, then the other versions.
- The application back button returns to primaries; standalone bars keep a
- local back button. */
+ Both the local and application back buttons return to primary images. */
export const ImageBar = forwardRef<HTMLDivElement | null, {
images: ProjectAsset[];
selectedId: string | null | undefined;
@@ -118,7 +117,7 @@ export const ImageBar = forwardRef<HTMLDivElement | null, {
const bounds = event.currentTarget.getBoundingClientRect();
onMenu(null, bounds.left, bounds.top, inFamily);
}}>
- {inFamily && !onBackNavigationChange && <button type="button" className="image-results__back" aria-label="Back to all images" data-tooltip="All images"
+ {inFamily && <button type="button" className="image-results__back" aria-label="Back to all images" data-tooltip="All images"
onClick={goBack}><ChevronLeft16 aria-hidden="true" /></button>}
{shown.map((asset) => <button key={asset.id} type="button" data-image-asset={asset.id} data-tooltip={asset.name}
aria-label={`View ${asset.name}${!inFamily && childCount(asset.id) ? `, ${childCount(asset.id) + 1} versions` : ""}`} aria-pressed={asset.id === pressed} aria-busy={pending.has(asset.id)}