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 (#270)

Daniel Kweon912afc792330
diff --git a/js/app/packages/core/component/Properties/api/converters.ts b/js/app/packages/core/component/Properties/api/converters.ts
index 22be22ebe8..65026397ce 100644
--- a/js/app/packages/core/component/Properties/api/converters.ts
+++ b/js/app/packages/core/component/Properties/api/converters.ts
@@ -2,12 +2,12 @@ import type { PropertyValue } from '@service-properties/generated/schemas/proper
import { NUMBER_DECIMAL_PLACES } from '../constants';
import type {
EntityPropertyWithDefinition,
- EntityReference,
Property,
PropertyApiValues,
SetPropertyValue,
ValueType,
} from '../types';
+import { isEntityReferenceArray, isStringArray } from '../utils/typeGuards';
/**
* Type guard to check if PropertyValue has a specific type
@@ -111,14 +111,11 @@ export function entityPropertyFromApi(
case 'SELECT_NUMBER': {
if (hasPropertyValueType(propertyValue, 'SelectOption')) {
const selectVal = propertyValue.value;
- if (
- Array.isArray(selectVal) &&
- selectVal.every((v) => typeof v === 'string')
- ) {
+ if (isStringArray(selectVal)) {
return {
...baseProperty,
valueType,
- value: selectVal as string[],
+ value: selectVal,
};
}
}
@@ -128,19 +125,8 @@ export function entityPropertyFromApi(
case 'ENTITY': {
if (hasPropertyValueType(propertyValue, 'EntityReference')) {
const entityVal = propertyValue.value;
- if (Array.isArray(entityVal)) {
- const refs: EntityReference[] = [];
- for (const ref of entityVal) {
- if (
- ref &&
- typeof ref === 'object' &&
- 'entity_id' in ref &&
- 'entity_type' in ref
- ) {
- refs.push(ref as EntityReference);
- }
- }
- return { ...baseProperty, valueType: 'ENTITY', value: refs };
+ if (isEntityReferenceArray(entityVal)) {
+ return { ...baseProperty, valueType: 'ENTITY', value: entityVal };
}
}
return { ...baseProperty, valueType: 'ENTITY', value: null };
@@ -149,14 +135,11 @@ export function entityPropertyFromApi(
case 'LINK': {
if (hasPropertyValueType(propertyValue, 'Link')) {
const linkVal = propertyValue.value;
- if (
- Array.isArray(linkVal) &&
- linkVal.every((v) => typeof v === 'string')
- ) {
+ if (isStringArray(linkVal)) {
return {
...baseProperty,
valueType: 'LINK',
- value: linkVal as string[],
+ value: linkVal,
};
}
}
diff --git a/js/app/packages/core/component/Properties/component/modal/CreatePropertyModal.tsx b/js/app/packages/core/component/Properties/component/modal/CreatePropertyModal.tsx
index 553a91e662..1d09789ffb 100644
--- a/js/app/packages/core/component/Properties/component/modal/CreatePropertyModal.tsx
+++ b/js/app/packages/core/component/Properties/component/modal/CreatePropertyModal.tsx
@@ -29,6 +29,89 @@ type DataTypeValue = ReturnType<
typeof getPropertyDataTypeDropdownOptions
>[number]['value'];
+type Option<T> = {
+ id: string;
+ value: T;
+ display_order: number;
+};
+
+type OptionInputProps<T extends string | number> = {
+ options: () => Option<T>[];
+ type: 'string' | 'number';
+ onAdd: () => string;
+ onRemove: (id: string) => void;
+ onUpdate: (id: string, value: T) => void;
+ placeholder?: string;
+};
+
+const OptionInput: Component<OptionInputProps<string | number>> = (props) => {
+ const handleKeyDown = (
+ e: KeyboardEvent,
+ _optionId: string,
+ currentValue: string | number
+ ) => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+
+ const hasValue =
+ props.type === 'string'
+ ? !!(currentValue as string).trim()
+ : props.type === 'number';
+
+ if (hasValue) {
+ const newOptionId = props.onAdd();
+
+ setTimeout(() => {
+ const newInput = document.querySelector(
+ `input[data-option-id="${newOptionId}"]`
+ ) as HTMLInputElement;
+ if (newInput) {
+ newInput.focus();
+ }
+ }, 50);
+ }
+ }
+ };
+
+ return (
+ <div class="space-y-2 max-h-40 overflow-y-auto">
+ <Index each={props.options()}>
+ {(option) => (
+ <div class="flex items-center gap-2">
+ <input
+ type={props.type === 'string' ? 'text' : 'number'}
+ value={option().value}
+ onInput={(e) => {
+ const value =
+ props.type === 'string'
+ ? e.currentTarget.value
+ : Number(e.currentTarget.value);
+ props.onUpdate(option().id, value as string | number);
+ }}
+ onKeyDown={(e) => handleKeyDown(e, option().id, option().value)}
+ placeholder={props.placeholder}
+ class="flex-1 px-2 py-1 border border-edge text-sm"
+ data-option-id={option().id}
+ />
+ <button
+ type="button"
+ onClick={() => props.onRemove(option().id)}
+ class="text-failure-ink hover:text-failure-ink text-md px-1"
+ >
+ ×
+ </button>
+ </div>
+ )}
+ </Index>
+ <Show when={props.options().length === 0}>
+ <div class="text-center py-4 text-ink-muted text-sm">
+ No options added yet
+ </div>
+ </Show>
+ </div>
+ );
+};
+
interface CreatePropertyModalProps {
isOpen: boolean;
onClose: () => void;
@@ -51,6 +134,54 @@ export const CreatePropertyModal: Component<CreatePropertyModalProps> = (
>([]);
const [error, setError] = createSignal<string | null>(null);
+ // Unified option management helpers
+ type Option<T> = { id: string; value: T; display_order: number };
+
+ const addOption = <T extends string | number>(
+ options: () => Option<T>[],
+ setOptions: (options: Option<T>[]) => void,
+ defaultValue: T
+ ): string => {
+ const newOption: Option<T> = {
+ id: crypto.randomUUID(),
+ value: defaultValue,
+ display_order: options().length,
+ };
+ setOptions([...options(), newOption]);
+ return newOption.id;
+ };
+
+ const removeOption = <T extends string | number>(
+ options: () => Option<T>[],
+ setOptions: (options: Option<T>[]) => void,
+ optionId: string
+ ) => {
+ setOptions(options().filter((opt) => opt.id !== optionId));
+ };
+
+ const updateOption = <T extends string | number>(
+ options: () => Option<T>[],
+ setOptions: (options: Option<T>[]) => void,
+ optionId: string,
+ value: T
+ ) => {
+ setOptions(
+ options().map((opt) => (opt.id === optionId ? { ...opt, value } : opt))
+ );
+ };
+
+ const hasDuplicateOptions = <T extends string | number>(
+ options: () => Option<T>[]
+ ): boolean => {
+ const values = options().map((opt) =>
+ typeof opt.value === 'string' ? opt.value.trim() : opt.value
+ );
+ const nonEmptyValues = values.filter((v) =>
+ typeof v === 'string' ? v !== '' : !isNaN(v)
+ );
+ return new Set(nonEmptyValues).size !== nonEmptyValues.length;
+ };
+
let propertyNameInputRef!: HTMLInputElement;
const organizationId = useOrganizationId();
@@ -166,9 +297,16 @@ export const CreatePropertyModal: Component<CreatePropertyModalProps> = (
}
// Check for duplicate options if options are required
- if (shouldShowOptions() && hasDuplicateOptions()) {
- setError(ERROR_MESSAGES.VALIDATION_DUPLICATE);
- return;
+ if (shouldShowOptions()) {
+ const { type } = parseDataTypeValue(selectedDataType());
+ const hasDuplicates =
+ type === 'select_string'
+ ? hasDuplicateOptions(newStringOptions)
+ : hasDuplicateOptions(newNumberOptions);
+ if (hasDuplicates) {
+ setError(ERROR_MESSAGES.VALIDATION_DUPLICATE);
+ return;
+ }
}
// Validate that select types have at least one option
@@ -234,104 +372,6 @@ export const CreatePropertyModal: Component<CreatePropertyModalProps> = (
setError(null);
};
- const addNewStringOption = () => {
- const newOption = {
- id: crypto.randomUUID(),
- value: '',
- display_order: newStringOptions().length,
- };
- setNewStringOptions([...newStringOptions(), newOption]);
- return newOption.id;
- };
-
- const addNewNumberOption = () => {
- const newOption = {
- id: crypto.randomUUID(),
- value: 0,
- display_order: newNumberOptions().length,
- };
- setNewNumberOptions([...newNumberOptions(), newOption]);
- return newOption.id;
- };
-
- const hasDuplicateOptions = () => {
- const dataType = selectedDataType();
-
- if (dataType === 'select_string') {
- const values = newStringOptions()
- .map((opt) => opt.value.trim())
- .filter((v) => v !== '');
- return new Set(values).size !== values.length;
- }
-
- if (dataType === 'select_number') {
- const values = newNumberOptions().map((opt) => opt.value);
- return new Set(values).size !== values.length;
- }
-
- return false;
- };
-
- const handleOptionKeyDown = (
- e: KeyboardEvent,
- _optionId: string,
- currentValue: string | number
- ) => {
- if (e.key === 'Enter') {
- e.preventDefault();
-
- const dataType = selectedDataType();
- const hasValue =
- dataType === 'select_string'
- ? !!(currentValue as string).trim()
- : dataType === 'select_number';
-
- if (hasValue) {
- const newOptionId =
- dataType === 'select_string'
- ? addNewStringOption()
- : addNewNumberOption();
-
- setTimeout(() => {
- const newInput = document.querySelector(
- `input[data-option-id="${newOptionId}"]`
- ) as HTMLInputElement;
- if (newInput) {
- newInput.focus();
- }
- }, 50);
- }
- }
- };
-
- const removeStringOption = (optionId: string) => {
- setNewStringOptions(
- newStringOptions().filter((opt) => opt.id !== optionId)
- );
- };
-
- const removeNumberOption = (optionId: string) => {
- setNewNumberOptions(
- newNumberOptions().filter((opt) => opt.id !== optionId)
- );
- };
-
- const updateStringOption = (optionId: string, value: string) => {
- setNewStringOptions(
- newStringOptions().map((opt) =>
- opt.id === optionId ? { ...opt, value } : opt
- )
- );
- };
-
- const updateNumberOption = (optionId: string, value: number) => {
- setNewNumberOptions(
- newNumberOptions().map((opt) =>
- opt.id === optionId ? { ...opt, value } : opt
- )
- );
- };
-
const shouldShowMultiSelect = createMemo(() => {
const { type } = parseDataTypeValue(selectedDataType());
return (
@@ -465,95 +505,67 @@ export const CreatePropertyModal: Component<CreatePropertyModalProps> = (
</label>
<button
type="button"
- onClick={() =>
- selectedDataType() === 'select_string'
- ? addNewStringOption()
- : addNewNumberOption()
- }
+ onClick={() => {
+ const { type } = parseDataTypeValue(selectedDataType());
+ if (type === 'select_string') {
+ addOption(newStringOptions, setNewStringOptions, '');
+ } else {
+ addOption(newNumberOptions, setNewNumberOptions, 0);
+ }
+ }}
class="px-2 py-1 text-xs bg-accent text-ink hover:bg-accent/90"
>
+ Add Option
</button>
</div>
- <div class="space-y-2 max-h-40 overflow-y-auto">
- <Show
- when={selectedDataType() === 'select_string'}
- fallback={
- <Index each={newNumberOptions()}>
- {(option) => (
- <div class="flex items-center gap-2">
- <input
- type="number"
- value={option().value}
- onInput={(e) =>
- updateNumberOption(
- option().id,
- Number(e.currentTarget.value)
- )
- }
- onKeyDown={(e) =>
- handleOptionKeyDown(
- e,
- option().id,
- option().value
- )
- }
- placeholder="Enter number"
- class="flex-1 px-2 py-1 border border-edge text-sm"
- data-option-id={option().id}
- />
- <button
- type="button"
- onClick={() => removeNumberOption(option().id)}
- class="text-failure-ink hover:text-failure-ink text-md px-1"
- >
- ×
- </button>
- </div>
- )}
- </Index>
+ <Show
+ when={selectedDataType() === 'select_string'}
+ fallback={
+ <OptionInput
+ options={newNumberOptions}
+ type="number"
+ onAdd={() =>
+ addOption(newNumberOptions, setNewNumberOptions, 0)
+ }
+ onRemove={(id) =>
+ removeOption(
+ newNumberOptions,
+ setNewNumberOptions,
+ id
+ )
+ }
+ onUpdate={(id, value) =>
+ updateOption(
+ newNumberOptions,
+ setNewNumberOptions,
+ id,
+ value as number
+ )
+ }
+ placeholder="Enter number"
+ />
+ }
+ >
+ <OptionInput
+ options={newStringOptions}
+ type="string"
+ onAdd={() =>
+ addOption(newStringOptions, setNewStringOptions, '')
}
- >
- <Index each={newStringOptions()}>
- {(option) => (
- <div class="flex items-center gap-2">
- <input
- type="text"
- value={option().value}
- onInput={(e) =>
- updateStringOption(
- option().id,
- e.currentTarget.value
- )
- }
- onKeyDown={(e) =>
- handleOptionKeyDown(
- e,
- option().id,
- option().value
- )
- }
- placeholder="Enter option value"
- class="flex-1 px-2 py-1 border border-edge text-sm"
- data-option-id={option().id}
- />
- <button
- type="button"
- onClick={() => removeStringOption(option().id)}
- class="text-failure-ink hover:text-failure-ink text-md px-1"
- >
- ×
- </button>
- </div>
- )}
- </Index>
- </Show>
- <Show when={getOptionsForCurrentType().length === 0}>
- <div class="text-center py-4 text-ink-muted text-sm">
- No options added yet
- </div>
- </Show>
- </div>
+ onRemove={(id) =>
+ removeOption(newStringOptions, setNewStringOptions, id)
+ }
+ onUpdate={(id, value) =>
+ updateOption(
+ newStringOptions,
+ setNewStringOptions,
+ id,
+ value as string
+ )
+ }
+ placeholder="Enter option value"
+ />
+ </Show>
</div>
</Show>
</div>
@@ -575,7 +587,7 @@ export const CreatePropertyModal: Component<CreatePropertyModalProps> = (
</div>
<button
type="button"
- class={`${PROPERTY_STYLES.button.base} ${newPropertyName().trim() && !isCreatingProperty() ? PROPERTY_STYLES.button.primary : 'bg-ink-muted text-ink cursor-not-allowed'}`}
+ class={`${PROPERTY_STYLES.button.base} ${PROPERTY_STYLES.button.accent} ${newPropertyName().trim() && !isCreatingProperty() ? '' : 'cursor-not-allowed'}`}
onClick={handleCreateProperty}
disabled={!newPropertyName().trim() || isCreatingProperty()}
>
diff --git a/js/app/packages/core/component/Properties/component/modal/Modals.tsx b/js/app/packages/core/component/Properties/component/modal/Modals.tsx
index 2706ef572a..ba9a801f80 100644
--- a/js/app/packages/core/component/Properties/component/modal/Modals.tsx
+++ b/js/app/packages/core/component/Properties/component/modal/Modals.tsx
@@ -1,12 +1,12 @@
import { useBlockId } from '@core/block';
import { DatePicker } from '@core/component/DatePicker';
-import { toast } from '@core/component/Toast/Toast';
import { type Component, createMemo } from 'solid-js';
import { Portal, Show } from 'solid-js/web';
import { saveEntityProperty } from '../../api';
import { usePropertiesContext } from '../../context/PropertiesContext';
import type { Property } from '../../types';
-import { ERROR_MESSAGES } from '../../utils/errorHandling';
+import { ERROR_MESSAGES, handlePropertyError } from '../../utils/errorHandling';
+import { useModalPosition } from '../../utils/position';
import { CreatePropertyModal } from './CreatePropertyModal';
import { EditPropertyValueModal } from './EditPropertyValueModal';
import { SelectPropertyModal } from './SelectPropertyModal';
@@ -43,13 +43,13 @@ export const Modals: Component = () => {
value: newDate.toISOString(),
});
- if (!result.ok) {
- console.error(
- 'Modals.handleDateSaved:',
- result.error,
- ERROR_MESSAGES.PROPERTY_SAVE
- );
- toast.failure(ERROR_MESSAGES.PROPERTY_SAVE);
+ if (
+ !handlePropertyError(
+ result,
+ ERROR_MESSAGES.PROPERTY_SAVE,
+ 'Modals.handleDateSaved'
+ )
+ ) {
return;
}
@@ -74,19 +74,14 @@ export const Modals: Component = () => {
<Show when={propertyEditorModal()}>
{(state) => {
- const position = state().anchor
- ? {
- top: state().anchor!.getBoundingClientRect().top,
- left: state().anchor!.getBoundingClientRect().left,
- }
- : undefined;
+ const position = useModalPosition(() => state().anchor);
return (
<EditPropertyValueModal
property={state().property}
onClose={closePropertyEditor}
onSaved={handlePropertySaved}
- position={position}
+ position={position()}
entityType={entityType}
/>
);
diff --git a/js/app/packages/core/component/Properties/component/modal/SelectPropertyModal.tsx b/js/app/packages/core/component/Properties/component/modal/SelectPropertyModal.tsx
index f1c5e83ac5..2aaa9de3b0 100644
--- a/js/app/packages/core/component/Properties/component/modal/SelectPropertyModal.tsx
+++ b/js/app/packages/core/component/Properties/component/modal/SelectPropertyModal.tsx
@@ -18,15 +18,13 @@ import {
getPropertyDefinitionTypeDisplay,
useSearchInputFocus,
} from '../../utils';
-import { ERROR_MESSAGES } from '../../utils/errorHandling';
-import { CreatePropertyModal } from './CreatePropertyModal';
-
+import { ERROR_MESSAGES, handlePropertyError } from '../../utils/errorHandling';
export function SelectPropertyModal(props: PropertySelectorProps) {
const blockId = useBlockId();
- const { entityType, onPropertyAdded } = usePropertiesContext();
+ const { entityType, onPropertyAdded, openCreateProperty } =
+ usePropertiesContext();
const [isAdding, setIsAdding] = createSignal(false);
const [searchQuery, setSearchQuery] = createSignal('');
- const [isCreating, setIsCreating] = createSignal(false);
let searchInputRef!: HTMLInputElement;
let modalRef!: HTMLDivElement;
@@ -53,16 +51,11 @@ export function SelectPropertyModal(props: PropertySelectorProps) {
propertyDefinitionId
);
- if (!result.ok) {
- console.error(
- 'SelectPropertyModal.handleAddProperties:',
- result.error,
- ERROR_MESSAGES.PROPERTY_ADD
- );
- toast.failure(ERROR_MESSAGES.PROPERTY_ADD);
- }
-
- return result.ok;
+ return handlePropertyError(
+ result,
+ ERROR_MESSAGES.PROPERTY_ADD,
+ 'SelectPropertyModal.handleAddProperties'
+ );
}
);
@@ -76,6 +69,7 @@ export function SelectPropertyModal(props: PropertySelectorProps) {
onPropertyAdded();
}
} catch (error) {
+ // Handle unexpected exceptions (e.g., Promise.all rejection)
console.error(
'SelectPropertyModal.handleAddProperties:',
error,
@@ -114,15 +108,13 @@ export function SelectPropertyModal(props: PropertySelectorProps) {
useSearchInputFocus(
() => searchInputRef,
- () =>
- props.isOpen && !isCreating() && state().availableProperties.length > 0
+ () => props.isOpen && state().availableProperties.length > 0
);
createEffect(() => {
if (props.isOpen) {
fetchAvailableProperties();
setSearchQuery('');
- setIsCreating(false);
}
});
@@ -143,217 +135,202 @@ export function SelectPropertyModal(props: PropertySelectorProps) {
});
return (
- <Show
- when={!isCreating()}
- fallback={
- <CreatePropertyModal
- isOpen={isCreating()}
- onClose={() => setIsCreating(false)}
- onPropertyCreated={() => {
- fetchAvailableProperties();
- onPropertyAdded();
- }}
- />
- }
- >
- <Portal>
+ <Portal>
+ <div
+ class="fixed inset-0 bg-overlay z-modal-overlay"
+ onClick={() => props.onClose()}
+ onKeyDown={(e) => e.key === 'Escape' && props.onClose()}
+ role="dialog"
+ aria-modal="true"
+ >
<div
- class="fixed inset-0 bg-overlay z-modal-overlay"
- onClick={() => props.onClose()}
- onKeyDown={(e) => e.key === 'Escape' && props.onClose()}
- role="dialog"
- aria-modal="true"
+ ref={modalRef}
+ class={`absolute bg-dialog border-3 border-edge shadow-xl w-full overflow-hidden font-mono z-modal-content max-w-md max-h-[80vh] ${MODAL_VIEWPORT_CLASSES}`}
+ style={{
+ ...modalPosition(),
+ 'max-width': '28rem',
+ 'max-height': '80vh',
+ }}
+ onClick={(e) => e.stopPropagation()}
+ onKeyDown={(e) => e.stopPropagation()}
+ role="document"
>
- <div
- ref={modalRef}
- class={`absolute bg-dialog border-3 border-edge shadow-xl w-full overflow-hidden font-mono z-modal-content max-w-md max-h-[80vh] ${MODAL_VIEWPORT_CLASSES}`}
- style={{
- ...modalPosition(),
- 'max-width': '28rem',
- 'max-height': '80vh',
- }}
- onClick={(e) => e.stopPropagation()}
- onKeyDown={(e) => e.stopPropagation()}
- role="document"
- >
- <div class="flex items-center justify-between p-4">
- <h3 class="text-base font-semibold text-ink">Add Properties</h3>
- <IconButton
- icon={XIcon}
- theme="clear"
- size="sm"
- onClick={() => props.onClose()}
- />
- </div>
+ <div class="flex items-center justify-between p-4">
+ <h3 class="text-base font-semibold text-ink">Add Properties</h3>
+ <IconButton
+ icon={XIcon}
+ theme="clear"
+ size="sm"
+ onClick={() => props.onClose()}
+ />
+ </div>
- <Show when={state().availableProperties.length > 0}>
- <div class="px-4 pb-2">
- <div class="relative">
- <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none z-10">
- <SearchIcon class="h-4 w-4 text-ink-muted" />
- </div>
- <input
- ref={searchInputRef}
- type="text"
- value={searchQuery()}
- onInput={(e) => setSearchQuery(e.currentTarget.value)}
- placeholder="Search properties..."
- class={`${PROPERTY_STYLES.input.search} relative z-0`}
- />
+ <Show when={state().availableProperties.length > 0}>
+ <div class="px-4 pb-2">
+ <div class="relative">
+ <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none z-10">
+ <SearchIcon class="h-4 w-4 text-ink-muted" />
</div>
+ <input
+ ref={searchInputRef}
+ type="text"
+ value={searchQuery()}
+ onInput={(e) => setSearchQuery(e.currentTarget.value)}
+ placeholder="Search properties..."
+ class={`${PROPERTY_STYLES.input.search} relative z-0`}
+ />
</div>
- </Show>
+ </div>
+ </Show>
- <div class="px-4 pb-2 overflow-y-auto max-h-[60vh]">
+ <div class="px-4 pb-2 overflow-y-auto max-h-[60vh]">
+ <Show
+ when={!state().isLoading}
+ fallback={
+ <div class="flex items-center justify-center py-8">
+ <div class="w-5 h-5 animate-spin">
+ <LoadingSpinner />
+ </div>
+ <span class="ml-2 text-ink-muted">Loading properties...</span>
+ </div>
+ }
+ >
<Show
- when={!state().isLoading}
+ when={!state().error}
fallback={
- <div class="flex items-center justify-center py-8">
- <div class="w-5 h-5 animate-spin">
- <LoadingSpinner />
+ <div class="text-center py-6">
+ <div class="text-failure-ink mb-3 text-sm">
+ {state().error}
</div>
- <span class="ml-2 text-ink-muted">
- Loading properties...
- </span>
+ <button
+ type="button"
+ onClick={fetchAvailableProperties}
+ class="px-3 py-1.5 bg-accent text-accent-ink text-sm hover:bg-accent/90"
+ >
+ Retry
+ </button>
</div>
}
>
<Show
- when={!state().error}
+ when={state().availableProperties.length > 0}
fallback={
<div class="text-center py-6">
- <div class="text-failure-ink mb-3 text-sm">
- {state().error}
+ <div class="text-ink-muted text-sm">
+ No additional properties available
</div>
- <button
- type="button"
- onClick={fetchAvailableProperties}
- class="px-3 py-1.5 bg-accent text-accent-ink text-sm hover:bg-accent/90"
- >
- Retry
- </button>
</div>
}
>
- <Show
- when={state().availableProperties.length > 0}
- fallback={
- <div class="text-center py-6">
- <div class="text-ink-muted text-sm">
- No additional properties available
+ <div class="space-y-2 max-h-80 overflow-y-auto">
+ <Show
+ when={filteredProperties().length > 0}
+ fallback={
+ <div class="text-center py-4 text-ink-muted text-sm">
+ No properties match your search
</div>
- </div>
- }
- >
- <div class="space-y-2 max-h-80 overflow-y-auto">
- <Show
- when={filteredProperties().length > 0}
- fallback={
- <div class="text-center py-4 text-ink-muted text-sm">
- No properties match your search
- </div>
- }
- >
- <For each={filteredProperties()}>
- {(property) => {
- const isSelected = () =>
- state().selectedPropertyIds.has(property.id);
+ }
+ >
+ <For each={filteredProperties()}>
+ {(property) => {
+ const isSelected = () =>
+ state().selectedPropertyIds.has(property.id);
- return (
- <button
- type="button"
- class={`w-full px-2.5 py-1.5 text-left border ${isSelected() ? 'bg-active border-accent text-accent-ink' : 'hover:bg-hover border-edge text-ink'}`}
- onClick={() =>
- togglePropertySelection(property.id)
- }
- >
- <div class="flex items-center justify-between">
- <div class="flex-1">
- <div class="flex items-center gap-2">
- <h4 class="font-medium text-xs">
- {property.display_name}
- </h4>
- </div>
- <div class="text-xs text-ink-muted mt-0.5">
- {getPropertyDefinitionTypeDisplay({
- dataType: property.data_type,
- specificEntityType:
- property.specific_entity_type,
- isMultiSelect: property.is_multi_select,
- })}
- </div>
+ return (
+ <button
+ type="button"
+ class={`w-full px-2.5 py-1.5 text-left border ${isSelected() ? 'bg-active border-accent text-accent-ink' : 'hover:bg-hover border-edge text-ink'}`}
+ onClick={() =>
+ togglePropertySelection(property.id)
+ }
+ >
+ <div class="flex items-center justify-between">
+ <div class="flex-1">
+ <div class="flex items-center gap-2">
+ <h4 class="font-medium text-xs">
+ {property.display_name}
+ </h4>
</div>
- <div
- class={`${PROPERTY_STYLES.checkbox.base} border-edge bg-transparent`}
- >
- <Show when={isSelected()}>
- <CheckIcon class="w-3 h-3 text-accent" />
- </Show>
+ <div class="text-xs text-ink-muted mt-0.5">
+ {getPropertyDefinitionTypeDisplay({
+ dataType: property.data_type,
+ specificEntityType:
+ property.specific_entity_type,
+ isMultiSelect: property.is_multi_select,
+ })}
</div>
</div>
- </button>
- );
- }}
- </For>
- </Show>
- </div>
- </Show>
+ <div
+ class={`${PROPERTY_STYLES.checkbox.base} border-edge bg-transparent`}
+ >
+ <Show when={isSelected()}>
+ <CheckIcon class="w-3 h-3 text-accent" />
+ </Show>
+ </div>
+ </div>
+ </button>
+ );
+ }}
+ </For>
+ </Show>
+ </div>
</Show>
</Show>
- </div>
+ </Show>
+ </div>
- <div class="flex items-center justify-between p-4 pt-2">
+ <div class="flex items-center justify-between p-4 pt-2">
+ <button
+ type="button"
+ class={`${PROPERTY_STYLES.button.base} ${PROPERTY_STYLES.button.secondary}`}
+ onClick={() => props.onClose()}
+ disabled={isAdding()}
+ >
+ Cancel
+ </button>
+ <Show when={state().selectedPropertyIds.size > 0}>
<button
type="button"
- class={`${PROPERTY_STYLES.button.base} ${PROPERTY_STYLES.button.secondary}`}
- onClick={() => props.onClose()}
- disabled={isAdding()}
+ class={`${PROPERTY_STYLES.button.base} ${state().selectedPropertyIds.size > 0 && !isAdding() ? PROPERTY_STYLES.button.accent : 'bg-ink-muted text-ink cursor-not-allowed'}`}
+ onClick={handleAddProperties}
+ disabled={state().selectedPropertyIds.size === 0 || isAdding()}
>
- Cancel
+ <Show
+ when={!isAdding()}
+ fallback={
+ <div class="flex items-center gap-1.5">
+ <div class="w-3 h-3 animate-spin">
+ <LoadingSpinner />
+ </div>
+ Adding...
+ </div>
+ }
+ >
+ Add{' '}
+ {state().selectedPropertyIds.size > 0
+ ? `(${state().selectedPropertyIds.size})`
+ : ''}
+ </Show>
</button>
- <Show when={state().selectedPropertyIds.size > 0}>
+ </Show>
+ <Show when={state().selectedPropertyIds.size === 0}>
+ <div class="flex gap-2">
<button
type="button"
- class={`${PROPERTY_STYLES.button.base} ${state().selectedPropertyIds.size > 0 && !isAdding() ? PROPERTY_STYLES.button.primary : 'bg-ink-muted text-ink cursor-not-allowed'}`}
- onClick={handleAddProperties}
- disabled={
- state().selectedPropertyIds.size === 0 || isAdding()
- }
+ onClick={() => {
+ props.onClose();
+ openCreateProperty();
+ }}
+ class={`${PROPERTY_STYLES.button.base} ${PROPERTY_STYLES.button.accent}`}
+ disabled={state().isLoading}
>
- <Show
- when={!isAdding()}
- fallback={
- <div class="flex items-center gap-1.5">
- <div class="w-3 h-3 animate-spin">
- <LoadingSpinner />
- </div>
- Adding...
- </div>
- }
- >
- Add{' '}
- {state().selectedPropertyIds.size > 0
- ? `(${state().selectedPropertyIds.size})`
- : ''}
- </Show>
+ Create New Property
</button>
- </Show>
- <Show when={state().selectedPropertyIds.size === 0}>
- <div class="flex gap-2">
- <button
- type="button"
- onClick={() => setIsCreating(true)}
- class={`${PROPERTY_STYLES.button.base} ${PROPERTY_STYLES.button.accent}`}
- disabled={state().isLoading}
- >
- Create New Property
- </button>
- </div>
- </Show>
- </div>
+ </div>
+ </Show>
</div>
</div>
- </Portal>
- </Show>
+ </div>
+ </Portal>
);
}
diff --git a/js/app/packages/core/component/Properties/component/modal/shared/PropertyEntitySelector.tsx b/js/app/packages/core/component/Properties/component/modal/shared/PropertyEntitySelector.tsx
index 378e634fb1..af24b18f7d 100644
--- a/js/app/packages/core/component/Properties/component/modal/shared/PropertyEntitySelector.tsx
+++ b/js/app/packages/core/component/Properties/component/modal/shared/PropertyEntitySelector.tsx
@@ -2,12 +2,8 @@ import { useChannelsContext } from '@core/component/ChannelsProvider';
import { EntityIcon } from '@core/component/EntityIcon';
import { UserIcon } from '@core/component/UserIcon';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
-import {
- type ChannelWithParticipants,
- type IUser,
- useContacts,
- useOrganizationUsers,
-} from '@core/user';
+import type { ChannelWithParticipants, IUser } from '@core/user';
+import { useContacts, useOrganizationUsers } from '@core/user';
import { mergeByKey } from '@core/util/compareUtils';
import { createFreshSearch } from '@core/util/freshSort';
import CheckIcon from '@icon/bold/check-bold.svg';
@@ -35,78 +31,63 @@ type EntityInputProps = {
setHasChanges: (hasChanges: boolean) => void;
};
-type EntityMap = {
- item: Item;
- user: IUser;
- channel: ChannelWithParticipants;
-};
-
-type Entity<T extends keyof EntityMap> = {
- kind: T;
- id: EntityMap[T]['id'];
- data: EntityMap[T];
-};
-
-type PickEntity<K extends keyof EntityMap> = {
- [P in K]: Entity<P>;
-}[K];
-
-type CombinedEntity<K extends keyof EntityMap = keyof EntityMap> =
- PickEntity<K>;
-
-type EntityMapper<K extends keyof EntityMap> = (
- data: EntityMap[K]
-) => PickEntity<K>;
-
-function entityMapper<K extends keyof EntityMap>(kind: K): EntityMapper<K> {
- return (data: EntityMap[K]) => ({ kind, data, id: data.id });
-}
-
-const ICON_CLASSES = 'size-4 text-ink-muted';
const INPUT_CLASSES = PROPERTY_STYLES.input.search;
const ENTITY_ITEM_BASE =
'flex items-center justify-between gap-2 py-1.5 px-2 border border-edge cursor-pointer min-w-0';
const CHECKBOX_BASE = 'w-4 h-4 border flex items-center justify-center';
+const ICON_CLASSES = 'size-4 text-ink-muted';
+
+type CombinedEntity =
+ | { kind: 'item'; id: string; data: Item }
+ | { kind: 'user'; id: string; data: IUser }
+ | { kind: 'channel'; id: string; data: ChannelWithParticipants };
-const getEntityName = (entity: CombinedEntity): string => {
+function entityMapper(kind: 'item' | 'user' | 'channel') {
+ return (data: Item | IUser | ChannelWithParticipants): CombinedEntity => {
+ return { kind, data, id: (data as { id: string }).id } as CombinedEntity;
+ };
+}
+
+function getEntityName(entity: CombinedEntity): string {
switch (entity.kind) {
case 'item':
return entity.data.name;
- case 'user':
+ case 'user': {
const { name, email } = entity.data;
if (name === email) return email;
return `${name} | ${email}`;
+ }
case 'channel':
return entity.data.name ?? '';
}
-};
+}
-const getEntitySearchText = (entity: CombinedEntity): string => {
+function getEntitySearchText(entity: CombinedEntity): string {
switch (entity.kind) {
case 'item':
return entity.data.name;
- case 'user':
+ case 'user': {
const { name, email } = entity.data;
if (name === email) return `${email} | ${email}`;
return `${name} | ${email}`;
+ }
case 'channel':
return entity.data.name ?? '';
}
-};
+}
-const getEntityType = (entity: CombinedEntity): string => {
+function getEntityType(entity: CombinedEntity): string {
switch (entity.kind) {
case 'user':
return 'USER';
case 'channel':
return 'CHANNEL';
case 'item':
- // Entity types from backend are already uppercase
return entity.data.type.toUpperCase();
}
-};
+}
-const getEntityIcon = (entity: CombinedEntity) => {
+function getEntityIcon(entity: CombinedEntity) {
switch (entity.kind) {
case 'user':
return (
@@ -130,7 +111,7 @@ const getEntityIcon = (entity: CombinedEntity) => {
default:
return <ChannelIcon class={ICON_CLASSES} />;
}
- case 'item':
+ case 'item': {
const blockName =
entity.data.type === 'document'
? fileTypeToBlockName(entity.data.fileType, true)
@@ -140,10 +121,16 @@ const getEntityIcon = (entity: CombinedEntity) => {
? 'project'
: 'unknown';
return <EntityIcon targetType={blockName} size="xs" />;
+ }
}
-};
+}
+
+export function PropertyEntitySelector(props: EntityInputProps) {
+ const [searchTerm, setSearchTerm] = createSignal('');
+ const [lastSearchTerm, setLastSearchTerm] = createSignal('');
+
+ let searchInputRef!: HTMLInputElement;
-function useEntityData(specificEntityType: EntityType | null | undefined) {
const history = useHistory();
const organizationUsers = useOrganizationUsers();
const contacts = useContacts();
@@ -151,16 +138,15 @@ function useEntityData(specificEntityType: EntityType | null | undefined) {
const channels = () => channelsContext.channels();
const entities = createMemo((): CombinedEntity[] => {
- // Only fetch what we need based on specific type
+ const { specificEntityType } = props.property;
+
if (!specificEntityType) {
- // All entities - combine everything
const allUsers = mergeByKey('id', contacts(), organizationUsers());
- const mapped = [
+ return [
...allUsers.map(entityMapper('user')),
...history().map(entityMapper('item')),
...channels().map(entityMapper('channel')),
];
- return mapped;
}
if (specificEntityType === ('USER' as EntityType)) {
@@ -172,7 +158,6 @@ function useEntityData(specificEntityType: EntityType | null | undefined) {
return channels().map(entityMapper('channel'));
}
- // include all except thread type
const itemTypes: EntityType[] = ['DOCUMENT', 'PROJECT', 'CHAT'];
if (itemTypes.includes(specificEntityType)) {
return history()
@@ -183,17 +168,6 @@ function useEntityData(specificEntityType: EntityType | null | undefined) {
return [];
});
- return { entities };
-}
-
-export function PropertyEntitySelector(props: EntityInputProps) {
- const [searchTerm, setSearchTerm] = createSignal('');
- const [lastSearchTerm, setLastSearchTerm] = createSignal('');
-
- let searchInputRef!: HTMLInputElement;
-
- const { entities } = useEntityData(props.property.specificEntityType);
-
const entitySearch = createFreshSearch<CombinedEntity>(
{ timeWeight: 0.1, brevityWeight: 0.3 },
getEntitySearchText
diff --git a/js/app/packages/core/component/Properties/component/panel/PropertyGrid.tsx b/js/app/packages/core/component/Properties/component/panel/PropertyGrid.tsx
index 8e49ff6a8d..9a691d7265 100644
--- a/js/app/packages/core/component/Properties/component/panel/PropertyGrid.tsx
+++ b/js/app/packages/core/component/Properties/component/panel/PropertyGrid.tsx
@@ -10,21 +10,30 @@ interface PropertiesListProps {
export const PropertyGrid: Component<PropertiesListProps> = (props) => {
const { openPropertyEditor, openDatePicker } = usePropertiesContext();
- const metadataProperties = createMemo(() =>
- props.properties.filter(
- (prop) =>
- prop.isMetadata &&
+ // Single pass through properties array to split into metadata and editable
+ // More efficient than two separate filter operations
+ const propertyGroups = createMemo(() => {
+ const metadata: Property[] = [];
+ const editable: Property[] = [];
+
+ for (const prop of props.properties) {
+ if (prop.isMetadata) {
// Hide "Project" property if value is null
- !(prop.displayName === 'Project' && prop.value == null)
- )
- );
+ if (prop.value != null) {
+ metadata.push(prop);
+ }
+ } else {
+ editable.push(prop);
+ }
+ }
- const editableProperties = createMemo(() =>
- props.properties.filter((prop) => !prop.isMetadata)
- );
+ return { metadata, editable };
+ });
const showSeparator = createMemo(
- () => metadataProperties().length > 0 && editableProperties().length > 0
+ () =>
+ propertyGroups().metadata.length > 0 &&
+ propertyGroups().editable.length > 0
);
const handleValueClick = (property: Property, anchor?: HTMLElement) => {
@@ -50,8 +59,8 @@ export const PropertyGrid: Component<PropertiesListProps> = (props) => {
}
>
<div class="grid grid-cols-[minmax(120px,50%)_minmax(150px,1fr)] gap-x-4 gap-y-3 pt-2 min-w-fit">
- <Show when={metadataProperties().length > 0}>
- <For each={metadataProperties()}>
+ <Show when={propertyGroups().metadata.length > 0}>
+ <For each={propertyGroups().metadata}>
{(property) => (
<PropertyRow
property={property}
@@ -65,8 +74,8 @@ export const PropertyGrid: Component<PropertiesListProps> = (props) => {
<div class="col-span-2 border-t border-edge my-4" />
</Show>
- <Show when={editableProperties().length > 0}>
- <For each={editableProperties()}>
+ <Show when={propertyGroups().editable.length > 0}>
+ <For each={propertyGroups().editable}>
{(property) => (
<PropertyRow
property={property}
diff --git a/js/app/packages/core/component/Properties/component/propertyValue/EntityValue.tsx b/js/app/packages/core/component/Properties/component/propertyValue/EntityValue.tsx
index 15ad6f85f8..f3dc7b0b6c 100644
--- a/js/app/packages/core/component/Properties/component/propertyValue/EntityValue.tsx
+++ b/js/app/packages/core/component/Properties/component/propertyValue/EntityValue.tsx
@@ -5,6 +5,8 @@ import type { Component } from 'solid-js';
import { createSignal, For, Show } from 'solid-js';
import { saveEntityProperty } from '../../api';
import type { Property } from '../../types';
+import { getEntityValues } from '../../utils';
+import { ERROR_MESSAGES, handlePropertyError } from '../../utils/errorHandling';
import { EntityIcon } from './EntityIcon';
import { AddPropertyValueButton, EmptyValue } from './ValueComponents';
@@ -36,7 +38,7 @@ export const EntityValue: Component<EntityValueProps> = (props) => {
setIsSaving(true);
try {
- const entities = (props.property.value as EntityReference[]) ?? [];
+ const entities = getEntityValues(props.property);
const newValues = entities.filter(
(entity: EntityReference) =>
entity.entity_id !== entityToRemove.entity_id ||
@@ -53,7 +55,13 @@ export const EntityValue: Component<EntityValueProps> = (props) => {
}
);
- if (result.ok) {
+ if (
+ handlePropertyError(
+ result,
+ ERROR_MESSAGES.PROPERTY_SAVE,
+ 'EntityValue.handleRemoveEntity'
+ )
+ ) {
props.onRefresh?.();
}
} finally {
@@ -62,7 +70,7 @@ export const EntityValue: Component<EntityValueProps> = (props) => {
};
const isReadOnly = () => props.property.isMetadata || !props.canEdit;
- const entities = (props.property.value as EntityReference[]) ?? [];
+ const entities = getEntityValues(props.property);
return (
<div class="flex flex-wrap gap-1 justify-start items-start w-full min-w-0">
<For each={entities}>
diff --git a/js/app/packages/core/component/Properties/component/propertyValue/LinkValue.tsx b/js/app/packages/core/component/Properties/component/propertyValue/LinkValue.tsx
index 7c5a4b724b..5d921e8ef5 100644
--- a/js/app/packages/core/component/Properties/component/propertyValue/LinkValue.tsx
+++ b/js/app/packages/core/component/Properties/component/propertyValue/LinkValue.tsx
@@ -10,7 +10,12 @@ import { createSignal, For, Show } from 'solid-js';
import { createStore } from 'solid-js/store';
import { saveEntityProperty } from '../../api';
import type { Property } from '../../types';
-import { extractDomain, isValidUrl, normalizeUrl } from '../../utils';
+import {
+ extractDomain,
+ getLinkValues,
+ isValidUrl,
+ normalizeUrl,
+} from '../../utils';
import { ERROR_MESSAGES } from '../../utils/errorHandling';
import { AddPropertyValueButton, EmptyValue } from './ValueComponents';
@@ -31,7 +36,7 @@ export const LinkValue: Component<LinkValueProps> = (props) => {
const [badLinks, setBadLinks] = createStore<Record<string, true>>({});
const isReadOnly = () => props.property.isMetadata || !props.canEdit;
- const linkValues = (props.property.value ?? []) as string[];
+ const linkValues = getLinkValues(props.property);
const startAdding = () => {
if (isReadOnly()) return;
@@ -104,7 +109,7 @@ export const LinkValue: Component<LinkValueProps> = (props) => {
setIsSaving(true);
try {
- const newValues = linkValues.filter((link) => link !== url);
+ const newValues = linkValues.filter((link: string) => link !== url);
const result = await saveEntityProperty(
blockId,
diff --git a/js/app/packages/core/component/Properties/component/propertyValue/SelectValue.tsx b/js/app/packages/core/component/Properties/component/propertyValue/SelectValue.tsx
index 265e89c4d1..5bb8d80ae5 100644
--- a/js/app/packages/core/component/Properties/component/propertyValue/SelectValue.tsx
+++ b/js/app/packages/core/component/Properties/component/propertyValue/SelectValue.tsx
@@ -7,7 +7,8 @@ import { createSignal, For, Show } from 'solid-js';
import { saveEntityProperty } from '../../api';
import { PROPERTY_STYLES } from '../../styles/styles';
import type { Property } from '../../types';
-import { formatPropertyValue } from '../../utils';
+import { formatPropertyValue, getSelectValues } from '../../utils';
+import { ERROR_MESSAGES, handlePropertyError } from '../../utils/errorHandling';
import { AddPropertyValueButton, EmptyValue } from './ValueComponents';
type SelectValueProps = {
@@ -57,7 +58,13 @@ export const SelectValue: Component<SelectValueProps> = (props) => {
}
);
- if (result.ok) {
+ if (
+ handlePropertyError(
+ result,
+ ERROR_MESSAGES.PROPERTY_SAVE,
+ 'SelectValue.handleRemoveValue'
+ )
+ ) {
props.onRefresh?.();
}
} finally {
@@ -66,7 +73,7 @@ export const SelectValue: Component<SelectValueProps> = (props) => {
};
const isReadOnly = () => props.property.isMetadata || !props.canEdit;
- const displayValues = (props.property.value ?? []) as string[];
+ const displayValues = getSelectValues(props.property);
return (
<div
diff --git a/js/app/packages/core/component/Properties/context/PropertiesContext.tsx b/js/app/packages/core/component/Properties/context/PropertiesContext.tsx
index 9334e2932f..6bec73471d 100644
--- a/js/app/packages/core/component/Properties/context/PropertiesContext.tsx
+++ b/js/app/packages/core/component/Properties/context/PropertiesContext.tsx
@@ -82,7 +82,7 @@ export interface PropertiesProviderProps extends ParentProps {
const PropertiesContext = createContext<PropertiesContextValue>();
export function PropertiesProvider(props: PropertiesProviderProps) {
- // Specific modal states
+ // Modal state signals
const [propertySelectorModal, setPropertySelectorModal] =
createSignal<PropertySelectorModalState | null>(null);
const [propertyEditorModal, setPropertyEditorModal] =
diff --git a/js/app/packages/core/component/Properties/hooks/useBooleanEditor.ts b/js/app/packages/core/component/Properties/hooks/useBooleanEditor.ts
index 8f1893e20a..a8183301cf 100644
--- a/js/app/packages/core/component/Properties/hooks/useBooleanEditor.ts
+++ b/js/app/packages/core/component/Properties/hooks/useBooleanEditor.ts
@@ -3,6 +3,7 @@ import type { EntityType } from '@service-properties/generated/schemas/entityTyp
import { type Accessor, createMemo, createSignal } from 'solid-js';
import { saveEntityProperty } from '../api';
import type { Property } from '../types';
+import { ERROR_MESSAGES, handlePropertyError } from '../utils/errorHandling';
/**
* Hook for editing boolean properties
@@ -44,7 +45,13 @@ export function useBooleanEditor(
value: newValue,
});
- if (result.ok) {
+ if (
+ handlePropertyError(
+ result,
+ ERROR_MESSAGES.PROPERTY_SAVE,
+ 'useBooleanEditor.toggle'
+ )
+ ) {
onSaved?.();
}
} finally {
diff --git a/js/app/packages/core/component/Properties/hooks/useInlineEditor.ts b/js/app/packages/core/component/Properties/hooks/useInlineEditor.ts
index 7f10aea6b2..f1acc32117 100644
--- a/js/app/packages/core/component/Properties/hooks/useInlineEditor.ts
+++ b/js/app/packages/core/component/Properties/hooks/useInlineEditor.ts
@@ -5,6 +5,7 @@ import { saveEntityProperty } from '../api';
import { NUMBER_DECIMAL_PLACES } from '../constants';
import type { Property, PropertyApiValues } from '../types';
import { formatPropertyValue } from '../utils';
+import { ERROR_MESSAGES, handlePropertyError } from '../utils/errorHandling';
/**
* Hook for inline editing of string and number properties
@@ -92,7 +93,13 @@ export function useInlineEditor(
apiValues
);
- if (result.ok) {
+ if (
+ handlePropertyError(
+ result,
+ ERROR_MESSAGES.PROPERTY_SAVE,
+ 'useInlineEditor.save'
+ )
+ ) {
setIsEditing(false);
onSaved?.();
}
diff --git a/js/app/packages/core/component/Properties/styles/styles.ts b/js/app/packages/core/component/Properties/styles/styles.ts
index 5240b480e5..8c1245b2dc 100644
--- a/js/app/packages/core/component/Properties/styles/styles.ts
+++ b/js/app/packages/core/component/Properties/styles/styles.ts
@@ -11,7 +11,6 @@ export const PROPERTY_STYLES = {
button: {
base: 'px-3 py-1.5 text-sm border',
- primary: 'bg-accent/90 hover:bg-accent/80 text-ink',
secondary: 'text-ink-muted hover:text-ink border-edge hover:bg-hover',
accent: 'text-accent hover:text-accent/80 border-accent hover:bg-accent/10',
},
diff --git a/js/app/packages/core/component/Properties/utils/errorHandling.ts b/js/app/packages/core/component/Properties/utils/errorHandling.ts
index be3dddf4bf..f927c22635 100644
--- a/js/app/packages/core/component/Properties/utils/errorHandling.ts
+++ b/js/app/packages/core/component/Properties/utils/errorHandling.ts
@@ -1,3 +1,6 @@
+import { toast } from '@core/component/Toast/Toast';
+import type { Result } from '../types';
+
/**
* Common error messages for consistency
* Organized by category: properties, options, validation
@@ -20,3 +23,28 @@ export const ERROR_MESSAGES = {
VALIDATION_DUPLICATE: 'Duplicate values not allowed',
VALIDATION_MIN_OPTIONS: 'At least one option required',
} as const;
+
+/**
+ * Handles property operation errors consistently
+ * - Logs error to console
+ * - Shows toast notification to user
+ * - Returns boolean indicating success/failure
+ *
+ * @param result - Result from property operation
+ * @param errorMessage - User-friendly error message
+ * @param context - Context for error logging (e.g., function name)
+ * @returns true if operation succeeded, false otherwise
+ */
+export function handlePropertyError(
+ result: Result<unknown>,
+ errorMessage: string,
+ context: string
+): boolean {
+ if (result.ok) {
+ return true;
+ }
+
+ console.error(`${context}:`, result.error, errorMessage);
+ toast.failure(errorMessage);
+ return false;
+}
diff --git a/js/app/packages/core/component/Properties/utils/index.ts b/js/app/packages/core/component/Properties/utils/index.ts
index bdfd0ec422..3553844baf 100644
--- a/js/app/packages/core/component/Properties/utils/index.ts
+++ b/js/app/packages/core/component/Properties/utils/index.ts
@@ -6,4 +6,6 @@ export * from './entityConversion';
export * from './errorHandling';
export * from './focus';
export * from './formatting';
+export * from './position';
+export * from './typeGuards';
export * from './validation';
diff --git a/js/app/packages/core/component/Properties/utils/position.ts b/js/app/packages/core/component/Properties/utils/position.ts
new file mode 100644
index 0000000000..9ed1a49f2d
--- /dev/null
+++ b/js/app/packages/core/component/Properties/utils/position.ts
@@ -0,0 +1,25 @@
+import { type Accessor, createMemo } from 'solid-js';
+
+/**
+ * Calculate modal position from an anchor element
+ * Returns position object with top and left coordinates, or undefined if no anchor
+ *
+ * @param anchor - Accessor for the anchor HTMLElement (or null/undefined)
+ * @returns Position object with top and left coordinates, or undefined
+ */
+export function useModalPosition(
+ anchor: Accessor<HTMLElement | null | undefined>
+): Accessor<{ top: number; left: number } | undefined> {
+ return createMemo(() => {
+ const anchorElement = anchor();
+ if (!anchorElement) {
+ return undefined;
+ }
+
+ const rect = anchorElement.getBoundingClientRect();
+ return {
+ top: rect.top,
+ left: rect.left,
+ };
+ });
+}
diff --git a/js/app/packages/core/component/Properties/utils/typeGuards.ts b/js/app/packages/core/component/Properties/utils/typeGuards.ts
new file mode 100644
index 0000000000..6c11a40270
--- /dev/null
+++ b/js/app/packages/core/component/Properties/utils/typeGuards.ts
@@ -0,0 +1,95 @@
+import type { EntityReference } from '@service-properties/generated/schemas/entityReference';
+import type { Property } from '../types';
+
+/**
+ * Type guard to check if property is a LINK type
+ */
+export function isLinkProperty(
+ property: Property
+): property is Property & { valueType: 'LINK'; value: string[] | null } {
+ return property.valueType === 'LINK';
+}
+
+/**
+ * Type guard to check if property is a SELECT_STRING or SELECT_NUMBER type
+ */
+export function isSelectProperty(
+ property: Property
+): property is Property &
+ (
+ | { valueType: 'SELECT_STRING'; value: string[] | null }
+ | { valueType: 'SELECT_NUMBER'; value: string[] | null }
+ ) {
+ return (
+ property.valueType === 'SELECT_STRING' ||
+ property.valueType === 'SELECT_NUMBER'
+ );
+}
+
+/**
+ * Type guard to check if property is an ENTITY type
+ */
+export function isEntityProperty(property: Property): property is Property & {
+ valueType: 'ENTITY';
+ value: EntityReference[] | null;
+} {
+ return property.valueType === 'ENTITY';
+}
+
+/**
+ * Safely extract link values from a property
+ * Returns empty array if property is not LINK type or value is null
+ */
+export function getLinkValues(property: Property): string[] {
+ if (isLinkProperty(property)) {
+ return property.value ?? [];
+ }
+ return [];
+}
+
+/**
+ * Safely extract select values from a property
+ * Returns empty array if property is not SELECT type or value is null
+ */
+export function getSelectValues(property: Property): string[] {
+ if (isSelectProperty(property)) {
+ return property.value ?? [];
+ }
+ return [];
+}
+
+/**
+ * Safely extract entity references from a property
+ * Returns empty array if property is not ENTITY type or value is null
+ */
+export function getEntityValues(property: Property): EntityReference[] {
+ if (isEntityProperty(property)) {
+ return property.value ?? [];
+ }
+ return [];
+}
+
+/**
+ * Type guard to check if a value is a string array
+ */
+export function isStringArray(value: unknown): value is string[] {
+ return Array.isArray(value) && value.every((v) => typeof v === 'string');
+}
+
+/**
+ * Type guard to check if a value is an EntityReference array
+ */
+export function isEntityReferenceArray(
+ value: unknown
+): value is EntityReference[] {
+ if (!Array.isArray(value)) {
+ return false;
+ }
+ return value.every(
+ (ref): ref is EntityReference =>
+ ref !== null &&
+ typeof ref === 'object' &&
+ 'entity_id' in ref &&
+ 'entity_type' in ref
+ );
+}