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
fix(properties): keep pill focus when property values update (#9330)
gbirmanb7bf0a48c4bc
diff --git a/apps/web/src/features/entity/extractors-property/entity-key-properties.test.tsx b/apps/web/src/features/entity/extractors-property/entity-key-properties.test.tsxnew file mode 100644index 0000000000..c1547483d1--- /dev/null+++ b/apps/web/src/features/entity/extractors-property/entity-key-properties.test.tsx@@ -0,0 +1,95 @@+import { SYSTEM_PROPERTY_IDS } from '@property/identifiers';+import type { Property } from '@property/types';+import type { SoupProperty } from '@service-storage/generated/schemas/soupProperty';+import { cleanup, render, screen } from '@solidjs/testing-library';+import { createSignal, type JSX } from 'solid-js';+import { afterEach, expect, it, vi } from 'vitest';+import type { EntityData, EntityWithProperties } from '../types/entity';+import { EntityKeyProperties } from './entity-key-properties';++vi.mock('@core/component/ScopedPortal', () => ({ ScopedPortal: () => null }));+vi.mock('@property', async (importOriginal) => {+ const passthrough = (props: { children: JSX.Element }) => props.children;+ return {+ ...(await importOriginal<typeof import('@property')>()),+ Property: {+ Root: (props: {+ property: Property;+ children: (property: () => Property) => JSX.Element;+ }) => props.children(() => props.property),+ Tooltip: passthrough,+ EditTrigger: (props: JSX.ButtonHTMLAttributes<HTMLButtonElement>) => (+ <button {...props} />+ ),+ Text: (props: { property: Property }) => (+ <span>+ {props.property.displayName}: {String(props.property.value)}+ </span>+ ),+ Icon: () => null,+ UserStack: () => null,+ Empty: () => null,+ Caret: () => null,+ PopoverEditor: () => null,+ },+ };+});+vi.mock('@property/component/modal', () => ({ Modals: () => null }));+vi.mock('@property/context/PropertiesContext', () => ({+ PropertiesProvider: (props: { children: JSX.Element }) => props.children,+ usePropertiesContext: () => ({+ entityType: 'TASK',+ canEdit: true,+ saveHandler: { saveProperty: vi.fn() },+ }),+}));+vi.mock('@queries/properties/entity', () => ({+ useBulkSaveEntityPropertiesMutation: () => ({ mutateAsync: vi.fn() }),+}));+vi.mock('@ui', async () => {+ const { cn } = await import('../../../components/ui/utils/classname');+ return {+ cn,+ Layer: (props: { children: JSX.Element }) => props.children,+ };+});++afterEach(cleanup);++const priority = (value: string) =>+ ({+ id: 'priority-assignment',+ definition: {+ id: SYSTEM_PROPERTY_IDS.PRIORITY,+ display_name: 'Priority',+ data_type: 'SELECT_STRING',+ is_multi_select: false,+ is_metadata: false,+ is_system: true,+ owner: { scope: 'system' },+ created_at: new Date(0).toISOString(),+ updated_at: new Date(0).toISOString(),+ },+ value: { type: 'SelectOption', value: [value] },+ }) as unknown as SoupProperty;++const task = (value: string) =>+ ({+ id: 'task',+ type: 'document',+ fileType: 'md',+ subType: { type: 'task' },+ properties: [priority(value)],+ }) as unknown as EntityWithProperties<EntityData>;++it('keeps a focused pill when the row hands it a fresh property', () => {+ const [entity, setEntity] = createSignal(task('low'));+ render(() => <EntityKeyProperties entity={entity()} />);+ const pill = screen.getByRole('button', { name: /^Priority/ });+ pill.focus();++ setEntity(task('low'));+ setEntity(task('high'));++ expect(document.activeElement).toBe(pill);+});diff --git a/apps/web/src/features/entity/extractors-property/entity-key-properties.tsx b/apps/web/src/features/entity/extractors-property/entity-key-properties.tsxindex b58b4a14e7..c560eda163 100644--- a/apps/web/src/features/entity/extractors-property/entity-key-properties.tsx+++ b/apps/web/src/features/entity/extractors-property/entity-key-properties.tsx@@ -11,11 +11,11 @@ import type { PropertyApiValues, Property as PropertyT } from '@property/types';import { getEntityValues, hasValue } from '@property/utils';import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity';import { EntityType } from '@service-properties/generated/schemas/entityType';+import { Key } from '@solid-primitives/keyed';import { cn, Layer } from '@ui';import {type Accessor,createMemo,- For,Match,Show,Suspense,@@ -163,10 +163,10 @@ function KeyPropertiesRow(props: {return (<div class="flex items-center gap-1 justify-start text-xs">- <For each={props.properties()}>+ <Key each={props.properties()} by="propertyDefinitionId">{(property) => (<Property.Root- property={property}+ property={property()}canEdit={ctx.canEdit}onSave={ctx.saveHandler.saveProperty}>@@ -247,7 +247,7 @@ function KeyPropertiesRow(props: {}}</Property.Root>)}- </For>+ </Key></div>);}diff --git a/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.test.tsx b/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.test.tsxnew file mode 100644index 0000000000..e14814d42f--- /dev/null+++ b/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.test.tsx@@ -0,0 +1,80 @@+import { SYSTEM_PROPERTY_IDS } from '@property/identifiers';+import type { Property } from '@property/types';+import type { SoupProperty } from '@service-storage/generated/schemas/soupProperty';+import { cleanup, render, screen } from '@solidjs/testing-library';+import { createSignal, type JSX } from 'solid-js';+import { afterEach, expect, it, vi } from 'vitest';+import {+ type InboxCardDisplayItem,+ TaskCardLayout,+} from './inbox-card-layouts';++vi.mock(+ '@app/features/next-soup/soup-view/views/tasks/list-property-value',+ () => ({+ ListPropertyValue: (props: { property: Property }) => (+ <button>+ {props.property.displayName}: {String(props.property.value)}+ </button>+ ),+ })+);+vi.mock('@core/component/EntityIcon', () => ({+ EntityIcon: () => null,+ getEntityIconType: () => 'task',+}));+vi.mock(+ '@core/component/LexicalMarkdown/component/core/StaticMarkdown',+ () => ({ StaticMarkdown: () => null })+);+vi.mock('@property/context/PropertiesContext', () => ({+ PropertiesProvider: (props: { children: JSX.Element }) => props.children,+}));+vi.mock('@queries/properties/entity', () => ({+ useBulkSaveEntityPropertiesMutation: () => ({ mutateAsync: vi.fn() }),+}));++afterEach(cleanup);++const priority = (value: string) =>+ ({+ id: 'priority-assignment',+ definition: {+ id: SYSTEM_PROPERTY_IDS.PRIORITY,+ display_name: 'Priority',+ data_type: 'SELECT_STRING',+ is_multi_select: false,+ is_metadata: false,+ is_system: true,+ owner: { scope: 'system' },+ created_at: new Date(0).toISOString(),+ updated_at: new Date(0).toISOString(),+ },+ value: { type: 'SelectOption', value: [value] },+ }) as unknown as SoupProperty;++const taskItem = (value: string) =>+ ({+ entity: {+ id: 'task',+ name: 'Task',+ type: 'document',+ fileType: 'md',+ subType: { type: 'task' },+ ownerId: 'macro|[email protected]',+ properties: [priority(value)],+ },+ unread: false,+ }) as unknown as InboxCardDisplayItem;++it('keeps a focused pill through each fresh emission of the task', () => {+ const [item, setItem] = createSignal(taskItem('low'));+ render(() => <TaskCardLayout item={item()} />);+ const pill = screen.getByRole('button', { name: /^Priority/ });+ pill.focus();++ setItem(taskItem('low'));+ setItem(taskItem('high'));++ expect(document.activeElement).toBe(pill);+});diff --git a/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx b/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsxindex 968e3df579..2fadf6ef16 100644--- a/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx+++ b/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx@@ -53,6 +53,7 @@ import type { PropertyApiValues, Property as PropertyT } from '@property/types';import { senderFromStorageId } from '@queries/messages/message-sender';import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity';import { EntityType } from '@service-storage/generated/schemas';+import { Key } from '@solid-primitives/keyed';import { Avatar, cn, Tooltip } from '@ui';import { parseISO } from 'date-fns';import { createMemo, For, type JSX, Match, Show, Switch } from 'solid-js';@@ -363,9 +364,9 @@ function PropertyPills(props: { entityId: string; properties?: PropertyT[] }) {saveHandler={saveHandler}><div class="flex flex-wrap items-center gap-1 text-xs">- <For each={properties()}>- {(property) => <ListPropertyValue property={property} />}- </For>+ <Key each={properties()} by="propertyDefinitionId">+ {(property) => <ListPropertyValue property={property()} />}+ </Key></div></PropertiesProvider></Show>diff --git a/apps/web/src/features/projects/views/project-workspace.test.tsx b/apps/web/src/features/projects/views/project-workspace.test.tsxnew file mode 100644index 0000000000..b5c4af3bda--- /dev/null+++ b/apps/web/src/features/projects/views/project-workspace.test.tsx@@ -0,0 +1,96 @@+import { SYSTEM_PROPERTY_IDS } from '@property/identifiers';+import type { Property } from '@property/types';+import { cleanup, render, screen } from '@solidjs/testing-library';+import { createSignal, type JSX } from 'solid-js';+import { afterEach, expect, it, vi } from 'vitest';+import { ProjectsProvider } from '../context/projects-context';+import type { ProjectDetail } from '../core/project';+import { ProjectWorkspace } from './project-workspace';++vi.mock('@components/app/side-panel', () => ({+ SidePanel: {+ Layout: (props: { children: JSX.Element }) => props.children,+ Footer: () => null,+ Section: () => null,+ },+}));+vi.mock('@components/app/side-panel/EntityMetadata', () => ({+ EntityMetadata: () => null,+}));+vi.mock('@core/component/InlineTitleEditor', () => ({+ InlineTitleEditor: () => null,+}));+vi.mock('@property/component/PropertyValuePill', () => ({+ PropertyValuePill: (props: { property: Property }) => (+ <button>+ {props.property.displayName}: {String(props.property.value)}+ </button>+ ),+}));+vi.mock('@property/side-panel/properties/EntityPropertiesSection', () => ({+ EntityPropertiesSection: () => null,+}));+vi.mock('./add-project-tasks', () => ({ AddProjectTasks: () => null }));+vi.mock('./project-tasks-list', () => ({ ProjectTasksList: () => null }));++afterEach(cleanup);++const priority = (value: string) =>+ ({+ propertyId: 'priority-assignment',+ propertyDefinitionId: SYSTEM_PROPERTY_IDS.PRIORITY,+ displayName: 'Priority',+ isMultiSelect: false,+ owner: { scope: 'system' },+ createdAt: new Date(0),+ updatedAt: new Date(0),+ valueType: 'SELECT_STRING',+ value: [value],+ }) satisfies Property;++const project = {+ id: 'launch',+ name: 'Launch',+ access: 'owner',+} as ProjectDetail;++it('keeps a focused pill through each fresh emission of the project source', () => {+ const [properties, setProperties] = createSignal<Property[]>([+ priority('low'),+ ]);+ const context = {+ createPropertyDefinitionsSource: () => ({+ properties: () => [],+ loading: () => false,+ error: () => undefined,+ }),+ } as unknown as Parameters<typeof ProjectsProvider>[0]['context'];+ render(() => (+ <ProjectsProvider context={context}>+ <ProjectWorkspace+ project={project}+ source={{+ project: () => project,+ properties,+ loading: () => false,+ error: () => undefined,+ refresh: async () => {},+ }}+ commands={{} as Parameters<typeof ProjectWorkspace>[0]['commands']}+ section="overview"+ onOpenTask={() => true}+ onCreateTask={() => {}}+ discussion={null}+ description={null}+ />+ </ProjectsProvider>+ ));+ const pill = screen.getByRole('button', { name: 'Priority: low' });+ pill.focus();++ setProperties([priority('low')]);+ setProperties([priority('high')]);++ expect(document.activeElement).toBe(pill);+ expect(pill.textContent).toBe('Priority: high');+});diff --git a/apps/web/src/features/projects/views/project-workspace.tsx b/apps/web/src/features/projects/views/project-workspace.tsxindex 922b382403..c675db97be 100644--- a/apps/web/src/features/projects/views/project-workspace.tsx+++ b/apps/web/src/features/projects/views/project-workspace.tsx@@ -5,7 +5,8 @@ import { fireAndForget } from '@core/util/fireAndForget';import { PropertyValuePill } from '@property/component/PropertyValuePill';import { SYSTEM_PROPERTY_IDS } from '@property/identifiers';import { EntityPropertiesSection } from '@property/side-panel/properties/EntityPropertiesSection';-import { createSignal, For, type JSX, Match, Show, Switch } from 'solid-js';+import { Key } from '@solid-primitives/keyed';+import { createSignal, type JSX, Match, Show, Switch } from 'solid-js';import {type ProjectSource,type ProjectsContext,@@ -132,12 +133,15 @@ export function ProjectWorkspace(props: {class="mb-6 mt-3 flex flex-row flex-wrap items-center gap-2 text-sm empty:hidden"aria-label="Project properties">- <For each={props.source.properties()}>+ <Key+ each={props.source.properties()}+ by="propertyDefinitionId"+ >{(property) => (<PropertyValuePillvariant="secondary"size="xs"- property={property}+ property={property()}canEdit={canEdit()}onSave={(property, value) =>props.commands.saveProperty(@@ -152,7 +156,7 @@ export function ProjectWorkspace(props: {}}/>)}- </For>+ </Key></div><div aria-label="Project description">{props.description}diff --git a/apps/web/src/lib/core/component/TaskPreviewProperties.test.tsx b/apps/web/src/lib/core/component/TaskPreviewProperties.test.tsxindex b276b51f8a..472f127a2c 100644--- a/apps/web/src/lib/core/component/TaskPreviewProperties.test.tsx+++ b/apps/web/src/lib/core/component/TaskPreviewProperties.test.tsx@@ -215,6 +215,44 @@ describe('task preview data ownership', () => {view.unmount();});+ it('keeps the focused status control and detail chips through a fresh emission', () => {+ const priority = {+ ...status,+ propertyDefinitionId: SYSTEM_PROPERTY_IDS.PRIORITY,+ displayName: 'Priority',+ } as Property;+ const [properties, setProperties] = createSignal<Property[]>([+ status,+ priority,+ ]);+ propertiesQuery.mockReturnValue({+ properties,+ isLoading: () => false,+ refetch: vi.fn(),+ });+ const view = render(() => (+ <TaskPropertiesPreviewProvider taskId="task">+ <TaskPropertiesPreview taskId="task" mode="status" />+ <TaskPropertiesPreview taskId="task" mode="details" />+ </TaskPropertiesPreviewProvider>+ ));+ const statusControl = view.getByRole('button', {+ name: /Task status: status-1/,+ });+ const detailChip = view.getByText('Priority');+ statusControl.focus();++ setProperties([+ { ...status, value: ['status-2'] } as Property,+ { ...priority },+ ]);++ expect(document.activeElement).toBe(statusControl);+ expect(statusControl.textContent).toContain('status-2');+ expect(detailChip.isConnected).toBe(true);+ view.unmount();+ });+it('omits the duplicate status chip from card details', () => {const priority = {...status,diff --git a/apps/web/src/lib/core/component/TaskPropertiesPreview.tsx b/apps/web/src/lib/core/component/TaskPropertiesPreview.tsxindex b99a0e79a1..0ca9e87f98 100644--- a/apps/web/src/lib/core/component/TaskPropertiesPreview.tsx+++ b/apps/web/src/lib/core/component/TaskPropertiesPreview.tsx@@ -19,11 +19,11 @@ import { hasValue } from '@property/utils/typeGuards';import type { PreviewDocumentProperties } from '@queries/preview/types';import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity';import { useDocumentAccessLevelQuery } from '@queries/storage/document-metadata';+import { Key } from '@solid-primitives/keyed';import {type Accessor,createContext,createMemo,- For,type JSX,Show,useContext,@@ -226,22 +226,22 @@ function TaskPropertiesPreviewContent(when={props.mode === 'status'}fallback={<div class="px-2 pb-2 flex flex-row flex-wrap gap-1 text-xs justify-start">- <For each={previewProperties()}>+ <Key each={previewProperties()} by="propertyDefinitionId">{(property) => (<InlinePropertyValue- property={property}+ property={property()}entityId={props.taskId}class="bg-surface-2 border border-edge"/>)}- </For>+ </Key></div>}>- <For each={previewProperties()}>+ <Key each={previewProperties()} by="propertyDefinitionId">{(property) => (<PropertyUI.Root- property={property}+ property={property()}canEdit={props.canEdit}onSave={saveHandler.saveProperty}>@@ -279,7 +279,7 @@ function TaskPropertiesPreviewContent()}</PropertyUI.Root>)}- </For>+ </Key></Show><Modals /></PropertiesProvider>