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.

fix(webv2): separate starred accordion from gallery grid

joshistoast0888bdfb653a
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 0bccfb18cb..b557e06fb7 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
@@ -500,7 +500,7 @@ describe('GalleryImageGrid mixed item cells', () => {
expect(getComputedStyle(trigger).backgroundColor).toBe('rgba(0, 0, 0, 0)');
});
- it('spaces the whole starred accordion away from the regular image grid', async () => {
+ it('keeps the starred label and grid together before a dedicated trailing gap', async () => {
await renderGallery(
createGallery({
items: [createItem('image', 'starred.png', { starred: true }), createItem('image', 'regular.png')],
@@ -512,9 +512,9 @@ describe('GalleryImageGrid mixed item cells', () => {
const starredRect = getButton('Select starred.png for preview').getBoundingClientRect();
const regularRect = getButton('Select regular.png for preview').getBoundingClientRect();
- expect((headerRect?.top ?? 0) - (listRect?.top ?? 0)).toBeCloseTo(8, 0);
+ expect((headerRect?.top ?? 0) - (listRect?.top ?? 0)).toBeCloseTo(0, 0);
expect(starredRect.top - (headerRect?.bottom ?? 0)).toBeLessThan(4);
- expect(regularRect.top - starredRect.bottom).toBeCloseTo(8, 0);
+ expect(regularRect.top - starredRect.bottom).toBeCloseTo(12, 0);
await click(getButton('Collapse starred items'));
@@ -522,9 +522,9 @@ describe('GalleryImageGrid mixed item cells', () => {
const collapsedRegularRect = getButton('Select regular.png for preview').getBoundingClientRect();
const collapsedSectionGap = collapsedRegularRect.top - (collapsedHeaderRect?.bottom ?? 0);
- expect((collapsedHeaderRect?.top ?? 0) - (listRect?.top ?? 0)).toBeCloseTo(8, 0);
- expect(collapsedSectionGap).toBeGreaterThanOrEqual(8);
- expect(collapsedSectionGap).toBeLessThan(12);
+ expect((collapsedHeaderRect?.top ?? 0) - (listRect?.top ?? 0)).toBeCloseTo(0, 0);
+ expect(collapsedSectionGap).toBeGreaterThanOrEqual(4);
+ expect(collapsedSectionGap).toBeLessThan(8);
});
it('collapses only the starred items and omits the disclosure when no stars are loaded', async () => {
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
index 63982c0eed..5bd33af969 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
@@ -34,7 +34,7 @@ import { useGalleryGridSelection } from './useGalleryGridSelection';
*/
const viewportWidthCache = new Map<string, number>();
const STARRED_HEADER_HEIGHT_PX = 24;
-const STARRED_SECTION_GAP_PX = 8;
+const STARRED_SECTION_GAP_PX = GALLERY_GRID_GAP_PX;
const STARRED_TRIGGER_HOVER_STYLES = { color: 'fg' } as const;
const dragEventContainsFiles = (event: DragEvent): boolean => Array.from(event.dataTransfer.types).includes('Files');
@@ -47,6 +47,7 @@ type GridSection = 'regular' | 'starred';
type GridRow =
| { kind: 'cells'; cells: GridCell[]; section: GridSection }
+ | { kind: 'starred-gap' }
| { kind: 'starred-header'; itemCount: number };
const chunkCellsIntoRows = (cells: GridCell[], columnCount: number, section: GridSection): GridRow[] => {
@@ -133,6 +134,10 @@ export const GalleryImageGrid = () => {
if (isStarredOpen) {
nextRows.push(...chunkCellsIntoRows(starredItemCells, columnCount, 'starred'));
}
+
+ if (regularCells.length > 0) {
+ nextRows.push({ kind: 'starred-gap' });
+ }
}
nextRows.push(...chunkCellsIntoRows(regularCells, columnCount, 'regular'));
@@ -148,10 +153,11 @@ export const GalleryImageGrid = () => {
const row = rows[index];
if (row?.kind === 'starred-header') {
- const nextRow = rows[index + 1];
- const isCollapsed = nextRow?.kind !== 'cells' || nextRow.section !== 'starred';
+ return STARRED_HEADER_HEIGHT_PX;
+ }
- return STARRED_SECTION_GAP_PX + STARRED_HEADER_HEIGHT_PX + (isCollapsed ? STARRED_SECTION_GAP_PX : 0);
+ if (row?.kind === 'starred-gap') {
+ return STARRED_SECTION_GAP_PX;
}
return rowHeightPx;
@@ -329,7 +335,7 @@ export const GalleryImageGrid = () => {
position="absolute"
px="1"
top="0"
- transform={`translateY(${virtualRow.start + STARRED_SECTION_GAP_PX}px)`}
+ transform={`translateY(${virtualRow.start}px)`}
w="full"
>
<chakra.button
@@ -385,6 +391,10 @@ export const GalleryImageGrid = () => {
);
}
+ if (row.kind === 'starred-gap') {
+ return null;
+ }
+
return (
<Box
key={virtualRow.key}