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
refactor(sidepanel): make md properties sidepanel generic (#3677)
Seamus5ab8dc7c33b3
diff --git a/js/app/packages/app/component/side-panel/properties/EntityPropertiesSection.tsx b/js/app/packages/app/component/side-panel/properties/EntityPropertiesSection.tsxnew file mode 100644index 0000000000..20e6288780--- /dev/null+++ b/js/app/packages/app/component/side-panel/properties/EntityPropertiesSection.tsx@@ -0,0 +1,618 @@+import Plus from '@phosphor/plus.svg';+import DeleteIcon from '@phosphor/x.svg';+import { Property as PropertyNS, useProperty } from '@property';+import { Modals } from '@property/component/modal';+import { PropertyValueIcon } from '@property/component/propertyValue/PropertyValueIcon';+import {+ PropertiesProvider,+ type PropertySaveHandler,+ usePropertiesContext,+} from '@property/context/PropertiesContext';+import { useEntityProperties, usePropertyEntityDisplay } from '@property/hooks';+import type { Property, PropertyApiValues } from '@property/types';+import { getEntityValues, hasValue } from '@property/utils';+import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity';+import type { EntityType } from '@service-properties/generated/schemas/entityType';+import { Button } from '@ui';+import { cn } from '@ui/utils/classname';+import {+ createEffect,+ createMemo,+ createSignal,+ For,+ Match,+ Show,+ Switch,+} from 'solid-js';+import { SidePanel } from '../SidePanel';++export interface EntityPropertiesSectionProps {+ entityId: string;+ entityType: EntityType;+ canEdit: boolean;+ documentName?: string;+ defaultPinnedPropertyIds?: () => readonly string[];+ pinnedPropertyIds?: () => string[];+ pinnedPropertyDefinitionOrder?: readonly string[];+ onPropertyPinned?: (propertyId: string) => void;+ onPropertyUnpinned?: (propertyId: string) => void;+}++export function EntityPropertiesSection(props: EntityPropertiesSectionProps) {+ const { properties, isLoading, error, refetch } = useEntityProperties(+ props.entityId,+ props.entityType,+ false+ );++ const filteredPinnedProperties = createMemo(() => {+ const defaultPinnedIds = props.defaultPinnedPropertyIds?.() ?? [];+ const pinnedIds = props.pinnedPropertyIds?.() ?? [];+ const pinned = properties().filter(+ (property) =>+ !property.isMetadata &&+ (defaultPinnedIds.includes(property.propertyDefinitionId) ||+ pinnedIds.includes(property.propertyId))+ );++ return sortPinnedProperties(pinned, props.pinnedPropertyDefinitionOrder);+ });++ const gridPinnedProperties = createMemo(() =>+ filteredPinnedProperties().filter(+ (property) => !isNonUserMultiEntityProperty(property)+ )+ );+ const collectionPinnedProperties = createMemo(() =>+ filteredPinnedProperties().filter(isNonUserMultiEntityProperty)+ );++ const [pendingPinDefIds, setPendingPinDefIds] = createSignal<Set<string>>(+ new Set()+ );++ const handlePropertyAdded = (addedDefinitionIds?: string[]) => {+ if (+ props.onPropertyPinned &&+ addedDefinitionIds &&+ addedDefinitionIds.length > 0+ ) {+ setPendingPinDefIds((prev) => {+ const next = new Set(prev);+ for (const id of addedDefinitionIds) next.add(id);+ return next;+ });+ }+ refetch();+ };++ createEffect(() => {+ const pending = pendingPinDefIds();+ if (pending.size === 0 || !props.onPropertyPinned) return;++ const remaining = new Set(pending);+ for (const defId of pending) {+ const instance = properties().find(+ (property) => property.propertyDefinitionId === defId+ );+ if (instance) {+ props.onPropertyPinned(instance.propertyId);+ remaining.delete(defId);+ }+ }++ if (remaining.size !== pending.size) {+ setPendingPinDefIds(remaining);+ }+ });++ const saveMutation = useBulkSaveEntityPropertiesMutation();+ const saveOne = (property: Property, apiValues: PropertyApiValues) =>+ saveMutation.mutateAsync({+ properties: [+ {+ entityId: props.entityId,+ entityType: props.entityType,+ property,+ apiValues,+ },+ ],+ });++ const saveHandler: PropertySaveHandler = {+ saveProperty: (property, value) => saveOne(property, value),+ saveDate: (property, date) =>+ saveOne(property, { valueType: 'DATE', value: date }),+ };++ return (+ <Show+ when={!error()}+ fallback={+ <div class="text-failure-ink text-center py-4 text-xs">{error()}</div>+ }+ >+ <div class="text-xs">+ <PropertiesProvider+ entityType={props.entityType}+ canEdit={props.canEdit}+ documentName={props.documentName}+ properties={filteredPinnedProperties}+ onRefresh={refetch}+ onPropertyAdded={handlePropertyAdded}+ onPropertyDeleted={refetch}+ onPropertyPinned={props.onPropertyPinned}+ onPropertyUnpinned={props.onPropertyUnpinned}+ pinnedPropertyIds={props.pinnedPropertyIds}+ saveHandler={saveHandler}+ >+ <Show when={isLoading()}>+ <SidePanel.Loading />+ </Show>++ <Show when={gridPinnedProperties().length > 0}>+ <SidePanel.Grid class="py-2">+ <For each={gridPinnedProperties()}>+ {(property) => (+ <SidePanelPropertyRow+ entityId={props.entityId}+ property={property}+ />+ )}+ </For>+ </SidePanel.Grid>+ </Show>++ <Show when={collectionPinnedProperties().length > 0}>+ <div class="flex flex-col gap-2 pb-2">+ <For each={collectionPinnedProperties()}>+ {(property) => (+ <EntityCollectionProperty+ entityId={props.entityId}+ property={property}+ />+ )}+ </For>+ </div>+ </Show>++ <Show when={props.canEdit}>+ <AddPinnedPropertyButton />+ </Show>+ <Modals />+ </PropertiesProvider>+ </div>+ </Show>+ );+}++function AddPinnedPropertyButton() {+ const { openPropertySelector } = usePropertiesContext();+ return (+ <button+ type="button"+ onClick={openPropertySelector}+ class={cn(+ 'inline-flex items-center gap-1.5 m-px ring ring-edge-muted bg-surface',+ 'px-2 py-1 leading-tight rounded-full text-ink-muted',+ 'hover:bg-hover hover:text-ink transition-colors'+ )}+ >+ <Plus class="size-3" />+ <span>Add property</span>+ </button>+ );+}++function sortPinnedProperties<T extends Property>(+ properties: T[],+ pinnedOrder: readonly string[] = []+): T[] {+ const rank = (id: string) => {+ const i = pinnedOrder.indexOf(id);+ return i === -1 ? pinnedOrder.length : i;+ };+ return [...properties].sort(+ (a, b) => rank(a.propertyDefinitionId) - rank(b.propertyDefinitionId)+ );+}++function isNonUserMultiEntityProperty(property: Property): boolean {+ return (+ property.valueType === 'ENTITY' &&+ property.isMultiSelect &&+ property.specificEntityType !== 'USER'+ );+}++function SidePanelPropertyRow(props: { entityId: string; property: Property }) {+ const ctx = usePropertiesContext();+ const t = () => props.property.valueType;+ const isMulti = () => !!props.property.isMultiSelect;++ const isMultiValueRow = () =>+ isMulti() &&+ (t() === 'SELECT_STRING' || t() === 'SELECT_NUMBER' || t() === 'ENTITY');+ const isInputType = () =>+ t() === 'STRING' || t() === 'NUMBER' || t() === 'LINK' || t() === 'BOOLEAN';++ return (+ <>+ <span+ class="text-ink-muted truncate self-center"+ title={props.property.displayName}+ >+ {props.property.displayName}+ </span>+ <div class="min-w-0 self-center">+ <PropertyNS.Root+ property={props.property}+ canEdit={ctx.canEdit}+ onSave={ctx.saveHandler.saveProperty}+ onRefresh={ctx.onRefresh}+ >+ <Switch fallback={<SinglePill property={props.property} />}>+ <Match when={isInputType()}>+ <InputValue />+ </Match>+ <Match when={isMultiValueRow()}>+ <MultiValue property={props.property} />+ </Match>+ </Switch>+ <PropertyNS.PopoverEditor+ entitySelfFilter={{+ entityType: ctx.entityType,+ blockId: props.entityId,+ }}+ />+ </PropertyNS.Root>+ </div>+ </>+ );+}++function SinglePill(props: { property: Property }) {+ const ctx = usePropertiesContext();+ const isReadOnly = () => !ctx.canEdit || props.property.isMetadata;+ const empty = () => !hasValue(props.property);+ const isNonUserEntity = () =>+ props.property.valueType === 'ENTITY' &&+ props.property.specificEntityType !== 'USER';++ const entity = () =>+ isNonUserEntity() ? getEntityValues(props.property)[0] : undefined;++ const entityDisplay = usePropertyEntityDisplay(+ () => entity()?.entity_id ?? '',+ () => entity()?.entity_type ?? 'DOCUMENT',+ {+ specificMessageId: () => entity()?.specific_message_id,+ }+ );++ return (+ <PropertyNS.Tooltip property={props.property}>+ <PropertyNS.EditTrigger+ class={cn(SidePanel.pillClass, 'w-fit', {+ 'hover:bg-hover': !isReadOnly(),+ })}+ >+ <Show when={!empty()} fallback={<SidePanel.EmptyPill />}>+ <Show+ when={isNonUserEntity() && entity()}+ fallback={+ <>+ <PropertyNS.Icon+ property={props.property}+ class="size-3 shrink-0"+ />+ <PropertyNS.Text property={props.property} />+ </>+ }+ >+ <span class="shrink-0 flex items-center">+ {entityDisplay.icon()}+ </span>+ <span class="truncate">{entityDisplay.name()}</span>+ </Show>+ </Show>+ <PropertyNS.Caret />+ </PropertyNS.EditTrigger>+ </PropertyNS.Tooltip>+ );+}++function UserStackPill(props: { property: Property }) {+ const ctx = usePropertiesContext();+ const isReadOnly = () => !ctx.canEdit || props.property.isMetadata;+ const empty = () => !hasValue(props.property);++ return (+ <PropertyNS.Tooltip property={props.property}>+ <PropertyNS.EditTrigger+ class={cn(SidePanel.pillClass, 'w-fit', {+ 'hover:bg-hover': !isReadOnly(),+ })}+ >+ <Show when={!empty()} fallback={<SidePanel.EmptyPill />}>+ <PropertyNS.UserStack property={props.property} maxUsers={3} />+ <PropertyNS.Text property={props.property} />+ </Show>+ <PropertyNS.Caret />+ </PropertyNS.EditTrigger>+ </PropertyNS.Tooltip>+ );+}++function MultiValue(props: { property: Property }) {+ const ctx = usePropertiesContext();+ const isReadOnly = () => !ctx.canEdit || props.property.isMetadata;+ const isEntity = () => props.property.valueType === 'ENTITY';+ const isUserEntity = () =>+ isEntity() && props.property.specificEntityType === 'USER';++ return (+ <Show+ when={!isUserEntity()}+ fallback={<UserStackPill property={props.property} />}+ >+ <PropertyNS.Tooltip property={props.property}>+ <Show+ when={!isEntity()}+ fallback={<NonUserEntityValue property={props.property} />}+ >+ <div class="flex flex-wrap items-center gap-1.5">+ <PropertyNS.Chips+ property={props.property}+ renderChip={(chip) => (+ <span+ class={cn(SidePanel.pillClass, 'text-xs max-w-35 bg-hover')}+ >+ <PropertyValueIcon+ optionId={chip.key}+ class="size-3 shrink-0"+ />+ <span class="truncate">{chip.label}</span>+ </span>+ )}+ />+ <Show when={!isReadOnly()}>+ <PropertyNS.EditTrigger+ class={cn(+ 'inline-flex items-center justify-center size-5 rounded-full',+ 'text-ink-muted hover:bg-hover hover:text-ink transition-colors'+ )}+ aria-label={`Add ${props.property.displayName}`}+ >+ <Plus class="size-3" />+ </PropertyNS.EditTrigger>+ </Show>+ </div>+ </Show>+ </PropertyNS.Tooltip>+ </Show>+ );+}++function NonUserEntityValue(props: { property: Property }) {+ const ctx = usePropertiesContext();+ const propertyCtx = useProperty();+ const entities = () => getEntityValues(props.property);+ const isReadOnly = () => !ctx.canEdit || props.property.isMetadata;++ const handleRemoveEntity = async (entityId: string) => {+ const remaining = entities().filter(+ (entity) => entity.entity_id !== entityId+ );+ await ctx.saveHandler.saveProperty(props.property, {+ valueType: 'ENTITY',+ refs: remaining.length > 0 ? remaining : null,+ });+ ctx.onRefresh();+ };++ return (+ <div class="flex flex-wrap gap-1 justify-start items-start w-full min-w-0">+ <For each={entities()}>+ {(entityRef) => (+ <NonUserEntityChip+ property={props.property}+ entityId={entityRef.entity_id}+ entityType={entityRef.entity_type}+ specificMessageId={entityRef.specific_message_id}+ canEdit={!isReadOnly()}+ onRemove={() => handleRemoveEntity(entityRef.entity_id)}+ onEdit={(anchor) => {+ if (isReadOnly()) return;+ propertyCtx.openEditor(anchor);+ }}+ />+ )}+ </For>+ <Show+ when={!isReadOnly()}+ fallback={+ <Show when={entities().length === 0}>+ <SidePanel.EmptyPill />+ </Show>+ }+ >+ <Show when={entities().length === 0 || props.property.isMultiSelect}>+ <Button+ type="button"+ variant="ghost"+ depth={0}+ size="icon-sm"+ class="size-5 rounded-full bg-surface"+ aria-label={`Add ${props.property.displayName}`}+ onClick={(event) => {+ event.stopPropagation();+ propertyCtx.openEditor(event.currentTarget);+ }}+ >+ <Plus class="size-3" />+ </Button>+ </Show>+ </Show>+ </div>+ );+}++function EntityCollectionProperty(props: {+ entityId: string;+ property: Property;+}) {+ const ctx = usePropertiesContext();++ return (+ <PropertyNS.Root+ property={props.property}+ canEdit={ctx.canEdit}+ onSave={ctx.saveHandler.saveProperty}+ onRefresh={ctx.onRefresh}+ >+ <EntityCollectionPropertyBody property={props.property} />+ <PropertyNS.PopoverEditor+ entitySelfFilter={{+ entityType: ctx.entityType,+ blockId: props.entityId,+ }}+ />+ </PropertyNS.Root>+ );+}++function EntityCollectionPropertyBody(props: { property: Property }) {+ const ctx = usePropertiesContext();+ const propertyCtx = useProperty();+ const entities = () => getEntityValues(props.property);+ const isReadOnly = () => !ctx.canEdit || props.property.isMetadata;++ const handleRemoveEntity = async (entityId: string) => {+ const remaining = entities().filter(+ (entity) => entity.entity_id !== entityId+ );+ await ctx.saveHandler.saveProperty(props.property, {+ valueType: 'ENTITY',+ refs: remaining.length > 0 ? remaining : null,+ });+ ctx.onRefresh();+ };++ return (+ <SidePanel.Card>+ <div class="p-2">+ <div class="flex items-center justify-between gap-2">+ <span+ class="min-w-0 truncate text-ink-muted"+ title={props.property.displayName}+ >+ {props.property.displayName}+ </span>+ <Show when={!isReadOnly()}>+ <Button+ type="button"+ variant="ghost"+ depth={0}+ size="icon-sm"+ class="size-5 rounded-full"+ aria-label={`Add ${props.property.displayName}`}+ onClick={(event) => {+ event.stopPropagation();+ propertyCtx.openEditor(event.currentTarget);+ }}+ >+ <Plus class="size-3" />+ </Button>+ </Show>+ </div>+ <div class="mt-2 flex flex-wrap gap-1.5">+ <For+ each={entities()}+ fallback={<span class="text-ink-extra-muted">Empty</span>}+ >+ {(entityRef) => (+ <NonUserEntityChip+ property={props.property}+ entityId={entityRef.entity_id}+ entityType={entityRef.entity_type}+ specificMessageId={entityRef.specific_message_id}+ canEdit={!isReadOnly()}+ onRemove={() => handleRemoveEntity(entityRef.entity_id)}+ onEdit={(anchor) => {+ if (isReadOnly()) return;+ propertyCtx.openEditor(anchor);+ }}+ />+ )}+ </For>+ </div>+ </div>+ </SidePanel.Card>+ );+}++function NonUserEntityChip(props: {+ property: Property;+ entityId: string;+ entityType: EntityType;+ specificMessageId?: string | null;+ canEdit?: boolean;+ onRemove?: () => void;+ onEdit?: (anchor?: HTMLElement) => void;+}) {+ let containerRef: HTMLDivElement | undefined;+ const { name, icon } = usePropertyEntityDisplay(+ () => props.entityId,+ () => props.entityType,+ {+ specificMessageId: () => props.specificMessageId,+ }+ );++ const openEditor = (event: MouseEvent) => {+ if (!props.canEdit || !props.onEdit) return;+ event.stopPropagation();+ props.onEdit(containerRef);+ };++ return (+ <div+ ref={containerRef}+ class="inline-flex shrink-0 border h-7 items-stretch border-edge-muted rounded-md text-ink overflow-clip"+ >+ <button+ type="button"+ class="flex min-w-0 max-w-[20ch] items-center gap-1.5 px-2 text-left"+ onClick={openEditor}+ disabled={!props.canEdit}+ >+ <span class="shrink-0 flex items-center">{icon()}</span>+ <span class="min-w-0 truncate">{name()}</span>+ </button>+ <Show when={props.canEdit && props.onRemove}>+ <div class="border-l border-edge-muted" />+ <Button+ type="button"+ size="icon-sm"+ class="flex w-6 p-1 h-full shrink-0 rounded-none text-ink-muted not-disabled:hover:text-failure-ink"+ onClick={(event) => {+ event.stopPropagation();+ props.onRemove?.();+ }}+ aria-label={`Remove ${name()}`}+ >+ <DeleteIcon />+ </Button>+ </Show>+ </div>+ );+}++function InputValue() {+ return (+ <div class="min-w-0 w-full">+ <PropertyNS.Display />+ </div>+ );+}diff --git a/js/app/packages/app/component/side-panel/properties/index.ts b/js/app/packages/app/component/side-panel/properties/index.tsnew file mode 100644index 0000000000..ea7ee445e7--- /dev/null+++ b/js/app/packages/app/component/side-panel/properties/index.ts@@ -0,0 +1,2 @@+export type { EntityPropertiesSectionProps } from './EntityPropertiesSection';+export { EntityPropertiesSection } from './EntityPropertiesSection';diff --git a/js/app/packages/block-md/component/TaskDuplicateMatches.tsx b/js/app/packages/block-md/component/TaskDuplicateMatches.tsxindex 03e1c6f520..d5cb11d3fc 100644--- a/js/app/packages/block-md/component/TaskDuplicateMatches.tsx+++ b/js/app/packages/block-md/component/TaskDuplicateMatches.tsx@@ -51,9 +51,9 @@ export function TaskDuplicateMatchesSidePanelSection() {<Show when={matches.count() > 0}><SidePanel.Sectionid="duplicates"- title="Matches"+ title="Duplicate Tasks"defaultOpen- order={30}+ order={60}><TaskDuplicateMatchesSidePanel matches={matches} /></SidePanel.Section>@@ -128,7 +128,7 @@ function TaskDuplicateMatchesSidePanel(props: {matches: TaskDuplicateMatchesState;}) {return (- <div class="flex flex-col gap-1 py-2">+ <div class="flex flex-col gap-1"><For each={props.matches.matches()}>{(match) => (<TaskDuplicateRowdiff --git a/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx b/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsxindex bfe3147329..f7badbcbc4 100644--- a/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx+++ b/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx@@ -1,5 +1,6 @@import { useGlobalNotificationSource } from '@app/component/GlobalAppState';import { SidePanel } from '@app/component/side-panel';+import { EntityPropertiesSection } from '@app/component/side-panel/properties';import { useBlockAliasedName, useBlockId, useBlockName } from '@core/block';import { EntityIcon } from '@core/component/EntityIcon';import { openDocument } from '@core/component/LexicalMarkdown/component/core/BlockLink';@@ -19,43 +20,27 @@ import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler'import GithubIcon from '@icon/mcp-github.svg';import { useNotificationsForEntity } from '@notifications';import ClockIcon from '@phosphor/clock.svg';-import Plus from '@phosphor/plus.svg';-import DeleteIcon from '@phosphor/x.svg';-import { Property as PropertyNS, useProperty } from '@property';-import { Modals } from '@property/component/modal';-import { PropertyValueIcon } from '@property/component/propertyValue/PropertyValueIcon';import {getDefaultPinnedProperties,SYSTEM_PROPERTY_IDS,} from '@property/constants';-import {- PropertiesProvider,- type PropertySaveHandler,- usePropertiesContext,-} from '@property/context/PropertiesContext';-import { useEntityProperties, usePropertyEntityDisplay } from '@property/hooks';-import type { Property, PropertyApiValues } from '@property/types';-import { getEntityValues, hasValue } from '@property/utils';-import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity';-import { useAttachmentReferencesQuery } from '@queries/storage/attachment-references';import { useDocumentMetadataQuery } from '@queries/storage/document-metadata';import { useDocumentGithubPullRequestsQuery } from '@queries/storage/github-pull-requests';import type { EntityType as PropertiesEntityType } from '@service-properties/generated/schemas/entityType';-import { blockNameToItemType } from '@service-storage/client';+import {+ blockNameToItemType,+ storageServiceClient,+} from '@service-storage/client';import type { GithubPullRequest } from '@service-storage/generated/schemas';import { createCallback } from '@solid-primitives/rootless';-import { Button } from '@ui';-import { cn } from '@ui/utils/classname';import {createEffect,createMemo,+ createResource,createSignal,For,- Match,onCleanup,Show,- Suspense,- Switch,} from 'solid-js';import { mdStore } from '../../signal/markdownBlockData';import { TaskDuplicateMatchesSidePanelSection } from '../TaskDuplicateMatches';@@ -103,12 +88,12 @@ export function MarkdownSidePanelSections(<StatsSectionContent /></SidePanel.Section></Show>+ <GithubSectionConditional documentId={blockId} isTask={isTask()} />+ <NotificationsSectionConditional entity={entity()} />+ <ReferencesSectionConditional documentId={blockId} /><Show when={isTask()}><TaskDuplicateMatchesSidePanelSection /></Show>- <GithubSectionConditional documentId={blockId} isTask={isTask} />- <NotificationsSectionConditional entity={entity()} />- <ReferencesSectionConditional documentId={blockId} /></>);}@@ -232,12 +217,6 @@ function PropertiesSectionContent(props: {const entityType: PropertiesEntityType =blockName === 'task' ? 'TASK' : 'DOCUMENT';- const { properties, isLoading, error, refetch } = useEntityProperties(- blockId,- entityType,- false- );-const [pinnedPropertyIds, setPinnedPropertyIds] = createSignal<string[]>([]);createEffect(() => {@@ -259,48 +238,6 @@ function PropertiesSectionContent(props: {onCleanup(unregister);});- const filteredPinnedProperties = createMemo(() => {- const allProps = properties();- const pinnedIds = pinnedPropertyIds();- const defaultPinnedIds = getDefaultPinnedProperties(blockName);-- const pinned = allProps.filter(- (prop) =>- !prop.isMetadata &&- (defaultPinnedIds.includes(prop.propertyDefinitionId) ||- pinnedIds.includes(prop.propertyId))- );-- return sortPinnedProperties(pinned);- });- const gridPinnedProperties = createMemo(() =>- filteredPinnedProperties().filter(- (property) => !isNonUserMultiEntityProperty(property)- )- );- const collectionPinnedProperties = createMemo(() =>- filteredPinnedProperties().filter(isNonUserMultiEntityProperty)- );-- const [pendingPinDefIds, setPendingPinDefIds] = createSignal<Set<string>>(- new Set()- );-- const handlePropertyAdded = async (addedDefinitionIds?: string[]) => {- if (addedDefinitionIds && addedDefinitionIds.length > 0) {- setPendingPinDefIds((prev) => {- const next = new Set(prev);- for (const id of addedDefinitionIds) next.add(id);- return next;- });- }- refetch();- };-- const handlePropertyDeleted = async () => {- refetch();- };-const handlePropertyPinned = (propertyId: string) => {const editor = mdData.editor;if (editor) {@@ -315,103 +252,18 @@ function PropertiesSectionContent(props: {}};- createEffect(() => {- const pending = pendingPinDefIds();- if (pending.size === 0) return;- const current = properties();- const remaining = new Set(pending);- for (const defId of pending) {- const instance = current.find((p) => p.propertyDefinitionId === defId);- if (instance) {- handlePropertyPinned(instance.propertyId);- remaining.delete(defId);- }- }- if (remaining.size !== pending.size) {- setPendingPinDefIds(remaining);- }- });-- const saveMutation = useBulkSaveEntityPropertiesMutation();-- const saveOne = (property: Property, apiValues: PropertyApiValues) =>- saveMutation.mutateAsync({- properties: [- { entityId: blockId, entityType: entityType, property, apiValues },- ],- });-- const saveHandler: PropertySaveHandler = {- saveProperty: (property, value) => saveOne(property, value),- saveDate: (property, date) =>- saveOne(property, { valueType: 'DATE', value: date }),- };-return (- <Show- when={!error()}- fallback={- <div class="text-failure-ink text-center py-4 text-xs">{error()}</div>- }- >- <div class="text-xs">- <PropertiesProvider- entityType={entityType}- canEdit={props.canEdit}- documentName={props.documentName}- properties={filteredPinnedProperties}- onRefresh={refetch}- onPropertyAdded={handlePropertyAdded}- onPropertyDeleted={handlePropertyDeleted}- onPropertyPinned={handlePropertyPinned}- onPropertyUnpinned={handlePropertyUnpinned}- pinnedPropertyIds={pinnedPropertyIds}- saveHandler={saveHandler}- >- <Show when={isLoading()}>- <SidePanel.Loading />- </Show>-- <Show when={gridPinnedProperties().length > 0}>- <SidePanel.Grid class="py-2">- <For each={gridPinnedProperties()}>- {(property) => <SidePanelPropertyRow property={property} />}- </For>- </SidePanel.Grid>- </Show>-- <Show when={collectionPinnedProperties().length > 0}>- <div class="flex flex-col gap-2 pb-2">- <For each={collectionPinnedProperties()}>- {(property) => <EntityCollectionProperty property={property} />}- </For>- </div>- </Show>-- <Show when={props.canEdit}>- <AddPinnedPropertyButton />- </Show>- <Modals />- </PropertiesProvider>- </div>- </Show>- );-}--function AddPinnedPropertyButton() {- const { openPropertySelector } = usePropertiesContext();- return (- <button- onClick={openPropertySelector}- class={cn(- 'inline-flex items-center gap-1.5 m-px ring ring-edge-muted bg-surface',- 'px-2 py-1 leading-tight rounded-full text-ink-muted',- 'hover:bg-hover hover:text-ink transition-colors'- )}- >- <Plus class="size-3" />- <span>Add property</span>- </button>+ <EntityPropertiesSection+ entityId={blockId}+ entityType={entityType}+ canEdit={props.canEdit}+ documentName={props.documentName}+ defaultPinnedPropertyIds={() => getDefaultPinnedProperties(blockName)}+ pinnedPropertyIds={pinnedPropertyIds}+ pinnedPropertyDefinitionOrder={PINNED_ORDER}+ onPropertyPinned={handlePropertyPinned}+ onPropertyUnpinned={handlePropertyUnpinned}+ />);}@@ -424,411 +276,6 @@ const PINNED_ORDER: readonly string[] = [SYSTEM_PROPERTY_IDS.ASSIGNEES,];-function sortPinnedProperties<T extends Property>(properties: T[]): T[] {- const rank = (id: string) => {- const i = PINNED_ORDER.indexOf(id);- return i === -1 ? PINNED_ORDER.length : i;- };- return [...properties].sort(- (a, b) => rank(a.propertyDefinitionId) - rank(b.propertyDefinitionId)- );-}--function isNonUserMultiEntityProperty(property: Property): boolean {- return (- property.valueType === 'ENTITY' &&- property.isMultiSelect &&- property.specificEntityType !== 'USER'- );-}--// ─────────────────────────────────────────────────────────────────────────────-// Pinned property rows — sidepanel-specific. Rendered into a two-column grid:-// the displayName label sits in the left column, the value pill in the right.-// Pills have no ring in this layout (the grid handles spacing/alignment).-// ─────────────────────────────────────────────────────────────────────────────--function SidePanelPropertyRow(props: { property: Property }) {- const ctx = usePropertiesContext();- const blockId = useBlockId();- const t = () => props.property.valueType;- const isMulti = () => !!props.property.isMultiSelect;-- const isMultiValueRow = () =>- isMulti() &&- (t() === 'SELECT_STRING' || t() === 'SELECT_NUMBER' || t() === 'ENTITY');- const isInputType = () =>- t() === 'STRING' || t() === 'NUMBER' || t() === 'LINK' || t() === 'BOOLEAN';-- return (- <>- <span- class="text-ink-muted truncate self-center"- title={props.property.displayName}- >- {props.property.displayName}- </span>- <div class="min-w-0 self-center">- <PropertyNS.Root- property={props.property}- canEdit={ctx.canEdit}- onSave={ctx.saveHandler.saveProperty}- onRefresh={ctx.onRefresh}- >- <Switch fallback={<SinglePill property={props.property} />}>- <Match when={isInputType()}>- <InputValue />- </Match>- <Match when={isMultiValueRow()}>- <MultiValue property={props.property} />- </Match>- </Switch>- <PropertyNS.PopoverEditor- entitySelfFilter={{ entityType: ctx.entityType, blockId }}- />- </PropertyNS.Root>- </div>- </>- );-}--function SinglePill(props: { property: Property }) {- const ctx = usePropertiesContext();- const isReadOnly = () => !ctx.canEdit || props.property.isMetadata;- const empty = () => !hasValue(props.property);- const isNonUserEntity = () =>- props.property.valueType === 'ENTITY' &&- props.property.specificEntityType !== 'USER';-- const entity = () =>- isNonUserEntity() ? getEntityValues(props.property)[0] : undefined;-- const entityDisplay = usePropertyEntityDisplay(- () => entity()?.entity_id ?? '',- () => entity()?.entity_type ?? 'DOCUMENT',- {- specificMessageId: () => entity()?.specific_message_id,- }- );-- return (- <PropertyNS.Tooltip property={props.property}>- <PropertyNS.EditTrigger- class={cn(SidePanel.pillClass, 'w-fit', {- 'hover:bg-hover': !isReadOnly(),- })}- >- <Show when={!empty()} fallback={<SidePanel.EmptyPill />}>- <Show- when={isNonUserEntity() && entity()}- fallback={- <>- <PropertyNS.Icon- property={props.property}- class="size-3 shrink-0"- />- <PropertyNS.Text property={props.property} />- </>- }- >- <span class="shrink-0 flex items-center">- {entityDisplay.icon()}- </span>- <span class="truncate">{entityDisplay.name()}</span>- </Show>- </Show>- <PropertyNS.Caret />- </PropertyNS.EditTrigger>- </PropertyNS.Tooltip>- );-}--function UserStackPill(props: { property: Property }) {- const ctx = usePropertiesContext();- const isReadOnly = () => !ctx.canEdit || props.property.isMetadata;- const empty = () => !hasValue(props.property);-- return (- <PropertyNS.Tooltip property={props.property}>- <PropertyNS.EditTrigger- class={cn(SidePanel.pillClass, 'w-fit', {- 'hover:bg-hover': !isReadOnly(),- })}- >- <Show when={!empty()} fallback={<SidePanel.EmptyPill />}>- <PropertyNS.UserStack property={props.property} maxUsers={3} />- <PropertyNS.Text property={props.property} />- </Show>- <PropertyNS.Caret />- </PropertyNS.EditTrigger>- </PropertyNS.Tooltip>- );-}--function MultiValue(props: { property: Property }) {- const ctx = usePropertiesContext();- const isReadOnly = () => !ctx.canEdit || props.property.isMetadata;- const isEntity = () => props.property.valueType === 'ENTITY';- const isUserEntity = () =>- isEntity() && props.property.specificEntityType === 'USER';-- return (- <Show- when={!isUserEntity()}- fallback={<UserStackPill property={props.property} />}- >- <PropertyNS.Tooltip property={props.property}>- <Show- when={!isEntity()}- fallback={<NonUserEntityValue property={props.property} />}- >- <div class="flex flex-wrap items-center gap-1.5">- <PropertyNS.Chips- property={props.property}- renderChip={(chip) => (- <span- class={cn(SidePanel.pillClass, 'text-xs max-w-35 bg-hover')}- >- <PropertyValueIcon- optionId={chip.key}- class="size-3 shrink-0"- />- <span class="truncate">{chip.label}</span>- </span>- )}- />- <Show when={!isReadOnly()}>- <PropertyNS.EditTrigger- class={cn(- 'inline-flex items-center justify-center size-5 rounded-full',- 'text-ink-muted hover:bg-hover hover:text-ink transition-colors'- )}- aria-label={`Add ${props.property.displayName}`}- >- <Plus class="size-3" />- </PropertyNS.EditTrigger>- </Show>- </div>- </Show>- </PropertyNS.Tooltip>- </Show>- );-}--function NonUserEntityValue(props: { property: Property }) {- const ctx = usePropertiesContext();- const propertyCtx = useProperty();- const entities = () => getEntityValues(props.property);- const isReadOnly = () => !ctx.canEdit || props.property.isMetadata;-- const handleRemoveEntity = async (entityId: string) => {- const remaining = entities().filter((e) => e.entity_id !== entityId);- await ctx.saveHandler.saveProperty(props.property, {- valueType: 'ENTITY',- refs: remaining.length > 0 ? remaining : null,- });- ctx.onRefresh();- };-- return (- <div class="flex flex-wrap gap-1 justify-start items-start w-full min-w-0">- <For each={entities()}>- {(entityRef) => (- <NonUserEntityChip- property={props.property}- entityId={entityRef.entity_id}- entityType={entityRef.entity_type}- specificMessageId={entityRef.specific_message_id}- canEdit={!isReadOnly()}- onRemove={() => handleRemoveEntity(entityRef.entity_id)}- onEdit={(anchor) => {- if (isReadOnly()) return;- propertyCtx.openEditor(anchor);- }}- />- )}- </For>- <Show- when={!isReadOnly()}- fallback={- <Show when={entities().length === 0}>- <SidePanel.EmptyPill />- </Show>- }- >- <Show when={entities().length === 0 || props.property.isMultiSelect}>- <Button- type="button"- variant="ghost"- depth={0}- size="icon-sm"- class="size-5 rounded-full bg-surface"- aria-label={`Add ${props.property.displayName}`}- onClick={(e) => {- e.stopPropagation();- propertyCtx.openEditor(e.currentTarget);- }}- >- <Plus class="size-3" />- </Button>- </Show>- </Show>- </div>- );-}--function EntityCollectionProperty(props: { property: Property }) {- const ctx = usePropertiesContext();- const blockId = useBlockId();-- return (- <PropertyNS.Root- property={props.property}- canEdit={ctx.canEdit}- onSave={ctx.saveHandler.saveProperty}- onRefresh={ctx.onRefresh}- >- <EntityCollectionPropertyBody property={props.property} />- <PropertyNS.PopoverEditor- entitySelfFilter={{ entityType: ctx.entityType, blockId }}- />- </PropertyNS.Root>- );-}--function EntityCollectionPropertyBody(props: { property: Property }) {- const ctx = usePropertiesContext();- const propertyCtx = useProperty();- const entities = () => getEntityValues(props.property);- const isReadOnly = () => !ctx.canEdit || props.property.isMetadata;-- const handleRemoveEntity = async (entityId: string) => {- const remaining = entities().filter((e) => e.entity_id !== entityId);- await ctx.saveHandler.saveProperty(props.property, {- valueType: 'ENTITY',- refs: remaining.length > 0 ? remaining : null,- });- ctx.onRefresh();- };-- return (- <SidePanel.Card>- <div class="p-2">- <div class="flex items-center justify-between gap-2">- <span- class="min-w-0 truncate text-ink-muted"- title={props.property.displayName}- >- {props.property.displayName}- </span>- <Show when={!isReadOnly()}>- <Button- type="button"- variant="ghost"- depth={0}- size="icon-sm"- class="size-5 rounded-full"- aria-label={`Add ${props.property.displayName}`}- onClick={(e) => {- e.stopPropagation();- propertyCtx.openEditor(e.currentTarget);- }}- >- <Plus class="size-3" />- </Button>- </Show>- </div>- <div class="mt-2 flex flex-wrap gap-1.5">- <For- each={entities()}- fallback={<span class="text-ink-extra-muted">Empty</span>}- >- {(entityRef) => (- <NonUserEntityChip- property={props.property}- entityId={entityRef.entity_id}- entityType={entityRef.entity_type}- specificMessageId={entityRef.specific_message_id}- canEdit={!isReadOnly()}- onRemove={() => handleRemoveEntity(entityRef.entity_id)}- onEdit={(anchor) => {- if (isReadOnly()) return;- propertyCtx.openEditor(anchor);- }}- />- )}- </For>- </div>- </div>- </SidePanel.Card>- );-}--function NonUserEntityChip(props: {- property: Property;- entityId: string;- entityType: PropertiesEntityType;- specificMessageId?: string | null;- canEdit?: boolean;- onRemove?: () => void;- onEdit?: (anchor?: HTMLElement) => void;-}) {- let containerRef: HTMLDivElement | undefined;- const { name, icon } = usePropertyEntityDisplay(- () => props.entityId,- () => props.entityType,- {- specificMessageId: () => props.specificMessageId,- }- );-- const openEditor = (e: MouseEvent) => {- if (!props.canEdit || !props.onEdit) return;- e.stopPropagation();- props.onEdit(containerRef);- };-- return (- <div- ref={containerRef}- class="inline-flex shrink-0 border h-7 items-stretch border-edge-muted rounded-md text-ink overflow-clip"- >- <button- type="button"- class="flex min-w-0 max-w-[20ch] items-center gap-1.5 px-2 text-left"- onClick={openEditor}- disabled={!props.canEdit}- >- <span class="shrink-0 flex items-center">{icon()}</span>- <span class="min-w-0 truncate">{name()}</span>- </button>- <Show when={props.canEdit && props.onRemove}>- <div class="border-l border-edge-muted" />- <Button- type="button"- size="icon-sm"- class="flex w-6 p-1 h-full shrink-0 rounded-none text-ink-muted not-disabled:hover:text-failure-ink"- onClick={(e) => {- e.stopPropagation();- props.onRemove?.();- }}- aria-label={`Remove ${name()}`}- >- <DeleteIcon />- </Button>- </Show>- </div>- );-}--function InputValue() {- return (- <div class="min-w-0 w-full">- <PropertyNS.Display />- </div>- );-}-// ─────────────────────────────────────────────────────────────────────────────// Stats Section// ─────────────────────────────────────────────────────────────────────────────@@ -845,17 +292,14 @@ function StatsSectionContent() {>{(stats) => (<Wordcount.Root stats={stats()}>- <div class="grid grid-cols-[auto_1fr] gap-x-4 gap-y-3 items-center text-xs">- <span class="text-xs text-ink-muted">Words</span>- <div class="flex items-center gap-2 min-w-0">+ <SidePanel.Grid>+ <SidePanel.Row label="Words"><Wordcount.Words />- </div>-- <span class="text-xs text-ink-muted">Characters</span>- <div class="flex items-center gap-2 min-w-0">+ </SidePanel.Row>+ <SidePanel.Row label="Characters"><Wordcount.Characters />- </div>- </div>+ </SidePanel.Row>+ </SidePanel.Grid></Wordcount.Root>)}</Show>@@ -902,12 +346,24 @@ function NotificationsSectionConditional(props: { entity: Entity }) {// ─────────────────────────────────────────────────────────────────────────────function ReferencesSectionConditional(props: { documentId: string }) {- const references = useAttachmentReferencesQuery(+ const [references] = createResource(() => props.documentId,- () => 'document'+ async (id) => {+ const response = await storageServiceClient.attachmentReferences({+ entity_type: 'document',+ entity_id: id,+ });++ if (response.isErr()) {+ console.error(response);+ return [];+ }++ return response.value.references;+ });- const count = createMemo(() => references.data?.length ?? 0);+ const count = createMemo(() => references()?.length ?? 0);return (<Show when={count() > 0}>@@ -916,11 +372,9 @@ function ReferencesSectionConditional(props: { documentId: string }) {title={<SidePanel.CountTitle label="References" count={count()} />}order={50}>- <Suspense fallback={<SidePanel.Loading />}>- <div class="text-xs">- <References documentId={props.documentId} />- </div>- </Suspense>+ <div class="text-xs">+ <References documentId={props.documentId} />+ </div></SidePanel.Section></Show>);@@ -932,7 +386,7 @@ function ReferencesSectionConditional(props: { documentId: string }) {function GithubSectionConditional(props: {documentId: string;- isTask: () => boolean;+ isTask: boolean;}) {const query = useDocumentGithubPullRequestsQuery(props.documentId,@@ -940,7 +394,7 @@ function GithubSectionConditional(props: {);const pullRequests = createMemo((): GithubPullRequest[] => {- if (!props.isTask() || query.isLoading || query.isError) return [];+ if (!props.isTask || query.isLoading || query.isError) return [];return query.data?.pullRequests ?? [];});const count = createMemo(() => pullRequests().length);