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] - refactor properties (#192)

Daniel Kweon9c299317cc82
diff --git a/js/app/packages/block-md/component/InlineProperties.tsx b/js/app/packages/block-md/component/InlineProperties.tsx
index daed2bb121..45519ad314 100644
--- a/js/app/packages/block-md/component/InlineProperties.tsx
+++ b/js/app/packages/block-md/component/InlineProperties.tsx
@@ -51,21 +51,17 @@ function InlinePropertyValue(props: {
property: any;
displayValue: string | null;
}) {
- const { openModal } = usePropertiesContext();
+ const { openDatePicker, openPropertyEditor } = usePropertiesContext();
const handleClick = (e: MouseEvent) => {
if (props.property.valueType === 'DATE') {
- openModal('date-picker', props.property, e.currentTarget as HTMLElement);
+ openDatePicker(props.property, e.currentTarget as HTMLElement);
} else if (
props.property.valueType === 'SELECT_STRING' ||
props.property.valueType === 'SELECT_NUMBER' ||
props.property.valueType === 'ENTITY'
) {
- openModal(
- 'edit-property',
- props.property,
- e.currentTarget as HTMLElement
- );
+ openPropertyEditor(props.property, e.currentTarget as HTMLElement);
}
};
@@ -99,7 +95,7 @@ function InlineEntityValue(props: {
canEdit: boolean;
onRefresh: () => void;
}) {
- const { openModal } = usePropertiesContext();
+ const { openPropertyEditor } = usePropertiesContext();
const entities = () =>
(props.property.value as EntityReference[] | undefined) ?? [];
@@ -110,7 +106,7 @@ function InlineEntityValue(props: {
return;
}
// Always allow clicking to open modal, even for metadata properties
- openModal('edit-property', props.property, e.currentTarget as HTMLElement);
+ openPropertyEditor(props.property, e.currentTarget as HTMLElement);
};
// For inline display, we want entity values to be clickable
diff --git a/js/app/packages/core/component/Properties/PropertiesView.tsx b/js/app/packages/core/component/Properties/PropertiesView.tsx
index d2000eddbb..fe18fac3f4 100644
--- a/js/app/packages/core/component/Properties/PropertiesView.tsx
+++ b/js/app/packages/core/component/Properties/PropertiesView.tsx
@@ -1,6 +1,6 @@
import { useBlockId } from '@core/block';
import LoadingSpinner from '@icon/regular/spinner.svg';
-import { createMemo, Show } from 'solid-js';
+import { type Accessor, createMemo, Show } from 'solid-js';
import { AddPropertyButton } from './components/AddPropertyButton';
import { PropertiesContent } from './components/PropertiesContent';
import { PropertiesModals } from './components/PropertiesModals';
@@ -9,7 +9,7 @@ import {
usePropertiesContext,
} from './context/PropertiesContext';
import { useProperties } from './hooks';
-import type { PropertiesPanelProps } from './types';
+import type { PropertiesPanelProps, Property } from './types';
const CONTAINER_CLASSES =
'h-full overflow-hidden relative font-mono flex flex-col';
@@ -55,46 +55,53 @@ export function PropertiesView(props: PropertiesPanelProps) {
onPropertyUnpinned={props.onPropertyUnpinned}
pinnedPropertyIds={props.pinnedPropertyIds}
>
- <div class={CONTAINER_CLASSES}>
- <Show when={isLoading()}>
- <div class={LOADING_CONTAINER_CLASSES}>
- <div class={SPINNER_CLASSES}>
- <LoadingSpinner />
- </div>
- </div>
- </Show>
-
- <Show when={error()}>
- <div class="text-failure-ink text-center py-4">{error()}</div>
- </Show>
-
- <PropertiesContent
- properties={properties}
- isLoading={isLoading}
- error={error}
- />
-
- <AddPropertyButtonWrapper properties={properties} />
-
- <PropertiesModals />
- </div>
+ <PropertiesViewContent
+ properties={properties}
+ isLoading={isLoading}
+ error={error}
+ canEdit={props.canEdit}
+ />
</PropertiesProvider>
);
}
-function AddPropertyButtonWrapper(props: { properties: () => any[] }) {
- const { canEdit, openModal } = usePropertiesContext();
+// Separated to allow context access while keeping PropertiesView clean
+function PropertiesViewContent(props: {
+ properties: Accessor<Property[]>;
+ isLoading: Accessor<boolean>;
+ error: Accessor<string | null>;
+ canEdit: boolean;
+}) {
+ const { openPropertySelector } = usePropertiesContext();
const hasProperties = createMemo(() => props.properties().length > 0);
- const handleAddProperty = () => {
- openModal('add-property');
- };
-
return (
- <Show when={canEdit && hasProperties()}>
- <div class="flex-shrink-0 p-4">
- <AddPropertyButton onClick={handleAddProperty} />
- </div>
- </Show>
+ <div class={CONTAINER_CLASSES}>
+ <Show when={props.isLoading()}>
+ <div class={LOADING_CONTAINER_CLASSES}>
+ <div class={SPINNER_CLASSES}>
+ <LoadingSpinner />
+ </div>
+ </div>
+ </Show>
+
+ <Show when={props.error()}>
+ <div class="text-failure-ink text-center py-4">{props.error()}</div>
+ </Show>
+
+ <PropertiesContent
+ properties={props.properties}
+ isLoading={props.isLoading}
+ error={props.error}
+ />
+
+ <Show when={props.canEdit && hasProperties()}>
+ <div class="flex-shrink-0 p-4">
+ <AddPropertyButton onClick={openPropertySelector} />
+ </div>
+ </Show>
+
+ <PropertiesModals />
+ </div>
);
}
diff --git a/js/app/packages/core/component/Properties/PropertyEditor.tsx b/js/app/packages/core/component/Properties/PropertyEditor.tsx
index f223555089..13725251eb 100644
--- a/js/app/packages/core/component/Properties/PropertyEditor.tsx
+++ b/js/app/packages/core/component/Properties/PropertyEditor.tsx
@@ -35,7 +35,6 @@ const CONTENT_CLASSES = 'flex-1 max-h-64 pt-2 px-4 pb-4';
export function PropertyEditor(props: PropertyEditorProps) {
const blockId = useBlockId();
- const [saveError, setSaveError] = createSignal<string | null>(null);
const [selectedEntityRefs, setSelectedEntityRefs] = createSignal<
EntityReference[]
@@ -54,8 +53,6 @@ export function PropertyEditor(props: PropertyEditorProps) {
} = usePropertyEditor(props.property);
const saveChanges = async () => {
- setSaveError(null);
-
const selectedArray = Array.from(editorState().selectedOptions);
let apiValues: PropertyApiValues;
@@ -93,6 +90,7 @@ export function PropertyEditor(props: PropertyEditorProps) {
return;
}
+ // savePropertyValue already handles error logging and user feedback
const result = await savePropertyValue(
blockId,
props.entityType,
@@ -102,9 +100,6 @@ export function PropertyEditor(props: PropertyEditorProps) {
if (result.ok) {
props.onSaved();
- // Note: hasChanges is managed internally by the hook now
- } else {
- setSaveError('Failed to save changes');
}
props.onClose();
@@ -259,12 +254,6 @@ export function PropertyEditor(props: PropertyEditorProps) {
onAddOption={addOption}
/>
</Show>
-
- <Show when={saveError()}>
- <div class="mt-3 text-failure-ink text-sm text-center">
- {saveError()}
- </div>
- </Show>
</div>
</div>
</div>
diff --git a/js/app/packages/core/component/Properties/components/PropertiesList.tsx b/js/app/packages/core/component/Properties/components/PropertiesList.tsx
index 3e6cf8eb4c..a3e195d8e9 100644
--- a/js/app/packages/core/component/Properties/components/PropertiesList.tsx
+++ b/js/app/packages/core/component/Properties/components/PropertiesList.tsx
@@ -8,7 +8,7 @@ interface PropertiesListProps {
}
export const PropertiesList: Component<PropertiesListProps> = (props) => {
- const { openModal } = usePropertiesContext();
+ const { openPropertyEditor, openDatePicker } = usePropertiesContext();
const metadataProperties = createMemo(() =>
props.properties.filter(
@@ -29,13 +29,13 @@ export const PropertiesList: Component<PropertiesListProps> = (props) => {
const handleValueClick = (property: Property, anchor?: HTMLElement) => {
if (property.valueType === 'DATE') {
- openModal('date-picker', property, anchor);
+ openDatePicker(property, anchor);
} else if (
property.valueType === 'SELECT_STRING' ||
property.valueType === 'SELECT_NUMBER' ||
property.valueType === 'ENTITY'
) {
- openModal('edit-property', property, anchor);
+ openPropertyEditor(property, anchor);
}
// LINK, STRING, NUMBER, BOOLEAN handle their own inline editing
};
diff --git a/js/app/packages/core/component/Properties/components/PropertiesModals.tsx b/js/app/packages/core/component/Properties/components/PropertiesModals.tsx
index 5ea420b201..aefc570a88 100644
--- a/js/app/packages/core/component/Properties/components/PropertiesModals.tsx
+++ b/js/app/packages/core/component/Properties/components/PropertiesModals.tsx
@@ -16,50 +16,66 @@ export const PropertiesModals: Component = () => {
onPropertyAdded,
properties,
onRefresh,
- closeModal,
- isModalOpen,
- getModalData,
- getModalAnchor,
+ propertySelectorModal,
+ propertyEditorModal,
+ datePickerModal,
+ createPropertyModal,
+ closePropertySelector,
+ closePropertyEditor,
+ closeDatePicker,
+ closeCreateProperty,
} = usePropertiesContext();
const existingPropertyIds = createMemo(() => {
return properties().map((prop) => prop.propertyDefinitionId);
});
- const handlePropertyAdded = () => {
- onPropertyAdded();
- closeModal();
- };
-
const handlePropertySaved = () => {
onRefresh();
- closeModal();
+ closePropertyEditor();
+ };
+
+ const handleDateSaved = async (newDate: Date, property: Property) => {
+ const success = await savePropertyValue(
+ blockId,
+ property,
+ { valueType: 'DATE', value: newDate.toISOString() },
+ entityType
+ );
+ if (success) {
+ onRefresh();
+ }
+ closeDatePicker();
+ };
+
+ const handlePropertyCreated = () => {
+ onPropertyAdded();
+ closeCreateProperty();
};
return (
<>
- <Show when={isModalOpen('add-property')}>
+ <Show when={propertySelectorModal()}>
<PropertySelector
isOpen={true}
- onClose={closeModal}
+ onClose={closePropertySelector}
existingPropertyIds={existingPropertyIds()}
/>
</Show>
- <Show when={isModalOpen('edit-property') && getModalData()}>
- {(property) => {
- const anchor = getModalAnchor();
- const position = anchor
+ <Show when={propertyEditorModal()}>
+ {(state) => {
+ const position = state().anchor
? {
- top: anchor.getBoundingClientRect().top,
- left: anchor.getBoundingClientRect().left,
+ top: state().anchor!.getBoundingClientRect().top,
+ left: state().anchor!.getBoundingClientRect().left,
}
: undefined;
return (
<PropertyEditor
- property={property() as Property}
- onClose={closeModal}
+ property={state().property}
+ onClose={closePropertyEditor}
onSaved={handlePropertySaved}
position={position}
entityType={entityType}
@@ -68,45 +84,32 @@ export const PropertiesModals: Component = () => {
}}
</Show>
- <Show
- when={isModalOpen('date-picker') && getModalAnchor() && getModalData()}
- >
- {(modalData) => {
- const property = modalData() as Property;
- const dateValue =
- property.valueType === 'DATE' && property.value
- ? new Date(property.value)
- : new Date();
+ <Show when={datePickerModal()}>
+ {(state) => {
+ const property = state().property;
+ const dateValue = property.value
+ ? new Date(property.value)
+ : new Date();
+ const anchor = state().anchor;
- return (
+ return anchor ? (
<Portal>
<DatePicker
value={dateValue}
- onChange={async (newDate) => {
- const success = await savePropertyValue(
- blockId,
- property,
- { valueType: 'DATE', value: newDate.toISOString() },
- entityType
- );
- if (success) {
- onRefresh();
- }
- closeModal();
- }}
- onClose={closeModal}
- anchorRef={getModalAnchor()!}
+ onChange={(newDate) => handleDateSaved(newDate, property)}
+ onClose={closeDatePicker}
+ anchorRef={anchor}
/>
</Portal>
- );
+ ) : null;
}}
</Show>
- <Show when={isModalOpen('create-property')}>
+ <Show when={createPropertyModal()}>
<CreatePropertyModal
isOpen={true}
- onClose={closeModal}
- onPropertyCreated={handlePropertyAdded}
+ onClose={closeCreateProperty}
+ onPropertyCreated={handlePropertyCreated}
/>
</Show>
</>
diff --git a/js/app/packages/core/component/Properties/components/property-display/DateValue.tsx b/js/app/packages/core/component/Properties/components/property-display/DateValue.tsx
index fa7e0b154e..cd8b8d5e94 100644
--- a/js/app/packages/core/component/Properties/components/property-display/DateValue.tsx
+++ b/js/app/packages/core/component/Properties/components/property-display/DateValue.tsx
@@ -2,6 +2,7 @@ import type { Component } from 'solid-js';
import { Show } from 'solid-js';
import type { Property } from '../../types';
import { formatDate } from '../../utils';
+import { EmptyValue } from './PropertyValuePrimitives';
type DateValueProps = {
property: Property;
@@ -35,7 +36,7 @@ export const DateValue: Component<DateValueProps> = (props) => {
: 'hover:bg-hover cursor-pointer bg-transparent text-ink'
} inline-block max-w-full break-words`}
>
- <Show when={displayValue} fallback={<>—</>}>
+ <Show when={displayValue} fallback={<EmptyValue />}>
<span class="block truncate max-w-full">{displayValue}</span>
</Show>
</button>
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 780a75cdd6..278cbcb706 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
@@ -6,6 +6,7 @@ import { createSignal, For, Show } from 'solid-js';
import { savePropertyValue } from '../../api/propertyValues';
import { EntityValueDisplay } from '../../EntityValueDisplay';
import type { Property } from '../../types';
+import { AddPropertyValueButton, EmptyValue } from './PropertyValuePrimitives';
type EntityValueProps = {
property: Property;
@@ -81,18 +82,13 @@ export const EntityValue: Component<EntityValueProps> = (props) => {
fallback={
<Show when={entities.length === 0}>
<div class="text-ink-muted text-xs px-2 py-1 border border-edge bg-transparent inline-block shrink-0">
- {<>—</>}
+ <EmptyValue />
</div>
</Show>
}
>
<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>
+ <AddPropertyValueButton onClick={handleEditClick} />
</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 42de617972..05d07e8d7c 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
@@ -11,6 +11,7 @@ import { createStore } from 'solid-js/store';
import { savePropertyValue } from '../../api/propertyValues';
import type { Property } from '../../types';
import { extractDomain, isValidUrl, normalizeUrl } from '../../utils';
+import { AddPropertyValueButton, EmptyValue } from './PropertyValuePrimitives';
type LinkValueProps = {
property: Property;
@@ -136,7 +137,7 @@ export const LinkValue: Component<LinkValueProps> = (props) => {
};
const AddLinkInput = () => (
- <div>
+ <>
<input
ref={(el) => {
setTimeout(() => el.focus(), 0);
@@ -154,12 +155,12 @@ export const LinkValue: Component<LinkValueProps> = (props) => {
}}
placeholder="Enter URL..."
disabled={isSaving()}
- class="text-left text-xs px-2 py-1 border border-edge bg-transparent focus:outline-none focus:border-accent text-ink"
+ class="text-left text-xs px-2 py-1 border border-edge bg-transparent focus:outline-none focus:border-accent text-ink inline-block shrink-0"
/>
<Show when={error()}>
- <div class="text-failure-ink text-xs mt-1">{error()}</div>
+ <div class="text-failure-ink text-xs mt-1 w-full">{error()}</div>
</Show>
- </div>
+ </>
);
return (
@@ -179,9 +180,11 @@ export const LinkValue: Component<LinkValueProps> = (props) => {
<Show
when={!isReadOnly()}
fallback={
- <div class="text-ink-muted text-xs px-2 py-1 border border-edge bg-transparent inline-block shrink-0">
- {<>—</>}
- </div>
+ <Show when={linkValues.length === 0}>
+ <div class="text-ink-muted text-xs px-2 py-1 border border-edge bg-transparent inline-block shrink-0">
+ <EmptyValue />
+ </div>
+ </Show>
}
>
<Show
@@ -190,18 +193,11 @@ export const LinkValue: Component<LinkValueProps> = (props) => {
<Show
when={props.property.isMultiSelect || linkValues.length === 0}
>
- <button
- onClick={startAdding}
- 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>
+ <AddPropertyValueButton onClick={startAdding} />
</Show>
}
>
- <div class="inline-block">
- <AddLinkInput />
- </div>
+ <AddLinkInput />
</Show>
</Show>
</div>
diff --git a/js/app/packages/core/component/Properties/components/property-display/NumberValue.tsx b/js/app/packages/core/component/Properties/components/property-display/NumberValue.tsx
index 94b730b7fd..034fe43cb0 100644
--- a/js/app/packages/core/component/Properties/components/property-display/NumberValue.tsx
+++ b/js/app/packages/core/component/Properties/components/property-display/NumberValue.tsx
@@ -4,6 +4,7 @@ import { Show } from 'solid-js';
import { useInlineEditor } from '../../hooks';
import type { Property } from '../../types';
import { formatNumber } from '../../utils';
+import { EmptyValue } from './PropertyValuePrimitives';
type NumberValueProps = {
property: Property;
@@ -62,7 +63,7 @@ export const NumberValue: Component<NumberValueProps> = (props) => {
: 'bg-transparent text-ink-muted cursor-default'
} block max-w-full break-words`}
>
- <Show when={hasValue()} fallback={<>—</>}>
+ <Show when={hasValue()} fallback={<EmptyValue />}>
<span class="block truncate max-w-full">{displayValue}</span>
</Show>
</button>
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 796b419d8e..76b5ebe8c5 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
@@ -94,5 +94,20 @@ export const PropertyValue: Component<PropertyValueProps> = (props) => {
onRefresh={onRefresh}
/>
);
+
+ default: {
+ // Exhaustive check: if we reach here, TypeScript will error
+ // because we haven't handled all PropertyValue types
+ const _exhaustiveCheck: never = props.property;
+ console.error(
+ 'Unhandled property type in PropertyValue:',
+ (_exhaustiveCheck as Property).valueType
+ );
+ return (
+ <div class="text-failure-ink text-xs px-2 py-1">
+ Unsupported Property Type
+ </div>
+ );
+ }
}
};
diff --git a/js/app/packages/core/component/Properties/components/property-display/PropertyValuePrimitives.tsx b/js/app/packages/core/component/Properties/components/property-display/PropertyValuePrimitives.tsx
new file mode 100644
index 0000000000..28e91299f8
--- /dev/null
+++ b/js/app/packages/core/component/Properties/components/property-display/PropertyValuePrimitives.tsx
@@ -0,0 +1,67 @@
+import type { Component, JSX } from 'solid-js';
+
+/**
+ * Shared UI primitives for property value display components
+ * Provides consistent styling and behavior across all value types
+ */
+
+/** CSS classes for common property value UI patterns */
+const STYLES = {
+ addButton:
+ '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',
+} as const;
+
+/**
+ * Empty value display - just the "—" symbol
+ * Consistent component used everywhere
+ */
+export const EmptyValue: Component = () => {
+ return <>—</>;
+};
+
+/**
+ * Button for adding values to multi-value properties (select, link, entity)
+ * Shows "+" with hover states
+ */
+export const AddPropertyValueButton: Component<{
+ onClick: ((e: MouseEvent) => void) | (() => void);
+ disabled?: boolean;
+}> = (props) => {
+ return (
+ <button
+ onClick={props.onClick as (e: MouseEvent) => void}
+ disabled={props.disabled}
+ class={STYLES.addButton}
+ >
+ +
+ </button>
+ );
+};
+
+/**
+ * Container for clickable property values (used by Date, Select, Entity)
+ * Provides consistent button styling with optional hover states
+ */
+export const PropertyValueButton: Component<{
+ onClick?: (e: MouseEvent) => void;
+ isReadOnly: boolean;
+ disabled?: boolean;
+ title?: string;
+ class?: string;
+ children: JSX.Element;
+}> = (props) => {
+ return (
+ <button
+ onClick={props.onClick}
+ disabled={props.disabled}
+ title={props.title}
+ class={`text-left text-xs px-2 py-1 border border-edge ${
+ props.isReadOnly
+ ? 'bg-transparent text-ink-muted cursor-default'
+ : 'hover:bg-hover cursor-pointer bg-transparent text-ink'
+ } ${props.class || ''}`}
+ >
+ {props.children}
+ </button>
+ );
+};
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 573e24cd08..bef191c51d 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
@@ -8,6 +8,7 @@ import { savePropertyValue } from '../../api/propertyValues';
import { PROPERTY_STYLES } from '../../styles/propertyStyles';
import type { Property } from '../../types';
import { formatPropertyValue } from '../../utils';
+import { AddPropertyValueButton, EmptyValue } from './PropertyValuePrimitives';
type SelectValueProps = {
property: Property;
@@ -104,18 +105,13 @@ export const SelectValue: Component<SelectValueProps> = (props) => {
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">
- {<>—</>}
+ <EmptyValue />
</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"
- >
- +
- </button>
+ <AddPropertyValueButton onClick={handleClick} />
</Show>
</Show>
</div>
diff --git a/js/app/packages/core/component/Properties/components/property-display/TextValue.tsx b/js/app/packages/core/component/Properties/components/property-display/TextValue.tsx
index 134fba6bb6..ef72cc0e6b 100644
--- a/js/app/packages/core/component/Properties/components/property-display/TextValue.tsx
+++ b/js/app/packages/core/component/Properties/components/property-display/TextValue.tsx
@@ -4,6 +4,7 @@ import { Show } from 'solid-js';
import { useInlineEditor } from '../../hooks';
import type { Property } from '../../types';
import { formatPropertyValue } from '../../utils';
+import { EmptyValue } from './PropertyValuePrimitives';
type TextValueProps = {
property: Property;
@@ -60,7 +61,7 @@ export const TextValue: Component<TextValueProps> = (props) => {
: 'bg-transparent text-ink-muted cursor-default'
} block max-w-full break-words`}
>
- <Show when={hasValue()} fallback={<>—</>}>
+ <Show when={hasValue()} fallback={<EmptyValue />}>
<span class="block max-w-full">
{formatPropertyValue(
props.property,
diff --git a/js/app/packages/core/component/Properties/constants.ts b/js/app/packages/core/component/Properties/constants.ts
index 48072ed146..037278ccbf 100644
--- a/js/app/packages/core/component/Properties/constants.ts
+++ b/js/app/packages/core/component/Properties/constants.ts
@@ -1,27 +1,20 @@
-/**
- * Common CSS classes used across property components
- */
+export const NUMBER_DECIMAL_PLACES = 4; // Matches backend precision
-// Number formatting
-export const NUMBER_DECIMAL_PLACES = 4;
-
-// Focus configuration
export const FOCUS_CONFIG = {
- DEFAULT_DELAY: 100,
- PROPERTY_NAME_DELAY: 200,
- MAX_ATTEMPTS: 10,
- RETRY_DELAY: 50,
+ DEFAULT_DELAY: 100, // Initial render delay
+ PROPERTY_NAME_DELAY: 200, // Modal animation delay
+ MAX_ATTEMPTS: 10, // Max focus retries
+ RETRY_DELAY: 50, // Retry interval
} as const;
-// Modal dimensions
export const MODAL_DIMENSIONS = {
- DEFAULT_WIDTH: 448,
- DEFAULT_HEIGHT: 384,
+ DEFAULT_WIDTH: 448, // 28rem
+ DEFAULT_HEIGHT: 384, // 24rem
PROPERTY_EDITOR_HEIGHT: 384,
- SELECTOR_TOP_PERCENTAGE: 0.2,
- SELECTOR_MIN_TOP_MARGIN: 16,
- SELECTOR_SMALL_SCREEN_THRESHOLD: 600,
- SELECTOR_SMALL_SCREEN_TOP_PERCENTAGE: 0.1,
+ SELECTOR_TOP_PERCENTAGE: 0.2, // 20% from top
+ SELECTOR_MIN_TOP_MARGIN: 16, // 1rem
+ SELECTOR_SMALL_SCREEN_THRESHOLD: 600, // Mobile breakpoint
+ SELECTOR_SMALL_SCREEN_TOP_PERCENTAGE: 0.1, // 10% from top
} as const;
// Button classes
diff --git a/js/app/packages/core/component/Properties/context/PropertiesContext.tsx b/js/app/packages/core/component/Properties/context/PropertiesContext.tsx
index 06e310594a..9334e2932f 100644
--- a/js/app/packages/core/component/Properties/context/PropertiesContext.tsx
+++ b/js/app/packages/core/component/Properties/context/PropertiesContext.tsx
@@ -1,5 +1,6 @@
import type { EntityType } from '@service-properties/generated/schemas/entityType';
import {
+ type Accessor,
createContext,
createEffect,
createSignal,
@@ -8,16 +9,23 @@ import {
} from 'solid-js';
import type { Property } from '../types';
-export type ModalType =
- | 'add-property'
- | 'edit-property'
- | 'date-picker'
- | 'create-property';
+// Specific modal state types with proper typing
+export interface PropertySelectorModalState {
+ isOpen: boolean;
+}
+
+export interface PropertyEditorModalState {
+ property: Property;
+ anchor?: HTMLElement;
+}
+
+export interface DatePickerModalState {
+ property: Property & { valueType: 'DATE' };
+ anchor?: HTMLElement;
+}
-export interface ModalState {
- type: ModalType | null;
- data: unknown;
- anchor?: HTMLElement | null;
+export interface CreatePropertyModalState {
+ isOpen: boolean;
}
export interface PropertiesContextValue {
@@ -31,13 +39,31 @@ export interface PropertiesContextValue {
onPropertyPinned?: (propertyId: string) => void;
onPropertyUnpinned?: (propertyId: string) => void;
pinnedPropertyIds?: () => string[];
- // Modal state
- modalState: () => ModalState;
- openModal: (type: ModalType, data?: unknown, anchor?: HTMLElement) => void;
- closeModal: () => void;
- isModalOpen: (type: ModalType) => boolean;
- getModalData: () => unknown;
- getModalAnchor: () => HTMLElement | null | undefined;
+
+ // Specific modal state accessors
+ propertySelectorModal: Accessor<PropertySelectorModalState | null>;
+ propertyEditorModal: Accessor<PropertyEditorModalState | null>;
+ datePickerModal: Accessor<DatePickerModalState | null>;
+ createPropertyModal: Accessor<CreatePropertyModalState | null>;
+
+ // Specific modal actions
+ openPropertySelector: () => void;
+ closePropertySelector: () => void;
+
+ openPropertyEditor: (property: Property, anchor?: HTMLElement) => void;
+ closePropertyEditor: () => void;
+
+ openDatePicker: (
+ property: Property & { valueType: 'DATE' },
+ anchor?: HTMLElement
+ ) => void;
+ closeDatePicker: () => void;
+
+ openCreateProperty: () => void;
+ closeCreateProperty: () => void;
+
+ // Convenience function to close all modals
+ closeAllModals: () => void;
}
export interface PropertiesProviderProps extends ParentProps {
@@ -56,44 +82,79 @@ export interface PropertiesProviderProps extends ParentProps {
const PropertiesContext = createContext<PropertiesContextValue>();
export function PropertiesProvider(props: PropertiesProviderProps) {
- const [modalState, setModalState] = createSignal<ModalState>({
- type: null,
- data: null,
- anchor: null,
- });
+ // Specific modal states
+ const [propertySelectorModal, setPropertySelectorModal] =
+ createSignal<PropertySelectorModalState | null>(null);
+ const [propertyEditorModal, setPropertyEditorModal] =
+ createSignal<PropertyEditorModalState | null>(null);
+ const [datePickerModal, setDatePickerModal] =
+ createSignal<DatePickerModalState | null>(null);
+ const [createPropertyModal, setCreatePropertyModal] =
+ createSignal<CreatePropertyModalState | null>(null);
+
+ // Property Selector actions
+ const openPropertySelector = () => {
+ setPropertySelectorModal({ isOpen: true });
+ };
+
+ const closePropertySelector = () => {
+ setPropertySelectorModal(null);
+ };
+
+ // Property Editor actions
+ const openPropertyEditor = (property: Property, anchor?: HTMLElement) => {
+ setPropertyEditorModal({ property, anchor });
+ };
+
+ const closePropertyEditor = () => {
+ setPropertyEditorModal(null);
+ };
- const openModal = (type: ModalType, data?: unknown, anchor?: HTMLElement) => {
- setModalState({ type, data, anchor });
+ // Date Picker actions
+ const openDatePicker = (
+ property: Property & { valueType: 'DATE' },
+ anchor?: HTMLElement
+ ) => {
+ setDatePickerModal({ property, anchor });
};
- const closeModal = () => {
- setModalState({ type: null, data: null, anchor: null });
+ const closeDatePicker = () => {
+ setDatePickerModal(null);
};
- const isModalOpen = (type: ModalType) => {
- return modalState().type === type;
+ // Create Property actions
+ const openCreateProperty = () => {
+ setCreatePropertyModal({ isOpen: true });
};
- const getModalData = () => {
- return modalState().data;
+ const closeCreateProperty = () => {
+ setCreatePropertyModal(null);
};
- const getModalAnchor = () => {
- return modalState().anchor;
+ // Convenience function to close all modals
+ const closeAllModals = () => {
+ setPropertySelectorModal(null);
+ setPropertyEditorModal(null);
+ setDatePickerModal(null);
+ setCreatePropertyModal(null);
};
// Handle ESC key to close modals
// Use capture phase listener to intercept before hotkey system (like drawer close)
createEffect(() => {
- const isModalOpen = modalState().type !== null;
+ const isAnyModalOpen =
+ propertySelectorModal() !== null ||
+ propertyEditorModal() !== null ||
+ datePickerModal() !== null ||
+ createPropertyModal() !== null;
- if (isModalOpen) {
+ if (isAnyModalOpen) {
const handleKeyDown = (e: KeyboardEvent) => {
- if (e.key === 'Escape' && modalState().type !== null) {
+ if (e.key === 'Escape') {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
- closeModal();
+ closeAllModals();
}
};
@@ -120,13 +181,21 @@ export function PropertiesProvider(props: PropertiesProviderProps) {
onPropertyPinned: props.onPropertyPinned,
onPropertyUnpinned: props.onPropertyUnpinned,
pinnedPropertyIds: props.pinnedPropertyIds,
- // Modal state
- modalState,
- openModal,
- closeModal,
- isModalOpen,
- getModalData,
- getModalAnchor,
+ // Specific modal state
+ propertySelectorModal,
+ propertyEditorModal,
+ datePickerModal,
+ createPropertyModal,
+ // Specific modal actions
+ openPropertySelector,
+ closePropertySelector,
+ openPropertyEditor,
+ closePropertyEditor,
+ openDatePicker,
+ closeDatePicker,
+ openCreateProperty,
+ closeCreateProperty,
+ closeAllModals,
};
return (
diff --git a/js/app/packages/core/component/Properties/types.ts b/js/app/packages/core/component/Properties/types.ts
index b1ff0a9114..b39657a2e7 100644
--- a/js/app/packages/core/component/Properties/types.ts
+++ b/js/app/packages/core/component/Properties/types.ts
@@ -34,14 +34,10 @@ export type ValueType =
| 'LINK';
/**
- * UI layer property representation with type-safe discriminated union
+ * UI layer property with discriminated union for type-safe values
*
- * TypeScript automatically narrows the value type based on valueType:
- * ```typescript
- * if (property.valueType === 'STRING') {
- * property.value // TypeScript knows this is string[]
- * }
- * ```
+ * Note: Single-value types use `value?: T`, multi-value types use `value?: T[]`
+ * This reflects the semantic difference between logically single vs multiple values.
*
* @see EntityPropertyWithDefinition - Backend structured type
* @see PropertyValue - Backend discriminated union for values
@@ -55,15 +51,14 @@ export type Property = {
options?: PropertyOption[];
owner: PropertyOwner;
specificEntityType?: EntityType | null;
- // Timestamps
createdAt: string;
updatedAt: string;
-} & (
+} & ( // Single-value types
| { valueType: 'STRING'; value?: string }
| { valueType: 'NUMBER'; value?: number }
| { valueType: 'BOOLEAN'; value?: boolean }
| { valueType: 'DATE'; value?: Date }
- // Select values are stored as option IDs (UUIDs as strings), not the actual option values
+ // Multi-value types (select values are option IDs, not display values)
| { valueType: 'SELECT_STRING'; value?: string[] }
| { valueType: 'SELECT_NUMBER'; value?: string[] }
| { valueType: 'ENTITY'; value?: EntityReference[] }