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(ui): support date tokens in gallery search

joshistoast1f2d08c3f272
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index de69cd4121..2f7fecdb45 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1698,6 +1698,11 @@
"toggleStarImage": "Toggle gallery image star"
},
"createBoardNamed": "Create board \"{{name}}\"",
+ "dateFilterDay": "{{date}}",
+ "dateFilterFrom": "From {{date}}",
+ "dateFilterInvalid": "Unrecognized date “{{value}}” — use YYYY-MM-DD, today, yesterday, 7d, 2w, 1m",
+ "dateFilterRange": "{{from}} – {{to}}",
+ "dateFilterThrough": "Through {{date}}",
"deleteBoard": "Delete Board",
"deleteBoardAndImages": "Delete Board and Images",
"deleteBoardDescription": "Deleted boards cannot be restored. Choose whether the board's images move to Uncategorized or are permanently deleted with it.",
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts
index 499364521e..96e78aa762 100644
--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts
@@ -12,7 +12,12 @@ vi.mock('@platform/transport/http', () => ({
sleep: vi.fn(),
}));
-import { getGalleryImageByName, imageMakeDurableChanges, imageSaveToGalleryChanges } from './backend';
+import {
+ getGalleryImageByName,
+ imageMakeDurableChanges,
+ imageSaveToGalleryChanges,
+ listGalleryImages,
+} from './backend';
describe('getGalleryImageByName', () => {
beforeEach(() => {
@@ -70,6 +75,65 @@ describe('getGalleryImageByName', () => {
});
});
+describe('listGalleryImages created-at range', () => {
+ beforeEach(() => {
+ mocks.apiFetchJson.mockReset();
+ mocks.apiFetchJson.mockResolvedValue({ items: [], limit: 20, offset: 0, total: 0 });
+ });
+
+ it('sends created_from/created_to as query params', async () => {
+ await listGalleryImages({
+ boardId: 'board-1',
+ createdFrom: '2026-07-01',
+ createdTo: '2026-07-15',
+ galleryView: 'images',
+ searchTerm: '',
+ });
+
+ const url = mocks.apiFetchJson.mock.calls[0]?.[0] as string;
+ const params = new URLSearchParams(url.split('?')[1]);
+ expect(params.get('created_from')).toBe('2026-07-01');
+ expect(params.get('created_to')).toBe('2026-07-15');
+ });
+
+ it('omits the range params when no range is given', async () => {
+ await listGalleryImages({ boardId: 'board-1', galleryView: 'images', searchTerm: 'sunset' });
+
+ const url = mocks.apiFetchJson.mock.calls[0]?.[0] as string;
+ const params = new URLSearchParams(url.split('?')[1]);
+ expect(params.has('created_from')).toBe(false);
+ expect(params.has('created_to')).toBe(false);
+ });
+
+ it('short-circuits a date board that falls outside the range without a request', async () => {
+ await expect(
+ listGalleryImages({
+ boardId: 'by_date:2026-07-18',
+ createdFrom: '2026-07-01',
+ createdTo: '2026-07-15',
+ galleryView: 'images',
+ searchTerm: '',
+ })
+ ).resolves.toEqual({ images: [], total: 0 });
+ expect(mocks.apiFetchJson).not.toHaveBeenCalled();
+ });
+
+ it('queries a date board normally when its day is inside the range', async () => {
+ mocks.apiFetchJson.mockResolvedValue({ image_names: [], total_count: 0 });
+
+ await expect(
+ listGalleryImages({
+ boardId: 'by_date:2026-07-10',
+ createdFrom: '2026-07-01',
+ createdTo: '2026-07-15',
+ galleryView: 'images',
+ searchTerm: '',
+ })
+ ).resolves.toEqual({ images: [], total: 0 });
+ expect(mocks.apiFetchJson).toHaveBeenCalledOnce();
+ });
+});
+
describe('imageSaveToGalleryChanges', () => {
it('promotes an intermediate candidate to a durable, gallery-visible image', () => {
// The backend `ImageRecordChanges` body: clear `is_intermediate` (stop GC)
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.ts
index d6852a3c17..b78b76b13d 100644
--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.ts
@@ -8,6 +8,7 @@ import type {
GalleryView,
} from '@features/gallery/core/types';
+import { isTimestampInRange } from '@platform/search/dateTokens';
import { absolutizeApiUrl, apiFetch, apiFetchJson, apiFetchRaw, sleep } from '@platform/transport/http';
import { getGalleryImageThumbnailUrl } from './imageUrls';
@@ -207,6 +208,8 @@ export const getGalleryImageByName = async (imageName: string, signal?: AbortSig
*/
const listGalleryDateBoardImages = async ({
boardId,
+ createdFrom,
+ createdTo,
galleryView,
limit,
offset,
@@ -215,6 +218,8 @@ const listGalleryDateBoardImages = async ({
starredFirst,
}: {
boardId: string;
+ createdFrom?: string;
+ createdTo?: string;
galleryView: GalleryView;
limit: number;
offset: number;
@@ -222,6 +227,15 @@ const listGalleryDateBoardImages = async ({
searchTerm: string;
starredFirst: boolean;
}): Promise<GalleryImagesPage> => {
+ // The board already pins a single day; a date filter either contains that
+ // day (and constrains nothing further) or excludes the whole board.
+ if (
+ (createdFrom !== undefined || createdTo !== undefined) &&
+ !isTimestampInRange(getDateFromBoardId(boardId), { from: createdFrom, to: createdTo })
+ ) {
+ return { images: [], total: 0 };
+ }
+
const query = toSearchParams({
categories: galleryView === 'assets' ? assetCategories : imageCategories,
order_dir: orderDir,
@@ -238,6 +252,8 @@ const listGalleryDateBoardImages = async ({
export const listGalleryImages = async ({
boardId,
+ createdFrom,
+ createdTo,
galleryView,
limit = 100,
offset = 0,
@@ -246,6 +262,8 @@ export const listGalleryImages = async ({
starredFirst = false,
}: {
boardId: string;
+ createdFrom?: string;
+ createdTo?: string;
galleryView: GalleryView;
limit?: number;
offset?: number;
@@ -254,12 +272,24 @@ export const listGalleryImages = async ({
starredFirst?: boolean;
}): Promise<GalleryImagesPage> => {
if (isDateBoardId(boardId)) {
- return listGalleryDateBoardImages({ boardId, galleryView, limit, offset, orderDir, searchTerm, starredFirst });
+ return listGalleryDateBoardImages({
+ boardId,
+ createdFrom,
+ createdTo,
+ galleryView,
+ limit,
+ offset,
+ orderDir,
+ searchTerm,
+ starredFirst,
+ });
}
const query = toSearchParams({
board_id: boardId,
categories: galleryView === 'assets' ? assetCategories : imageCategories,
+ created_from: createdFrom,
+ created_to: createdTo,
is_intermediate: false,
limit,
offset,
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/queries.test.ts b/invokeai/frontend/webv2/src/features/gallery/data/queries.test.ts
index 69f91eac49..0cb74f363b 100644
--- a/invokeai/frontend/webv2/src/features/gallery/data/queries.test.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/data/queries.test.ts
@@ -52,4 +52,18 @@ describe('Gallery query read model', () => {
galleryImagesOptions({ ...base, revision: 'images:2' }).queryKey
);
});
+
+ it('keeps the created-at range in the image query key', () => {
+ const base = {
+ boardId: 'board-1',
+ galleryView: 'images' as const,
+ searchTerm: '',
+ };
+ const ranged = { ...base, createdFrom: '2026-07-01', createdTo: '2026-07-15' };
+
+ expect(galleryImagesOptions(base).queryKey).not.toEqual(galleryImagesOptions(ranged).queryKey);
+ expect(galleryImagesOptions(ranged).queryKey).not.toEqual(
+ galleryImagesOptions({ ...ranged, createdTo: '2026-07-16' }).queryKey
+ );
+ });
});
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/queries.ts b/invokeai/frontend/webv2/src/features/gallery/data/queries.ts
index 540138c1f4..091c7c2f4f 100644
--- a/invokeai/frontend/webv2/src/features/gallery/data/queries.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/data/queries.ts
@@ -14,6 +14,10 @@ export interface GalleryBoardsQuery {
export interface GalleryImagesQuery {
boardId: string;
+ /** Inclusive lower-bound calendar day (YYYY-MM-DD) on created_at. */
+ createdFrom?: string;
+ /** Inclusive upper-bound calendar day (YYYY-MM-DD) on created_at. */
+ createdTo?: string;
galleryView: GalleryView;
limit?: number;
offset?: number;
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryToolbar.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryToolbar.tsx
index 952c04dbbe..71d25bb04c 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryToolbar.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryToolbar.tsx
@@ -15,6 +15,12 @@ import {
Text,
} from '@chakra-ui/react';
import { isDateBoardId } from '@features/gallery/data/backend';
+import {
+ formatIsoDate,
+ isPossibleDatePrefix,
+ matchTrailingDateToken,
+ parseDateTokens,
+} from '@platform/search/dateTokens';
import { Button, CloseButton, IconButton, Tabs } from '@platform/ui';
import { SearchIcon, SettingsIcon, UploadIcon } from 'lucide-react';
import { useCallback, useMemo, useRef } from 'react';
@@ -32,9 +38,10 @@ const galleryViewTabs = [
const UPLOAD_INPUT_STYLE = { display: 'none' } as const;
const GALLERY_SETTINGS_POSITIONING = { placement: 'bottom-end' } as const;
const SEARCH_START_ELEMENT = <Icon as={SearchIcon} size="sm" />;
+const SEARCH_DATE_HINT_ID = 'gallery-search-date-hint';
export const GalleryToolbar = ({ layout }: { layout: 'stacked' | 'wide' }) => {
- const { t } = useTranslation();
+ const { i18n, t } = useTranslation();
const { actions, gallery } = useGalleryWidget();
const isWide = layout === 'wide';
@@ -83,19 +90,83 @@ export const GalleryToolbar = ({ layout }: { layout: 'stacked' | 'wide' }) => {
[]
);
+ // Derived from the raw search term: an applied-range summary, or invalid-
+ // token feedback. A trailing token that could still become valid (`from:`,
+ // `from:2026-`) is normal typing, not an error.
+ const dateHint = useMemo(() => {
+ const parse = parseDateTokens(gallery.searchTerm);
+ const trailing = matchTrailingDateToken(gallery.searchTerm);
+ const invalid = parse.invalidTokens.find(
+ (token) =>
+ !(
+ trailing &&
+ token.key === trailing.key &&
+ token.raw === trailing.partialValue &&
+ isPossibleDatePrefix(token.raw)
+ )
+ );
+
+ if (invalid) {
+ return { isInvalid: true, label: t('widgets.gallery.dateFilterInvalid', { value: invalid.raw }) };
+ }
+
+ if (!parse.range) {
+ return null;
+ }
+
+ const locale = i18n.language;
+ const { from, to } = parse.range;
+
+ if (from !== undefined && to !== undefined) {
+ return {
+ isInvalid: false,
+ label:
+ from === to
+ ? t('widgets.gallery.dateFilterDay', { date: formatIsoDate(from, locale) })
+ : t('widgets.gallery.dateFilterRange', {
+ from: formatIsoDate(from, locale),
+ to: formatIsoDate(to, locale),
+ }),
+ };
+ }
+
+ if (from !== undefined) {
+ return { isInvalid: false, label: t('widgets.gallery.dateFilterFrom', { date: formatIsoDate(from, locale) }) };
+ }
+
+ return {
+ isInvalid: false,
+ label: t('widgets.gallery.dateFilterThrough', { date: formatIsoDate(to ?? '', locale) }),
+ };
+ }, [gallery.searchTerm, i18n.language, t]);
+
const searchInput = useMemo(
() => (
- <InputGroup startElement={SEARCH_START_ELEMENT} endElement={searchClearButton}>
- <Input
- aria-label={t('widgets.gallery.searchImagesAriaLabel')}
- placeholder={t('widgets.gallery.searchImagesPlaceholder')}
- size="xs"
- value={gallery.searchTerm}
- onChange={handleSearchChange}
- />
- </InputGroup>
+ <Stack gap="1">
+ <InputGroup startElement={SEARCH_START_ELEMENT} endElement={searchClearButton}>
+ <Input
+ aria-describedby={dateHint?.isInvalid ? SEARCH_DATE_HINT_ID : undefined}
+ aria-invalid={dateHint?.isInvalid || undefined}
+ aria-label={t('widgets.gallery.searchImagesAriaLabel')}
+ placeholder={t('widgets.gallery.searchImagesPlaceholder')}
+ size="xs"
+ value={gallery.searchTerm}
+ onChange={handleSearchChange}
+ />
+ </InputGroup>
+ {dateHint ? (
+ <Text
+ color={dateHint.isInvalid ? 'fg.error' : 'fg.subtle'}
+ fontSize="2xs"
+ id={SEARCH_DATE_HINT_ID}
+ role="status"
+ >
+ {dateHint.label}
+ </Text>
+ ) : null}
+ </Stack>
),
- [gallery.searchTerm, handleSearchChange, searchClearButton, t]
+ [dateHint, gallery.searchTerm, handleSearchChange, searchClearButton, t]
);
return (
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.ts b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.ts
index b41e64118b..1fd26eba7c 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.ts
@@ -2,8 +2,9 @@ import type { GallerySettings } from '@features/gallery/core/settings';
import type { GalleryBoard, GalleryImage, GalleryView } from '@features/gallery/core/types';
import { galleryBoardsOptions, galleryImagesOptions } from '@features/gallery/data/queries';
+import { parseDateTokens } from '@platform/search/dateTokens';
import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query';
-import { useCallback, useState } from 'react';
+import { useCallback, useMemo, useState } from 'react';
export const GALLERY_PAGE_SIZE = 60;
@@ -62,14 +63,19 @@ export const useGalleryData = ({
const pageCount = infiniteWindow.baseKey === baseKey ? infiniteWindow.pageCount : 1;
const offset = isPaginated ? page * GALLERY_PAGE_SIZE : 0;
const limit = isPaginated ? GALLERY_PAGE_SIZE : pageCount * GALLERY_PAGE_SIZE;
+ // The raw search term stays the source of truth; date tokens are derived
+ // here so both the text filter and the range reach the query together.
+ const dateParse = useMemo(() => parseDateTokens(searchTerm), [searchTerm]);
const options = galleryImagesOptions({
boardId,
+ createdFrom: dateParse.range?.from,
+ createdTo: dateParse.range?.to,
galleryView,
limit,
offset,
orderDir: settings.imageOrderDir,
revision: `${imageRefreshToken}:${recentImagesKey}`,
- searchTerm,
+ searchTerm: dateParse.text,
starredFirst: settings.starredFirst,
});
const query = useQuery({ ...options, placeholderData: keepPreviousData });