Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
refactor(soup): add group by support and update soup state data type (#2819)
dev-rb966c505d780c
diff --git a/js/app/packages/app/component/interactive-onboarding/OnboardingEntityList.tsx b/js/app/packages/app/component/interactive-onboarding/OnboardingEntityList.tsxindex b5994170ef..7cf1d21b84 100644--- a/js/app/packages/app/component/interactive-onboarding/OnboardingEntityList.tsx+++ b/js/app/packages/app/component/interactive-onboarding/OnboardingEntityList.tsx@@ -28,11 +28,11 @@ export function OnboardingEntityList(props: OnboardingEntityListProps) {class="flex flex-col w-full h-full scrollbar-hidden overflow-scroll"role="listbox">- <For each={props.soup.data()}>- {(entity) => {- const isFocused = () => props.soup.focus.id() === entity.id;- const isRemoving = () =>- props.removingIds?.().has(entity.id) ?? false;+ <For each={props.soup.rows()}>+ {(row) => {+ const entity = () => row.original;+ const isFocused = () => props.soup.focus.id() === row.id;+ const isRemoving = () => props.removingIds?.().has(row.id) ?? false;let rowRef: HTMLDivElement | undefined;createEffect(() => {@@ -44,7 +44,7 @@ export function OnboardingEntityList(props: OnboardingEntityListProps) {return (<Entity.Rootref={rowRef}- entity={entity as EntityData}+ entity={entity() as EntityData}class={cn('relative w-full min-h-10 flex items-center gap-2 px-5 text-sm font-semibold',{@@ -62,16 +62,16 @@ export function OnboardingEntityList(props: OnboardingEntityListProps) {)}/><Show- when={entity.type === 'email'}+ when={entity().type === 'email'}fallback={<><span class="size-1.5 shrink-0" /><div class="size-4 shrink-0">- <Entity.Icon entity={entity as EntityData} />+ <Entity.Icon entity={entity() as EntityData} /></div>- <Entity.Title entity={entity as EntityData} />+ <Entity.Title entity={entity() as EntityData} /><span class="ml-auto font-mono font-light uppercase tracking-wide text-xs text-ink/40 shrink-0">- <Entity.Timestamp entity={entity as EntityData} />+ <Entity.Timestamp entity={entity() as EntityData} /></span></>}@@ -81,25 +81,25 @@ export function OnboardingEntityList(props: OnboardingEntityListProps) {<spanclass={cn('size-1.5 rounded-full bg-accent shrink-0', {'opacity-0': (- entity as EntityData & { isRead: boolean }+ entity() as EntityData & { isRead: boolean }).isRead,})}/><div class="size-4 shrink-0">- <Entity.Icon entity={entity as EntityData} />+ <Entity.Icon entity={entity() as EntityData} /></div><spanclass={cn('truncate', {'text-ink font-semibold': !(- entity as EntityData & { isRead: boolean }+ entity() as EntityData & { isRead: boolean }).isRead,'text-ink/60 font-normal': (- entity as EntityData & { isRead: boolean }+ entity() as EntityData & { isRead: boolean }).isRead,})}>{- (entity as EntityData & { senderName: string })+ (entity() as EntityData & { senderName: string }).senderName}</span>@@ -108,21 +108,21 @@ export function OnboardingEntityList(props: OnboardingEntityListProps) {<spanclass={cn('truncate shrink-0 max-w-[40%]', {'font-semibold': !(- entity as EntityData & { isRead: boolean }+ entity() as EntityData & { isRead: boolean }).isRead,'font-normal text-ink/70': (- entity as EntityData & { isRead: boolean }+ entity() as EntityData & { isRead: boolean }).isRead,})}>- <Entity.Title entity={entity as EntityData} />+ <Entity.Title entity={entity() as EntityData} /></span><span class="truncate text-ink/50 font-normal">- {(entity as EntityData & { snippet: string }).snippet}+ {(entity() as EntityData & { snippet: string }).snippet}</span></span><span class="ml-auto font-mono font-light uppercase tracking-wide text-xs text-ink/40 shrink-0">- <Entity.Timestamp entity={entity as EntityData} />+ <Entity.Timestamp entity={entity() as EntityData} /></span></Show></Entity.Root>diff --git a/js/app/packages/app/component/interactive-onboarding/lessons/command-k.tsx b/js/app/packages/app/component/interactive-onboarding/lessons/command-k.tsxindex 7dc70b863f..ae0c04af58 100644--- a/js/app/packages/app/component/interactive-onboarding/lessons/command-k.tsx+++ b/js/app/packages/app/component/interactive-onboarding/lessons/command-k.tsx@@ -136,13 +136,10 @@ function CommandKDemo(props: LessonContentProps) {let contentEl: HTMLDivElement | undefined;- const soup = createSoupState({- initialData: filteredSandboxEntities(),- wrapNavigation: true,- });+ const soup = createSoupState({ wrapNavigation: true });createEffect(() => {- soup.setData(filteredSandboxEntities());+ soup.setRows(filteredSandboxEntities().map((e) => soup.buildRow(e)));});return (diff --git a/js/app/packages/app/component/interactive-onboarding/lessons/create-entity.tsx b/js/app/packages/app/component/interactive-onboarding/lessons/create-entity.tsxindex 141492bc21..2634a230dc 100644--- a/js/app/packages/app/component/interactive-onboarding/lessons/create-entity.tsx+++ b/js/app/packages/app/component/interactive-onboarding/lessons/create-entity.tsx@@ -1,5 +1,7 @@-import { createSoupState } from '@app/component/next-soup/create-soup-state';-import type { SoupState } from '@app/component/next-soup/create-soup-state';+import {+ createSoupState,+ type SoupState,+} from '@app/component/next-soup/create-soup-state';import {LauncherInner,CREATABLE_BLOCKS,@@ -129,7 +131,6 @@ function CreateEntityContent(props: LessonContentProps) {function CreateEntityDemo(props: LessonContentProps) {const soup = createSoupState({- initialData: filteredSandboxEntities(),wrapNavigation: true,});@@ -143,7 +144,7 @@ function CreateEntityDemo(props: LessonContentProps) {// Keep soup synced with sandbox storecreateEffect(() => {- soup.setData(filteredSandboxEntities());+ soup.setRows(filteredSandboxEntities().map((e) => soup.buildRow(e)));});// Build sandbox versions of all creatable blocksdiff --git a/js/app/packages/app/component/interactive-onboarding/lessons/home.tsx b/js/app/packages/app/component/interactive-onboarding/lessons/home.tsxindex f20d82581f..4ed8e0e5e5 100644--- a/js/app/packages/app/component/interactive-onboarding/lessons/home.tsx+++ b/js/app/packages/app/component/interactive-onboarding/lessons/home.tsx@@ -29,7 +29,7 @@ function HomeDemo() {});createEffect(() => {- soup.setData(filteredSandboxEntities());+ soup.setRows(filteredSandboxEntities().map((e) => soup.buildRow(e)));});return (diff --git a/js/app/packages/app/component/interactive-onboarding/lessons/sidebar-nav.tsx b/js/app/packages/app/component/interactive-onboarding/lessons/sidebar-nav.tsxindex b9c2680291..7c93e5a19d 100644--- a/js/app/packages/app/component/interactive-onboarding/lessons/sidebar-nav.tsx+++ b/js/app/packages/app/component/interactive-onboarding/lessons/sidebar-nav.tsx@@ -48,13 +48,10 @@ function SidebarNavContent(props: LessonContentProps) {}function SidebarNavDemo() {- const soup = createSoupState({- initialData: filteredSandboxEntities(),- wrapNavigation: true,- });+ const soup = createSoupState({ wrapNavigation: true });createEffect(() => {- soup.setData(filteredSandboxEntities());+ soup.setRows(filteredSandboxEntities().map((e) => soup.buildRow(e)));});return (diff --git a/js/app/packages/app/component/next-soup/actions/make-delete-action.ts b/js/app/packages/app/component/next-soup/actions/make-delete-action.tsindex 26ec3d0380..f7c1637580 100644--- a/js/app/packages/app/component/next-soup/actions/make-delete-action.ts+++ b/js/app/packages/app/component/next-soup/actions/make-delete-action.ts@@ -49,7 +49,7 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {const executeWithSoup = async (entities: EntityData[], soup: SoupState) => {const currentIndex = soup.focus.index();- const nextEntity =+ const nextRow =soup.items.at(currentIndex + 1) ?? soup.items.at(currentIndex - 1);const inPreview = previewPanel !== undefined;@@ -70,8 +70,8 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {}soup.selection.clear();- if (nextEntity) {- soup.focus.set(nextEntity.id);+ if (nextRow) {+ soup.focus.set(nextRow.id);}const toastId = toast.success(@@ -100,12 +100,12 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {toast.failure('Failed to move to Trash');});- restoreSoupFocus(nextEntity?.id, inPreview);+ restoreSoupFocus(nextRow?.id, inPreview);};if (nonEmailEntities.length > 0) {// Handle non-email entities first via the bulk edit modal,- // then trash emails in onFinish so nextEntity/focus are still valid.+ // then trash emails in onFinish so nextRow/focus are still valid.openBulkEditModal({view: 'delete',entities: nonEmailEntities,@@ -128,10 +128,10 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {trashEmailEntities();} else {soup.selection.clear();- if (nextEntity) {- soup.focus.set(nextEntity.id);+ if (nextRow) {+ soup.focus.set(nextRow.id);}- restoreSoupFocus(nextEntity?.id, inPreview);+ restoreSoupFocus(nextRow?.id, inPreview);}},onCancel: () => {diff --git a/js/app/packages/app/component/next-soup/actions/make-mark-done-action.ts b/js/app/packages/app/component/next-soup/actions/make-mark-done-action.tsindex 3ddf805740..6cb1eab890 100644--- a/js/app/packages/app/component/next-soup/actions/make-mark-done-action.ts+++ b/js/app/packages/app/component/next-soup/actions/make-mark-done-action.ts@@ -171,7 +171,7 @@ export const makeMarkDoneAction = (options: MakeMarkDoneOptions) => {) => {const currentIndex = soup.focus.index();const focusedIdBeforeMarkDone = soup.focus.id();- const nextEntity =+ const nextRow =soup.items.at(currentIndex + 1) ?? soup.items.at(currentIndex - 1);if (soup.collapseEntity.shouldCollapse()) {@@ -187,9 +187,9 @@ export const makeMarkDoneAction = (options: MakeMarkDoneOptions) => {soup.selection.clear();- if (nextEntity) {- soup.focus.set(nextEntity.id);- onNavigate?.(nextEntity);+ if (nextRow) {+ soup.focus.set(nextRow.id);+ onNavigate?.(nextRow.original);}await execute(entities, restoreFocus);diff --git a/js/app/packages/app/component/next-soup/actions/make-move-to-project-action.ts b/js/app/packages/app/component/next-soup/actions/make-move-to-project-action.tsindex 787464eed1..b04654bee4 100644--- a/js/app/packages/app/component/next-soup/actions/make-move-to-project-action.ts+++ b/js/app/packages/app/component/next-soup/actions/make-move-to-project-action.ts@@ -28,7 +28,7 @@ export const makeMoveToProjectAction = () => {const executeWithSoup = async (entities: EntityData[], soup: SoupState) => {const currentIndex = soup.focus.index();- const nextEntity =+ const nextRow =soup.items.at(currentIndex + 1) ?? soup.items.at(currentIndex - 1);const inPreview = previewPanel !== undefined;@@ -38,15 +38,15 @@ export const makeMoveToProjectAction = () => {entities,onFinish: () => {soup.selection.clear();- if (nextEntity) {- soup.focus.set(nextEntity.id);+ if (nextRow) {+ soup.focus.set(nextRow.id);}toast.success(entities.length > 1? `Moved ${entities.length} items`: 'Moved to folder');- restoreSoupFocus(nextEntity?.id, inPreview);+ restoreSoupFocus(nextRow?.id, inPreview);},onCancel: () => {const firstEntity = entities[0];diff --git a/js/app/packages/app/component/next-soup/create-soup-state.test.ts b/js/app/packages/app/component/next-soup/create-soup-state.test.tsindex 55bbf1e2cb..3574a7d957 100644--- a/js/app/packages/app/component/next-soup/create-soup-state.test.ts+++ b/js/app/packages/app/component/next-soup/create-soup-state.test.ts@@ -49,23 +49,24 @@ const createTestEntity = (id: string, name?: string): EntityData => ({describe('createSoupState', () => {describe('initial state', () => {- it('should start with empty data', () => {+ it('should start with empty rows', () => {createRoot((dispose) => {const state = createSoupState();- expect(state.data()).toEqual([]);+ expect(state.rows()).toEqual([]);expect(state.items.count()).toBe(0);dispose();});});- it('should accept initial data', () => {+ it('should accept initial rows via setRows', () => {createRoot((dispose) => {+ const state = createSoupState();const entities = [createTestEntity('1'), createTestEntity('2')];- const state = createSoupState({ initialData: entities });+ state.setRows(entities.map((e) => state.buildRow(e)));- expect(state.data()).toEqual(entities);+ expect(state.rows().map((r) => r.original)).toEqual(entities);expect(state.items.count()).toBe(2);dispose();@@ -73,15 +74,15 @@ describe('createSoupState', () => {});});- describe('setData', () => {- it('should update data', () => {+ describe('setRows', () => {+ it('should update rows', () => {createRoot((dispose) => {const state = createSoupState();const entities = [createTestEntity('1'), createTestEntity('2')];- state.setData(entities);+ state.setRows(entities.map((e) => state.buildRow(e)));- expect(state.data()).toEqual(entities);+ expect(state.rows().map((r) => r.original)).toEqual(entities);dispose();});@@ -89,28 +90,29 @@ describe('createSoupState', () => {});describe('items', () => {- it('should get item by id', () => {+ it('should get row by id', () => {createRoot((dispose) => {const entity1 = createTestEntity('1');const entity2 = createTestEntity('2');- const state = createSoupState({ initialData: [entity1, entity2] });+ const state = createSoupState();+ state.setRows([entity1, entity2].map((e) => state.buildRow(e)));- expect(state.items.get('1')).toBe(entity1);- expect(state.items.get('2')).toBe(entity2);+ expect(state.items.get('1')?.original).toBe(entity1);+ expect(state.items.get('2')?.original).toBe(entity2);expect(state.items.get('nonexistent')).toBeUndefined();dispose();});});- it('should get item at index', () => {+ it('should get row at index', () => {createRoot((dispose) => {const entity1 = createTestEntity('1');const entity2 = createTestEntity('2');- const state = createSoupState({ initialData: [entity1, entity2] });+ const state = createSoupState({});- expect(state.items.at(0)).toBe(entity1);- expect(state.items.at(1)).toBe(entity2);+ expect(state.items.at(0)?.original).toBe(entity1);+ expect(state.items.at(1)?.original).toBe(entity2);expect(state.items.at(99)).toBeUndefined();dispose();@@ -190,11 +192,11 @@ describe('createSoupState', () => {const state = createSoupState({ initialData: entities });const result1 = state.navigate.down();- expect(result1?.item).toBe(entities[0]);+ expect(result1?.row.original).toBe(entities[0]);expect(result1?.index).toBe(0);const result2 = state.navigate.down();- expect(result2?.item).toBe(entities[1]);+ expect(result2?.row.original).toBe(entities[1]);expect(result2?.index).toBe(1);dispose();@@ -212,11 +214,11 @@ describe('createSoupState', () => {// When no focus, up goes to lastconst result1 = state.navigate.up();- expect(result1?.item).toBe(entities[2]);+ expect(result1?.row.original).toBe(entities[2]);expect(result1?.index).toBe(2);const result2 = state.navigate.up();- expect(result2?.item).toBe(entities[1]);+ expect(result2?.row.original).toBe(entities[1]);expect(result2?.index).toBe(1);dispose();@@ -231,7 +233,7 @@ describe('createSoupState', () => {state.focus.set('2');const result = state.navigate.toFirst();- expect(result?.item).toBe(entities[0]);+ expect(result?.row.original).toBe(entities[0]);expect(state.focus.id()).toBe('1');dispose();@@ -246,7 +248,7 @@ describe('createSoupState', () => {state.focus.set('1');const result = state.navigate.toLast();- expect(result?.item).toBe(entities[1]);+ expect(result?.row.original).toBe(entities[1]);expect(state.focus.id()).toBe('2');dispose();@@ -264,7 +266,7 @@ describe('createSoupState', () => {const result = state.navigate.toIndex(1);- expect(result?.item).toBe(entities[1]);+ expect(result?.row.original).toBe(entities[1]);expect(state.focus.id()).toBe('2');dispose();@@ -278,7 +280,7 @@ describe('createSoupState', () => {const result = state.navigate.toId('2');- expect(result?.item).toBe(entities[1]);+ expect(result?.row.original).toBe(entities[1]);expect(state.focus.id()).toBe('2');dispose();@@ -356,7 +358,7 @@ describe('createSoupState', () => {expect(state.focus.id()).toBe('2');const peeked = state.navigate.peekOffset(1);- expect(peeked?.item).toBe(entities[2]);+ expect(peeked?.row.original).toBe(entities[2]);// Focus should remain unchangedexpect(state.focus.id()).toBe('2');@@ -427,20 +429,37 @@ describe('createSoupState', () => {});});- describe('groups', () => {- it('should manage group configs', () => {+ describe('grouping', () => {+ it('should manage group expansion state', () => {createRoot((dispose) => {const state = createSoupState();- expect(state.groups()).toEqual([]);+ // Groups start expanded+ expect(state.grouping.isExpanded('group-1')).toBe(true);++ // Toggle to collapse+ state.grouping.toggle('group-1');+ expect(state.grouping.isExpanded('group-1')).toBe(false);++ // Toggle to expand+ state.grouping.toggle('group-1');+ expect(state.grouping.isExpanded('group-1')).toBe(true);++ dispose();+ });+ });++ it('should collapse and expand all groups', () => {+ createRoot((dispose) => {+ const state = createSoupState();- const groupConfig = {- id: 'type',- getValue: (_item: unknown) => 'test',- };- state.setGroups([groupConfig]);+ state.grouping.collapseAll(['group-1', 'group-2']);+ expect(state.grouping.isExpanded('group-1')).toBe(false);+ expect(state.grouping.isExpanded('group-2')).toBe(false);- expect(state.groups()).toEqual([groupConfig]);+ state.grouping.expandAll();+ expect(state.grouping.isExpanded('group-1')).toBe(true);+ expect(state.grouping.isExpanded('group-2')).toBe(true);dispose();});diff --git a/js/app/packages/app/component/next-soup/create-soup-state.ts b/js/app/packages/app/component/next-soup/create-soup-state.tsindex 7e379197af..99135794b9 100644--- a/js/app/packages/app/component/next-soup/create-soup-state.ts+++ b/js/app/packages/app/component/next-soup/create-soup-state.ts@@ -11,16 +11,49 @@ import { createSelectionState } from '@app/component/next-soup/selection-state';import { SORT_CONFIGS } from '@app/component/next-soup/soup-view/sort-options';import { isModality } from '@core/mobile/inputModality';import { isTouchDevice } from '@core/mobile/isTouchDevice';-import type { EntityData, WithSearch } from '@entity';-import { createMemo, createSignal } from 'solid-js';+import type { EntityData, WithSearch, WithNotification } from '@entity';+import { createMemo, createSignal, type JSX } from 'solid-js';-type SoupEntity = EntityData | WithSearch<EntityData>;+export type SoupEntity = WithNotification<EntityData | WithSearch<EntityData>>;-export type NavigationResult<T> = { item: T; index: number } | undefined;+export type GroupMeta = {+ id: string;+ value: unknown;+ label: string;+ count: number;+ isExpanded: () => boolean;+ toggle: () => void;+ renderHeader?: (props: {+ value: unknown;+ label: string;+ count: number;+ }) => JSX.Element;+};++export type SoupRow = {+ original: SoupEntity;+ id: string;+ depth: number;+ group?: GroupMeta;+ parentGroupId: string | null;+ isFocused: () => boolean;+ isSelected: () => boolean;+ isExpanded: () => boolean;+ isGrouped: () => boolean;+};++export type NavigationResult = { row: SoupRow; index: number } | undefined;export type GroupConfig<T> = {id: string;+ label: string;getValue: (item: T) => unknown;+ getLabel?: (value: unknown) => string;+ renderHeader?: (props: {+ value: unknown;+ label: string;+ count: number;+ }) => JSX.Element;};export type SortConfig<T> = {@@ -36,13 +69,19 @@ interface SoupContextOptions<TId extends string = FilterID> {};predicateConfigs?: PredicateConfig<SoupEntity, string>[];wrapNavigation?: boolean;+ skipGroupHeaders?: boolean;}export const createSoupState = <TId extends string = FilterID>(- options: SoupContextOptions<TId> = { wrapNavigation: false }+ options: SoupContextOptions<TId> = {}) => {- const { wrapNavigation, initialData, initialPredicates, predicateConfigs } =- options;+ const {+ wrapNavigation,+ initialData,+ initialPredicates,+ predicateConfigs,+ skipGroupHeaders,+ } = options;const selection = createSelectionState<SoupEntity>({getItemId: (i) => i.id,@@ -55,12 +94,57 @@ export const createSoupState = <TId extends string = FilterID>(const sort = createSortState(SORT_CONFIGS, ['updated_at']);- const [groups, setGroups] = createSignal<GroupConfig<SoupEntity>[]>([]);+ const [focusedId, setFocusedId] = createSignal<string | undefined>();++ const [activeGroupId, setActiveGroupId] = createSignal<string | undefined>();++ const [collapsedGroups, setCollapsedGroups] = createSignal<Set<string>>(+ new Set()+ );++ const toggleGroup = (groupId: string) => {+ setCollapsedGroups((prev) => {+ const next = new Set(prev);+ if (next.has(groupId)) {+ next.delete(groupId);+ } else {+ next.add(groupId);+ }+ return next;+ });+ };++ const isGroupExpanded = (groupId: string) => !collapsedGroups().has(groupId);++ const buildRow = (+ entity: SoupEntity,+ options: {+ depth?: number;+ group?: GroupMeta;+ parentGroupId?: string | null;+ } = {}+ ): SoupRow => {+ const { depth = 0, group, parentGroupId = null } = options;+ const rowId = group ? group.id : entity.id;+ return {+ original: entity,+ id: rowId,+ depth,+ group,+ parentGroupId,+ isFocused: () => focusedId() === rowId,+ isSelected: () => selection.isSelected(entity.id),+ isGrouped: () => parentGroupId !== null,+ isExpanded: () => (group ? isGroupExpanded(group.id) : false),+ };+ };- const [data, setDataInternal] = createSignal<SoupEntity[]>(initialData ?? []);+ const [rows, setRowsInternal] = createSignal<SoupRow[]>(+ initialData?.map((e) => buildRow(e)) ?? []+ );- const setData = (newData: SoupEntity[]) => {- setDataInternal(newData);+ const setRows = (newRows: SoupRow[]) => {+ setRowsInternal(newRows);};const [previewEntity, setPreviewEntity] = createSignal<string | undefined>();@@ -69,9 +153,7 @@ export const createSoupState = <TId extends string = FilterID>(((entityId: string) => Promise<void>) | undefined>(undefined);- const [focusedId, setFocusedId] = createSignal<string | undefined>();-- const indexOf = (id: string): number => data().findIndex((r) => r.id === id);+ const indexOf = (id: string): number => rows().findIndex((r) => r.id === id);const focusedIndex = createMemo(() => {const id = focusedId();@@ -79,62 +161,108 @@ export const createSoupState = <TId extends string = FilterID>(return indexOf(id);});- const focused = createMemo(() => {+ const focusedRow = createMemo(() => {const index = focusedIndex();if (index === -1) return undefined;- return data()[index];+ return rows()[index];+ });++ const focusedItem = createMemo(() => {+ const row = focusedRow();+ return row?.original;});- const getItem = (id: string): SoupEntity | undefined =>- data().find((e) => e.id === id);+ const getRow = (id: string): SoupRow | undefined =>+ rows().find((r) => r.id === id);- const getItemAt = (index: number): SoupEntity | undefined => data()[index];+ const getRowAt = (index: number): SoupRow | undefined => rows()[index];- const calculateFocusItem = (index: number) => {- const visibleRows = data();- if (visibleRows.length === 0) return undefined;+ const calculateFocusRow = (index: number): NavigationResult => {+ const allRows = rows();+ if (allRows.length === 0) return undefined;let targetIndex = index;if (targetIndex < 0) {- targetIndex = wrapNavigation ? visibleRows.length - 1 : 0;- } else if (targetIndex >= visibleRows.length) {- targetIndex = wrapNavigation ? 0 : visibleRows.length - 1;+ targetIndex = wrapNavigation ? allRows.length - 1 : 0;+ } else if (targetIndex >= allRows.length) {+ targetIndex = wrapNavigation ? 0 : allRows.length - 1;}- const row = visibleRows[targetIndex];+ const row = allRows[targetIndex];if (!row) return undefined;- return { item: row, index: targetIndex };+ return { row, index: targetIndex };};- // Navigation implementation- const setFocus = (index: number): NavigationResult<SoupEntity> => {- // On touch devices there is no concept of a "focused entity", return early+ const setFocus = (index: number): NavigationResult => {if (isTouchDevice()) return;- const result = calculateFocusItem(index);+ const result = calculateFocusRow(index);if (result) {- setFocusedId(result.item.id);+ setFocusedId(result.row.id);}return result;};- const peek = (offset: number) => {+ const peek = (offset: number): NavigationResult => {const current = focusedIndex();if (current === -1) {- return calculateFocusItem(offset > 0 ? 0 : data().length - 1);+ return calculateFocusRow(offset > 0 ? 0 : rows().length - 1);+ }+ return calculateFocusRow(current + offset);+ };++ const findNextIndex = (startIndex: number, offset: number): number => {+ const allRows = rows();+ if (allRows.length === 0) return -1;++ let targetIndex = startIndex;+ const direction = offset > 0 ? 1 : -1;+ let steps = Math.abs(offset);++ while (steps > 0) {+ targetIndex += direction;++ if (targetIndex < 0) {+ targetIndex = wrapNavigation ? allRows.length - 1 : 0;+ if (!wrapNavigation) break;+ } else if (targetIndex >= allRows.length) {+ targetIndex = wrapNavigation ? 0 : allRows.length - 1;+ if (!wrapNavigation) break;+ }++ const row = allRows[targetIndex];+ if (!row) break;++ if (skipGroupHeaders && row.group) {+ continue;+ }++ steps--;}- return calculateFocusItem(current + offset);++ return targetIndex;};- const navigateBy = (offset: number): NavigationResult<SoupEntity> => {+ const navigateBy = (offset: number): NavigationResult => {const current = focusedIndex();+ const allRows = rows();+if (current === -1) {- return setFocus(offset > 0 ? 0 : data().length - 1);+ let startIndex = offset > 0 ? 0 : allRows.length - 1;+ if (skipGroupHeaders) {+ const row = allRows[startIndex];+ if (row?.group) {+ startIndex = findNextIndex(startIndex, offset);+ }+ }+ return setFocus(startIndex);}- return setFocus(current + offset);++ const nextIndex = findNextIndex(current, offset);+ return setFocus(nextIndex);};const clearFocus = () => {@@ -142,16 +270,25 @@ export const createSoupState = <TId extends string = FilterID>(};return {- data,- setData,+ rows,+ setRows,+ buildRow,predicates,selection,sort,- groups,- setGroups,+ grouping: {+ activeGroupId,+ setActiveGroupId,+ collapsedGroups,+ isExpanded: isGroupExpanded,+ toggle: toggleGroup,+ collapseAll: (ids: string[]) => setCollapsedGroups(new Set(ids)),+ expandAll: () => setCollapsedGroups(new Set<string>()),+ },focus: {- item: focused,+ row: focusedRow,+ item: focusedItem,id: focusedId,index: focusedIndex,clear: clearFocus,@@ -169,15 +306,15 @@ export const createSoupState = <TId extends string = FilterID>(return setFocus(index);},toFirst: () => setFocus(0),- toLast: () => setFocus(data().length - 1),+ toLast: () => setFocus(rows().length - 1),peekOffset: peek,},items: {- data,- count: () => data().length,- get: getItem,- at: getItemAt,+ rows,+ count: () => rows().length,+ get: getRow,+ at: getRowAt,indexOf,},diff --git a/js/app/packages/app/component/next-soup/soup-view/sort-options.tsx b/js/app/packages/app/component/next-soup/soup-view/sort-options.tsxindex 879f916cab..371e0adb72 100644--- a/js/app/packages/app/component/next-soup/soup-view/sort-options.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/sort-options.tsx@@ -1,5 +1,7 @@-import type { SortConfig } from '@app/component/next-soup/create-soup-state';-import type { SoupEntity } from '@app/component/next-soup/soup-view/soup-view-context';+import type {+ SortConfig,+ SoupEntity,+} from '@app/component/next-soup/create-soup-state';import type {EntityData,TaskEntityWithProperties,diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsxindex 5c28c91e96..6bd8cb8c10 100644--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx@@ -2,15 +2,12 @@ import { useGlobalNotificationSource } from '@app/component/GlobalAppState';import {createSoupState,type SoupState,+ type SoupRow,+ type SoupEntity,} from '@app/component/next-soup/create-soup-state';import { createSearchState } from '@app/component/next-soup/soup-view/create-search-state';import { deduplicateEntities } from '@app/component/next-soup/utils';-import {- isWithNotification,- type EntityData,- type WithNotification,- type WithSearch,-} from '@entity';+import { isWithNotification, type EntityData } from '@entity';import { ENABLE_FEATURED_SEARCH_RESULTS } from '@core/constant/featureFlags';import { useNotificationsForEntity } from '@notifications';import { type SoupParams, useSoupAstItemsQuery } from '@queries/soup/items';@@ -39,21 +36,6 @@ import { soupKeys } from '@queries/soup/keys';import type { InfiniteData } from '@tanstack/solid-query';import type { SoupPage } from '@service-storage/generated/schemas';-type Row<T> = {- original: T;- id: string;- depth: number;- isSelected: () => boolean;- isExpanded: () => boolean;- isGrouped: () => boolean;- isFocused: () => boolean;- toggleExpanded: (expanded?: boolean) => void;-};--export type SoupRow = Row<SoupEntity>;--export type SoupEntity = WithNotification<EntityData | WithSearch<EntityData>>;-type DataSource<T> = {data: Accessor<T[]>;isLoading: Accessor<boolean>;@@ -221,32 +203,6 @@ export const SoupViewContextProvider: FlowComponent<};};- const attachMethods = (- entity: WithNotification<EntityData>,- depth = 0- ): SoupRow => {- return {- original: entity,- id: entity.id,- depth,- isFocused() {- return soup.focus.id() === entity.id;- },- isSelected() {- return soup.selection.isSelected(entity.id);- },- isGrouped() {- return false;- },- isExpanded() {- return soup.selection.isSelected(entity.id);- },- toggleExpanded() {- return soup.selection.isSelected(entity.id);- },- };- };-const itemsQuery = useSoupAstItemsQuery(() => ({params: soupParams(),@@ -349,7 +305,7 @@ export const SoupViewContextProvider: FlowComponent<};const rows = createMemo(() => {- return entities().map((e) => attachMethods(e));+ return entities().map((e) => soup.buildRow(e));});const { searchQuery } = search;@@ -398,7 +354,7 @@ export const SoupViewContextProvider: FlowComponent<<SoupViewContext.Provider value={context}>{props.children}<Suspense>- <SyncWithSoup soup={soup} entities={entities()} />+ <SyncWithSoup soup={soup} rows={rows()} /></Suspense></SoupViewContext.Provider>);@@ -406,11 +362,11 @@ export const SoupViewContextProvider: FlowComponent<interface SyncWithSoupProps {soup: SoupState;- entities: SoupEntity[];+ rows: SoupRow[];}const SyncWithSoup = (props: SyncWithSoupProps) => {- createRenderEffect(on(() => props.entities, props.soup.setData));+ createRenderEffect(on(() => props.rows, props.soup.setRows));return null;};diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsxindex bc040b0d3a..793eba8e7e 100644--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx@@ -13,7 +13,6 @@ import { useSoup } from '@app/component/next-soup/soup-context';import { SoupEntityContextMenu } from '@app/component/next-soup/soup-view/soup-entity-context-menu';import { MaybeSoupEntityActionDrawerManager } from '@app/component/next-soup/soup-view/SoupEntityActionDrawerManager';import {- type SoupRow,SoupViewContextProvider,useSoupView,} from '@app/component/next-soup/soup-view/soup-view-context';@@ -114,6 +113,7 @@ import SearchIcon from '@macro-icons/macro-magnifying-glass.svg';import type { SetPredicatesInput } from '@app/component/next-soup/filters/filter-store/predicates-store';import { VIEW_TAB_PRESETS } from '@app/component/app-sidebar/soup-filter-presets';import { canExecuteMarkDoneOnView } from '@app/component/next-soup/actions/make-mark-done-action';+import type { SoupRow } from '@app/component/next-soup/create-soup-state';const useSoupNotificationInvalidators = () => {const notificationSource = useGlobalNotificationSource();@@ -173,6 +173,8 @@ type PersistedSoupViewState = {sort: SystemSortOption[];previewEntity: string | undefined;assigneeFilter: string[];+ groupBy: string | undefined;+ collapsedGroups: string[];};const PERSISTED_STATE_VERSION = 6;@@ -763,6 +765,8 @@ export const SoupViewList = (props: SoupViewListProps) => {batch(() => {soup.sort.setAll(initialPersistedState.sort ?? []);setAssigneeFilter(initialPersistedState.assigneeFilter ?? []);+ soup.grouping.setActiveGroupId(initialPersistedState.groupBy);+ soup.grouping.collapseAll(initialPersistedState.collapsedGroups ?? []);});} else {if (props.initialClientFilters) {@@ -792,6 +796,8 @@ export const SoupViewList = (props: SoupViewListProps) => {sort: soup.sort.active().map((s) => s.id),previewEntity: soup.previewEntity(),assigneeFilter: assigneeFilter(),+ groupBy: soup.grouping.activeGroupId(),+ collapsedGroups: [...soup.grouping.collapsedGroups()],}) satisfies PersistedSoupViewState,(state) => {if (!persistenceDisabled) setPersistedState(state);@@ -974,6 +980,7 @@ export const SoupViewList = (props: SoupViewListProps) => {More Results</div></Show>+<SoupEntityContextMenu entity={row.original}><ListEntityentity={row.original}@@ -984,10 +991,10 @@ export const SoupViewList = (props: SoupViewListProps) => {onMouseMove={() => {if (isKeypressActive()) return;if (soup.previewEntity()) return;- soup.focus.set(row.original.id);+ soup.focus.set(row.id);}}showUnrollNotifications={- soup.predicates.isActive('inbox') &&+ soup.predicates.isActive('signal') &&!soup.predicates.isActive('noise')}checked={row.isSelected()}diff --git a/js/app/packages/app/component/next-soup/soup-view/use-soup-navigation-hotkeys.ts b/js/app/packages/app/component/next-soup/soup-view/use-soup-navigation-hotkeys.tsindex 4fe6626871..4abc94c6ba 100644--- a/js/app/packages/app/component/next-soup/soup-view/use-soup-navigation-hotkeys.ts+++ b/js/app/packages/app/component/next-soup/soup-view/use-soup-navigation-hotkeys.ts@@ -43,7 +43,7 @@ export const useSoupNavigationHotkeys = (const navigateAndSelectEntity = (offset: number) => {const nextRow = soup.navigate.by(offset);if (!nextRow) return true;- soup.selection.select(nextRow.item);+ soup.selection.select(nextRow.row.original);scrollTo(nextRow.index);return true;};@@ -54,12 +54,12 @@ export const useSoupNavigationHotkeys = (const selection = soup.selection;- const nextRow = next?.item;- if (!nextRow) return true;+ const nextEntity = next?.row.original;+ if (!nextEntity) return true;// At the boundary (top/bottom), peekOffset clamps and returns the// same item we're already focused on. No-op to avoid toggling.- if (focusedEntity && nextRow.id === focusedEntity.id) return true;+ if (focusedEntity && nextEntity.id === focusedEntity.id) return true;if (!focusedEntity) {navigateAndSelectEntity(offset);@@ -73,14 +73,14 @@ export const useSoupNavigationHotkeys = (if (!selection.isSelected(focusedEntity.id) &&- !selection.isSelected(nextRow.id)+ !selection.isSelected(nextEntity.id)) {selection.toggle(focusedEntity);navigateAndSelectEntity(offset);return true;}- if (selection.isSelected(nextRow.id)) {+ if (selection.isSelected(nextEntity.id)) {selection.toggle(focusedEntity);soup.navigate.by(offset);scrollTo(next.index);@@ -100,7 +100,7 @@ export const useSoupNavigationHotkeys = (if (!next) return true;scrollTo(next.index);- openEntity(next.item);+ openEntity(next.row.original);return true;};@@ -111,7 +111,7 @@ export const useSoupNavigationHotkeys = (if (!next) return true;scrollTo(next.index);- openEntity(next.item);+ openEntity(next.row.original);return true;};diff --git a/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.ts b/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.tsindex feed6a99c8..94b4eadc81 100644--- a/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.ts+++ b/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.ts@@ -135,7 +135,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {);};- // enter - Open entity in split+ // enter - Open entity in split or toggle groupregisterHotkey({hotkey: ['enter'],hotkeyToken: TOKENS.entity.open,@@ -143,6 +143,15 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {description: 'Open',hide: true,keyDownHandler: () => {+ const focusedRow = soup.focus.row();+ if (!focusedRow) return false;++ // If focused on a group header, toggle expand/collapse+ if (focusedRow.group) {+ focusedRow.group.toggle();+ return true;+ }+if (tryOpenChannelNotification(false)) return true;const entity = soup.focus.item();@@ -237,13 +246,13 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {scopeId,description: 'Toggle select all',keyDownHandler: (e) => {- const items = soup.items.data();- if (items.length === 0) return false;+ const rows = soup.rows();+ if (rows.length === 0) return false;e?.preventDefault();- if (soup.selection.count() === items.length) {+ if (soup.selection.count() === rows.length) {soup.selection.clear();} else {- soup.selection.set(items.slice());+ soup.selection.set(rows.map((r) => r.original));}return true;},diff --git a/js/app/packages/app/component/useNavigatedFromJK.ts b/js/app/packages/app/component/useNavigatedFromJK.tsindex 883157280f..480a6847bb 100644--- a/js/app/packages/app/component/useNavigatedFromJK.ts+++ b/js/app/packages/app/component/useNavigatedFromJK.ts@@ -6,10 +6,10 @@ import { useSoup } from '@app/component/next-soup/soup-context';export function useNavigatedFromJK() {const soup = useSoup();const navigatedFromJK = createMemo(() => {- const entities = soup.data();- if (!entities) return false;+ const rows = soup.rows();+ if (!rows) return false;return (- entities.length > 0 &&+ rows.length > 0 &&document.documentElement.getAttribute('data-modality') === 'keyboard' &&(lastExecutedCommand()?.hotkeyToken === TOKENS.entity.step.end ||lastExecutedCommand()?.hotkeyToken === TOKENS.entity.select.end)diff --git a/js/app/packages/block-email/component/EmailContext.tsx b/js/app/packages/block-email/component/EmailContext.tsxindex 1e68254b4b..2b4cc9c681 100644--- a/js/app/packages/block-email/component/EmailContext.tsx+++ b/js/app/packages/block-email/component/EmailContext.tsx@@ -339,13 +339,13 @@ export function EmailProvider(props: FlowProps<{ threadID: string }>) {if (!props) return false;- const selectedEntity = soup?.items.get(thread.db_id);+ const selectedRow = soup?.items.get(thread.db_id);- if (selectedEntity) {+ if (selectedRow) {if (soup) {- markAsDoneAction.executeWithSoup([selectedEntity], soup);+ markAsDoneAction.executeWithSoup([selectedRow.original], soup);} else {- markAsDoneAction.execute([selectedEntity]);+ markAsDoneAction.execute([selectedRow.original]);}} else {archiveMutation.mutate({diff --git a/js/app/packages/block-email/component/TopBar.tsx b/js/app/packages/block-email/component/TopBar.tsxindex 9450313dd0..095c0d55d2 100644--- a/js/app/packages/block-email/component/TopBar.tsx+++ b/js/app/packages/block-email/component/TopBar.tsx@@ -56,7 +56,8 @@ export function TopBar(props: {const linksQuery = useEmailLinksQuery();const isInvite = () => {- const entity = soup?.items.get(props.id);+ const row = soup?.items.get(props.id);+ const entity = row?.original;return entity?.type === 'email' && entity.hasIcsAttachment === true;};@@ -71,8 +72,8 @@ export function TopBar(props: {const thread = emailCtx.thread();if (!thread?.db_id) return;- // Calculate next entity before trashing so we can navigate to it- const nextEntity = (() => {+ // Calculate next row before trashing so we can navigate to it+ const nextRow = (() => {if (!soup) return undefined;const currentIndex = soup.focus.index();return soup.items.at(currentIndex + 1) ?? soup.items.at(currentIndex - 1);@@ -80,10 +81,10 @@ export function TopBar(props: {const handle = trashEmails([thread.db_id]);- if (soup && nextEntity) {+ if (soup && nextRow) {soup.selection.clear();- soup.focus.set(nextEntity.id);- openEntityInSplitFromUnifiedList(nextEntity, {});+ soup.focus.set(nextRow.id);+ openEntityInSplitFromUnifiedList(nextRow.original, {});}const toastId = toast.success(