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] - select options delete

Daniel Kweon2be737b764e6
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 1572a81ea6..796b419d8e 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
@@ -68,7 +68,9 @@ export const PropertyValue: Component<PropertyValueProps> = (props) => {
<SelectValue
property={props.property}
canEdit={canEdit}
+ entityType={entityType}
onEdit={props.onEdit}
+ onRefresh={onRefresh}
/>
);
diff --git a/js/app/packages/core/component/Properties/components/property-display/SelectValue.tsx b/js/app/packages/core/component/Properties/components/property-display/SelectValue.tsx
index 079362c4db..0bf2c4c22c 100644
--- a/js/app/packages/core/component/Properties/components/property-display/SelectValue.tsx
+++ b/js/app/packages/core/component/Properties/components/property-display/SelectValue.tsx
@@ -1,5 +1,10 @@
+import { useBlockId } from '@core/block';
+import { IconButton } from '@core/component/IconButton';
+import DeleteIcon from '@icon/bold/x-bold.svg';
+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 { PROPERTY_STYLES } from '../../styles/propertyStyles';
import type { Property } from '../../types';
import { formatPropertyValue } from '../../utils';
@@ -7,7 +12,9 @@ import { formatPropertyValue } from '../../utils';
type SelectValueProps = {
property: Property;
canEdit: boolean;
+ entityType: EntityType;
onEdit?: (property: Property, anchor?: HTMLElement) => void;
+ onRefresh?: () => void;
};
/**
@@ -15,66 +22,94 @@ type SelectValueProps = {
* Opens options modal on click
*/
export const SelectValue: Component<SelectValueProps> = (props) => {
+ const blockId = useBlockId();
+ const [hoveredValue, setHoveredValue] = createSignal<string | null>(null);
+ const [isSaving, setIsSaving] = createSignal(false);
+
const handleClick = (e: MouseEvent) => {
if (props.canEdit && !props.property.isMetadata) {
props.onEdit?.(props.property, e.currentTarget as HTMLElement);
}
};
+ const handleRemoveValue = async (valueToRemove: string) => {
+ if (isReadOnly() || isSaving()) return;
+
+ setIsSaving(true);
+
+ try {
+ const values = displayValues;
+ const newValues = values.filter((v) => v !== valueToRemove);
+
+ const valueType = props.property.valueType;
+ if (valueType !== 'SELECT_STRING' && valueType !== 'SELECT_NUMBER') {
+ return;
+ }
+
+ const result = await savePropertyValue(
+ blockId,
+ props.entityType,
+ props.property,
+ {
+ valueType,
+ values: newValues.length > 0 ? newValues : null,
+ }
+ );
+
+ if (result.ok) {
+ props.onRefresh?.();
+ }
+ } finally {
+ setIsSaving(false);
+ }
+ };
+
const isReadOnly = () => props.property.isMetadata || !props.canEdit;
const displayValues = (props.property.value || []) as string[];
- const isMultiValue = () => props.property.isMultiSelect;
return (
- <Show
- when={isMultiValue()}
- fallback={
- <button
- onClick={handleClick}
- class={`text-left text-xs px-2 py-1 border border-edge ${
- isReadOnly()
- ? 'bg-transparent text-ink-muted cursor-default'
- : 'hover:bg-hover cursor-pointer bg-transparent text-ink'
- } inline-block max-w-full break-words`}
- >
- <Show when={displayValues.length > 0} fallback={<>—</>}>
- <span class="block truncate max-w-full">
- {formatPropertyValue(props.property, displayValues[0])}
- </span>
- </Show>
- </button>
- }
+ <div
+ class={`flex flex-wrap gap-1 justify-start items-start w-full min-w-0`}
>
- <div
- class={`flex flex-wrap gap-1 justify-start items-start w-full min-w-0`}
- >
- <For each={displayValues}>
- {(value) => {
- const formatted = formatPropertyValue(props.property, value);
- return (
- <Show
- when={isReadOnly()}
- fallback={
- <button
- onClick={handleClick}
- class={PROPERTY_STYLES.value.multiButton}
- title={formatted}
- >
- <span class="block truncate">{formatted}</span>
- </button>
- }
- >
- <div
- class={`${PROPERTY_STYLES.value.multi} text-ink-muted`}
- title={formatted}
- >
- <span class="block truncate">{formatted}</span>
+ <For each={displayValues}>
+ {(value) => {
+ const formatted = formatPropertyValue(props.property, value);
+ const isHovered = () => hoveredValue() === value;
+ return (
+ <div
+ class="relative inline-flex max-w-[150px] shrink-0"
+ onMouseEnter={() => setHoveredValue(value)}
+ onMouseLeave={() => setHoveredValue(null)}
+ >
+ <div class={PROPERTY_STYLES.value.multiButton} title={formatted}>
+ <span class="block truncate">{formatted}</span>
+ </div>
+ <Show when={!isReadOnly() && isHovered() && !isSaving()}>
+ <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={() => handleRemoveValue(value)}
+ />
</div>
</Show>
- );
- }}
- </For>
- <Show when={!isReadOnly()}>
+ </div>
+ );
+ }}
+ </For>
+ <Show
+ when={!isReadOnly()}
+ fallback={
+ <Show when={displayValues.length === 0}>
+ <div class="text-ink-muted text-xs px-2 py-1 border border-edge bg-transparent inline-block shrink-0">
+ {<>—</>}
+ </div>
+ </Show>
+ }
+ >
+ <Show when={props.property.isMultiSelect || displayValues.length === 0}>
<button
onClick={handleClick}
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"
@@ -82,7 +117,7 @@ export const SelectValue: Component<SelectValueProps> = (props) => {
+
</button>
</Show>
- </div>
- </Show>
+ </Show>
+ </div>
);
};