Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(dynamic-ui): wrap soup list notifications as accessors (#7814)

Wolf Mermelstein88a4f823cec0
diff --git a/apps/web/src/features/dynamic-ui/widgets/List.test.tsx b/apps/web/src/features/dynamic-ui/widgets/List.test.tsx
new file mode 100644
index 0000000000..ed5d3791aa
--- /dev/null
+++ b/apps/web/src/features/dynamic-ui/widgets/List.test.tsx
@@ -0,0 +1,83 @@
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import type { JSX } from 'solid-js';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+const fixture = vi.hoisted(() => ({
+ entities: [
+ {
+ type: 'document' as const,
+ id: 'doc-1',
+ name: 'Doc',
+ ownerId: 'owner',
+ notifications: [{ id: 'n1', state: 'unseen' }],
+ },
+ ],
+}));
+
+vi.mock('@components/app/GlobalAppState', () => ({
+ useGlobalNotificationSource: () => ({
+ notificationsByEntity: () => ({}),
+ }),
+}));
+
+vi.mock('@queries/soup/items', () => ({
+ useSoupAstItemsQuery: () => ({
+ data: { entities: fixture.entities },
+ }),
+}));
+
+vi.mock('@app/features/next-soup/filters/filter-store', () => ({
+ compileToAst: () => ({}),
+ defineQueryFilters: (query: unknown) => query,
+ queryStateFrom: (query: unknown) => query,
+}));
+
+vi.mock('@app/features/next-soup/filters/query-filters', () => ({
+ soupItemMatchesQuery: () => true,
+}));
+
+vi.mock('@app/features/next-soup/utils', () => ({
+ openEntityInSplitFromUnifiedList: vi.fn(),
+}));
+
+vi.mock('@entity', () => ({
+ ListEntityMetadataQueryProvider: (props: { children: unknown }) =>
+ props.children,
+}));
+
+vi.mock('@entity/composed/ListEntity', () => ({
+ ListEntity: (props: { entity: { notifications?: unknown } }) => (
+ <div
+ data-testid="list-row"
+ data-notifications={typeof props.entity.notifications}
+ />
+ ),
+ ListLayoutProvider: (props: { children: unknown }) => props.children,
+}));
+
+vi.mock('@entity/components/CollapsibleList', () => ({
+ CollapsibleList: (props: {
+ items: unknown[];
+ children: (item: unknown) => JSX.Element;
+ }) => <div>{props.children(props.items[0])}</div>,
+}));
+
+import { List } from './List';
+
+afterEach(cleanup);
+
+describe('list widget soup notifications', () => {
+ it('wraps raw GraphQL notification arrays as accessors before ListEntity', () => {
+ render(() => (
+ <List
+ source={{
+ kind: 'items',
+ entities: [{ id: 'doc-1', type: 'document' }],
+ }}
+ />
+ ));
+ expect(
+ screen.getByTestId('list-row').getAttribute('data-notifications')
+ ).toBe('function');
+ });
+});
diff --git a/apps/web/src/features/dynamic-ui/widgets/List.tsx b/apps/web/src/features/dynamic-ui/widgets/List.tsx
index 0c9b32642f..ee9d62f0f9 100644
--- a/apps/web/src/features/dynamic-ui/widgets/List.tsx
+++ b/apps/web/src/features/dynamic-ui/widgets/List.tsx
@@ -7,6 +7,7 @@ import {
import type { FieldFilters } from '@app/features/next-soup/filters/filter-store/types';
import { soupItemMatchesQuery } from '@app/features/next-soup/filters/query-filters';
import { openEntityInSplitFromUnifiedList } from '@app/features/next-soup/utils';
+import { withEntityNotifications } from '@app/features/soup/entity-notifications';
import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
import { ListEntityMetadataQueryProvider } from '@entity';
import { CollapsibleList } from '@entity/components/CollapsibleList';
@@ -125,11 +126,11 @@ function queryItemFilter(source: Query): SoupApiItemFilter {
* dispatches per `entity.type` and works for every type here already,
* `email` included.
*/
-function Row(props: { entity: EntityData }) {
+function Row(props: { entity: WithNotification<EntityData> }) {
const notificationSource = useGlobalNotificationSource();
return (
<ListEntity
- entity={props.entity as WithNotification<EntityData>}
+ entity={props.entity}
hideCheckbox
onClick={() =>
openEntityInSplitFromUnifiedList(props.entity, {
@@ -154,6 +155,7 @@ function Rows(props: {
// and return nothing — which is the correct "No items." outcome anyway.
// `groupBy` orders the returned entities by the requested facet (the grouped
// select flattens groups into `data.entities` in group order).
+ const notificationSource = useGlobalNotificationSource();
const itemsQuery = useSoupAstItemsQuery(
() => ({
params: { limit: 200 },
@@ -169,9 +171,13 @@ function Rows(props: {
}
);
- const entities = createMemo<EntityData[]>(() => {
+ const entities = createMemo(() => {
const all = itemsQuery.data?.entities ?? [];
- return props.limit != null ? all.slice(0, props.limit) : all;
+ const sliced = props.limit != null ? all.slice(0, props.limit) : all;
+ // Soup rows carry raw notification arrays; ListEntity reads an accessor.
+ return sliced.map((entity) =>
+ withEntityNotifications(entity, notificationSource)
+ );
});
return (
diff --git a/apps/web/src/features/entity/tests/filter.test.ts b/apps/web/src/features/entity/tests/filter.test.ts
index f48c8e862b..5860660217 100644
--- a/apps/web/src/features/entity/tests/filter.test.ts
+++ b/apps/web/src/features/entity/tests/filter.test.ts
@@ -117,6 +117,22 @@ describe('unreadFilterFn', () => {
it('returns false when the optional notifications accessor is absent', () => {
expect(unreadFilterFn(document())).toBe(false);
});
+
+ it('reads a GraphQL soup notification array without calling it', () => {
+ const entity = {
+ ...document(),
+ notifications: [notification()],
+ } as unknown as WithNotification<DocumentEntity>;
+ expect(unreadFilterFn(entity)).toBe(true);
+ expect(
+ unreadFilterFn({
+ ...entity,
+ notifications: [
+ notification({ state: 'seen', viewed_at: firstView }),
+ ],
+ } as unknown as WithNotification<DocumentEntity>)
+ ).toBe(false);
+ });
});
describe('mixed scenarios', () => {
diff --git a/apps/web/src/features/entity/utils/filter.test.ts b/apps/web/src/features/entity/utils/filter.test.ts
index 1389e2983e..b06d603e02 100644
--- a/apps/web/src/features/entity/utils/filter.test.ts
+++ b/apps/web/src/features/entity/utils/filter.test.ts
@@ -1,4 +1,4 @@
-import { expect, it } from 'vitest';
+import { expect, it, vi } from 'vitest';
import type { EmailEntity } from '../types/entity';
import type { Notification, WithNotification } from '../types/notification';
import { unreadFilterFn } from './filter';
@@ -25,6 +25,34 @@ it('shows an unseen reminder dot on a read email without changing mailbox state'
expect(unreadFilterFn(email)).toBe(false);
});
+it('reads a GraphQL soup reminder array on a read email', () => {
+ const email = {
+ type: 'email',
+ id: 'thread',
+ isRead: true,
+ notifications: [
+ {
+ entity_type: 'email_thread',
+ notification_event_type: 'reminder',
+ state: 'unseen',
+ } as Notification,
+ ],
+ } as unknown as WithNotification<EmailEntity>;
+ expect(unreadFilterFn(email)).toBe(true);
+});
+
+it('does not read notifications for an unread email', () => {
+ const notifications = vi.fn((): Notification[] => []);
+ const email = {
+ type: 'email',
+ id: 'thread',
+ isRead: false,
+ notifications,
+ } as unknown as WithNotification<EmailEntity>;
+ expect(unreadFilterFn(email)).toBe(true);
+ expect(notifications).not.toHaveBeenCalled();
+});
+
it('keeps ordinary new-mail dots tied to mailbox read state', () => {
const email = {
type: 'email',
diff --git a/apps/web/src/features/entity/utils/filter.ts b/apps/web/src/features/entity/utils/filter.ts
index a9db7565ed..4f512d5826 100644
--- a/apps/web/src/features/entity/utils/filter.ts
+++ b/apps/web/src/features/entity/utils/filter.ts
@@ -1,19 +1,34 @@
+import type { Accessor } from 'solid-js';
import type { EntityData } from '../types/entity';
-import type { WithNotification } from '../types/notification';
+import type { Notification, WithNotification } from '../types/notification';
import { notificationIsRead } from './notification';
+/**
+ * GraphQL soup rows attach a raw array; list surfaces wrap it as an accessor.
+ * Read either shape so an unwrapped row cannot throw during render.
+ */
+function attachedNotifications(entity: {
+ notifications?: Accessor<Notification[] | undefined> | Notification[];
+}): Notification[] | undefined {
+ const attached = entity.notifications;
+ if (typeof attached === 'function') return attached() ?? undefined;
+ if (Array.isArray(attached)) return attached;
+ return undefined;
+}
+
export function unreadFilterFn(entity: WithNotification<EntityData>) {
if (entity.type === 'email') {
+ // Mailbox unread is enough; skip attached notifications so list scans
+ // do not touch every unread email's reminder accessor.
+ if (!entity.isRead) return true;
return (
- !entity.isRead ||
- (entity
- .notifications?.()
- ?.some(
- (n) =>
- n.notification_event_type === 'reminder' && !notificationIsRead(n)
- ) ??
- false)
+ attachedNotifications(entity)?.some(
+ (n) =>
+ n.notification_event_type === 'reminder' && !notificationIsRead(n)
+ ) ?? false
);
}
- return entity.notifications?.()?.some((n) => !notificationIsRead(n)) ?? false;
+ return (
+ attachedNotifications(entity)?.some((n) => !notificationIsRead(n)) ?? false
+ );
}