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.

improve [properties-fe] - entity options delete (#110)

Daniel Kweon544c809b93e9
diff --git a/js/app/packages/core/component/Properties/EntityValueDisplay.tsx b/js/app/packages/core/component/Properties/EntityValueDisplay.tsx
index 0deeccaee8..5147ec6944 100644
--- a/js/app/packages/core/component/Properties/EntityValueDisplay.tsx
+++ b/js/app/packages/core/component/Properties/EntityValueDisplay.tsx
@@ -1,24 +1,34 @@
import { useChannelName } from '@core/component/ChannelsProvider';
import { EntityIcon } from '@core/component/EntityIcon';
+import { IconButton } from '@core/component/IconButton';
import { BlockLink } from '@core/component/LexicalMarkdown/component/core/BlockLink';
import { UserIcon } from '@core/component/UserIcon';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { isAccessiblePreviewItem, useItemPreview } from '@core/signal/preview';
import { idToDisplayName } from '@core/user';
+import DeleteIcon from '@icon/bold/x-bold.svg';
import ChannelBuildingIcon from '@icon/duotone/building-office-duotone.svg';
import GlobeIcon from '@icon/duotone/globe-duotone.svg';
import ChannelIcon from '@icon/duotone/hash-duotone.svg';
import User from '@icon/duotone/user-duotone.svg';
import ThreeUsersIcon from '@icon/duotone/users-three-duotone.svg';
import type { EntityType } from '@service-properties/generated/schemas/entityType';
-import { type Component, createMemo, type ParentProps, Show } from 'solid-js';
+import {
+ type Component,
+ createMemo,
+ createSignal,
+ type ParentProps,
+ Show,
+} from 'solid-js';
import type { Property } from './types';
type EntityValueDisplayProps = ParentProps<{
property: Property;
entityId: string;
entityType: EntityType;
- enableLink?: boolean;
+ canEdit?: boolean;
+ onRemove?: () => void;
+ isSaving?: boolean;
}>;
const ICON_CLASSES = 'size-4 text-ink-muted';
@@ -26,6 +36,8 @@ const ICON_CLASSES = 'size-4 text-ink-muted';
export const EntityValueDisplay: Component<EntityValueDisplayProps> = (
props
) => {
+ const [isHovered, setIsHovered] = createSignal(false);
+
// Get preview for items that need it (document, project, chat, channel for icon)
const previewTypes: EntityType[] = ['DOCUMENT', 'PROJECT', 'CHAT', 'CHANNEL'];
const needsPreview = previewTypes.includes(props.entityType);
@@ -130,8 +142,6 @@ export const EntityValueDisplay: Component<EntityValueDisplayProps> = (
});
const blockOrFileType = createMemo(() => {
- if (!props.enableLink) return null;
-
// For channels and chats, use the entity type directly (lowercase for BlockLink)
const linkableTypes: EntityType[] = ['CHANNEL', 'CHAT', 'PROJECT'];
if (linkableTypes.includes(props.entityType)) {
@@ -161,7 +171,7 @@ export const EntityValueDisplay: Component<EntityValueDisplayProps> = (
</div>
);
- return (
+ const innerContent = (
<Show when={blockOrFileType()} fallback={props.children ?? content}>
{(linkType) => (
<BlockLink blockOrFileName={linkType()} id={props.entityId}>
@@ -170,4 +180,33 @@ export const EntityValueDisplay: Component<EntityValueDisplayProps> = (
)}
</Show>
);
+
+ return (
+ <div
+ class="relative inline-flex max-w-[150px] shrink-0"
+ onMouseEnter={() => setIsHovered(true)}
+ onMouseLeave={() => setIsHovered(false)}
+ >
+ <div
+ class={`text-xs px-2 py-1 border border-edge hover:bg-hover cursor-pointer bg-transparent text-ink inline-flex items-center w-full min-h-[24px]`}
+ >
+ <span class="truncate flex-1">{innerContent}</span>
+ <Show
+ when={
+ props.canEdit && isHovered() && !props.isSaving && props.onRemove
+ }
+ >
+ <div class="absolute right-1 inset-y-0 flex items-center">
+ <IconButton
+ icon={DeleteIcon}
+ theme="clear"
+ size="xs"
+ class="!text-failure !bg-[#2a2a2a] hover:!bg-[#444444] !cursor-pointer !w-4 !h-4 !min-w-4 !min-h-4"
+ onClick={props.onRemove}
+ />
+ </div>
+ </Show>
+ </div>
+ </div>
+ );
};
diff --git a/js/app/packages/core/component/Properties/components/property-display/EntityValue.tsx b/js/app/packages/core/component/Properties/components/property-display/EntityValue.tsx
index f779bb6bcf..f5f17589a7 100644
--- a/js/app/packages/core/component/Properties/components/property-display/EntityValue.tsx
+++ b/js/app/packages/core/component/Properties/components/property-display/EntityValue.tsx
@@ -1,7 +1,9 @@
+import { useBlockId } from '@core/block';
import type { EntityReference } from '@service-properties/generated/schemas/entityReference';
import type { EntityType } from '@service-properties/generated/schemas/entityType';
import type { Component } from 'solid-js';
-import { For, Show } from 'solid-js';
+import { createSignal, For, Show } from 'solid-js';
+import { savePropertyValue } from '../../api/propertyValues';
import { EntityValueDisplay } from '../../EntityValueDisplay';
import type { Property } from '../../types';
@@ -10,6 +12,7 @@ type EntityValueProps = {
canEdit: boolean;
entityType: EntityType;
onEdit?: (property: Property, anchor?: HTMLElement) => void;
+ onRefresh?: () => void;
};
/**
@@ -17,40 +20,61 @@ type EntityValueProps = {
* Shows entity badges and opens modal on click
*/
export const EntityValue: Component<EntityValueProps> = (props) => {
+ const blockId = useBlockId();
+ const [isSaving, setIsSaving] = createSignal(false);
+
const handleEditClick = (e: MouseEvent) => {
if (props.canEdit && !props.property.isMetadata) {
props.onEdit?.(props.property, e.currentTarget as HTMLElement);
}
};
+ const handleRemoveEntity = async (entityToRemove: EntityReference) => {
+ if (isReadOnly() || isSaving()) return;
+
+ setIsSaving(true);
+
+ try {
+ const entities = (props.property.value as EntityReference[]) ?? [];
+ const newValues = entities.filter(
+ (entity) =>
+ entity.entity_id !== entityToRemove.entity_id ||
+ entity.entity_type !== entityToRemove.entity_type
+ );
+
+ const result = await savePropertyValue(
+ blockId,
+ props.entityType,
+ props.property,
+ {
+ valueType: 'ENTITY',
+ refs: newValues.length > 0 ? newValues : null,
+ }
+ );
+
+ if (result.ok) {
+ props.onRefresh?.();
+ }
+ } finally {
+ setIsSaving(false);
+ }
+ };
+
const isReadOnly = () => props.property.isMetadata || !props.canEdit;
const entities = (props.property.value as EntityReference[]) ?? [];
return (
<div class="flex flex-wrap gap-1 justify-start items-start w-full min-w-0">
<For each={entities}>
- {(entityRef) => {
- const linkableEntityTypes: EntityType[] = [
- 'CHANNEL',
- 'CHAT',
- 'DOCUMENT',
- 'PROJECT',
- ]; // thread, user
- const isLinkEnabled = linkableEntityTypes.includes(
- entityRef.entity_type
- );
- return (
- <div
- class={`text-xs px-2 py-1 border border-edge ${isLinkEnabled ? 'hover:bg-hover cursor-pointer' : ''} bg-transparent text-ink max-w-[150px] truncate shrink-0`}
- >
- <EntityValueDisplay
- property={props.property}
- entityId={entityRef.entity_id}
- entityType={entityRef.entity_type}
- enableLink={isLinkEnabled}
- />
- </div>
- );
- }}
+ {(entityRef) => (
+ <EntityValueDisplay
+ property={props.property}
+ entityId={entityRef.entity_id}
+ entityType={entityRef.entity_type}
+ canEdit={!isReadOnly()}
+ onRemove={() => handleRemoveEntity(entityRef)}
+ isSaving={isSaving()}
+ />
+ )}
</For>
<Show
when={!isReadOnly()}
@@ -65,12 +89,14 @@ export const EntityValue: Component<EntityValueProps> = (props) => {
</Show>
}
>
- <button
- onClick={handleEditClick}
- class="text-ink-muted hover:text-ink text-xs hover:bg-hover px-2 py-1 cursor-pointer border border-edge bg-transparent inline-block shrink-0"
- >
- {props.property.isMultiSelect ? '+' : '>'}
- </button>
+ <Show when={entities.length === 0 || props.property.isMultiSelect}>
+ <button
+ onClick={handleEditClick}
+ class="text-ink-muted hover:text-ink text-xs hover:bg-hover px-2 py-1 cursor-pointer border border-edge bg-transparent inline-block shrink-0"
+ >
+ {<>+</>}
+ </button>
+ </Show>
</Show>
</div>
);
diff --git a/js/app/packages/core/component/Properties/components/property-display/LinkValue.tsx b/js/app/packages/core/component/Properties/components/property-display/LinkValue.tsx
index 2e6c2a5697..d27c72892b 100644
--- a/js/app/packages/core/component/Properties/components/property-display/LinkValue.tsx
+++ b/js/app/packages/core/component/Properties/components/property-display/LinkValue.tsx
@@ -324,7 +324,6 @@ const LinkDisplay: Component<LinkDisplayProps> = (props) => {
theme="clear"
size="xs"
class="!text-failure hover:!bg-failure/15"
- tooltip={{ label: 'Remove link' }}
onClick={handleRemoveClick}
/>
</div>
diff --git a/js/app/packages/core/component/Properties/components/property-display/PropertyValue.tsx b/js/app/packages/core/component/Properties/components/property-display/PropertyValue.tsx
index e6889dc657..1572a81ea6 100644
--- a/js/app/packages/core/component/Properties/components/property-display/PropertyValue.tsx
+++ b/js/app/packages/core/component/Properties/components/property-display/PropertyValue.tsx
@@ -79,6 +79,7 @@ export const PropertyValue: Component<PropertyValueProps> = (props) => {
canEdit={canEdit}
entityType={entityType}
onEdit={props.onEdit}
+ onRefresh={onRefresh}
/>
);