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(tags): preserve picker drafts across live updates (#9407)

dev-rbf51301cfd57b
diff --git a/apps/web/src/features/property/README.md b/apps/web/src/features/property/README.md
index 55fe3aaa53..d8b8ae9d25 100644
--- a/apps/web/src/features/property/README.md
+++ b/apps/web/src/features/property/README.md
@@ -60,9 +60,13 @@ tags. For multiple tags, label the overflow chip “N tags” when every tag is
collapsed; use “+N tags” only when individual tag chips remain visible.
Hidden tags keep the existing overflow picker and hover actions. Keep the visible
chip count stable while a picker or its nested editor is active so resizing
-cannot discard the editing session. Key visible chips by option ID so refreshed
-tag objects do not remount a picker or leave overflow collapsing paused.
-Release active-picker state when a live update removes its chip or overflow trigger.
+cannot discard the editing session. A live sorted insertion keeps the active
+chip visible within that count, then restores normal order on close. Key visible
+chips by option ID so refreshed tag objects do not remount a picker or leave
+collapse paused. Release active-picker state when a live update deletes its chip
+or overflow trigger. While the tag picker is open, reconcile remote selections
+and deleted options without resetting staged additions or removals. Preserve
+staged intent through deletion rollbacks; exclude missing options when saving.
When editing ends, immediately re-evaluate new tags against the title's full
width, even if the title is already truncated.
Hosts without a controller retain their explicit or default chip limit.
diff --git a/apps/web/src/features/property/tags/EntityRowTags.tsx b/apps/web/src/features/property/tags/EntityRowTags.tsx
index d564f336eb..e9ffbbd1c5 100644
--- a/apps/web/src/features/property/tags/EntityRowTags.tsx
+++ b/apps/web/src/features/property/tags/EntityRowTags.tsx
@@ -327,6 +327,7 @@ export function EntityRowTags(props: {
const createDocTags = () =>
useSoupDocTags(props.entityId, props.entityType, () => props.properties);
const [pickerActive, setPickerActive] = createSignal(false);
+ const [activeChipId, setActiveChipId] = createSignal<string>();
const [visibleLimit, setVisibleLimit] = createSignal(Infinity);
const id = createUniqueId();
const limit = createMemo(() =>
@@ -358,8 +359,30 @@ export function EntityRowTags(props: {
);
}
});
- const visible = () => appliedTags().slice(0, maxVisible());
- const hidden = () => appliedTags().slice(maxVisible());
+ const visible = () => {
+ const tags = appliedTags();
+ const count = maxVisible();
+ const activeId = activeChipId();
+ if (
+ !activeId ||
+ count === 0 ||
+ !tags.some((tag) => tag.optionId === activeId)
+ ) {
+ return tags.slice(0, count);
+ }
+ const selected = new Set(
+ tags
+ .filter((tag) => tag.optionId !== activeId)
+ .slice(0, Math.max(0, count - 1))
+ .map((tag) => tag.optionId)
+ );
+ selected.add(activeId);
+ return tags.filter((tag) => selected.has(tag.optionId));
+ };
+ const hidden = () => {
+ const visibleIds = new Set(visible().map((tag) => tag.optionId));
+ return appliedTags().filter((tag) => !visibleIds.has(tag.optionId));
+ };
const [editingTag, setEditingTag] = createSignal<ResolvedTag>();
return (
@@ -379,7 +402,10 @@ export function EntityRowTags(props: {
createDocTags={createDocTags}
onFilterByTag={props.onFilterByTag}
onEdit={setEditingTag}
- onActiveChange={setPickerActive}
+ onActiveChange={(active) => {
+ setActiveChipId(active ? tag().optionId : undefined);
+ setPickerActive(active);
+ }}
withClickBlock
/>
)}
diff --git a/apps/web/src/features/property/tags/tag-picker-session.ts b/apps/web/src/features/property/tags/tag-picker-session.ts
index 94f2bdde9f..b024d2e54b 100644
--- a/apps/web/src/features/property/tags/tag-picker-session.ts
+++ b/apps/web/src/features/property/tags/tag-picker-session.ts
@@ -120,10 +120,23 @@ export function createTagPickerSession(props: {
};
});
+ // Retain draft intent if an optimistic option deletion later rolls back.
+ const locallyAddedIds = new Set<string>();
+ const locallyRemovedIds = new Set<string>();
createEffect(() => {
const appliedTags = initialAppliedTags();
+ const validIds = initialTagState().optionScopes;
if (untrack(saved)) return;
- setSelectedIds(new Set(appliedTags.map((tag) => tag.optionId)));
+
+ const next = new Set(
+ appliedTags
+ .map((tag) => tag.optionId)
+ .filter((id) => validIds.has(id) && !locallyRemovedIds.has(id))
+ );
+ for (const id of locallyAddedIds) {
+ if (validIds.has(id)) next.add(id);
+ }
+ setSelectedIds(next);
});
const isSelected = (optionId: string) => selectedIds().has(optionId);
@@ -131,8 +144,15 @@ export function createTagPickerSession(props: {
const toggleSelected = (optionId: string) => {
setSelectedIds((prev) => {
const next = new Set(prev);
- if (next.has(optionId)) next.delete(optionId);
- else next.add(optionId);
+ if (next.has(optionId)) {
+ next.delete(optionId);
+ locallyAddedIds.delete(optionId);
+ if (initialAppliedIds().has(optionId)) locallyRemovedIds.add(optionId);
+ } else {
+ next.add(optionId);
+ locallyRemovedIds.delete(optionId);
+ if (!initialAppliedIds().has(optionId)) locallyAddedIds.add(optionId);
+ }
return next;
});
};
@@ -170,6 +190,10 @@ export function createTagPickerSession(props: {
};
const clearAll = () => {
+ for (const id of selectedIds()) {
+ if (initialAppliedIds().has(id)) locallyRemovedIds.add(id);
+ }
+ locallyAddedIds.clear();
setSelectedIds(new Set<string>());
if (!props.confirmsWithDone) fireAndForget(saveAndClose(), 'tag-picker');
};
diff --git a/apps/web/src/features/property/tags/tag-sets-context.test.tsx b/apps/web/src/features/property/tags/tag-sets-context.test.tsx
index e6954b61f8..699a79c62f 100644
--- a/apps/web/src/features/property/tags/tag-sets-context.test.tsx
+++ b/apps/web/src/features/property/tags/tag-sets-context.test.tsx
@@ -8,9 +8,10 @@ import type { TagSetResponse } from '@service-properties/generated/schemas/tagSe
import type { SoupProperty } from '@service-storage/generated/schemas/soupProperty';
import { fireEvent, render, screen } from '@solidjs/testing-library';
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';
-import { createSignal, type JSX } from 'solid-js';
+import { createRoot, createSignal, type JSX } from 'solid-js';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { EntityRowTags } from './EntityRowTags';
+import { createTagPickerSession, type DocTags } from './tag-picker-session';
import { TagSetsProvider } from './tag-sets-context';
const mocks = vi.hoisted(() => ({
@@ -50,6 +51,38 @@ vi.mock('./useDocTags', () => ({
useSoupDocTags: mocks.useSoupDocTags,
}));
+vi.mock('@components/app/split-layout/layout', async (importOriginal) => ({
+ ...(await importOriginal<object>()),
+ useSplitLayout: () => ({}),
+}));
+vi.mock('@components/app/split-layout/layoutUtils', async (importOriginal) => ({
+ ...(await importOriginal<object>()),
+ useSplitPanel: () => undefined,
+}));
+vi.mock(
+ '@property/editors/selectors/PropertyOptionSelector',
+ async (importOriginal) => ({
+ ...(await importOriginal<object>()),
+ useDropdownSearch: () => ({
+ setSelectedIndex: () => {},
+ selectedIndex: () => 0,
+ keyboardMode: () => false,
+ }),
+ })
+);
+vi.mock('@queries/properties/options', async (importOriginal) => ({
+ ...(await importOriginal<object>()),
+ useAddPropertyOptionMutation: () => ({ isPending: false }),
+}));
+vi.mock('@queries/properties/tags', async (importOriginal) => ({
+ ...(await importOriginal<object>()),
+ useEnsureTagSetMutation: () => ({ isPending: false }),
+}));
+vi.mock('@queries/team/teams', async (importOriginal) => ({
+ ...(await importOriginal<object>()),
+ useCurrentTeamQuery: () => ({}),
+}));
+
beforeEach(() => {
mocks.useDocTags.mockReset();
mocks.useSoupDocTags.mockReset();
@@ -245,3 +278,136 @@ describe('TagSetsContext', () => {
expect(view.getByRole('button', { name: '4 tags' })).toBeTruthy();
});
});
+
+describe('TagPickerSession', () => {
+ it('reconciles live selections and deletion rollbacks without losing staged changes', async () => {
+ const option = (id: string) => ({
+ id,
+ propertyDefinitionId: 'tag-definition',
+ displayOrder: 0,
+ value: { type: 'string' as const, value: id },
+ });
+ const [applied, setApplied] = createSignal(['a', 'b']);
+ const [options, setOptions] = createSignal(['a', 'b', 'c', 'd', 'e']);
+ const setTagSelection = vi.fn(async (_ids: ReadonlySet<string>) => {});
+ let dispose = () => {};
+ const session = createRoot((cleanup) => {
+ dispose = cleanup;
+ return createTagPickerSession({
+ docTags: {
+ appliedTags: () =>
+ applied().map((optionId) => ({
+ optionId,
+ propertyDefinitionId: 'tag-definition',
+ scope: 'user' as const,
+ label: optionId,
+ })),
+ tagSets: () => [
+ {
+ scope: 'user',
+ definition: { id: 'tag-definition' },
+ options: options().map(option),
+ },
+ ],
+ setTagSelection,
+ } as unknown as DocTags,
+ onClose: () => {},
+ onOpenEditEditor: () => {},
+ confirmsWithDone: true,
+ });
+ });
+
+ session.pick({ scope: 'user', option: option('a') });
+ session.pick({ scope: 'user', option: option('c') });
+ setApplied(['a', 'b', 'd']);
+ expect(session.isSelected('a')).toBe(false);
+ expect(session.isSelected('b')).toBe(true);
+ expect(session.isSelected('c')).toBe(true);
+ expect(session.isSelected('d')).toBe(true);
+
+ setOptions(['a', 'b', 'd', 'e']);
+ expect(session.isSelected('c')).toBe(false);
+ session.pick({ scope: 'user', option: option('e') });
+ setApplied(['a', 'b', 'd', 'e']);
+ expect(session.isSelected('a')).toBe(false);
+ expect(session.isSelected('e')).toBe(true);
+
+ setOptions(['b', 'd', 'e']);
+ setOptions(['a', 'b', 'c', 'd', 'e']);
+ expect(session.isSelected('a')).toBe(false);
+ expect(session.isSelected('c')).toBe(true);
+ await session.persistSelection();
+ expect([...setTagSelection.mock.calls[0][0]].sort()).toEqual([
+ 'b',
+ 'c',
+ 'd',
+ 'e',
+ ]);
+ dispose();
+ });
+});
+
+describe('EntityRowTags live insertions', () => {
+ it('keeps an active chip mounted within the visible cap until close', async () => {
+ const registrations = new Map<string, CollapsibleRegistration>();
+ const collapse = {
+ register(registration: CollapsibleRegistration) {
+ registrations.set(registration.id, registration);
+ return () => registrations.delete(registration.id);
+ },
+ };
+ const [tagIds, setTagIds] = createSignal(['b', 'c']);
+ const tagSets = (): TagSetResponse[] => [
+ {
+ scope: 'user',
+ definition: { id: 'tag-definition' },
+ options: ['a', 'b', 'c'].map((id, displayOrder) => ({
+ id,
+ propertyDefinitionId: 'tag-definition',
+ displayOrder,
+ value: { type: 'string', value: id },
+ })),
+ } as TagSetResponse,
+ ];
+ const properties = () => [
+ {
+ id: 'assignment',
+ definition: { id: 'tag-definition' },
+ value: { type: 'SelectOption', value: tagIds() },
+ } as SoupProperty,
+ ];
+ const view = render(() => (
+ <QueryClientProvider client={new QueryClient()}>
+ <TagSetsProvider tagSets={tagSets}>
+ <EntityRowTags
+ entityId="document-live-insert"
+ entityType={EntityType.DOCUMENT}
+ properties={properties()}
+ maxVisible={2}
+ collapse={collapse}
+ />
+ </TagSetsProvider>
+ </QueryClientProvider>
+ ));
+
+ const active = view.getByRole('button', { name: 'c' });
+ await fireEvent.click(active);
+ setTagIds(['a', 'b', 'c']);
+ expect(view.getByRole('button', { name: 'c' })).toBe(active);
+ expect(view.queryByRole('button', { name: 'b' })).toBeNull();
+ expect(view.getByRole('button', { name: '+1 tag' })).toBeTruthy();
+ expect(registrations.size).toBe(0);
+
+ await fireEvent.click(active);
+ expect(registrations.size).toBe(2);
+ expect(active.isConnected).toBe(false);
+ expect(view.getByRole('button', { name: 'b' })).toBeTruthy();
+ expect(view.queryByRole('button', { name: 'c' })).toBeNull();
+
+ const removed = view.getByRole('button', { name: 'b' });
+ await fireEvent.click(removed);
+ setTagIds(['a', 'c']);
+ expect(removed.isConnected).toBe(false);
+ expect(registrations.size).toBe(2);
+ });
+});
diff --git a/docs/agent-guide/tasks.md b/docs/agent-guide/tasks.md
index ddf3652634..dcfe011ce3 100644
--- a/docs/agent-guide/tasks.md
+++ b/docs/agent-guide/tasks.md
@@ -109,7 +109,11 @@ keeps that named chip, including on phones, rather than showing “1 tag”.
Open the overflow to edit all tags; hover it for hidden-tag names and filter/edit actions.
The overflow chip reads “N tags” when it represents all tags, or “+N tags” when
individual tag chips remain visible.
-An open picker or nested tag editor stays mounted while resizing. Add tags in a
+An open picker or nested tag editor stays mounted while resizing or when a
+sorted insertion moves its chip into overflow. Keep the active chip within the
+visible-chip cap until closing, then restore normal order. Live tag refreshes
+retain staged picker changes while accepting remote changes and deleted tags,
+including when a failed tag deletion restores its option. Add tags in a
constrained row and close the picker: excess tags must enter overflow without
resizing or reloading, restoring title space before truncating it. The share
indicator remains immediately beside the title whenever it is shown.