Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(webv2): show starred items above in-progress in the gallery

Josh Corbettd4eb9d75a30d
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
index 8a6f1c1039..af2ae50f5f 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
@@ -1565,7 +1565,7 @@ describe('shared gallery progress section', () => {
expect(followProgressSession).toHaveBeenCalledWith('run:1', { revealPreview: true });
expect(host?.querySelectorAll('[role="listitem"]')).toHaveLength(currentGallery.items.length);
});
- it('steps the arrow keys between the followed tile, the strip and the listing as one sequence', async () => {
+ it('steps the arrow keys between the strip, the followed tile and the listing as one sequence', async () => {
const starred = createItem('image', 'starred.png', { starred: true });
const regular = createItem('image', 'regular.png');
currentProgressSessions = [session, { ...session, id: 'run:2', itemIndex: 2, backendItemId: 11 }];
@@ -1577,28 +1577,24 @@ describe('shared gallery progress section', () => {
createGallery({ items: [regular], selectedItemKey: 'image:regular.png', selectedItemKeys: ['image:regular.png'] })
);
- // Down from the second tile lands on the strip's only cell; right steps off the tiles into it too.
- registeredCommands.get('gallery.galleryNavDown')?.();
+ // Up from the second tile lands on the strip above; right steps off the tiles into the listing.
+ registeredCommands.get('gallery.galleryNavUp')?.();
expect(actionMocks.selectItem).toHaveBeenLastCalledWith(starred);
registeredCommands.get('gallery.galleryNavRight')?.();
- expect(actionMocks.selectItem).toHaveBeenLastCalledWith(starred);
+ expect(actionMocks.selectItem).toHaveBeenLastCalledWith(regular);
registeredCommands.get('gallery.galleryNavLeft')?.();
expect(followProgressSession).toHaveBeenLastCalledWith('run:1', { revealPreview: false });
- // From the strip, up and left follow a tile again; down and right reach the listing.
+ // From the strip, down and right follow a tile; up and left have nowhere to go.
currentLiveFollowEnabled = false;
currentPinnedSessionId = null;
await renderGallery(
createGallery({ items: [regular], selectedItemKey: 'image:starred.png', selectedItemKeys: ['image:starred.png'] })
);
- registeredCommands.get('gallery.galleryNavUp')?.();
- expect(followProgressSession).toHaveBeenLastCalledWith('run:1', { revealPreview: false });
- registeredCommands.get('gallery.galleryNavLeft')?.();
- expect(followProgressSession).toHaveBeenLastCalledWith('run:2', { revealPreview: false });
registeredCommands.get('gallery.galleryNavDown')?.();
expect(actionMocks.selectItem).toHaveBeenLastCalledWith(regular);
registeredCommands.get('gallery.galleryNavRight')?.();
- expect(actionMocks.selectItem).toHaveBeenLastCalledWith(regular);
+ expect(followProgressSession).toHaveBeenLastCalledWith('run:1', { revealPreview: false });
expect(followProgressSession).toHaveBeenCalledTimes(3);
});
it('skips waiting tiles, which cannot be followed, and steps past a collapsed section', async () => {
@@ -1609,13 +1605,13 @@ describe('shared gallery progress section', () => {
];
currentLiveFollowEnabled = true;
setStrip([starred]);
- await renderGallery(createGallery({ selectedItemKey: null, selectedItemKeys: [] }));
+ await renderGallery(createGallery({ items: [regular], selectedItemKey: null, selectedItemKeys: [] }));
registeredCommands.get('gallery.galleryNavRight')?.();
- expect(actionMocks.selectItem).toHaveBeenLastCalledWith(starred);
+ expect(actionMocks.selectItem).toHaveBeenLastCalledWith(regular);
expect(followProgressSession).not.toHaveBeenCalled();
- // A collapsed in-progress section shows no tiles, so the strip is the top of the sequence.
+ // A collapsed in-progress section shows no tiles, so the strip sits directly above the listing.
currentLiveFollowEnabled = false;
await renderGallery(
createGallery({
@@ -1626,11 +1622,13 @@ describe('shared gallery progress section', () => {
);
registeredCommands.get('gallery.galleryNavLeft')?.();
expect(followProgressSession).not.toHaveBeenCalled();
- expect(actionMocks.selectItem).toHaveBeenCalledTimes(1);
+ expect(actionMocks.selectItem).toHaveBeenCalledTimes(2);
});
+ expect(actionMocks.selectItem).toHaveBeenCalledTimes(2);
it('steps out of a starred selection the strip does not show instead of resetting', async () => {
const shown = Array.from({ length: 12 }, (_, index) =>
createItem('image', `starred-${index}.png`, { starred: true })
+ const regular = createItem('image', 'regular.png');
);
const hidden = createItem('image', 'starred-hidden.png', { starred: true });
const regular = createItem('image', 'regular.png');
@@ -1647,8 +1645,12 @@ describe('shared gallery progress section', () => {
expect(shownCount).toBeLessThan(13);
registeredCommands.get('gallery.galleryNavRight')?.();
- expect(actionMocks.selectItem).toHaveBeenLastCalledWith(regular);
+ items: [regular],
+ expect(followProgressSession).toHaveBeenLastCalledWith('run:1', { revealPreview: false });
+ registeredCommands.get('gallery.galleryNavUp')?.();
registeredCommands.get('gallery.galleryNavLeft')?.();
+ registeredCommands.get('gallery.galleryNavDown')?.();
+ expect(actionMocks.selectItem).toHaveBeenLastCalledWith(regular);
expect(actionMocks.selectItem).toHaveBeenLastCalledWith(shown[shownCount - 1]);
// Under a collapsed disclosure the whole strip is hidden; the selection still steps into the listing.
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
index 2d5b729ae2..5d26671873 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
@@ -273,6 +273,7 @@ export const GalleryImageGrid = () => {
}
return [
+ stripEntries,
isProgressOpen
? progressSessions.map((session) => ({
id: session.id,
@@ -280,7 +281,6 @@ export const GalleryImageGrid = () => {
navigable: session.state === 'running',
}))
: [],
- stripEntries,
gallery.items.map((item) => ({ item, kind: 'item' })),
];
}, [
@@ -352,7 +352,23 @@ export const GalleryImageGrid = () => {
};
const scrollToEntry = (entry: GalleryNavigationEntry) => {
if (entry.kind === 'session') {
- viewportRef.current?.scrollTo({ top: 0 });
+ // In-progress tiles sit below the starred strip; scroll only when the target tile's row is out of view.
+ const viewport = viewportRef.current;
+ const sessionIndex = progressSessions.findIndex((session) => session.id === entry.id);
+
+ if (viewport && sessionIndex >= 0) {
+ const rowTop =
+ starredLayout.height +
+ progressLayout.headerHeight +
+ Math.floor(sessionIndex / progressLayout.columns) * progressLayout.rowHeight;
+ const rowBottom = rowTop + progressLayout.rowHeight;
+
+ if (rowTop < viewport.scrollTop) {
+ viewport.scrollTo({ top: rowTop - progressLayout.headerHeight });
+ } else if (rowBottom > viewport.scrollTop + viewport.clientHeight) {
+ viewport.scrollTo({ top: rowBottom - viewport.clientHeight });
+ }
+ }
} else {
scrollToItemKey(toGalleryItemKey(entry.item));
}
@@ -632,7 +648,6 @@ export const GalleryImageGrid = () => {
mb={`${GALLERY_PINNED_FOOTER_PX - 1}px`}
minW="0"
>
- <GalleryProgressSection layout={progressLayout} getScrollElement={getScrollElement} />
{starredCells.length > 0 ? (
<GalleryStarredSection
cells={starredCells}
@@ -645,6 +660,11 @@ export const GalleryImageGrid = () => {
onToggle={handleToggleStarredSection}
/>
) : null}
+ <GalleryProgressSection
+ getScrollElement={getScrollElement}
+ layout={progressLayout}
+ offsetTopPx={starredLayout.height}
+ />
</Box>
) : null}
{isEmpty ? (
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryProgressSection.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryProgressSection.tsx
index 8d77936aa4..888cb23abe 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryProgressSection.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryProgressSection.tsx
@@ -20,9 +20,12 @@ export const GalleryProgressSection = ({
layout,
getScrollElement,
}: {
+ offsetTopPx,
layout: GalleryProgressLayout;
getScrollElement(): HTMLDivElement | null;
}) => {
+ /** Height of the pinned content above this section in the shared scroll viewport. */
+ offsetTopPx: number;
const { t } = useTranslation();
const { progressSessions, pinnedProgressSessionId, liveFollowEnabled, followProgressSession } = useGalleryUi();
const { actions, gallery } = useGalleryWidget();
@@ -100,6 +103,7 @@ export const GalleryProgressSection = ({
fit={gallery.settings.thumbnailFit}
getScrollElement={getScrollElement}
pinnedSessionId={pinnedProgressSessionId}
+ offsetTopPx={offsetTopPx}
liveFollowEnabled={liveFollowEnabled}
onFollow={followProgressSession}
restoreFocus={restoreFocus}
@@ -116,6 +120,7 @@ const GalleryProgressGrid = ({
fit,
getScrollElement,
pinnedSessionId,
+ offsetTopPx,
liveFollowEnabled,
onFollow,
restoreFocus,
@@ -125,6 +130,7 @@ const GalleryProgressGrid = ({
fit: GalleryThumbnailFit;
getScrollElement(): HTMLDivElement | null;
pinnedSessionId: string | null;
+ offsetTopPx: number;
liveFollowEnabled: boolean;
onFollow(id: string, options: { revealPreview: boolean }): void;
restoreFocus(): void;
@@ -132,10 +138,11 @@ const GalleryProgressGrid = ({
const { columns, tileSize, headerHeight, paddingBottom, rowCount, rowHeight } = layout;
const estimateSize = useCallback(() => rowHeight, [rowHeight]);
const virtualizer = useVirtualizer({
+ const scrollMargin = offsetTopPx + headerHeight;
count: rowCount,
getScrollElement,
estimateSize,
- scrollMargin: headerHeight,
+ scrollMargin,
overscan: 2,
});
const measure = useEffectEvent(() => virtualizer.measure());
@@ -150,7 +157,7 @@ const GalleryProgressGrid = ({
<Box
key={session.id}
position="absolute"
- top={`${row.start - headerHeight}px`}
+ top={`${row.start - scrollMargin}px`}
left={`${column * rowHeight}px`}
>
<GalleryProgressTile
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryGridHotkeys.ts b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryGridHotkeys.ts
index 4efba3b6bd..5cc795a684 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryGridHotkeys.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryGridHotkeys.ts
@@ -43,7 +43,7 @@ export const useGalleryGridHotkeys = ({
cursorKey: string | null;
/** Everything on hand for star-state lookups, strip included. */
loadedItems: readonly GalleryItem[];
- /** The arrow-key sections in visual order: in progress, the starred strip, the listing. */
+ /** The arrow-key sections in visual order: the starred strip, in progress, the listing. */
navigationSections: readonly (readonly GalleryNavigationEntry[])[];
scrollToEntry: (entry: GalleryNavigationEntry) => void;
}) => {