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(tasks): keep title-row property chips mounted across refetches (#9119)

gbirman241543c30526
diff --git a/apps/web/src/features/block-md/component/InlineTaskProperties.test.tsx b/apps/web/src/features/block-md/component/InlineTaskProperties.test.tsx
index decfc53fd1..b8cb4f8d8f 100644
--- a/apps/web/src/features/block-md/component/InlineTaskProperties.test.tsx
+++ b/apps/web/src/features/block-md/component/InlineTaskProperties.test.tsx
@@ -382,6 +382,25 @@ it('unpins an implicit task default without dropping the other defaults', async
expect(mocks.properties()).toEqual(taskProperties);
});
+it('updates task title chips in place when the properties emit new objects', async () => {
+ mocks.kind = 'task';
+ setup(taskProperties);
+ const status = screen.getByRole('button', { name: 'Unpin Status' });
+
+ mocks.setProperties?.(
+ taskProperties.map((item) => ({
+ ...item,
+ displayName: `${item.displayName} saved`,
+ }))
+ );
+
+ await waitFor(() =>
+ expect(screen.getByRole('button', { name: 'Unpin Status saved' })).toBe(
+ status
+ )
+ );
+});
+
it('keeps all task title pins cleared after serialization and reopening', async () => {
mocks.kind = 'task';
const editor = setup(taskProperties);
diff --git a/apps/web/src/features/block-md/component/InlineTaskProperties.tsx b/apps/web/src/features/block-md/component/InlineTaskProperties.tsx
index 3d1303d8e9..bddffa0234 100644
--- a/apps/web/src/features/block-md/component/InlineTaskProperties.tsx
+++ b/apps/web/src/features/block-md/component/InlineTaskProperties.tsx
@@ -19,11 +19,11 @@ import { InlineFetchedEntityTagsPill } from '@property/tags';
import type { Property, PropertyApiValues } from '@property/types';
import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity';
import { useTagsQuery } from '@queries/properties/tags';
+import { Key } from '@solid-primitives/keyed';
import {
createEffect,
createMemo,
createSignal,
- For,
Show,
Suspense,
} from 'solid-js';
@@ -180,25 +180,27 @@ export function InlineTaskProperties() {
size="xs"
showAddButton={documentKind === 'document' && canEdit()}
/>
- <For each={inlineProperties()}>
+ <Key each={inlineProperties()} by="propertyId">
{(property) => (
<InlinePropertyValue
- property={property}
+ property={property()}
entityId={blockId}
canManage={
- !property.propertyId.startsWith('pending:') ||
- defaultDefinitionIds().includes(property.propertyDefinitionId)
+ !property().propertyId.startsWith('pending:') ||
+ defaultDefinitionIds().includes(
+ property().propertyDefinitionId
+ )
}
canRemove={
- !property.propertyId.startsWith('pending:') &&
+ !property().propertyId.startsWith('pending:') &&
(documentKind !== 'task' ||
!getBuiltinPropertyIds('task').includes(
- property.propertyDefinitionId
+ property().propertyDefinitionId
))
}
/>
)}
- </For>
+ </Key>
<Show when={documentKind === 'document' && canEdit()}>
<AddPropertyButton variant="secondary" size="xs" class="gap-1.5" />
</Show>
diff --git a/apps/web/src/features/property/extractors/PropertyText.test.tsx b/apps/web/src/features/property/extractors/PropertyText.test.tsx
new file mode 100644
index 0000000000..b15951cd81
--- /dev/null
+++ b/apps/web/src/features/property/extractors/PropertyText.test.tsx
@@ -0,0 +1,66 @@
+import { cleanup, render } from '@solidjs/testing-library';
+import { createSignal } from 'solid-js';
+import { afterEach, expect, it, vi } from 'vitest';
+import type { EntityProperty } from '../types';
+import { PropertyText } from './PropertyText';
+
+const displays = vi.hoisted(() => ({ mounts: [] as string[] }));
+
+vi.mock('@ui', async () => {
+ const { cn } = await import('../../../components/ui/utils/classname');
+ return { cn };
+});
+vi.mock('../hooks/usePropertyEntityDisplay', () => ({
+ usePropertyEntityDisplay: (id: () => string) => {
+ displays.mounts.push(id());
+ return {
+ name: () => (id() === 'launch' ? 'Product launch' : 'Website redesign'),
+ icon: () => null,
+ };
+ },
+}));
+vi.mock('../hooks/usePropertyUserDisplay', () => ({
+ usePropertyUserDisplay: () => ({ shortName: () => 'Alice' }),
+}));
+
+const project: EntityProperty = {
+ propertyId: 'task-project',
+ propertyDefinitionId: 'project-definition',
+ displayName: 'Project',
+ isMultiSelect: false,
+ owner: { scope: 'system' },
+ createdAt: new Date(0),
+ updatedAt: new Date(0),
+ valueType: 'ENTITY',
+ specificEntityType: 'INITIATIVE',
+ value: [{ entity_id: 'launch', entity_type: 'INITIATIVE' }],
+};
+
+afterEach(() => {
+ cleanup();
+ displays.mounts = [];
+});
+
+it('keeps a linked project in place while its property re-emits the same project', () => {
+ const [property, setProperty] = createSignal(project);
+ const view = render(() => (
+ <PropertyText property={property()} resolveSingleEntity />
+ ));
+ const name = view.getByText('Product launch');
+
+ setProperty({
+ ...project,
+ value: [{ entity_id: 'launch', entity_type: 'INITIATIVE' }],
+ });
+
+ expect(view.getByText('Product launch')).toBe(name);
+ expect(displays.mounts).toEqual(['launch']);
+
+ setProperty({
+ ...project,
+ value: [{ entity_id: 'redesign', entity_type: 'INITIATIVE' }],
+ });
+
+ expect(view.getByText('Website redesign')).toBeTruthy();
+ expect(displays.mounts).toEqual(['launch', 'redesign']);
+});
diff --git a/apps/web/src/features/property/extractors/PropertyText.tsx b/apps/web/src/features/property/extractors/PropertyText.tsx
index 4a0da2a460..86b618d284 100644
--- a/apps/web/src/features/property/extractors/PropertyText.tsx
+++ b/apps/web/src/features/property/extractors/PropertyText.tsx
@@ -76,21 +76,28 @@ export function PropertyText(props: Props) {
return (
<Show
keyed
- when={singleEntity()}
+ when={singleEntity()?.entity_id}
fallback={<PropertyTextValue {...props} userId={userId()} />}
>
- {(entity) => <EntityPropertyText entity={entity} class={props.class} />}
+ {(entityId) => (
+ <EntityPropertyText
+ entityId={entityId}
+ entityType={singleEntity()?.entity_type}
+ class={props.class}
+ />
+ )}
</Show>
);
}
function EntityPropertyText(props: {
- entity: EntityReference;
+ entityId: string;
+ entityType: EntityReference['entity_type'] | undefined;
class?: string;
}) {
const { name, icon } = usePropertyEntityDisplay(
- () => props.entity.entity_id,
- () => props.entity.entity_type
+ () => props.entityId,
+ () => props.entityType
);
return (
<span class={cn('inline-flex min-w-0 items-center gap-1.5', props.class)}>
diff --git a/apps/web/src/features/property/extractors/PropertyUserStack.test.tsx b/apps/web/src/features/property/extractors/PropertyUserStack.test.tsx
new file mode 100644
index 0000000000..a8a6246bba
--- /dev/null
+++ b/apps/web/src/features/property/extractors/PropertyUserStack.test.tsx
@@ -0,0 +1,67 @@
+import { cleanup, render } from '@solidjs/testing-library';
+import { createSignal, type JSX } from 'solid-js';
+import { afterEach, expect, it, vi } from 'vitest';
+import type { EntityProperty } from '../types';
+import { PropertyUserStack } from './PropertyUserStack';
+
+const avatars = vi.hoisted(() => ({ mounts: [] as string[] }));
+
+vi.mock('@core/component/UserIcon', () => ({
+ UserIcon: (props: { id: string }) => {
+ avatars.mounts.push(props.id);
+ return <span>{props.id}</span>;
+ },
+}));
+vi.mock('@ui', () => ({
+ AvatarGroup: Object.assign(
+ (props: { children: JSX.Element }) => <div>{props.children}</div>,
+ {
+ Count: (props: { children: JSX.Element }) => (
+ <span>{props.children}</span>
+ ),
+ }
+ ),
+}));
+
+const assignees: EntityProperty = {
+ propertyId: 'task-assignees',
+ propertyDefinitionId: 'assignees-definition',
+ displayName: 'Assignees',
+ isMultiSelect: true,
+ owner: { scope: 'system' },
+ createdAt: new Date(0),
+ updatedAt: new Date(0),
+ valueType: 'ENTITY',
+ specificEntityType: 'USER',
+ value: [
+ { entity_id: 'macro|[email protected]', entity_type: 'USER' },
+ { entity_id: 'macro|[email protected]', entity_type: 'USER' },
+ ],
+};
+
+afterEach(() => {
+ cleanup();
+ avatars.mounts = [];
+});
+
+it('keeps each avatar in place while the assignees re-emit', () => {
+ const [property, setProperty] = createSignal(assignees);
+ const view = render(() => <PropertyUserStack property={property()} />);
+ const alice = view.getByText('macro|[email protected]');
+
+ setProperty({
+ ...assignees,
+ value: [
+ { entity_id: 'macro|[email protected]', entity_type: 'USER' },
+ { entity_id: 'macro|[email protected]', entity_type: 'USER' },
+ { entity_id: 'macro|[email protected]', entity_type: 'USER' },
+ ],
+ });
+
+ expect(view.getByText('macro|[email protected]')).toBe(alice);
+ expect(avatars.mounts).toEqual([
+ ]);
+});
diff --git a/apps/web/src/features/property/extractors/PropertyUserStack.tsx b/apps/web/src/features/property/extractors/PropertyUserStack.tsx
index e0601d7388..c515d94db2 100644
--- a/apps/web/src/features/property/extractors/PropertyUserStack.tsx
+++ b/apps/web/src/features/property/extractors/PropertyUserStack.tsx
@@ -1,6 +1,7 @@
import { UserIcon } from '@core/component/UserIcon';
+import { Key } from '@solid-primitives/keyed';
import { AvatarGroup } from '@ui';
-import { For, Show } from 'solid-js';
+import { Show } from 'solid-js';
import type { Property } from '../types';
import { getEntityValues, isEntityProperty } from '../utils';
@@ -28,17 +29,17 @@ export function PropertyUserStack(props: Props) {
return (
<Show when={isUser()}>
<AvatarGroup size="sm">
- <For each={display()}>
+ <Key each={display()} by="entity_id">
{(entity) => (
<UserIcon
- id={entity.entity_id}
+ id={entity().entity_id}
size="sm"
suppressClick
showTooltip={false}
class={props.avatarClass}
/>
)}
- </For>
+ </Key>
<Show when={remaining() > 0}>
<AvatarGroup.Count size="sm">+{remaining()}</AvatarGroup.Count>
</Show>
diff --git a/apps/web/src/features/property/hooks/usePropertyEntityDisplay.test.tsx b/apps/web/src/features/property/hooks/usePropertyEntityDisplay.test.tsx
index 51f9cd555a..c307f8b619 100644
--- a/apps/web/src/features/property/hooks/usePropertyEntityDisplay.test.tsx
+++ b/apps/web/src/features/property/hooks/usePropertyEntityDisplay.test.tsx
@@ -1,5 +1,5 @@
import { QueryClient, useQuery } from '@tanstack/solid-query';
-import { createRoot, createSignal, onCleanup } from 'solid-js';
+import { createComputed, createRoot, createSignal, onCleanup } from 'solid-js';
import { afterEach, describe, expect, it, vi } from 'vitest';
const fixture = vi.hoisted(() => ({
@@ -12,6 +12,7 @@ const fixture = vi.hoisted(() => ({
projectsEnabled: undefined as (() => boolean | undefined) | undefined,
projectMounts: 0,
projectDisposals: 0,
+ projectIdReads: 0,
userIcons: 0,
flagMounts: 0,
}));
@@ -30,9 +31,13 @@ vi.mock('@core/constant/featureFlags', () => ({
}));
vi.mock('@core/context/user', () => ({ useUserId: () => () => 'user' }));
vi.mock('../../projects/queries/project-identity', () => ({
- useProjectIdentityQuery: () => {
+ useProjectIdentityQuery: (id: () => string) => {
fixture.projectMounts++;
onCleanup(() => fixture.projectDisposals++);
+ createComputed(() => {
+ id();
+ fixture.projectIdReads++;
+ });
return {
isError: false,
isPending: false,
@@ -93,6 +98,7 @@ afterEach(() => {
fixture.projectsEnabled = undefined;
fixture.projectMounts = 0;
fixture.projectDisposals = 0;
+ fixture.projectIdReads = 0;
fixture.userIcons = 0;
fixture.flagMounts = 0;
});
@@ -150,6 +156,28 @@ describe('usePropertyEntityDisplay subscription ownership', () => {
expect(display.name()).toBe('Project');
});
+ it('keeps one project read while the property value re-emits the same project', () => {
+ fixture.projectsEnabled = () => true;
+ const [reference, setReference] = createSignal({
+ entity_id: 'entity-1',
+ entity_type: 'INITIATIVE' as const,
+ });
+ const display = createRoot((dispose) => {
+ disposals.push(dispose);
+ return usePropertyEntityDisplay(
+ () => reference().entity_id,
+ () => reference().entity_type
+ );
+ });
+
+ setReference({ entity_id: 'entity-1', entity_type: 'INITIATIVE' });
+
+ expect(fixture.flagMounts).toBe(1);
+ expect(fixture.projectMounts).toBe(1);
+ expect(fixture.projectIdReads).toBe(1);
+ expect(display.name()).toBe('Launch');
+ });
+
it('keeps the generic project label, without fetching, until the rollout enables it', () => {
const [enabled, setEnabled] = createSignal<boolean | undefined>();
fixture.projectsEnabled = enabled;
diff --git a/apps/web/src/features/property/hooks/usePropertyEntityDisplay.tsx b/apps/web/src/features/property/hooks/usePropertyEntityDisplay.tsx
index 416e71d251..30bef8be86 100644
--- a/apps/web/src/features/property/hooks/usePropertyEntityDisplay.tsx
+++ b/apps/web/src/features/property/hooks/usePropertyEntityDisplay.tsx
@@ -57,14 +57,14 @@ type PropertyEntityDisplayResult = {
* Hook to resolve entity display information (name, icon) for property entity values.
* Handles preview fetching, channel name resolution, and user display names.
*
- * @param entityId - The entity's unique identifier
- * @param entityType - The type of entity (USER, CHANNEL, DOCUMENT, etc.)
+ * @param entityIdSource - The entity's unique identifier
+ * @param entityTypeSource - The type of entity (USER, CHANNEL, DOCUMENT, etc.)
* @param options - Optional configuration
* @returns Object with name, icon, isLoading, and blockOrFileType accessors
*/
export function usePropertyEntityDisplay(
- entityId: Accessor<string>,
- entityType: Accessor<EntityType | undefined>,
+ entityIdSource: Accessor<string>,
+ entityTypeSource: Accessor<EntityType | undefined>,
options?: {
/** Custom fallback icon for unknown entity types (null to show nothing) */
fallbackIcon?: JSX.Element | null;
@@ -72,6 +72,10 @@ export function usePropertyEntityDisplay(
specificMessageId?: Accessor<string | null | undefined>;
}
): PropertyEntityDisplayResult {
+ // Callers usually read these from a property value, which every properties
+ // emission replaces. Only a real change may rebuild or re-run the reads below.
+ const entityId = createMemo(entityIdSource);
+ const entityType = createMemo(entityTypeSource);
const projectsFlag = createMemo(() =>
entityType() === 'INITIATIVE' ? useFeatureFlag(enableProjects) : undefined
);