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
feat(soup): frontend group by [stack/02] (#3164)
dev-rbf27ea46d7be8
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 80f91e9134..589f6f6029 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,7 +136,11 @@ function CommandKDemo(props: LessonContentProps) {const soup = createSoupState({ wrapNavigation: true });createEffect(() => {- soup.setRows(filteredSandboxEntities().map((e) => soup.buildRow(e)));+ soup.setRows(+ filteredSandboxEntities().map((e, i) =>+ soup.buildRow({ id: e.id, index: i, original: 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 4d2eb59006..ca10409069 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@@ -144,7 +144,11 @@ function CreateEntityDemo(props: LessonContentProps) {// Keep soup synced with sandbox storecreateEffect(() => {- soup.setRows(filteredSandboxEntities().map((e) => soup.buildRow(e)));+ soup.setRows(+ filteredSandboxEntities().map((e, i) =>+ soup.buildRow({ id: e.id, index: i, original: 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 7ec7555cc8..ffd63a4b40 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,11 @@ function HomeDemo() {});createEffect(() => {- soup.setRows(filteredSandboxEntities().map((e) => soup.buildRow(e)));+ soup.setRows(+ filteredSandboxEntities().map((e, i) =>+ soup.buildRow({ id: e.id, index: i, original: 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 d21f8a3b83..261a4fab7d 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@@ -51,7 +51,11 @@ function SidebarNavDemo() {const soup = createSoupState({ wrapNavigation: true });createEffect(() => {- soup.setRows(filteredSandboxEntities().map((e) => soup.buildRow(e)));+ soup.setRows(+ filteredSandboxEntities().map((e, i) =>+ soup.buildRow({ id: e.id, index: i, original: e })+ )+ );});return (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 d2316ad01a..f7ca283b5c 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@@ -64,7 +64,11 @@ describe('createSoupState', () => {createRoot((dispose) => {const state = createSoupState();const entities = [createTestEntity('1'), createTestEntity('2')];- state.setRows(entities.map((e) => state.buildRow(e)));+ state.setRows(+ entities.map((e, i) =>+ state.buildRow({ id: e.id, index: i, original: e })+ )+ );expect(state.rows().map((r) => r.original)).toEqual(entities);expect(state.items.count()).toBe(2);@@ -80,7 +84,11 @@ describe('createSoupState', () => {const state = createSoupState();const entities = [createTestEntity('1'), createTestEntity('2')];- state.setRows(entities.map((e) => state.buildRow(e)));+ state.setRows(+ entities.map((e, i) =>+ state.buildRow({ id: e.id, index: i, original: e })+ )+ );expect(state.rows().map((r) => r.original)).toEqual(entities);@@ -95,7 +103,11 @@ describe('createSoupState', () => {const entity1 = createTestEntity('1');const entity2 = createTestEntity('2');const state = createSoupState();- state.setRows([entity1, entity2].map((e) => state.buildRow(e)));+ state.setRows(+ [entity1, entity2].map((e, i) =>+ state.buildRow({ id: e.id, index: i, original: e })+ )+ );expect(state.items.get('1')?.original).toBe(entity1);expect(state.items.get('2')?.original).toBe(entity2);@@ -109,7 +121,9 @@ describe('createSoupState', () => {createRoot((dispose) => {const entity1 = createTestEntity('1');const entity2 = createTestEntity('2');- const state = createSoupState({});+ const state = createSoupState({+ initialData: [entity1, entity2],+ });expect(state.items.at(0)?.original).toBe(entity1);expect(state.items.at(1)?.original).toBe(entity2);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 5be1bc4d00..2e79ff7424 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@@ -16,30 +16,33 @@ import { createMemo, createSignal, type JSX } from 'solid-js';export type SoupEntity = WithNotification<EntityData | WithSearch<EntityData>>;+export type GroupHeaderProps = {+ group: GroupMeta;+ highlighted?: boolean;+};+export type GroupMeta = {- id: string;- value: unknown;+ key: string;label: string;+ value: unknown;count: number;isExpanded: () => boolean;toggle: () => void;- renderHeader?: (props: {- value: unknown;- label: string;- count: number;- }) => JSX.Element;+ hasMore: () => boolean;+ loadMore: () => Promise<void>;+ isLoading: () => boolean;+ renderHeader?: (props: GroupHeaderProps) => JSX.Element;};export type SoupRow = {- original: SoupEntity;id: string;- depth: number;- group?: GroupMeta;- parentGroupId: string | null;+ index: number;+ original: SoupEntity;+ group: GroupMeta | undefined;+ getIsGrouped: () => boolean;+ getIsLoadMore: () => boolean;isFocused: () => boolean;isSelected: () => boolean;- isExpanded: () => boolean;- isGrouped: () => boolean;};export type NavigationResult = { row: SoupRow; index: number } | undefined;@@ -116,31 +119,38 @@ export const createSoupState = <TId extends string = FilterID>(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;+ const buildRow = (options: {+ id: string;+ index: number;+ original: SoupEntity;+ group?: GroupMeta;+ isGrouped?: boolean;+ isLoadMore?: boolean;+ }): SoupRow => {+ const {+ id,+ index,+ original,+ group,+ isGrouped = false,+ isLoadMore = false,+ } = options;return {- original: entity,- id: rowId,- depth,+ id,+ index,+ original,group,- parentGroupId,- isFocused: () => focusedId() === rowId,- isSelected: () => selection.isSelected(entity.id),- isGrouped: () => parentGroupId !== null,- isExpanded: () => (group ? isGroupExpanded(group.id) : false),+ getIsGrouped: () => isGrouped,+ getIsLoadMore: () => isLoadMore,+ isFocused: () => focusedId() === id,+ isSelected: () =>+ !isGrouped && !isLoadMore && selection.isSelected(original.id),};};const [rows, setRowsInternal] = createSignal<SoupRow[]>(- initialData?.map((e) => buildRow(e)) ?? []+ initialData?.map((e, i) => buildRow({ id: e.id, index: i, original: e })) ??+ []);const setRows = (newRows: SoupRow[]) => {diff --git a/js/app/packages/app/component/next-soup/soup-view/create-infinite-queries.ts b/js/app/packages/app/component/next-soup/soup-view/create-infinite-queries.tsnew file mode 100644index 0000000000..037d647e2e--- /dev/null+++ b/js/app/packages/app/component/next-soup/soup-view/create-infinite-queries.ts@@ -0,0 +1,92 @@+import {+ createInfiniteQuery,+ type InfiniteData,+ type InfiniteQueryObserverResult,+} from '@tanstack/solid-query';+import { type Accessor, createMemo, mapArray } from 'solid-js';++type InfiniteQueryConfig<TData, TSelect = TData[]> = {+ key: string;+ queryKey: readonly unknown[];+ queryFn: (ctx: { pageParam: string | null }) => Promise<TData>;+ getNextPageParam: (lastPage: TData) => string | null;+ initialData?: InfiniteData<TData, string | null>;+ select?: (pages: TData[]) => TSelect;+ enabled?: boolean;+ staleTime?: number;+};++type InfiniteQueryResult<TData, TSelect> = {+ key: string;+ data: Accessor<TSelect | undefined>;+ hasNextPage: Accessor<boolean>;+ isFetchingNextPage: Accessor<boolean>;+ fetchNextPage: () => Promise<+ InfiniteQueryObserverResult<+ InfiniteData<TData | null, string | null>,+ Error+ >+ >;+};++export function createInfiniteQueries<TData, TSelect = TData[]>(+ getConfigs: Accessor<InfiniteQueryConfig<TData, TSelect>[]>+): Accessor<InfiniteQueryResult<TData, TSelect>[]> {+ const queries = mapArray(+ () => getConfigs().map((c) => c.key),+ (key): InfiniteQueryResult<TData, TSelect> => {+ const getConfig = createMemo(() =>+ getConfigs().find((c) => c.key === key)+ );++ const getSelect = createMemo(() => getConfig()?.select);++ const query = createInfiniteQuery<+ TData | null,+ Error,+ InfiniteData<TData | null, string | null>,+ readonly unknown[],+ string | null+ >(() => {+ const config = getConfig();++ return {+ queryKey: config?.queryKey ?? (['__disabled__', key] as const),+ queryFn: async (ctx) => {+ if (!config) return null;+ return config.queryFn({ pageParam: ctx.pageParam });+ },+ initialPageParam: null,+ getNextPageParam: (lastPage) =>+ lastPage ? (config?.getNextPageParam(lastPage) ?? null) : null,+ enabled: config?.enabled ?? false,+ staleTime: config?.staleTime ?? Infinity,+ initialData: config?.initialData as InfiniteData<+ TData | null,+ string | null+ >,+ };+ });++ const data = () => {+ const pages = query.data?.pages.filter((p): p is TData => p !== null);+ if (!pages) return undefined;+ const select = getSelect();+ if (select) {+ return select(pages);+ }+ return pages as TSelect;+ };++ return {+ key,+ data,+ hasNextPage: () => query.hasNextPage ?? false,+ isFetchingNextPage: () => query.isFetchingNextPage,+ fetchNextPage: () => query.fetchNextPage(),+ };+ }+ );++ return queries;+}diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/group-dropdown.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/group-dropdown.tsxnew file mode 100644index 0000000000..7ea0e62e41--- /dev/null+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/group-dropdown.tsx@@ -0,0 +1,63 @@+import type {+ GroupOption,+ GroupOptionId,+} from '@app/component/next-soup/soup-view/group-options';+import CheckIcon from '@icon/regular/check.svg';+import StackSimpleIcon from '@icon/regular/stack-simple.svg';+import { Dropdown, Layer, Tooltip } from '@ui';+import { type Component, For, Show } from 'solid-js';++export interface GroupDropdownProps {+ value: () => GroupOptionId;+ onChange: (value: GroupOptionId) => void;+ options: GroupOption[];+ open?: boolean;+ onOpenChange?: (open: boolean) => void;+}++export const GroupDropdown: Component<GroupDropdownProps> = (props) => {+ return (+ <Dropdown+ open={props.open}+ onOpenChange={props.onOpenChange}+ placement="bottom-start"+ gutter={4}+ >+ <Tooltip label="Group">+ <Dropdown.Trigger depth={2} class="bg-surface">+ <StackSimpleIcon />+ <span>Group</span>+ </Dropdown.Trigger>+ </Tooltip>+ <Dropdown.Portal>+ <Layer depth={2}>+ <Dropdown.Content class="z-action-menu bg-surface border border-edge-muted rounded-sm shadow-sm min-w-35 p-1">+ <For each={props.options}>+ {(option) => (+ <Dropdown.Item+ class="w-full flex items-center gap-2 px-2 py-1.5 text-left text-xs transition-colors hover:bg-ink/5 focus:bg-ink/5 outline-none cursor-default rounded-md"+ onSelect={() => props.onChange(option.value)}+ >+ <span+ class="flex-1 truncate"+ classList={{+ 'text-ink font-medium': props.value() === option.value,+ 'text-ink-muted': props.value() !== option.value,+ }}+ >+ {option.label}+ </span>+ <span class="size-3.5 flex items-center justify-center shrink-0">+ <Show when={props.value() === option.value}>+ <CheckIcon class="size-3 text-accent" />+ </Show>+ </span>+ </Dropdown.Item>+ )}+ </For>+ </Dropdown.Content>+ </Layer>+ </Dropdown.Portal>+ </Dropdown>+ );+};diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsxindex 198c798426..28985e1688 100644--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx@@ -1,5 +1,6 @@import { useAnalytics } from '@app/component/analytics-context';import { ActiveFilterChips } from '@app/component/next-soup/soup-view/filters-bar/active-filter-chips';+import { SoupViewContextGroup } from '@app/component/next-soup/soup-view/filters-bar/soup-view-context-group';import { SoupViewContextSort } from '@app/component/next-soup/soup-view/filters-bar/soup-view-context-sort';import { UnifiedFilterDropdown } from '@app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown';import { useFilterRefinements } from '@app/component/next-soup/soup-view/filters-bar/use-filter-refinements';@@ -76,6 +77,7 @@ export const SoupFiltersBar = () => {</Tooltip><Show when={!isSearchView()}><SoupViewContextSort />+ <SoupViewContextGroup /></Show></div></Show>diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-context-group.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-context-group.tsxnew file mode 100644index 0000000000..c98e1a2772--- /dev/null+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-context-group.tsx@@ -0,0 +1,59 @@+import { GroupDropdown } from '@app/component/next-soup/soup-view/filters-bar/group-dropdown';+import {+ type GroupOptionId,+ TASK_GROUP_OPTIONS,+} from '@app/component/next-soup/soup-view/group-options';+import { useSoupView } from '@app/component/next-soup/soup-view/soup-view-context';+import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';+import type { ListView } from '@app/constants/list-views';+import { useFeatureFlag } from '@app/lib/analytics/posthog';+import { ENABLE_SOUP_GROUP_BY_OVERRIDE } from '@core/constant/featureFlags';+import { createMemo, createSignal, Show } from 'solid-js';++export const SoupViewContextGroup = () => {+ const panel = useSplitPanelOrThrow();+ const { soup } = useSoupView();+ const groupByEnabled = useFeatureFlag('enable-soup-group-by', {+ enabledOverride: ENABLE_SOUP_GROUP_BY_OVERRIDE,+ });++ const [groupOpen, setGroupOpen] = createSignal(false);++ const component = createMemo(() => {+ const content = panel.handle.content();+ if (content.type !== 'component') return;+ return content.id;+ });++ const isComponentListView = (listView: ListView) => {+ return component() === listView;+ };++ const value = createMemo(+ (): GroupOptionId =>+ (soup.grouping.activeGroupId() as GroupOptionId) ?? 'none'+ );++ const onChange = (groupOption: GroupOptionId) => {+ if (groupOption === 'none') {+ soup.grouping.setActiveGroupId(undefined);+ } else {+ soup.grouping.setActiveGroupId(groupOption);+ soup.grouping.expandAll();+ }+ };++ return (+ <Show when={groupByEnabled().enabled}>+ <Show when={isComponentListView('tasks')}>+ <GroupDropdown+ value={value}+ onChange={onChange}+ options={TASK_GROUP_OPTIONS}+ open={groupOpen()}+ onOpenChange={setGroupOpen}+ />+ </Show>+ </Show>+ );+};diff --git a/js/app/packages/app/component/next-soup/soup-view/group-options.ts b/js/app/packages/app/component/next-soup/soup-view/group-options.tsnew file mode 100644index 0000000000..65cd2b8c5c--- /dev/null+++ b/js/app/packages/app/component/next-soup/soup-view/group-options.ts@@ -0,0 +1,47 @@+import { SYSTEM_PROPERTY_IDS } from '@core/component/Properties/constants';++export type GroupOptionId =+ | 'none'+ | 'date'+ | 'entity_type'+ | 'project'+ | `property:${string}`;++export interface GroupOption {+ value: GroupOptionId;+ label: string;+}++export const GROUP_OPTIONS: GroupOption[] = [+ { value: 'none', label: 'None' },+ { value: 'date', label: 'Date' },+ { value: 'entity_type', label: 'Type' },+ { value: 'project', label: 'Project' },+];++export const DEFAULT_GROUP_OPTIONS: GroupOption[] = [+ { value: 'none', label: 'None' },+ { value: 'entity_type', label: 'Type' },+ { value: 'project', label: 'Project' },+];++export const TASK_GROUP_OPTIONS: GroupOption[] = [+ { value: 'none', label: 'None' },+ { value: `property:${SYSTEM_PROPERTY_IDS.STATUS}`, label: 'Status' },+ { value: `property:${SYSTEM_PROPERTY_IDS.PRIORITY}`, label: 'Priority' },+ { value: 'project', label: 'Project' },+ { value: 'date', label: 'Date' },+];++export const EMAIL_GROUP_OPTIONS: GroupOption[] = [+ { value: 'none', label: 'None' },+ { value: 'date', label: 'Date' },+ { value: 'project', label: 'Project' },+];++export const INBOX_GROUP_OPTIONS: GroupOption[] = [+ { value: 'none', label: 'None' },+ { value: 'date', label: 'Date' },+ { value: 'entity_type', label: 'Type' },+ { value: 'project', label: 'Project' },+];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 893e9e79b1..8d83c24d5f 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@@ -1,6 +1,7 @@import { useGlobalNotificationSource } from '@app/component/GlobalAppState';import {createSoupState,+ type GroupMeta,type SoupEntity,type SoupRow,type SoupState,@@ -11,15 +12,33 @@ import {type Query,type QueryStore,} from '@app/component/next-soup/filters/filter-store/query-store';+import { createInfiniteQueries } from '@app/component/next-soup/soup-view/create-infinite-queries';import { createSearchState } from '@app/component/next-soup/soup-view/create-search-state';import { deduplicateEntities } from '@app/component/next-soup/utils';import { ENABLE_FEATURED_SEARCH_RESULTS } from '@core/constant/featureFlags';import { useUserId } from '@core/context/user';-import { type EntityData, isWithNotification } from '@entity';+import { throwOnErr } from '@core/util/maybeResult';+import {+ type EntityData,+ getPropertyOptionLabel,+ isWithNotification,+} from '@entity';import { useNotificationsForEntity } from '@notifications';import { useQueryClient } from '@queries/client';+import {+ parseGroupedSoupPage,+ serializeGroupByField,+} from '@queries/soup/grouped/api';+import type {+ GroupMeta as ApiGroupMeta,+ GroupByField,+ GroupedSoupPage,+} from '@queries/soup/grouped/types';import { type SoupParams, useSoupAstItemsQuery } from '@queries/soup/items';import { soupKeys } from '@queries/soup/keys';+import { mapSoupPageToEntityList } from '@queries/soup/transform-utils';+import { useInstructionsMdIdQuery } from '@queries/storage/instructions-md';+import { storageServiceClient } from '@service-storage/client';import type { SoupPage } from '@service-storage/generated/schemas';import type { InfiniteData } from '@tanstack/solid-query';import {@@ -163,6 +182,21 @@ export const SoupViewContextProvider: FlowComponent<const [assigneeFilter, setAssigneeFilter] = createSignal<string[]>([]);const [activeTab, setActiveTab] = createSignal<string | undefined>(undefined);+ const groupByField = createMemo((): GroupByField | undefined => {+ const id = soup.grouping.activeGroupId();+ if (!id) return undefined;+ if (id === 'date') return { type: 'date' };+ if (id === 'entity_type') return { type: 'entity_type' };+ if (id === 'project') return { type: 'project' };+ if (id.startsWith('property:')) {+ return {+ type: 'property',+ propertyDefinitionId: id.slice('property:'.length),+ };+ }+ return undefined;+ });+// Clear sub-filters when task filter is deactivatedcreateEffect(() => {if (!soup.predicates.isActive('task')) {@@ -203,6 +237,7 @@ export const SoupViewContextProvider: FlowComponent<() => ({params: soupParams(),body: soupBody(),+ groupBy: groupByField(),}),() => ({enabled: !search.isSearching(),@@ -215,15 +250,21 @@ export const SoupViewContextProvider: FlowComponent<if (!searching) {const data = itemsQuery.data;+if (!data) return prev;- const base = data.map((e) =>++ const base = data.entities.map((e) =>isWithNotification(e) ? e : attachNotifications(e)) as SoupEntity[];+const extras = props.additionalEntities?.() ?? [];+if (extras.length === 0) return base;+const extraEntities = extras.map((e) =>isWithNotification(e) ? e : attachNotifications(e)) as SoupEntity[];+return [...extraEntities, ...base];}@@ -292,18 +333,191 @@ export const SoupViewContextProvider: FlowComponent<const entityMap = new Map(base.map((e) => [e.id, e]));const featuredIdSet = new Set(featuredIds);const featured: SoupEntity[] = [];+for (const id of featuredIds) {const e = entityMap.get(id);if (e) featured.push(e);}+const rest = base.filter((e) => !featuredIdSet.has(e.id));+return [...featured, ...rest];};- const rows = createMemo(() => {- return entities().map((e) => soup.buildRow(e));+ const rows = createMemo((): SoupRow[] => {+ const field = groupByField();+ const groups = itemsQuery.data?.groups;++ // Not grouped - build simple entity rows+ if (!field || !groups) {+ return entities().map((entity, index) =>+ soup.buildRow({ id: entity.id, index, original: entity })+ );+ }++ // Grouped - build header + entity + loadMore rows for each group+ const result: SoupRow[] = [];+ let globalIndex = 0;++ for (const apiGroup of groups) {+ const groupMeta = buildGroupMeta(apiGroup);+ const isExpanded = soup.grouping.isExpanded(apiGroup.key);+ const query = groupQueries().find((q) => q.key === apiGroup.key);+ const groupEntities = query?.data() ?? [];++ // Get first entity to use for header original+ // If the group has no entities, we can skip it+ const firstEntity = groupEntities[0];++ if (!firstEntity) continue;++ // Header row+ result.push(+ soup.buildRow({+ id: `header:${apiGroup.key}`,+ index: globalIndex++,+ original: firstEntity,+ group: groupMeta,+ isGrouped: true,+ })+ );++ // We skip building rows for entities that are+ // not visible because the group is collapsed+ if (!isExpanded) continue;++ // Entity rows+ for (const entity of groupEntities) {+ result.push(+ soup.buildRow({+ id: entity.id,+ index: globalIndex++,+ original: entity,+ group: groupMeta,+ })+ );+ }++ // We can stop here if the group has no more data+ // that needs to be fetched+ if (!groupMeta.hasMore()) continue;++ const lastEntity = groupEntities[groupEntities.length - 1];++ result.push(+ soup.buildRow({+ id: `loadmore:${apiGroup.key}`,+ index: globalIndex++,+ original: lastEntity,+ group: groupMeta,+ isLoadMore: true,+ })+ );+ }++ return result;});+ const instructionsIdQuery = useInstructionsMdIdQuery();++ const groupQueries = createInfiniteQueries<GroupedSoupPage, SoupEntity[]>(+ () => {+ const field = groupByField();+ const groups = itemsQuery.data?.groups;+ const items = itemsQuery.data?.items;++ if (!field || !groups || !items) {+ return [];+ }++ return groups.map((group) => {+ const initialGroupItems = items.slice(+ group.startIndex,+ group.startIndex + group.pageCount+ );++ return {+ key: group.key,+ queryKey: soupKeys.groupedGroup({+ params: soupParams(),+ body: soupBody(),+ groupBy: field,+ groupKey: group.key,+ }).queryKey as readonly unknown[],+ queryFn: async (ctx: { pageParam: string | null }) => {+ const response = await throwOnErr(async () =>+ storageServiceClient.getGroupedSoupAstItems({+ params: {+ cursor: ctx.pageParam ?? undefined,+ group_by: serializeGroupByField(field),+ group_key: group.key,+ },+ body: {+ ...soupBody(),+ ...soupParams(),+ },+ })+ );+ return parseGroupedSoupPage(response);+ },+ getNextPageParam: (lastPage: GroupedSoupPage): string | null => {+ const meta = lastPage.groups.find((g) => g.key === group.key);+ return meta?.nextCursor ?? null;+ },+ initialData: {+ pages: [+ {+ items: initialGroupItems,+ nextCursor: group.nextCursor,+ groups: [group],+ },+ ],+ pageParams: [null],+ },+ select: (pages: GroupedSoupPage[]): SoupEntity[] => {+ const allItems = pages.flatMap((p) => p.items);+ return mapSoupPageToEntityList(+ { items: allItems, next_cursor: null },+ { instructionsIdQuery }+ ).map((e) => attachNotifications(e)) as SoupEntity[];+ },+ enabled: true,+ staleTime: Infinity,+ };+ });+ }+ );++ const loadMoreForGroup = async (groupKey: string): Promise<void> => {+ const query = groupQueries().find((q) => q.key === groupKey);+ await query?.fetchNextPage();+ };++ const isGroupLoadingMore = (groupKey: string) => {+ const query = groupQueries().find((q) => q.key === groupKey);+ return query?.isFetchingNextPage() ?? false;+ };++ const hasMoreForGroup = (groupKey: string) => {+ const query = groupQueries().find((q) => q.key === groupKey);+ return query?.hasNextPage() ?? false;+ };++ const buildGroupMeta = (group: ApiGroupMeta): GroupMeta => {+ const resolvedLabel = getPropertyOptionLabel(group.key) ?? group.label;+ return {+ key: group.key,+ value: group.key,+ label: resolvedLabel,+ count: group.totalCount,+ isExpanded: () => soup.grouping.isExpanded(group.key),+ toggle: () => soup.grouping.toggle(group.key),+ hasMore: () => hasMoreForGroup(group.key),+ loadMore: () => loadMoreForGroup(group.key),+ isLoading: () => isGroupLoadingMore(group.key),+ };+ };+const { searchQuery } = search;const context = {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 acd577df9a..d342effc5e 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@@ -9,7 +9,10 @@ import {useEntityActionHotkeys,} from '@app/component/next-soup/actions';import { canExecuteMarkDoneOnView } from '@app/component/next-soup/actions/make-mark-done-action';-import type { SoupRow } from '@app/component/next-soup/create-soup-state';+import type {+ GroupHeaderProps,+ SoupRow,+} from '@app/component/next-soup/create-soup-state';import type { QueryState } from '@app/component/next-soup/filters/filter-store';import type { SetPredicatesInput } from '@app/component/next-soup/filters/filter-store/predicates-store';import { useSoup } from '@app/component/next-soup/soup-context';@@ -38,7 +41,6 @@ import {SoupViewTabs,useApplyPreset,} from '@app/component/next-soup/soup-view/soup-view-tabs';-import { TaskListEntity } from '@app/component/next-soup/soup-view/views/tasks/TaskListEntity';import { ResponsiveTaskListHeader } from '@app/component/next-soup/soup-view/views/tasks/TaskListHeader';import {openEntityInNewTab,@@ -62,6 +64,7 @@ import { CustomScrollbar } from '@core/component/CustomScrollbar';import { EmailPermissionsBanner } from '@core/component/EmailPermissionsBanner';import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';import { LoadingBlock } from '@core/component/LoadingBlock';+import { PropertyValueIcon } from '@core/component/Properties/component/propertyValue/PropertyValueIcon';import { Resize } from '@core/component/Resize';import { ENABLE_UNIFIED_LIST_AI_INPUT } from '@core/constant/featureFlags';import { useUserId } from '@core/context/user';@@ -77,6 +80,8 @@ import {type SearchLocation,} from '@entity';import CheckIcon from '@icon/bold/check-bold.svg';+import CaretDownIcon from '@icon/regular/caret-down.svg';+import ChevronRightIcon from '@icon/regular/caret-right.svg';import Spinner from '@icon/regular/spinner.svg';import SearchIcon from '@macro-icons/macro-magnifying-glass.svg';import { createEffectOnEntityTypeNotification } from '@notifications';@@ -116,6 +121,40 @@ import { SoupEntitySelectionToolbar } from './soup-entity-selection-toolbar';import { useSoupNavigationHotkeys } from './use-soup-navigation-hotkeys';import { useSoupViewHotkeys } from './use-soup-view-hotkeys';+const DefaultGroupHeader = (+ props: GroupHeaderProps & { highlighted?: boolean }+) => {+ return (+ <button+ type="button"+ class={cn(+ 'w-full px-3 py-3 flex items-center gap-2 text-sm font-medium text-text-muted bg-ink/5 hover:bg-hover relative',+ {+ 'outline-1 outline-accent/20 -outline-offset-1': props.highlighted,+ }+ )}+ onClick={() => props.group.toggle()}+ >+ <div+ class={cn('absolute h-full w-0.75 left-0 top-0 bg-accent opacity-0', {+ 'opacity-100': props.highlighted,+ })}+ />+ <ChevronRightIcon+ class={cn('size-3 transition-transform', {+ 'rotate-90': props.group.isExpanded(),+ })}+ />+ <PropertyValueIcon+ optionId={props.group.value as string}+ class="size-3.5"+ />+ <span>{props.group.label}</span>+ <span class="text-text-subtle">{props.group.count}</span>+ </button>+ );+};+const useSoupNotificationInvalidators = () => {const notificationSource = useGlobalNotificationSource();const entityQueryClient = useQueryClient();@@ -442,10 +481,15 @@ export const SoupViewList = (props: SoupViewListProps) => {const [soupViewRef, setSoupViewRef] = createSignal<HTMLElement | undefined>();const focusFirstEntity = () => {- const next = soup.navigate.toFirst();+ const allRows = rows();+ const firstEntityIndex = allRows.findIndex(+ (row) => !row.getIsGrouped() && !row.getIsLoadMore()+ );+ if (firstEntityIndex === -1) return;- if (next) {- virtualizerHandle()?.scrollToIndex(next.index, { align: 'nearest' });+ const result = soup.navigate.toIndex(firstEntityIndex);+ if (result) {+ virtualizerHandle()?.scrollToIndex(result.index, { align: 'nearest' });}};@@ -975,69 +1019,142 @@ export const SoupViewList = (props: SoupViewListProps) => {</div></Show>- <SoupEntityContextMenu entity={row.original}>- <Dynamic- component={- currentView() === 'tasks'- ? TaskListEntity- : ListEntity- }- entity={row.original}- timestamp={timestamp()}- highlighted={- panel.isPanelActive() && row.isFocused()- }- onMouseMove={() => {- if (isKeypressActive()) return;- if (soup.previewEntity()) return;- soup.focus.set(row.id);- }}- showUnrollNotifications={- soup.predicates.isActive('inbox') &&- !soup.predicates.isActive('noise')- }- checked={row.isSelected()}- onChecked={(next, shiftKey) =>- handleMultiSelectChecked({- entity: row.original,- entityIndex: i(),- next,- shiftKey: shiftKey ?? false,- })- }- onClick={(event) => {- onEntityClick({- type: 'entity',- entity: row.original,- event,- location: undefined,- });- }}- onProjectClick={(projectEntity, event) => {- onEntityClick({- type: 'project',- projectEntity,- entity: row.original,- event,- location: undefined,- });- }}- onContentHitClick={(e, location) => {- onEntityClick({- type: 'entity',- entity: row.original,- event: e,- location,- });- }}- entityRowConfig={{- swipeLeftColor: 'bg-success',- swipeLeftRevealedComponent: (- <CheckIcon class="size-8 text-surface" />- ),+ <Switch>+ {/* Group header row */}+ <Match when={row.getIsGrouped() && row.group}>+ {(group) => (+ <Dynamic+ component={+ group().renderHeader ??+ DefaultGroupHeader+ }+ group={group()}+ highlighted={+ panel.isPanelActive() &&+ row.isFocused()+ }+ />+ )}+ </Match>++ {/* Load more row */}+ <Match+ when={row.getIsLoadMore() && row.group}+ >+ {(group) => {+ const highlighted = () =>+ panel.isPanelActive() &&+ row.isFocused();+ return (+ <button+ type="button"+ class={cn(+ 'w-full min-h-10 flex items-center justify-center gap-1.5 relative text-sm text-text-muted hover:bg-hover',+ {+ 'bg-accent/5 outline-1 outline-accent/20 -outline-offset-1':+ highlighted(),+ }+ )}+ onClick={() => group().loadMore()}+ disabled={group().isLoading()}+ >+ <div+ class={cn(+ 'absolute h-full w-0.75 left-0 top-0 bg-accent opacity-0',+ { 'opacity-100': highlighted() }+ )}+ />+ <Show+ when={!group().isLoading()}+ fallback={+ <>+ <Spinner class="size-3 animate-spin" />+ Loading...+ </>+ }+ >+ <CaretDownIcon class="size-3" />+ Load more+ </Show>+ </button>+ );}}- />- </SoupEntityContextMenu>+ </Match>++ {/* Entity row */}+ <Match when={true}>+ <SoupEntityContextMenu+ entity={row.original}+ >+ <ListEntity+ entity={row.original}+ timestamp={timestamp()}+ highlighted={+ panel.isPanelActive() &&+ row.isFocused()+ }+ onMouseMove={() => {+ if (isKeypressActive()) return;+ if (soup.previewEntity()) return;+ soup.focus.set(row.id);+ }}+ showUnrollNotifications={+ soup.predicates.isActive('inbox') &&+ !soup.predicates.isActive('noise')+ }+ checked={row.isSelected()}+ onChecked={(+ next: boolean,+ shiftKey: boolean+ ) =>+ handleMultiSelectChecked({+ entity: row.original,+ entityIndex: i(),+ next,+ shiftKey: shiftKey ?? false,+ })+ }+ onClick={(event: MouseEvent) => {+ onEntityClick({+ type: 'entity',+ entity: row.original,+ event,+ location: undefined,+ });+ }}+ onProjectClick={(+ projectEntity,+ event+ ) => {+ onEntityClick({+ type: 'project',+ projectEntity,+ entity: row.original,+ event,+ location: undefined,+ });+ }}+ onContentHitClick={(+ e: PointerEvent | MouseEvent,+ location?: SearchLocation+ ) => {+ onEntityClick({+ type: 'entity',+ entity: row.original,+ event: e,+ location,+ });+ }}+ entityRowConfig={{+ swipeLeftColor: 'bg-success',+ swipeLeftRevealedComponent: (+ <CheckIcon class="size-8 text-panel" />+ ),+ }}+ />+ </SoupEntityContextMenu>+ </Match>+ </Switch><Showwhen={i() === rows().length - 1 &&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 feebb18abb..1d41acd591 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 or toggle group+ // enter - Open entity in split, toggle group, or load moreregisterHotkey({hotkey: ['enter'],hotkeyToken: TOKENS.entity.open,@@ -147,11 +147,23 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {if (!focusedRow) return false;// If focused on a group header, toggle expand/collapse- if (focusedRow.group) {+ if (focusedRow.getIsGrouped() && focusedRow.group) {focusedRow.group.toggle();return true;}+ // If focused on a load more row, trigger load more and stay at same index+ if (focusedRow.getIsLoadMore() && focusedRow.group) {+ const currentIndex = focusedRow.index;+ focusedRow.group.loadMore().then(() => {+ soup.navigate.toIndex(currentIndex);+ virtualizerHandle()?.scrollToIndex(currentIndex, {+ align: 'nearest',+ });+ });+ return true;+ }+if (tryOpenChannelNotification(false)) return true;const entity = soup.focus.item();diff --git a/js/app/packages/core/constant/featureFlags.ts b/js/app/packages/core/constant/featureFlags.tsindex 41015bdef4..d0bc6173f3 100644--- a/js/app/packages/core/constant/featureFlags.ts+++ b/js/app/packages/core/constant/featureFlags.ts@@ -338,6 +338,8 @@ export const ENABLE_TEAM_INVITE_TIERS_OVERRIDE = DEV_MODE_ENV? true: undefined;+export const ENABLE_SOUP_GROUP_BY_OVERRIDE = DEV_MODE_ENV ? true : undefined;+export const ENABLE_AUTO_UPDATE_UI = resolveFeatureFlag('ENABLE_AUTO_UPDATE_UI',falsediff --git a/js/app/packages/entity/src/index.ts b/js/app/packages/entity/src/index.tsindex e023f241ec..da74eb004f 100644--- a/js/app/packages/entity/src/index.ts+++ b/js/app/packages/entity/src/index.ts@@ -32,10 +32,12 @@ export {} from './utils/notification';export { useIsShared } from './utils/shared';export {+ getPropertyOptionLabel,getTaskAssigneeIds,getTaskStatusOptionId,isCurrentUserAssigned,isTaskClosed,+ TASK_PRIORITY_OPTIONS,TASK_STATUS_OPTIONS,} from './utils/task-properties';export {diff --git a/js/app/packages/entity/src/utils/task-properties.ts b/js/app/packages/entity/src/utils/task-properties.tsindex 5983eed7fd..d8dc5a722c 100644--- a/js/app/packages/entity/src/utils/task-properties.ts+++ b/js/app/packages/entity/src/utils/task-properties.ts@@ -12,6 +12,24 @@ export const TASK_STATUS_OPTIONS = [{ value: PROPERTY_OPTION_IDS.STATUS.CANCELED, label: 'Canceled' },] as const;+export const TASK_PRIORITY_OPTIONS = [+ { value: PROPERTY_OPTION_IDS.PRIORITY.URGENT, label: 'Urgent' },+ { value: PROPERTY_OPTION_IDS.PRIORITY.HIGH, label: 'High' },+ { value: PROPERTY_OPTION_IDS.PRIORITY.MEDIUM, label: 'Medium' },+ { value: PROPERTY_OPTION_IDS.PRIORITY.LOW, label: 'Low' },+] as const;++const PROPERTY_OPTION_LABELS: Record<string, string> = {+ ...Object.fromEntries(TASK_STATUS_OPTIONS.map((o) => [o.value, o.label])),+ ...Object.fromEntries(TASK_PRIORITY_OPTIONS.map((o) => [o.value, o.label])),+};++export const getPropertyOptionLabel = (+ optionId: string+): string | undefined => {+ return PROPERTY_OPTION_LABELS[optionId];+};+const getTaskPropertyByDefinitionId = (entity: TaskEntityWithProperties,definitionId: stringdiff --git a/js/app/packages/queries/soup/grouped/api.ts b/js/app/packages/queries/soup/grouped/api.tsnew file mode 100644index 0000000000..bd6fa8590e--- /dev/null+++ b/js/app/packages/queries/soup/grouped/api.ts@@ -0,0 +1,54 @@+import type { GroupByField, GroupedSoupPage, GroupMeta } from './types';++/**+ * Serialize GroupByField to the API's expected JSON format.+ */+export function serializeGroupByField(field: GroupByField): unknown {+ switch (field.type) {+ case 'date':+ return 'date';+ case 'entity_type':+ return 'entity_type';+ case 'project':+ return 'project';+ case 'property':+ return {+ property: {+ property_definition_id: field.propertyDefinitionId,+ ...(field.entityType && { entity_type: field.entityType }),+ },+ };+ }+}++/**+ * Parse raw API group metadata to typed GroupMeta.+ */+export function parseGroupMeta(raw: Record<string, unknown>): GroupMeta {+ return {+ key: raw.key as string,+ label: raw.label as string,+ displayOrder: (raw.display_order as number) ?? null,+ totalCount: raw.total_count as number,+ pageCount: raw.page_count as number,+ startIndex: raw.start_index as number,+ nextCursor: (raw.next_cursor as string) ?? null,+ };+}++/**+ * Parse the API response into our typed GroupedSoupPage.+ * Handles snake_case to camelCase conversion.+ */+export function parseGroupedSoupPage(response: unknown): GroupedSoupPage {+ const data = response as Record<string, unknown>;+ const items = (data.items ?? []) as GroupedSoupPage['items'];+ const nextCursor = (data.next_cursor as string) ?? null;+ const rawGroups = (data.groups ?? []) as Array<Record<string, unknown>>;++ return {+ items,+ nextCursor,+ groups: rawGroups.map(parseGroupMeta),+ };+}diff --git a/js/app/packages/queries/soup/grouped/types.ts b/js/app/packages/queries/soup/grouped/types.tsnew file mode 100644index 0000000000..d924b3da32--- /dev/null+++ b/js/app/packages/queries/soup/grouped/types.ts@@ -0,0 +1,37 @@+import type { SoupApiItem } from '@service-storage/generated/schemas';++export type GroupByField =+ | { type: 'date' }+ | { type: 'entity_type' }+ | { type: 'project' }+ | {+ type: 'property';+ propertyDefinitionId: string;+ entityType?: PropertyEntityType;+ };++export type PropertyEntityType =+ | 'CHANNEL'+ | 'CHAT'+ | 'COMPANY'+ | 'DOCUMENT'+ | 'PROJECT'+ | 'TASK'+ | 'THREAD'+ | 'USER';++export interface GroupMeta {+ key: string;+ label: string;+ displayOrder: number | null;+ totalCount: number;+ pageCount: number;+ startIndex: number;+ nextCursor: string | null;+}++export interface GroupedSoupPage {+ items: SoupApiItem[];+ nextCursor: string | null;+ groups: GroupMeta[];+}diff --git a/js/app/packages/queries/soup/items.ts b/js/app/packages/queries/soup/items.tsindex 8ee9f61bd9..0c2b03b960 100644--- a/js/app/packages/queries/soup/items.ts+++ b/js/app/packages/queries/soup/items.ts@@ -1,6 +1,11 @@import { filterSoupItemByRequestBody } from '@app/component/next-soup/filters/query-filters';import { throwOnErr } from '@core/util/maybeResult';import type { EntityData } from '@entity';+import {+ parseGroupMeta,+ serializeGroupByField,+} from '@queries/soup/grouped/api';+import type { GroupByField, GroupMeta } from '@queries/soup/grouped/types';import { soupKeys } from '@queries/soup/keys';import { mapSoupPageToEntityList } from '@queries/soup/transform-utils';import { useInstructionsMdIdQuery } from '@queries/storage/instructions-md';@@ -36,6 +41,8 @@ export type SoupAstBody = EntityFilterAst & PostSoupAstRequestAllOf;export type SoupAstItemsQueryArgs = {params: SoupAstParams;body: SoupAstBody;+ groupBy?: GroupByField;+ groupKey?: string;};export type UseSoupQueryResult = UseInfiniteQueryResult<EntityData[], Error>;@@ -47,6 +54,18 @@ interface SoupItemsQueryOptions {staleTime?: StaleTime;}+export type SoupAstItemsPage = {+ items: SoupApiItem[];+ nextCursor: string | null;+ groups?: GroupMeta[];+};++export type SoupAstItemsData = {+ entities: EntityData[];+ groups: GroupMeta[] | undefined;+ items: SoupApiItem[];+};+export const useSoupItemsQuery = (args: Accessor<SoupItemsQueryArgs>,options?: Accessor<SoupItemsQueryOptions>@@ -97,34 +116,85 @@ export const useSoupAstItemsQuery = () => {const instructionsIdQuery = useInstructionsMdIdQuery();- return useInfiniteQuery(() => ({- queryKey: soupKeys.astItems(args()).queryKey,- queryFn: async (ctx) => {- const { params, body } = args();-- return throwOnErr(- async () =>- await storageServiceClient.getSoupAstItems({- params: { cursor: ctx.pageParam },- body: {- ...body,- ...params,- },- })- );- },- initialPageParam: null as string | null,- getNextPageParam: (lastPage) => {- return lastPage.next_cursor;- },- select: (data) => {- return data.pages.flatMap((page) => {- return mapSoupPageToEntityList(page, { instructionsIdQuery });- });- },- enabled: options?.().enabled,- staleTime: options?.().staleTime,- placeholderData: (p) => p,- meta: { normalize: true },- }));+ return useInfiniteQuery(() => {+ const { params, body, groupBy, groupKey } = args();++ return {+ queryKey: soupKeys.astItems({ params, body, groupBy, groupKey }).queryKey,+ queryFn: async (ctx): Promise<SoupAstItemsPage> => {+ if (groupBy) {+ const response = await throwOnErr(+ async () =>+ await storageServiceClient.getGroupedSoupAstItems({+ params: {+ cursor: ctx.pageParam,+ group_by: serializeGroupByField(groupBy),+ group_key: groupKey,+ },+ body: {+ ...body,+ ...params,+ },+ })+ );++ const groups = response.groups+ ? (response.groups as Array<Record<string, unknown>>).map(+ parseGroupMeta+ )+ : undefined;++ return {+ items: response.items,+ nextCursor: response.next_cursor ?? null,+ groups,+ };+ }++ const response = await throwOnErr(+ async () =>+ await storageServiceClient.getSoupAstItems({+ params: {+ cursor: ctx.pageParam,+ },+ body: {+ ...body,+ ...params,+ },+ })+ );++ return {+ items: response.items,+ nextCursor: response.next_cursor ?? null,+ groups: [],+ };+ },+ initialPageParam: null as string | null,+ getNextPageParam: (lastPage): string | null => {+ if (groupBy) return null;+ return lastPage.nextCursor;+ },+ select: (data): SoupAstItemsData => {+ const items = data.pages.flatMap((page) => page.items);+ const entities = data.pages.flatMap((page) => {+ return mapSoupPageToEntityList(page, { instructionsIdQuery });+ });+ const rawGroups = data.pages[0]?.groups;+ // Sort groups by displayOrder (nulls last)+ const groups = rawGroups?.slice().sort((a, b) => {+ if (a.displayOrder === null && b.displayOrder === null) return 0;+ if (a.displayOrder === null) return 1;+ if (b.displayOrder === null) return -1;+ return a.displayOrder - b.displayOrder;+ });++ return { entities, groups, items };+ },+ enabled: options?.().enabled,+ staleTime: options?.().staleTime,+ placeholderData: (p) => p,+ meta: { normalize: true },+ };+ });};diff --git a/js/app/packages/queries/soup/keys.ts b/js/app/packages/queries/soup/keys.tsindex f6209be225..60c8c1db42 100644--- a/js/app/packages/queries/soup/keys.ts+++ b/js/app/packages/queries/soup/keys.ts@@ -1,4 +1,5 @@import { createQueryKeys } from '@lukemorales/query-key-factory';+import type { GroupByField } from './grouped/types';import type { SoupAstItemsQueryArgs, SoupItemsQueryArgs } from './items';import type { SearchSoupQueryArgs } from './search';@@ -7,9 +8,17 @@ export const soupKeys = createQueryKeys('soup', {queryKey: [args.params, args.body],}),astItems: (args: SoupAstItemsQueryArgs) => ({- queryKey: [args.params, args.body],+ queryKey: [args.params, args.body, args.groupBy, args.groupKey],}),search: (args: SearchSoupQueryArgs) => ({queryKey: [args.params, args.body],}),+ groupedGroup: (args: {+ params: SoupAstItemsQueryArgs['params'];+ body: SoupAstItemsQueryArgs['body'];+ groupBy: GroupByField;+ groupKey: string;+ }) => ({+ queryKey: ['group', args.groupKey, args.groupBy, args.params, args.body],+ }),});diff --git a/js/app/packages/service-clients/service-storage/client.ts b/js/app/packages/service-clients/service-storage/client.tsindex dd0b09bdec..e0a126491e 100644--- a/js/app/packages/service-clients/service-storage/client.ts+++ b/js/app/packages/service-clients/service-storage/client.ts@@ -184,7 +184,6 @@ export function stringToItemType(str: string): ItemType | undefined {case 'thread': {return 'email';}- case 'call':case 'chat':case 'document':case 'project':@@ -268,6 +267,40 @@ export const storageServiceClient = {});},+ async getGroupedSoupAstItems(args: {+ params: {+ cursor?: string | null;+ group_by: unknown;+ group_key?: string | null;+ };+ body: PostSoupAstRequest;+ }) {+ const params = new URLSearchParams();+ if (args.params.cursor) params.set('cursor', args.params.cursor);+ const searchParams = params.toString() ? `?${params.toString()}` : '';++ const body: Record<string, unknown> = { ...args.body };+ if (args.params.group_by) body.group_by = args.params.group_by;+ if (args.params.group_key) body.group_key = args.params.group_key;++ return await dssFetch<+ SoupPage & {+ groups?: {+ key: string;+ label: string;+ display_order: number | null;+ total_count: number;+ page_count: number;+ start_index: number;+ next_cursor: string | null;+ }[];+ }+ >(`/items/soup/ast/grouped${searchParams}`, {+ method: 'POST',+ body: JSON.stringify(body),+ });+ },+permissionsTokens: {// Uses SYNC_PERMISSION_TOKEN_DSS_HOST instead of dssFetch so that tokens are// always signed by the DSS whose JWT secret matches the sync service's secret.diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rsindex 01b3551f25..24caaf3290 100644--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs@@ -1486,7 +1486,7 @@ fn build_grouped_query<'a>(match &grouping.field {GroupByField::Date => {- builder.push(date_bucket_sql_order("\"sort_ts\""));+ builder.push(date_bucket_sql_order("sort_ts"));}_ => {builder.push("\"group_key\"");