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.

add [properties-fe] - filter and sort to unified list filter (#633)

Daniel Kweon4b04891d4f27
diff --git a/js/app/packages/app/component/PropertyFilter/FilterAction.tsx b/js/app/packages/app/component/PropertyFilter/FilterAction.tsx
new file mode 100644
index 0000000000..50eb7300c6
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterAction.tsx
@@ -0,0 +1,116 @@
+import type { PropertyDefinition } from '@service-properties/generated/schemas/propertyDefinition';
+import type { Component } from 'solid-js';
+import {
+ createMemo,
+ createSignal,
+ For,
+ onCleanup,
+ onMount,
+ Show,
+} from 'solid-js';
+import type { FilterAction } from '../PropertyFilterTypes';
+import {
+ ACTION_DISPLAY_NAMES,
+ ACTION_SYMBOLS,
+ getValidFilterActions,
+} from '../PropertyFilterTypes';
+
+export type FilterActionSelectProps = {
+ property: PropertyDefinition;
+ selectedAction: FilterAction | null;
+ onSelectAction: (action: FilterAction) => void;
+};
+
+export const FilterActionSelect: Component<FilterActionSelectProps> = (
+ props
+) => {
+ const [isOpen, setIsOpen] = createSignal(false);
+
+ let containerRef!: HTMLDivElement;
+ let dropdownRef!: HTMLDivElement;
+
+ const validActions = createMemo(() => {
+ return getValidFilterActions(
+ props.property.data_type,
+ props.property.is_multi_select ?? false
+ );
+ });
+
+ const handleSelectAction = (action: FilterAction) => {
+ props.onSelectAction(action);
+ setIsOpen(false);
+ };
+
+ // Close dropdown when clicking outside
+ const handleClickOutside = (event: MouseEvent) => {
+ if (!isOpen()) return;
+ const target = event.target;
+ if (!(target instanceof Node)) return;
+
+ const isInsideContainer = containerRef?.contains(target);
+ const isInsideDropdown = dropdownRef?.contains(target);
+
+ if (!isInsideContainer && !isInsideDropdown) {
+ setIsOpen(false);
+ }
+ };
+
+ onMount(() => {
+ document.addEventListener('mousedown', handleClickOutside);
+ onCleanup(() =>
+ document.removeEventListener('mousedown', handleClickOutside)
+ );
+ });
+
+ return (
+ <div ref={containerRef} class="flex relative">
+ <button
+ type="button"
+ onClick={() => setIsOpen(!isOpen())}
+ class="h-6 px-2 min-w-fit text-[10px] border border-edge hover:bg-hover text-left font-mono flex items-center"
+ classList={{
+ 'text-ink': props.selectedAction !== null,
+ 'text-ink-muted': props.selectedAction === null,
+ }}
+ >
+ {props.selectedAction
+ ? ACTION_SYMBOLS[props.selectedAction]
+ : 'Select...'}
+ </button>
+ <Show when={isOpen()}>
+ <div
+ ref={dropdownRef}
+ class="absolute left-0 top-full mt-1 border border-edge bg-menu shadow-lg max-h-48 overflow-y-auto font-mono min-w-[120px] z-1"
+ >
+ <Show
+ when={validActions().length > 0}
+ fallback={
+ <div class="px-3 py-2 text-[10px] text-ink-muted text-center">
+ No actions available
+ </div>
+ }
+ >
+ <For each={validActions()}>
+ {(action) => (
+ <button
+ type="button"
+ onMouseDown={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ handleSelectAction(action);
+ }}
+ class="w-full px-2 py-1.5 text-[10px] text-ink hover:bg-hover text-left"
+ classList={{
+ 'bg-hover': props.selectedAction === action,
+ }}
+ >
+ {ACTION_DISPLAY_NAMES[action]}
+ </button>
+ )}
+ </For>
+ </Show>
+ </div>
+ </Show>
+ </div>
+ );
+};
diff --git a/js/app/packages/app/component/PropertyFilter/FilterProperty.tsx b/js/app/packages/app/component/PropertyFilter/FilterProperty.tsx
new file mode 100644
index 0000000000..ce67243b7c
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterProperty.tsx
@@ -0,0 +1,140 @@
+import { listPropertiesFlat } from '@core/component/Properties/utils';
+import { PropertyDataTypeIcon } from '@core/component/Properties/utils/PropertyDataTypeIcon';
+import MagnifyingGlassIcon from '@phosphor-icons/core/assets/regular/magnifying-glass.svg';
+import type { PropertyDefinition } from '@service-properties/generated/schemas/propertyDefinition';
+import type { Component } from 'solid-js';
+import {
+ createMemo,
+ createSignal,
+ For,
+ onCleanup,
+ onMount,
+ Show,
+} from 'solid-js';
+import { isFilterableDataType } from '../PropertyFilterTypes';
+
+export type FilterPropertySelectProps = {
+ onSelectProperty: (property: PropertyDefinition) => void;
+ onCancel?: () => void;
+};
+
+export const FilterPropertySelect: Component<FilterPropertySelectProps> = (
+ props
+) => {
+ const [availableProperties, setAvailableProperties] = createSignal<
+ PropertyDefinition[]
+ >([]);
+ const [searchQuery, setSearchQuery] = createSignal('');
+ const [isDropdownOpen, setIsDropdownOpen] = createSignal(false);
+
+ let searchInputRef!: HTMLInputElement;
+ let dropdownRef!: HTMLDivElement;
+ let containerRef!: HTMLDivElement;
+
+ const fetchAvailableProperties = async () => {
+ const properties = await listPropertiesFlat('all');
+ setAvailableProperties(properties);
+ };
+
+ // Filter to only filterable properties (exclude COMPANY entity type)
+ const filterableProperties = createMemo(() => {
+ return availableProperties().filter(
+ (property) =>
+ isFilterableDataType(property.data_type) &&
+ property.specific_entity_type !== 'COMPANY'
+ );
+ });
+
+ const filteredProperties = createMemo(() => {
+ const query = searchQuery().toLowerCase().trim();
+ const properties = filterableProperties();
+
+ if (!query) return properties;
+
+ return properties.filter((property) => {
+ const name = property.display_name.toLowerCase();
+ return name.includes(query);
+ });
+ });
+
+ const handleSelectProperty = (property: PropertyDefinition) => {
+ props.onSelectProperty(property);
+ setSearchQuery('');
+ setIsDropdownOpen(false);
+ };
+
+ // Close dropdown and cancel when clicking outside
+ const handleClickOutside = (event: MouseEvent) => {
+ if (!isDropdownOpen()) return;
+ const target = event.target;
+ if (!(target instanceof Node)) return;
+
+ const isInsideContainer = containerRef?.contains(target);
+ const isInsideDropdown = dropdownRef?.contains(target);
+
+ if (!isInsideContainer && !isInsideDropdown) {
+ setIsDropdownOpen(false);
+ props.onCancel?.();
+ }
+ };
+
+ onMount(() => {
+ fetchAvailableProperties();
+ // Autofocus the search input
+ searchInputRef?.focus();
+ document.addEventListener('mousedown', handleClickOutside);
+ onCleanup(() =>
+ document.removeEventListener('mousedown', handleClickOutside)
+ );
+ });
+
+ return (
+ <div ref={containerRef} class="flex relative w-full h-6">
+ <MagnifyingGlassIcon class="absolute left-2 top-1/2 -translate-y-1/2 size-3 text-ink-muted pointer-events-none" />
+ <input
+ ref={searchInputRef}
+ type="text"
+ value={searchQuery()}
+ onInput={(e) => {
+ setSearchQuery(e.currentTarget.value);
+ setIsDropdownOpen(true);
+ }}
+ onFocus={() => setIsDropdownOpen(true)}
+ placeholder="Search Properties..."
+ class="w-full h-full pl-6 pr-2 font-mono text-[10px] text-ink placeholder-ink-muted bg-transparent border border-edge focus:ring-2 focus:ring-accent/50 focus:border-accent"
+ />
+ <Show when={isDropdownOpen()}>
+ <div
+ ref={dropdownRef}
+ class="absolute left-0 right-0 top-full mt-1 border border-edge bg-menu shadow-lg max-h-48 overflow-y-auto font-mono z-1"
+ >
+ <Show
+ when={filteredProperties().length > 0}
+ fallback={
+ <div class="px-3 py-2 text-[10px] text-ink-muted text-center">
+ No filterable properties found
+ </div>
+ }
+ >
+ <For each={filteredProperties()}>
+ {(property) => (
+ <button
+ type="button"
+ onMouseDown={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ handleSelectProperty(property);
+ }}
+ class="w-full px-2 py-1.5 text-[10px] text-ink hover:bg-hover flex items-center gap-2 text-left"
+ >
+ <PropertyDataTypeIcon property={property} />
+ <span class="truncate flex-1">{property.display_name}</span>
+ </button>
+ )}
+ </For>
+ </Show>
+ </div>
+ </Show>
+ </div>
+ );
+};
diff --git a/js/app/packages/app/component/PropertyFilter/FilterPropertyPill.tsx b/js/app/packages/app/component/PropertyFilter/FilterPropertyPill.tsx
new file mode 100644
index 0000000000..b07ef519ce
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterPropertyPill.tsx
@@ -0,0 +1,629 @@
+import { PropertyDataTypeIcon } from '@core/component/Properties/utils/PropertyDataTypeIcon';
+import CheckIcon from '@phosphor-icons/core/assets/regular/check.svg';
+import XIcon from '@phosphor-icons/core/assets/regular/x.svg';
+import type { PropertyDefinition } from '@service-properties/generated/schemas/propertyDefinition';
+import type { Component } from 'solid-js';
+import { createSignal, Match, Show, Switch } from 'solid-js';
+import type {
+ EntityFilterValue,
+ FilterAction,
+ PropertyFilter,
+} from '../PropertyFilterTypes';
+import {
+ ComparisonAction,
+ ContainsAction,
+ EqualityAction,
+} from '../PropertyFilterTypes';
+
+// Type guards for action types
+const isEqualityAction = (a: FilterAction): a is EqualityAction =>
+ a === EqualityAction.EQUAL || a === EqualityAction.NOT_EQUAL;
+
+const isComparisonActionType = (a: FilterAction): a is ComparisonAction =>
+ a === ComparisonAction.GREATER_THAN ||
+ a === ComparisonAction.GREATER_THAN_OR_EQUAL ||
+ a === ComparisonAction.LESS_THAN ||
+ a === ComparisonAction.LESS_THAN_OR_EQUAL;
+
+const isContainsAction = (a: FilterAction): a is ContainsAction =>
+ a === ContainsAction.HAS_ANY ||
+ a === ContainsAction.HAS_ALL ||
+ a === ContainsAction.DOES_NOT_HAVE;
+import { FilterActionSelect } from './FilterAction';
+import { FilterPropertySelect } from './FilterProperty';
+import { FilterValueBoolean } from './FilterValueBoolean';
+import { FilterValueDate } from './FilterValueDate';
+import { FilterValueDateMulti } from './FilterValueDateMulti';
+import { FilterValueEntity } from './FilterValueEntity';
+import { FilterValueNumber } from './FilterValueNumber';
+import { FilterValueNumberMulti } from './FilterValueNumberMulti';
+import { FilterValueSelect } from './FilterValueSelect';
+import { FilterValueSelectMulti } from './FilterValueSelectMulti';
+
+type FilterPillProps = {
+ id: string;
+ savedData: PropertyFilter | null; // null = pending, non-null = saved
+ /** Property definition for restoring saved filters (looked up by parent) */
+ initialProperty?: PropertyDefinition;
+ onSave: (data: PropertyFilter) => void;
+ onCancel: () => void;
+};
+
+export const FilterPropertyPill: Component<FilterPillProps> = (props) => {
+ // Initialize state from savedData if available
+ const initBooleanValue = (): boolean | null => {
+ if (props.savedData?.dataType === 'BOOLEAN' && 'value' in props.savedData) {
+ return props.savedData.value as boolean;
+ }
+ return null;
+ };
+
+ const initDateValue = (): string | null => {
+ if (props.savedData?.dataType === 'DATE' && 'value' in props.savedData) {
+ return props.savedData.value as string;
+ }
+ return null;
+ };
+
+ const initDateValues = (): string[] => {
+ if (props.savedData?.dataType === 'DATE' && 'values' in props.savedData) {
+ return props.savedData.values as string[];
+ }
+ return [];
+ };
+
+ const initNumberValue = (): number | null => {
+ if (props.savedData?.dataType === 'NUMBER' && 'value' in props.savedData) {
+ return props.savedData.value as number;
+ }
+ return null;
+ };
+
+ const initNumberValues = (): number[] => {
+ if (props.savedData?.dataType === 'NUMBER' && 'values' in props.savedData) {
+ return props.savedData.values as number[];
+ }
+ return [];
+ };
+
+ const initSelectValue = (): string | null => {
+ if (
+ (props.savedData?.dataType === 'SELECT_STRING' ||
+ props.savedData?.dataType === 'SELECT_NUMBER') &&
+ 'value' in props.savedData
+ ) {
+ return String(props.savedData.value);
+ }
+ return null;
+ };
+
+ const initSelectValues = (): string[] => {
+ if (
+ (props.savedData?.dataType === 'SELECT_STRING' ||
+ props.savedData?.dataType === 'SELECT_NUMBER') &&
+ 'values' in props.savedData
+ ) {
+ return (props.savedData.values as (string | number)[]).map(String);
+ }
+ return [];
+ };
+
+ const initEntityValues = (): EntityFilterValue[] => {
+ if (props.savedData?.dataType === 'ENTITY' && 'values' in props.savedData) {
+ return props.savedData.values as EntityFilterValue[];
+ }
+ return [];
+ };
+
+ // Internal editing state - initialized from props
+ const [selectedProperty, setSelectedProperty] =
+ createSignal<PropertyDefinition | null>(props.initialProperty ?? null);
+ const [action, setAction] = createSignal<FilterAction | null>(
+ props.savedData?.action ?? null
+ );
+ const [values, _setValues] = createSignal<string[]>([]);
+ const [booleanValue, setBooleanValue] = createSignal<boolean | null>(
+ initBooleanValue()
+ );
+ const [dateValue, setDateValue] = createSignal<string | null>(
+ initDateValue()
+ );
+ const [dateValues, setDateValues] = createSignal<string[]>(initDateValues());
+ const [numberValue, setNumberValue] = createSignal<number | null>(
+ initNumberValue()
+ );
+ const [numberValues, setNumberValues] = createSignal<number[]>(
+ initNumberValues()
+ );
+ const [selectValue, setSelectValue] = createSignal<string | null>(
+ initSelectValue()
+ );
+ const [selectValues, setSelectValues] = createSignal<string[]>(
+ initSelectValues()
+ );
+ const [entityValues, setEntityValues] = createSignal<EntityFilterValue[]>(
+ initEntityValues()
+ );
+
+ // Track if user is editing property (to show search instead of pill)
+ const [previousProperty, setPreviousProperty] =
+ createSignal<PropertyDefinition | null>(null);
+
+ const isPending = () => props.savedData === null;
+
+ // Helper to check if action is a comparison
+ const isComparisonAction = (a: FilterAction | null) =>
+ a === ComparisonAction.GREATER_THAN ||
+ a === ComparisonAction.GREATER_THAN_OR_EQUAL ||
+ a === ComparisonAction.LESS_THAN ||
+ a === ComparisonAction.LESS_THAN_OR_EQUAL;
+
+ // Check if value is set based on data type
+ const hasValue = () => {
+ const property = selectedProperty();
+ if (!property) return false;
+
+ if (property.data_type === 'BOOLEAN') {
+ return booleanValue() !== null;
+ }
+ if (property.data_type === 'DATE') {
+ if (isComparisonAction(action())) {
+ return dateValue() !== null;
+ }
+ return dateValues().length > 0; // Equality actions use multi-date
+ }
+ if (property.data_type === 'NUMBER') {
+ if (isComparisonAction(action())) {
+ return numberValue() !== null;
+ }
+ return numberValues().length > 0; // Equality actions use multi-number
+ }
+ if (
+ property.data_type === 'SELECT_STRING' ||
+ property.data_type === 'SELECT_NUMBER'
+ ) {
+ if (isComparisonAction(action())) {
+ return selectValue() !== null;
+ }
+ return selectValues().length > 0; // Equality actions use multi-select
+ }
+ if (property.data_type === 'ENTITY') {
+ return entityValues().length > 0;
+ }
+ return values().length > 0;
+ };
+
+ const canConfirm = () => selectedProperty() && action() && hasValue();
+
+ const handleSelectProperty = (property: PropertyDefinition) => {
+ // Only clear action/values if property actually changed
+ const prev = previousProperty();
+ if (prev && prev.id !== property.id) {
+ setAction(null);
+ setBooleanValue(null);
+ setDateValue(null);
+ setDateValues([]);
+ setNumberValue(null);
+ setNumberValues([]);
+ setSelectValue(null);
+ setSelectValues([]);
+ setEntityValues([]);
+ _setValues([]);
+ }
+ setSelectedProperty(property);
+ setPreviousProperty(null);
+ };
+
+ const handleStartEditProperty = () => {
+ setPreviousProperty(selectedProperty());
+ setSelectedProperty(null);
+ // Don't clear action here - we might select the same property
+ };
+
+ const handleCancelEditProperty = () => {
+ // Restore previous property if we were editing
+ if (previousProperty()) {
+ setSelectedProperty(previousProperty());
+ }
+ setPreviousProperty(null);
+ };
+
+ const handleSelectAction = (selectedAction: FilterAction) => {
+ setAction(selectedAction);
+
+ // Auto-save to store when action is selected
+ const property = selectedProperty();
+ if (property) {
+ // Build partial filter with current values
+ const filter = buildPartialFilter(property, selectedAction);
+ if (filter) {
+ props.onSave(filter);
+ }
+ }
+ };
+
+ const handleValueChange = (value: boolean | string | number) => {
+ const property = selectedProperty();
+ if (!property) return;
+
+ // Set the appropriate value based on data type
+ if (property.data_type === 'BOOLEAN' && typeof value === 'boolean') {
+ setBooleanValue(value);
+ } else if (property.data_type === 'DATE' && typeof value === 'string') {
+ setDateValue(value);
+ } else if (property.data_type === 'NUMBER' && typeof value === 'number') {
+ setNumberValue(value);
+ } else if (
+ (property.data_type === 'SELECT_STRING' ||
+ property.data_type === 'SELECT_NUMBER') &&
+ typeof value === 'string'
+ ) {
+ setSelectValue(value);
+ }
+
+ // Auto-save when value changes
+ const currentAction = action();
+ if (currentAction) {
+ const filter = buildPartialFilter(property, currentAction);
+ if (filter) {
+ props.onSave(filter);
+ }
+ }
+ };
+
+ // Handler for multi-date values
+ const handleDateValuesChange = (newValues: string[]) => {
+ setDateValues(newValues);
+
+ // Auto-save when values change
+ const property = selectedProperty();
+ const currentAction = action();
+ if (property && currentAction) {
+ const filter = buildPartialFilter(property, currentAction);
+ if (filter) {
+ props.onSave(filter);
+ }
+ }
+ };
+
+ // Handler for multi-number values
+ const handleNumberValuesChange = (newValues: number[]) => {
+ setNumberValues(newValues);
+
+ // Auto-save when values change
+ const property = selectedProperty();
+ const currentAction = action();
+ if (property && currentAction) {
+ const filter = buildPartialFilter(property, currentAction);
+ if (filter) {
+ props.onSave(filter);
+ }
+ }
+ };
+
+ // Handler for multi-select values
+ const handleSelectValuesChange = (newValues: string[]) => {
+ setSelectValues(newValues);
+
+ // Auto-save when values change
+ const property = selectedProperty();
+ const currentAction = action();
+ if (property && currentAction) {
+ const filter = buildPartialFilter(property, currentAction);
+ if (filter) {
+ props.onSave(filter);
+ }
+ }
+ };
+
+ // Handler for entity values
+ const handleEntityValuesChange = (newValues: EntityFilterValue[]) => {
+ setEntityValues(newValues);
+
+ // Auto-save when values change
+ const property = selectedProperty();
+ const currentAction = action();
+ if (property && currentAction) {
+ const filter = buildPartialFilter(property, currentAction);
+ if (filter) {
+ props.onSave(filter);
+ }
+ }
+ };
+
+ const handleConfirm = () => {
+ if (!canConfirm()) return;
+ const property = selectedProperty();
+ const currentAction = action();
+ if (!property || !currentAction) return;
+
+ // Build filter with actual values
+ const filter = buildPartialFilter(property, currentAction, values());
+ if (filter) {
+ props.onSave(filter);
+ }
+ };
+
+ // Build a PropertyFilter from the current state
+ const buildPartialFilter = (
+ property: PropertyDefinition,
+ filterAction: FilterAction,
+ _filterValues: string[] = []
+ ): PropertyFilter | null => {
+ const dataType = property.data_type;
+ const propertyId = property.id;
+
+ switch (dataType) {
+ case 'BOOLEAN':
+ if (!isEqualityAction(filterAction)) return null;
+ return {
+ propertyId,
+ dataType: 'BOOLEAN',
+ action: filterAction,
+ value: booleanValue() ?? false,
+ };
+ case 'DATE':
+ if (isComparisonActionType(filterAction)) {
+ return {
+ propertyId,
+ dataType: 'DATE',
+ action: filterAction,
+ value: dateValue() ?? '',
+ };
+ }
+ if (isEqualityAction(filterAction)) {
+ return {
+ propertyId,
+ dataType: 'DATE',
+ action: filterAction,
+ values: dateValues(),
+ };
+ }
+ return null;
+ case 'NUMBER':
+ if (isComparisonActionType(filterAction)) {
+ return {
+ propertyId,
+ dataType: 'NUMBER',
+ action: filterAction,
+ value: numberValue() ?? 0,
+ };
+ }
+ if (isEqualityAction(filterAction)) {
+ return {
+ propertyId,
+ dataType: 'NUMBER',
+ action: filterAction,
+ values: numberValues(),
+ };
+ }
+ return null;
+ case 'SELECT_NUMBER':
+ case 'SELECT_STRING':
+ if (isComparisonActionType(filterAction)) {
+ return {
+ propertyId,
+ dataType,
+ action: filterAction,
+ value: selectValue() ?? '',
+ };
+ }
+ if (isEqualityAction(filterAction)) {
+ return {
+ propertyId,
+ dataType,
+ action: filterAction,
+ values: selectValues(),
+ };
+ }
+ if (isContainsAction(filterAction)) {
+ return {
+ propertyId,
+ dataType,
+ action: filterAction,
+ values: selectValues(),
+ };
+ }
+ return null;
+ case 'ENTITY':
+ if (isEqualityAction(filterAction)) {
+ return {
+ propertyId,
+ dataType: 'ENTITY',
+ action: filterAction,
+ values: entityValues(),
+ };
+ }
+ if (isContainsAction(filterAction)) {
+ return {
+ propertyId,
+ dataType: 'ENTITY',
+ action: filterAction,
+ values: entityValues(),
+ };
+ }
+ return null;
+ default:
+ return null;
+ }
+ };
+
+ return (
+ <Show
+ when={selectedProperty()}
+ fallback={
+ <div class="flex items-center gap-0.5 w-full">
+ <FilterPropertySelect
+ onSelectProperty={handleSelectProperty}
+ onCancel={handleCancelEditProperty}
+ />
+ {/* Cancel/Remove button */}
+ <button
+ type="button"
+ onClick={props.onCancel}
+ class="h-6 w-6 flex items-center justify-center text-ink hover:text-failure-ink hover:bg-hover"
+ >
+ <XIcon class="size-3" />
+ </button>
+ </div>
+ }
+ >
+ <div class="flex items-start gap-0.5">
+ {/* Property pill */}
+ <button
+ type="button"
+ onClick={handleStartEditProperty}
+ class="h-6 px-2 text-[10px] text-ink border border-edge hover:bg-hover text-left flex items-center gap-1.5 font-mono shrink-0"
+ >
+ <PropertyDataTypeIcon
+ property={selectedProperty()!}
+ class="size-3.5 shrink-0"
+ />
+ <span class="truncate max-w-[120px]">
+ {selectedProperty()!.display_name}
+ </span>
+ </button>
+
+ {/* Action dropdown */}
+ <div class="shrink-0">
+ <FilterActionSelect
+ property={selectedProperty()!}
+ selectedAction={action()}
+ onSelectAction={handleSelectAction}
+ />
+ </div>
+
+ {/* Value input - only show after action is set */}
+ <Show when={action()}>
+ <Switch
+ fallback={
+ <button
+ type="button"
+ class="h-6 px-2 w-fit text-[10px] text-ink-muted font-mono border border-edge hover:bg-hover text-left flex items-center"
+ >
+ {values().length > 0 ? values().join(', ') : '...'}
+ </button>
+ }
+ >
+ <Match when={selectedProperty()?.data_type === 'BOOLEAN'}>
+ <FilterValueBoolean
+ value={booleanValue()}
+ onSelect={handleValueChange}
+ />
+ </Match>
+ <Match
+ when={
+ selectedProperty()?.data_type === 'DATE' &&
+ isComparisonAction(action())
+ }
+ >
+ <FilterValueDate
+ value={dateValue()}
+ onChange={handleValueChange}
+ />
+ </Match>
+ <Match
+ when={
+ selectedProperty()?.data_type === 'DATE' &&
+ !isComparisonAction(action())
+ }
+ >
+ <FilterValueDateMulti
+ values={dateValues()}
+ onChange={handleDateValuesChange}
+ />
+ </Match>
+ <Match
+ when={
+ selectedProperty()?.data_type === 'NUMBER' &&
+ isComparisonAction(action())
+ }
+ >
+ <FilterValueNumber
+ value={numberValue()}
+ onChange={handleValueChange}
+ />
+ </Match>
+ <Match
+ when={
+ selectedProperty()?.data_type === 'NUMBER' &&
+ !isComparisonAction(action())
+ }
+ >
+ <FilterValueNumberMulti
+ values={numberValues()}
+ onChange={handleNumberValuesChange}
+ />
+ </Match>
+ <Match
+ when={
+ (selectedProperty()?.data_type === 'SELECT_STRING' ||
+ selectedProperty()?.data_type === 'SELECT_NUMBER') &&
+ isComparisonAction(action())
+ }
+ >
+ <FilterValueSelect
+ propertyId={selectedProperty()!.id}
+ dataType={
+ selectedProperty()!.data_type as
+ | 'SELECT_STRING'
+ | 'SELECT_NUMBER'
+ }
+ value={selectValue()}
+ onChange={handleValueChange}
+ />
+ </Match>
+ <Match
+ when={
+ (selectedProperty()?.data_type === 'SELECT_STRING' ||
+ selectedProperty()?.data_type === 'SELECT_NUMBER') &&
+ !isComparisonAction(action())
+ }
+ >
+ <FilterValueSelectMulti
+ propertyId={selectedProperty()!.id}
+ dataType={
+ selectedProperty()!.data_type as
+ | 'SELECT_STRING'
+ | 'SELECT_NUMBER'
+ }
+ values={selectValues()}
+ onChange={handleSelectValuesChange}
+ />
+ </Match>
+ <Match when={selectedProperty()?.data_type === 'ENTITY'}>
+ <FilterValueEntity
+ specificEntityType={selectedProperty()!.specific_entity_type!}
+ values={entityValues()}
+ onChange={handleEntityValuesChange}
+ />
+ </Match>
+ </Switch>
+ </Show>
+
+ {/* Confirm button - only show when pending and all fields filled */}
+ <Show when={action() && hasValue() && isPending()}>
+ <button
+ type="button"
+ onClick={handleConfirm}
+ disabled={!canConfirm()}
+ class="h-6 w-6 flex items-center justify-center text-ink hover:bg-hover border border-edge disabled:opacity-50 disabled:cursor-not-allowed shrink-0"
+ >
+ <CheckIcon class="size-4" />
+ </button>
+ </Show>
+
+ {/* Cancel/Remove button */}
+ <button
+ type="button"
+ onClick={props.onCancel}
+ class="h-6 w-6 flex items-center justify-center text-ink hover:text-failure-ink hover:bg-hover shrink-0"
+ >
+ <XIcon class="size-3" />
+ </button>
+ </div>
+ </Show>
+ );
+};
+
+export default FilterPropertyPill;
diff --git a/js/app/packages/app/component/PropertyFilter/FilterValueBoolean.tsx b/js/app/packages/app/component/PropertyFilter/FilterValueBoolean.tsx
new file mode 100644
index 0000000000..002698544b
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterValueBoolean.tsx
@@ -0,0 +1,94 @@
+import type { Component } from 'solid-js';
+import { createSignal, onCleanup, onMount, Show } from 'solid-js';
+
+export type FilterValueBooleanProps = {
+ value: boolean | null;
+ onSelect: (value: boolean) => void;
+};
+
+export const FilterValueBoolean: Component<FilterValueBooleanProps> = (
+ props
+) => {
+ const [isOpen, setIsOpen] = createSignal(false);
+
+ let containerRef!: HTMLDivElement;
+ let dropdownRef!: HTMLDivElement;
+
+ const handleSelect = (value: boolean) => {
+ props.onSelect(value);
+ setIsOpen(false);
+ };
+
+ // Close dropdown when clicking outside
+ const handleClickOutside = (event: MouseEvent) => {
+ if (!isOpen()) return;
+ const target = event.target;
+ if (!(target instanceof Node)) return;
+
+ const isInsideContainer = containerRef?.contains(target);
+ const isInsideDropdown = dropdownRef?.contains(target);
+
+ if (!isInsideContainer && !isInsideDropdown) {
+ setIsOpen(false);
+ }
+ };
+
+ onMount(() => {
+ document.addEventListener('mousedown', handleClickOutside);
+ onCleanup(() =>
+ document.removeEventListener('mousedown', handleClickOutside)
+ );
+ });
+
+ const displayValue = () => {
+ if (props.value === null) return 'Select...';
+ return props.value ? 'True' : 'False';
+ };
+
+ return (
+ <div ref={containerRef} class="flex relative">
+ <button
+ type="button"
+ onClick={() => setIsOpen(!isOpen())}
+ class="h-6 px-2 w-fit text-[10px] border border-edge hover:bg-hover text-left font-mono flex items-center"
+ classList={{
+ 'text-ink': props.value !== null,
+ 'text-ink-muted': props.value === null,
+ }}
+ >
+ {displayValue()}
+ </button>
+ <Show when={isOpen()}>
+ <div
+ ref={dropdownRef}
+ class="absolute left-0 top-full mt-1 border border-edge bg-menu shadow-lg font-mono min-w-[80px] z-1"
+ >
+ <button
+ type="button"
+ onMouseDown={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ handleSelect(true);
+ }}
+ class="w-full px-2 py-1.5 text-[10px] text-ink hover:bg-hover text-left"
+ classList={{ 'bg-hover': props.value === true }}
+ >
+ True
+ </button>
+ <button
+ type="button"
+ onMouseDown={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ handleSelect(false);
+ }}
+ class="w-full px-2 py-1.5 text-[10px] text-ink hover:bg-hover text-left"
+ classList={{ 'bg-hover': props.value === false }}
+ >
+ False
+ </button>
+ </div>
+ </Show>
+ </div>
+ );
+};
diff --git a/js/app/packages/app/component/PropertyFilter/FilterValueDate.tsx b/js/app/packages/app/component/PropertyFilter/FilterValueDate.tsx
new file mode 100644
index 0000000000..8d8c2fcf64
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterValueDate.tsx
@@ -0,0 +1,72 @@
+import { DatePicker } from '@core/component/DatePicker';
+import type { Component } from 'solid-js';
+import { createSignal, Show } from 'solid-js';
+
+export type FilterValueDateProps = {
+ value: string | null; // ISO date string or null
+ onChange: (value: string) => void;
+};
+
+export const FilterValueDate: Component<FilterValueDateProps> = (props) => {
+ const [isOpen, setIsOpen] = createSignal(false);
+ let buttonRef!: HTMLButtonElement;
+
+ // Parse YYYY-MM-DD as local date (not UTC)
+ const parseLocalDate = (dateStr: string): Date => {
+ const [year, month, day] = dateStr.split('-').map(Number);
+ return new Date(year, month - 1, day);
+ };
+
+ // Format Date as YYYY-MM-DD using local date components (not UTC)
+ const formatLocalDate = (date: Date): string => {
+ const year = date.getFullYear();
+ const month = String(date.getMonth() + 1).padStart(2, '0');
+ const day = String(date.getDate()).padStart(2, '0');
+ return `${year}-${month}-${day}`;
+ };
+
+ const dateValue = () => {
+ if (!props.value) return new Date();
+ return parseLocalDate(props.value);
+ };
+
+ const displayValue = () => {
+ if (!props.value) return 'Select date...';
+ const date = parseLocalDate(props.value);
+ return date.toLocaleDateString('en-US', {
+ month: 'short',
+ day: 'numeric',
+ year: 'numeric',
+ });
+ };
+
+ const handleDateChange = (date: Date) => {
+ props.onChange(formatLocalDate(date));
+ setIsOpen(false);
+ };
+
+ return (
+ <div class="relative">
+ <button
+ ref={buttonRef}
+ type="button"
+ onClick={() => setIsOpen(true)}
+ class="h-6 px-2 w-fit text-[10px] border border-edge hover:bg-hover text-left font-mono flex items-center"
+ classList={{
+ 'text-ink': props.value !== null,
+ 'text-ink-muted': props.value === null,
+ }}
+ >
+ {displayValue()}
+ </button>
+ <Show when={isOpen()}>
+ <DatePicker
+ value={dateValue()}
+ onChange={handleDateChange}
+ onClose={() => setIsOpen(false)}
+ anchorRef={buttonRef}
+ />
+ </Show>
+ </div>
+ );
+};
diff --git a/js/app/packages/app/component/PropertyFilter/FilterValueDateMulti.tsx b/js/app/packages/app/component/PropertyFilter/FilterValueDateMulti.tsx
new file mode 100644
index 0000000000..5f2d2273bc
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterValueDateMulti.tsx
@@ -0,0 +1,94 @@
+import { DatePicker } from '@core/component/DatePicker';
+import XIcon from '@phosphor-icons/core/assets/regular/x.svg';
+import type { Component } from 'solid-js';
+import { createSignal, For, Show } from 'solid-js';
+
+export type FilterValueDateMultiProps = {
+ values: string[]; // Array of ISO date strings
+ onChange: (values: string[]) => void;
+};
+
+export const FilterValueDateMulti: Component<FilterValueDateMultiProps> = (
+ props
+) => {
+ const [isPickerOpen, setIsPickerOpen] = createSignal(false);
+ let addButtonRef!: HTMLButtonElement;
+
+ // Parse YYYY-MM-DD as local date (not UTC)
+ const parseLocalDate = (dateStr: string): Date => {
+ const [year, month, day] = dateStr.split('-').map(Number);
+ return new Date(year, month - 1, day);
+ };
+
+ // Format Date as YYYY-MM-DD using local date components (not UTC)
+ const formatLocalDate = (date: Date): string => {
+ const year = date.getFullYear();
+ const month = String(date.getMonth() + 1).padStart(2, '0');
+ const day = String(date.getDate()).padStart(2, '0');
+ return `${year}-${month}-${day}`;
+ };
+
+ // Format for display (shorter)
+ const formatDisplayDate = (dateStr: string): string => {
+ const date = parseLocalDate(dateStr);
+ return date.toLocaleDateString('en-US', {
+ month: 'short',
+ day: 'numeric',
+ year: 'numeric',
+ });
+ };
+
+ const handleAddDate = (date: Date) => {
+ const dateStr = formatLocalDate(date);
+ // Don't add duplicates
+ if (!props.values.includes(dateStr)) {
+ props.onChange([...props.values, dateStr]);
+ }
+ setIsPickerOpen(false);
+ };
+
+ const handleRemoveDate = (dateStr: string) => {
+ props.onChange(props.values.filter((d) => d !== dateStr));
+ };
+
+ return (
+ <div class="flex flex-wrap items-center gap-0.5 min-w-0">
+ {/* Selected date pills */}
+ <For each={props.values}>
+ {(dateStr) => (
+ <div class="group relative h-6 px-1.5 text-[10px] text-ink border border-edge bg-panel font-mono flex items-center">
+ <span class="whitespace-nowrap">{formatDisplayDate(dateStr)}</span>
+ {/* X shows on hover, overlays the text */}
+ <button
+ type="button"
+ onClick={() => handleRemoveDate(dateStr)}
+ class="absolute inset-0 flex items-center justify-end pr-1 bg-gradient-to-l from-panel via-panel to-transparent opacity-0 group-hover:opacity-100 hover:text-failure-ink"
+ >
+ <XIcon class="size-3" />
+ </button>
+ </div>
+ )}
+ </For>
+
+ {/* Add button */}
+ <div class="relative">
+ <button
+ ref={addButtonRef}
+ type="button"
+ onClick={() => setIsPickerOpen(true)}
+ class="h-6 px-2 text-[10px] text-ink-muted border border-edge hover:bg-hover font-mono flex items-center"
+ >
+ {props.values.length === 0 ? 'Add date...' : '+'}
+ </button>
+ <Show when={isPickerOpen()}>
+ <DatePicker
+ value={new Date()}
+ onChange={handleAddDate}
+ onClose={() => setIsPickerOpen(false)}
+ anchorRef={addButtonRef}
+ />
+ </Show>
+ </div>
+ </div>
+ );
+};
diff --git a/js/app/packages/app/component/PropertyFilter/FilterValueEntity.tsx b/js/app/packages/app/component/PropertyFilter/FilterValueEntity.tsx
new file mode 100644
index 0000000000..cbc0434e17
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterValueEntity.tsx
@@ -0,0 +1,356 @@
+import { useChannelsContext } from '@core/component/ChannelsProvider';
+import {
+ type CombinedEntity,
+ ENTITY_SEARCH_CONFIG,
+ entityMapper,
+ getEntityName,
+ getEntitySearchText,
+ getEntityType,
+ threadMapper,
+} from '@core/component/Properties/component/modal/shared/entityUtils';
+import { usePropertyEntityDisplay } from '@core/component/Properties/hooks/usePropertyEntityDisplay';
+import { useContacts } from '@core/user';
+import { createFreshSearch } from '@core/util/freshSort';
+import {
+ createEmailsInfiniteQuery,
+ createUnifiedSearchInfiniteQuery,
+ type EmailEntity,
+} from '@macro-entity';
+import XIcon from '@phosphor-icons/core/assets/regular/x.svg';
+import type { EntityType } from '@service-properties/generated/schemas/entityType';
+import { useHistory } from '@service-storage/history';
+import { debounce } from '@solid-primitives/scheduled';
+import type { Component } from 'solid-js';
+import {
+ createEffect,
+ createMemo,
+ createSignal,
+ For,
+ onCleanup,
+ onMount,
+ Show,
+} from 'solid-js';
+import type { EntityFilterValue } from '../PropertyFilterTypes';
+
+export type FilterValueEntityProps = {
+ specificEntityType: EntityType;
+ values: EntityFilterValue[];
+ onChange: (values: EntityFilterValue[]) => void;
+};
+
+/** Pill component that uses usePropertyEntityDisplay for proper name/icon resolution */
+const EntityPill: Component<{
+ value: EntityFilterValue;
+ onRemove: () => void;
+}> = (props) => {
+ const { name, icon, isLoading } = usePropertyEntityDisplay(
+ () => props.value.entityId,
+ () => props.value.entityType
+ );
+
+ return (
+ <div class="group relative h-6 px-1.5 text-[10px] text-ink border border-edge bg-panel font-mono flex items-center gap-1.5">
+ <span class="size-3 flex items-center justify-center shrink-0">
+ {icon()}
+ </span>
+ <span class="whitespace-nowrap max-w-[80px] truncate">
+ {isLoading() ? 'Loading...' : name()}
+ </span>
+ {/* X shows on hover, overlays the text */}
+ <button
+ type="button"
+ onClick={props.onRemove}
+ class="absolute inset-0 flex items-center justify-end pr-1 bg-gradient-to-l from-panel via-panel to-transparent opacity-0 group-hover:opacity-100 hover:text-failure-ink"
+ >
+ <XIcon class="size-3" />
+ </button>
+ </div>
+ );
+};
+
+export const FilterValueEntity: Component<FilterValueEntityProps> = (props) => {
+ const [isAdding, setIsAdding] = createSignal(false);
+ const [searchQuery, setSearchQuery] = createSignal('');
+ const [searchTerm, setSearchTerm] = createSignal('');
+
+ // Debounce search term updates (same as PropertyEntitySelector)
+ const debouncedSetSearchTerm = debounce(
+ (term: string) => setSearchTerm(term.toLowerCase()),
+ 60
+ );
+ createEffect(() => debouncedSetSearchTerm(searchQuery()));
+
+ let inputRef!: HTMLInputElement;
+ let containerRef!: HTMLDivElement;
+ let dropdownRef!: HTMLDivElement;
+
+ // Data sources (same pattern as PropertyEntitySelector)
+ const contacts = useContacts();
+ const channelsContext = useChannelsContext();
+ const channels = () => channelsContext.channels();
+ const history = useHistory();
+
+ // Email queries for THREAD type or generic ENTITY (no specific type)
+ const needsEmailSearch = () =>
+ props.specificEntityType === 'THREAD' || !props.specificEntityType;
+
+ const emailsQuery = createEmailsInfiniteQuery(() => ({ view: 'all' }), {
+ disabled: () => !needsEmailSearch(),
+ });
+ const emails = () => emailsQuery.data ?? [];
+
+ // Server-side email search
+ const emailSearchQuery = createUnifiedSearchInfiniteQuery(
+ () => ({
+ params: { page: 0, page_size: 20 },
+ request: {
+ query: searchTerm(),
+ match_type: 'partial' as const,
+ include: ['emails' as const],
+ search_on: 'name' as const,
+ },
+ }),
+ {
+ disabled: () => !needsEmailSearch(),
+ }
+ );
+
+ // Server search results mapped to our format
+ const serverEmails = createMemo((): CombinedEntity[] => {
+ if (emailSearchQuery.status !== 'success' || !emailSearchQuery.data) {
+ return [];
+ }
+ return emailSearchQuery.data
+ .filter((entity) => entity.type === 'email')
+ .map((entity) => threadMapper(entity as EmailEntity));
+ });
+
+ // Get entities based on specific entity type (same logic as PropertyEntitySelector)
+ const entities = createMemo((): CombinedEntity[] => {
+ const entityType = props.specificEntityType;
+
+ // Generic entity - include all types
+ if (!entityType) {
+ return [
+ ...contacts().map(entityMapper('user')),
+ ...history().map(entityMapper('item')),
+ ...channels().map(entityMapper('channel')),
+ ...emails().map(threadMapper),
+ ];
+ }
+
+ if (entityType === 'USER') {
+ return contacts().map(entityMapper('user'));
+ }
+
+ if (entityType === 'CHANNEL') {
+ return channels().map(entityMapper('channel'));
+ }
+
+ if (entityType === 'THREAD') {
+ return emails().map(threadMapper);
+ }
+
+ // Item-based types: DOCUMENT, PROJECT, CHAT
+ const itemTypes: EntityType[] = ['DOCUMENT', 'PROJECT', 'CHAT'];
+ if (itemTypes.includes(entityType)) {
+ return history()
+ .filter((item) => item.type.toUpperCase() === entityType)
+ .map(entityMapper('item'));
+ }
+
+ if (entityType === 'TASK') {
+ return history()
+ .filter(
+ (item) => item.type === 'document' && item.subType?.type === 'task'
+ )
+ .map(entityMapper('item'));
+ }
+
+ // COMPANY not yet implemented
+ return [];
+ });
+
+ // Search function for fuzzy matching (same config as PropertyEntitySelector)
+ const entitySearch = createFreshSearch<CombinedEntity>(
+ ENTITY_SEARCH_CONFIG,
+ getEntitySearchText
+ );
+
+ // Get selected entity IDs for filtering
+ const selectedIds = createMemo(
+ () => new Set(props.values.map((v) => v.entityId))
+ );
+
+ // Get available options (not already selected, filtered by search)
+ const availableEntities = createMemo(() => {
+ const query = searchTerm();
+ const ids = selectedIds();
+ const available = entities().filter((e) => !ids.has(e.id));
+
+ const MAX_RESULTS = 50;
+
+ if (!query) return available.slice(0, MAX_RESULTS);
+
+ // Local search results
+ const localResults = entitySearch(available, query)
+ .slice(0, MAX_RESULTS)
+ .map((result) => result.item);
+
+ // For THREAD or generic entity: merge local + server results (local first, server appended, deduped)
+ if (needsEmailSearch() && query) {
+ const localIds = new Set(localResults.map((e) => e.id));
+ const serverResults = serverEmails().filter(
+ (e) => !localIds.has(e.id) && !ids.has(e.id)
+ );
+ return [...localResults, ...serverResults].slice(0, MAX_RESULTS);
+ }
+
+ return localResults;
+ });
+
+ const handleAddClick = () => {
+ setIsAdding(true);
+ setSearchQuery('');
+ setTimeout(() => inputRef?.focus(), 0);
+ };
+
+ const handleSelectEntity = (entity: CombinedEntity) => {
+ if (!selectedIds().has(entity.id)) {
+ const newValue: EntityFilterValue = {
+ entityId: entity.id,
+ entityType: getEntityType(entity),
+ };
+ props.onChange([...props.values, newValue]);
+ }
+ setSearchQuery('');
+ setIsAdding(false);
+ };
+
+ const handleRemoveValue = (entityId: string) => {
+ props.onChange(props.values.filter((v) => v.entityId !== entityId));
+ };
+
+ // Close when clicking outside
+ const handleClickOutside = (event: MouseEvent) => {
+ if (!isAdding()) return;
+ const target = event.target;
+ if (!(target instanceof Node)) return;
+
+ const isInsideContainer = containerRef?.contains(target);
+ const isInsideDropdown = dropdownRef?.contains(target);
+
+ if (!isInsideContainer && !isInsideDropdown) {
+ setIsAdding(false);
+ setSearchQuery('');
+ }
+ };
+
+ onMount(() => {
+ document.addEventListener('mousedown', handleClickOutside);
+ onCleanup(() => {
+ document.removeEventListener('mousedown', handleClickOutside);
+ });
+ });
+
+ const getPlaceholderText = () => {
+ const type = props.specificEntityType?.toLowerCase() ?? '';
+ if (props.values.length === 0) {
+ return `Select ${type}...`;
+ }
+ return '+';
+ };
+
+ return (
+ <div class="flex flex-wrap items-center gap-0.5 min-w-0">
+ {/* Selected value pills - uses usePropertyEntityDisplay for proper resolution */}
+ <For each={props.values}>
+ {(value) => (
+ <EntityPill
+ value={value}
+ onRemove={() => handleRemoveValue(value.entityId)}
+ />
+ )}
+ </For>
+
+ {/* Add button / input */}
+ <div ref={containerRef} class="relative flex items-center">
+ <Show
+ when={isAdding()}
+ fallback={
+ <button
+ type="button"
+ onClick={handleAddClick}
+ class="h-6 px-2 text-[10px] text-ink-muted border border-edge hover:bg-hover font-mono flex items-center"
+ >
+ {getPlaceholderText()}
+ </button>
+ }
+ >
+ <input
+ ref={inputRef}
+ type="text"
+ value={searchQuery()}
+ onInput={(e) => setSearchQuery(e.currentTarget.value)}
+ placeholder="Search..."
+ class="h-6 px-2 min-w-16 w-fit text-[10px] text-ink border border-edge hover:bg-hover focus:ring-1 focus:ring-accent font-mono placeholder:text-ink-muted"
+ />
+ <div
+ ref={dropdownRef}
+ class="absolute left-0 top-full mt-1 border border-edge bg-menu shadow-lg font-mono min-w-[200px] max-h-48 overflow-y-auto z-1"
+ >
+ <Show
+ when={availableEntities().length > 0}
+ fallback={
+ <div class="px-3 py-2 text-[10px] text-ink-muted text-center">
+ {entities().length === 0
+ ? 'No entities available'
+ : searchQuery()
+ ? 'No matches'
+ : 'All selected'}
+ </div>
+ }
+ >
+ <For each={availableEntities()}>
+ {(entity) => (
+ <DropdownEntityRow
+ entity={entity}
+ onSelect={() => handleSelectEntity(entity)}
+ />
+ )}
+ </For>
+ </Show>
+ </div>
+ </Show>
+ </div>
+ </div>
+ );
+};
+
+/** Dropdown row that uses usePropertyEntityDisplay for proper icon resolution */
+const DropdownEntityRow: Component<{
+ entity: CombinedEntity;
+ onSelect: () => void;
+}> = (props) => {
+ const { icon } = usePropertyEntityDisplay(
+ () => props.entity.id,
+ () => getEntityType(props.entity)
+ );
+
+ return (
+ <button
+ type="button"
+ onMouseDown={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ props.onSelect();
+ }}
+ class="w-full px-2 py-1.5 text-[10px] text-ink hover:bg-hover text-left flex items-center gap-2"
+ >
+ <span class="size-3 flex items-center justify-center shrink-0">
+ {icon()}
+ </span>
+ <span class="truncate">{getEntityName(props.entity)}</span>
+ </button>
+ );
+};
diff --git a/js/app/packages/app/component/PropertyFilter/FilterValueNumber.tsx b/js/app/packages/app/component/PropertyFilter/FilterValueNumber.tsx
new file mode 100644
index 0000000000..82303924bc
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterValueNumber.tsx
@@ -0,0 +1,93 @@
+import type { Component } from 'solid-js';
+import { createSignal, Show } from 'solid-js';
+
+export type FilterValueNumberProps = {
+ value: number | null;
+ onChange: (value: number) => void;
+};
+
+export const FilterValueNumber: Component<FilterValueNumberProps> = (props) => {
+ const [isEditing, setIsEditing] = createSignal(false);
+ // Track local input value for controlled input
+ const [inputValue, setInputValue] = createSignal(
+ props.value !== null ? String(props.value) : ''
+ );
+ let inputRef!: HTMLInputElement;
+
+ const handleInput = (e: InputEvent) => {
+ const target = e.currentTarget as HTMLInputElement;
+ // Only allow digits, decimal point, and minus sign
+ const filtered = target.value.replace(/[^0-9.\-]/g, '');
+ // Prevent multiple decimals or minus signs
+ const parts = filtered.split('.');
+ const sanitized =
+ parts.length > 2
+ ? parts[0] + '.' + parts.slice(1).join('')
+ : filtered.replace(/(?!^)-/g, ''); // Only allow minus at start
+ setInputValue(sanitized);
+ target.value = sanitized; // Update DOM to match filtered value
+ };
+
+ const handleFocus = () => {
+ setIsEditing(true);
+ };
+
+ const handleBlur = () => {
+ const parsed = parseFloat(inputValue());
+ if (!isNaN(parsed)) {
+ props.onChange(parsed);
+ }
+ setIsEditing(false);
+ };
+
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.key === 'Enter') {
+ const parsed = parseFloat(inputValue());
+ if (!isNaN(parsed)) {
+ props.onChange(parsed);
+ }
+ }
+ };
+
+ const handleClick = () => {
+ setIsEditing(true);
+ setTimeout(() => inputRef?.focus(), 0);
+ };
+
+ const displayValue = () => {
+ if (props.value === null) return 'Value...';
+ return String(props.value);
+ };
+
+ return (
+ <Show
+ when={isEditing()}
+ fallback={
+ <button
+ type="button"
+ onClick={handleClick}
+ class="h-6 px-2 w-fit text-[10px] border border-edge hover:bg-hover text-left font-mono flex items-center"
+ classList={{
+ 'text-ink': props.value !== null,
+ 'text-ink-muted': props.value === null,
+ }}
+ >
+ {displayValue()}
+ </button>
+ }
+ >
+ <input
+ ref={inputRef}
+ type="text"
+ inputMode="decimal"
+ value={inputValue()}
+ onInput={handleInput}
+ onFocus={handleFocus}
+ onBlur={handleBlur}
+ onKeyDown={handleKeyDown}
+ placeholder="Enter value..."
+ class="h-6 px-2 min-w-8 w-fit text-[10px] text-ink border border-edge hover:bg-hover focus:ring-1 focus:ring-accent font-mono placeholder:text-ink-muted"
+ />
+ </Show>
+ );
+};
diff --git a/js/app/packages/app/component/PropertyFilter/FilterValueNumberMulti.tsx b/js/app/packages/app/component/PropertyFilter/FilterValueNumberMulti.tsx
new file mode 100644
index 0000000000..0104888512
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterValueNumberMulti.tsx
@@ -0,0 +1,107 @@
+import XIcon from '@phosphor-icons/core/assets/regular/x.svg';
+import type { Component } from 'solid-js';
+import { createSignal, For, Show } from 'solid-js';
+
+export type FilterValueNumberMultiProps = {
+ values: number[];
+ onChange: (values: number[]) => void;
+};
+
+export const FilterValueNumberMulti: Component<FilterValueNumberMultiProps> = (
+ props
+) => {
+ const [isAdding, setIsAdding] = createSignal(false);
+ const [inputValue, setInputValue] = createSignal('');
+ let inputRef!: HTMLInputElement;
+
+ const handleInput = (e: InputEvent) => {
+ const target = e.currentTarget as HTMLInputElement;
+ // Only allow digits, decimal point, and minus sign
+ const filtered = target.value.replace(/[^0-9.\-]/g, '');
+ // Prevent multiple decimals or minus signs
+ const parts = filtered.split('.');
+ const sanitized =
+ parts.length > 2
+ ? parts[0] + '.' + parts.slice(1).join('')
+ : filtered.replace(/(?!^)-/g, ''); // Only allow minus at start
+ setInputValue(sanitized);
+ target.value = sanitized;
+ };
+
+ const handleAddClick = () => {
+ setIsAdding(true);
+ setInputValue('');
+ setTimeout(() => inputRef?.focus(), 0);
+ };
+
+ const handleConfirm = () => {
+ const parsed = parseFloat(inputValue());
+ if (!isNaN(parsed) && !props.values.includes(parsed)) {
+ props.onChange([...props.values, parsed]);
+ }
+ setIsAdding(false);
+ setInputValue('');
+ };
+
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.key === 'Enter') {
+ handleConfirm();
+ } else if (e.key === 'Escape') {
+ setIsAdding(false);
+ setInputValue('');
+ }
+ };
+
+ const handleRemoveValue = (value: number) => {
+ props.onChange(props.values.filter((v) => v !== value));
+ };
+
+ return (
+ <div class="flex flex-wrap items-center gap-0.5 min-w-0">
+ {/* Selected value pills */}
+ <For each={props.values}>
+ {(value) => (
+ <div class="group relative h-6 px-1.5 text-[10px] text-ink border border-edge bg-panel font-mono flex items-center">
+ <span class="whitespace-nowrap">{String(value)}</span>
+ {/* X shows on hover, overlays the text */}
+ <button
+ type="button"
+ onClick={() => handleRemoveValue(value)}
+ class="absolute inset-0 flex items-center justify-end pr-1 bg-gradient-to-l from-panel via-panel to-transparent opacity-0 group-hover:opacity-100 hover:text-failure-ink"
+ >
+ <XIcon class="size-3" />
+ </button>
+ </div>
+ )}
+ </For>
+
+ {/* Add button / input */}
+ <div class="relative flex items-center">
+ <Show
+ when={isAdding()}
+ fallback={
+ <button
+ type="button"
+ onClick={handleAddClick}
+ class="h-6 px-2 text-[10px] text-ink-muted border border-edge hover:bg-hover font-mono flex items-center"
+ >
+ {props.values.length === 0 ? 'Add value...' : '+'}
+ </button>
+ }
+ >
+ <input
+ ref={inputRef}
+ type="text"
+ inputMode="decimal"
+ value={inputValue()}
+ onInput={handleInput}
+ onBlur={handleConfirm}
+ onKeyDown={handleKeyDown}
+ placeholder="Enter value..."
+ class="h-6 px-2 min-w-8 w-fit text-[10px] text-ink border border-edge hover:bg-hover focus:ring-1 focus:ring-accent font-mono placeholder:text-ink-muted"
+ />
+ </Show>
+ </div>
+ </div>
+ );
+};
diff --git a/js/app/packages/app/component/PropertyFilter/FilterValueSelect.tsx b/js/app/packages/app/component/PropertyFilter/FilterValueSelect.tsx
new file mode 100644
index 0000000000..6cf2bcc8d2
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterValueSelect.tsx
@@ -0,0 +1,182 @@
+import { isErr } from '@core/util/maybeResult';
+import { propertiesServiceClient } from '@service-properties/client';
+import type { PropertyOption } from '@service-properties/generated/schemas/propertyOption';
+import type { Component } from 'solid-js';
+import {
+ createMemo,
+ createSignal,
+ For,
+ onCleanup,
+ onMount,
+ Show,
+} from 'solid-js';
+
+export type FilterValueSelectProps = {
+ propertyId: string;
+ dataType: 'SELECT_STRING' | 'SELECT_NUMBER';
+ value: string | null; // option ID
+ onChange: (optionId: string) => void;
+};
+
+export const FilterValueSelect: Component<FilterValueSelectProps> = (props) => {
+ const [isEditing, setIsEditing] = createSignal(false);
+ const [options, setOptions] = createSignal<PropertyOption[]>([]);
+ const [isLoading, setIsLoading] = createSignal(true);
+ const [searchQuery, setSearchQuery] = createSignal('');
+
+ let inputRef!: HTMLInputElement;
+ let containerRef!: HTMLDivElement;
+ let dropdownRef!: HTMLDivElement;
+
+ // Fetch options for this property
+ const fetchOptions = async () => {
+ setIsLoading(true);
+ try {
+ const result = await propertiesServiceClient.getPropertyOptions({
+ definition_id: props.propertyId,
+ });
+
+ if (isErr(result)) {
+ setOptions([]);
+ return;
+ }
+
+ const [, data] = result;
+ setOptions(Array.isArray(data) ? data : []);
+ } catch (_error) {
+ setOptions([]);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ onMount(() => {
+ fetchOptions();
+ });
+
+ // Get display value for an option
+ const getOptionDisplayValue = (option: PropertyOption): string => {
+ if (option.value.type === 'string') {
+ return option.value.value;
+ }
+ return String(option.value.value);
+ };
+
+ // Get selected option display
+ const selectedDisplay = () => {
+ if (isLoading()) return '...';
+ if (!props.value) return 'Select...';
+ const option = options().find((o) => o.id === props.value);
+ if (!option) return 'Select...';
+ return getOptionDisplayValue(option);
+ };
+
+ // Filter options by search query
+ const filteredOptions = createMemo(() => {
+ const query = searchQuery().toLowerCase().trim();
+ if (!query) return options();
+ return options().filter((o) =>
+ getOptionDisplayValue(o).toLowerCase().includes(query)
+ );
+ });
+
+ const handleClick = () => {
+ setIsEditing(true);
+ setSearchQuery('');
+ setTimeout(() => inputRef?.focus(), 0);
+ };
+
+ const handleSelectOption = (option: PropertyOption) => {
+ props.onChange(option.id);
+ setSearchQuery('');
+ setIsEditing(false);
+ };
+
+ // Close when clicking outside
+ const handleClickOutside = (event: MouseEvent) => {
+ if (!isEditing()) return;
+ const target = event.target;
+ if (!(target instanceof Node)) return;
+
+ const isInsideContainer = containerRef?.contains(target);
+ const isInsideDropdown = dropdownRef?.contains(target);
+
+ if (!isInsideContainer && !isInsideDropdown) {
+ setIsEditing(false);
+ setSearchQuery('');
+ }
+ };
+
+ onMount(() => {
+ document.addEventListener('mousedown', handleClickOutside);
+ onCleanup(() => {
+ document.removeEventListener('mousedown', handleClickOutside);
+ });
+ });
+
+ return (
+ <div ref={containerRef} class="relative">
+ <Show
+ when={isEditing()}
+ fallback={
+ <button
+ type="button"
+ onClick={handleClick}
+ class="h-6 px-2 w-fit text-[10px] border border-edge hover:bg-hover text-left font-mono flex items-center"
+ classList={{
+ 'text-ink': props.value !== null,
+ 'text-ink-muted': props.value === null,
+ }}
+ >
+ {selectedDisplay()}
+ </button>
+ }
+ >
+ <input
+ ref={inputRef}
+ type="text"
+ value={searchQuery()}
+ onInput={(e) => setSearchQuery(e.currentTarget.value)}
+ placeholder="Search..."
+ class="h-6 px-2 min-w-16 w-fit text-[10px] text-ink border border-edge hover:bg-hover focus:ring-1 focus:ring-accent font-mono placeholder:text-ink-muted"
+ />
+ <div
+ ref={dropdownRef}
+ class="absolute left-0 top-full mt-1 border border-edge bg-menu shadow-lg font-mono min-w-[160px] max-h-48 overflow-y-auto z-1"
+ >
+ <Show
+ when={filteredOptions().length > 0}
+ fallback={
+ <div class="px-3 py-2 text-[10px] text-ink-muted text-center">
+ {isLoading()
+ ? 'Loading...'
+ : options().length === 0
+ ? 'No options available'
+ : 'No matches'}
+ </div>
+ }
+ >
+ <For each={filteredOptions()}>
+ {(option) => (
+ <button
+ type="button"
+ onMouseDown={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ handleSelectOption(option);
+ }}
+ class="w-full px-2 py-1.5 text-[10px] text-ink hover:bg-hover text-left"
+ classList={{
+ 'bg-hover': props.value === option.id,
+ }}
+ >
+ {getOptionDisplayValue(option)}
+ </button>
+ )}
+ </For>
+ </Show>
+ </div>
+ </Show>
+ </div>
+ );
+};
diff --git a/js/app/packages/app/component/PropertyFilter/FilterValueSelectMulti.tsx b/js/app/packages/app/component/PropertyFilter/FilterValueSelectMulti.tsx
new file mode 100644
index 0000000000..0c1aa09fbd
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/FilterValueSelectMulti.tsx
@@ -0,0 +1,223 @@
+import { isErr } from '@core/util/maybeResult';
+import XIcon from '@phosphor-icons/core/assets/regular/x.svg';
+import { propertiesServiceClient } from '@service-properties/client';
+import type { PropertyOption } from '@service-properties/generated/schemas/propertyOption';
+import type { Component } from 'solid-js';
+import {
+ createMemo,
+ createSignal,
+ For,
+ onCleanup,
+ onMount,
+ Show,
+} from 'solid-js';
+
+export type FilterValueSelectMultiProps = {
+ propertyId: string;
+ dataType: 'SELECT_STRING' | 'SELECT_NUMBER';
+ values: string[]; // Array of option IDs
+ onChange: (values: string[]) => void;
+};
+
+export const FilterValueSelectMulti: Component<FilterValueSelectMultiProps> = (
+ props
+) => {
+ const [isAdding, setIsAdding] = createSignal(false);
+ const [options, setOptions] = createSignal<PropertyOption[]>([]);
+ const [isLoading, setIsLoading] = createSignal(true);
+ const [searchQuery, setSearchQuery] = createSignal('');
+
+ let inputRef!: HTMLInputElement;
+ let containerRef!: HTMLDivElement;
+ let dropdownRef!: HTMLDivElement;
+
+ // Fetch options for this property
+ const fetchOptions = async () => {
+ setIsLoading(true);
+ try {
+ const result = await propertiesServiceClient.getPropertyOptions({
+ definition_id: props.propertyId,
+ });
+
+ if (isErr(result)) {
+ setOptions([]);
+ return;
+ }
+
+ const [, data] = result;
+ setOptions(Array.isArray(data) ? data : []);
+ } catch (_error) {
+ setOptions([]);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ onMount(() => {
+ fetchOptions();
+ });
+
+ // Get display value for an option
+ const getOptionDisplayValue = (option: PropertyOption): string => {
+ if (option.value.type === 'string') {
+ return option.value.value;
+ }
+ return String(option.value.value);
+ };
+
+ // Get option by ID
+ const getOptionById = (id: string): PropertyOption | undefined => {
+ return options().find((o) => o.id === id);
+ };
+
+ // Get available options (not already selected, filtered by search)
+ const availableOptions = createMemo(() => {
+ const query = searchQuery().toLowerCase().trim();
+ return options()
+ .filter((o) => !props.values.includes(o.id))
+ .filter((o) => {
+ if (!query) return true;
+ return getOptionDisplayValue(o).toLowerCase().includes(query);
+ });
+ });
+
+ const handleAddClick = () => {
+ setIsAdding(true);
+ setSearchQuery('');
+ setTimeout(() => inputRef?.focus(), 0);
+ };
+
+ const handleSelectOption = (option: PropertyOption) => {
+ if (!props.values.includes(option.id)) {
+ props.onChange([...props.values, option.id]);
+ }
+ setSearchQuery('');
+ setIsAdding(false);
+ };
+
+ const handleRemoveValue = (optionId: string) => {
+ props.onChange(props.values.filter((id) => id !== optionId));
+ };
+
+ // Close when clicking outside
+ const handleClickOutside = (event: MouseEvent) => {
+ if (!isAdding()) return;
+ const target = event.target;
+ if (!(target instanceof Node)) return;
+
+ const isInsideContainer = containerRef?.contains(target);
+ const isInsideDropdown = dropdownRef?.contains(target);
+
+ if (!isInsideContainer && !isInsideDropdown) {
+ setIsAdding(false);
+ setSearchQuery('');
+ }
+ };
+
+ onMount(() => {
+ document.addEventListener('mousedown', handleClickOutside);
+ onCleanup(() => {
+ document.removeEventListener('mousedown', handleClickOutside);
+ });
+ });
+
+ // Resolve display values for selected options
+ const getDisplayValue = (optionId: string): string => {
+ const option = getOptionById(optionId);
+ return option ? getOptionDisplayValue(option) : optionId;
+ };
+
+ return (
+ <div class="flex flex-wrap items-center gap-0.5 min-w-0">
+ {/* Selected value pills - show loading if we have values but options not loaded */}
+ <Show
+ when={!isLoading() || props.values.length === 0}
+ fallback={
+ <div class="h-6 px-1.5 text-[10px] text-ink-muted border border-edge font-mono flex items-center">
+ ...
+ </div>
+ }
+ >
+ <For each={props.values}>
+ {(optionId) => (
+ <div class="group relative h-6 px-1.5 text-[10px] text-ink border border-edge bg-panel font-mono flex items-center">
+ <span class="whitespace-nowrap">{getDisplayValue(optionId)}</span>
+ {/* X shows on hover, overlays the text */}
+ <button
+ type="button"
+ onClick={() => handleRemoveValue(optionId)}
+ class="absolute inset-0 flex items-center justify-end pr-1 bg-gradient-to-l from-panel via-panel to-transparent opacity-0 group-hover:opacity-100 hover:text-failure-ink"
+ >
+ <XIcon class="size-3" />
+ </button>
+ </div>
+ )}
+ </For>
+ </Show>
+
+ {/* Add button / input */}
+ <div ref={containerRef} class="relative flex items-center">
+ <Show
+ when={isAdding()}
+ fallback={
+ <button
+ type="button"
+ onClick={handleAddClick}
+ class="h-6 px-2 text-[10px] text-ink-muted border border-edge hover:bg-hover font-mono flex items-center"
+ >
+ {isLoading()
+ ? '...'
+ : props.values.length === 0
+ ? 'Select...'
+ : '+'}
+ </button>
+ }
+ >
+ <input
+ ref={inputRef}
+ type="text"
+ value={searchQuery()}
+ onInput={(e) => setSearchQuery(e.currentTarget.value)}
+ placeholder="Search..."
+ class="h-6 px-2 min-w-16 w-fit text-[10px] text-ink border border-edge hover:bg-hover focus:ring-1 focus:ring-accent font-mono placeholder:text-ink-muted"
+ />
+ <div
+ ref={dropdownRef}
+ class="absolute left-0 top-full mt-1 border border-edge bg-menu shadow-lg font-mono min-w-[160px] max-h-48 overflow-y-auto z-1"
+ >
+ <Show
+ when={availableOptions().length > 0}
+ fallback={
+ <div class="px-3 py-2 text-[10px] text-ink-muted text-center">
+ {isLoading()
+ ? 'Loading...'
+ : options().length === 0
+ ? 'No options available'
+ : searchQuery()
+ ? 'No matches'
+ : 'All options selected'}
+ </div>
+ }
+ >
+ <For each={availableOptions()}>
+ {(option) => (
+ <button
+ type="button"
+ onMouseDown={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ handleSelectOption(option);
+ }}
+ class="w-full px-2 py-1.5 text-[10px] text-ink hover:bg-hover text-left"
+ >
+ {getOptionDisplayValue(option)}
+ </button>
+ )}
+ </For>
+ </Show>
+ </div>
+ </Show>
+ </div>
+ </div>
+ );
+};
diff --git a/js/app/packages/app/component/PropertyFilter/index.ts b/js/app/packages/app/component/PropertyFilter/index.ts
new file mode 100644
index 0000000000..0b15c148cf
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilter/index.ts
@@ -0,0 +1,11 @@
+export { FilterActionSelect } from './FilterAction';
+export { FilterPropertySelect } from './FilterProperty';
+export { FilterPropertyPill } from './FilterPropertyPill';
+export { FilterValueBoolean } from './FilterValueBoolean';
+export { FilterValueDate } from './FilterValueDate';
+export { FilterValueDateMulti } from './FilterValueDateMulti';
+export { FilterValueEntity } from './FilterValueEntity';
+export { FilterValueNumber } from './FilterValueNumber';
+export { FilterValueNumberMulti } from './FilterValueNumberMulti';
+export { FilterValueSelect } from './FilterValueSelect';
+export { FilterValueSelectMulti } from './FilterValueSelectMulti';
diff --git a/js/app/packages/app/component/PropertyFilterControl.tsx b/js/app/packages/app/component/PropertyFilterControl.tsx
new file mode 100644
index 0000000000..86b298a424
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilterControl.tsx
@@ -0,0 +1,204 @@
+import { listPropertiesFlat } from '@core/component/Properties/utils';
+import type { PropertyDefinition } from '@service-properties/generated/schemas/propertyDefinition';
+import type { Accessor, Component } from 'solid-js';
+import {
+ createEffect,
+ createMemo,
+ createSignal,
+ For,
+ onMount,
+ Show,
+} from 'solid-js';
+import { createStore, reconcile } from 'solid-js/store';
+import { FilterPropertyPill } from './PropertyFilter';
+import type { PropertyFilter } from './PropertyFilterTypes';
+import { checkFilterConflict } from './PropertyFilterTypes';
+
+type FilterEntry = {
+ id: string;
+ data: PropertyFilter | null; // null = incomplete, non-null = complete
+};
+
+type PropertyFilterControlProps = {
+ propertyFilters: Accessor<PropertyFilter[]>;
+ setPropertyFilters: (filters: PropertyFilter[]) => void;
+ /** Called when incomplete filter state changes */
+ onIncompleteFiltersChange?: (hasIncomplete: boolean) => void;
+ /** Register a clear handler that parent can call to clear all filters */
+ registerClearHandler?: (clearFn: () => void) => void;
+};
+
+export const PropertyFilterControl: Component<PropertyFilterControlProps> = (
+ props
+) => {
+ // Fetch all properties once for looking up saved filters
+ const [allProperties, setAllProperties] = createSignal<PropertyDefinition[]>(
+ []
+ );
+
+ onMount(async () => {
+ const properties = await listPropertiesFlat('all');
+ setAllProperties(properties);
+ });
+
+ // Look up property definition by ID
+ const getPropertyById = (id: string): PropertyDefinition | undefined =>
+ allProperties().find((p) => p.id === id);
+
+ // Simple incrementing ID generator (unique within component lifetime)
+ let nextFilterId = 0;
+ const getNextFilterId = () => `property-filter-${nextFilterId++}`;
+
+ // Check if a filter has all required fields: propertyId, action, and value(s)
+ const isFilterComplete = (
+ filter: PropertyFilter | null
+ ): filter is PropertyFilter => {
+ if (!filter) return false;
+ if (!filter.propertyId || !filter.action) return false;
+
+ // Check value based on filter variant
+ if ('value' in filter) {
+ // BOOLEAN value can be false, so check for undefined/null only
+ return filter.value !== undefined && filter.value !== null;
+ }
+ if ('values' in filter) {
+ return Array.isArray(filter.values) && filter.values.length > 0;
+ }
+
+ return false;
+ };
+
+ // Extract only complete filters
+ const getCompleteFilters = (entries: FilterEntry[]): PropertyFilter[] =>
+ entries.filter((f) => isFilterComplete(f.data)).map((f) => f.data!);
+
+ // Convert saved filters to entries with stable IDs
+ const createEntriesFromProps = (): FilterEntry[] =>
+ props.propertyFilters().map((f) => ({
+ id: getNextFilterId(),
+ data: f,
+ }));
+
+ // Local state for UI (includes incomplete filters)
+ const [filters, setFilters] = createStore<FilterEntry[]>(
+ createEntriesFromProps()
+ );
+
+ // Clear all local filters (called by parent via registerClearHandler)
+ const clearFilters = () => {
+ setFilters(reconcile([]));
+ };
+
+ // Register clear handler with parent
+ props.registerClearHandler?.(clearFilters);
+
+ // Sync only complete filters to props
+ const syncCompleteFiltersToProps = (entries: FilterEntry[]) => {
+ props.setPropertyFilters(getCompleteFilters(entries));
+ };
+
+ const addFilter = () => {
+ const newId = getNextFilterId();
+ setFilters([...filters, { id: newId, data: null }]);
+ };
+
+ const removeFilter = (id: string) => {
+ const newFilters = filters.filter((f) => f.id !== id);
+ setFilters(reconcile(newFilters));
+ // Sync complete filters to props
+ syncCompleteFiltersToProps(newFilters);
+ };
+
+ const updateFilter = (id: string, data: PropertyFilter) => {
+ const newFilters = filters.map((f) => (f.id === id ? { ...f, data } : f));
+ setFilters(reconcile(newFilters));
+ // Sync complete filters to props
+ syncCompleteFiltersToProps(newFilters);
+ };
+
+ // Check for conflicts among all saved filters
+ const conflictErrors = createMemo(() => {
+ const completed = filters
+ .filter((f) => f.data !== null)
+ .map((f) => f.data!);
+ const errors: string[] = [];
+
+ for (let i = 0; i < completed.length; i++) {
+ const filtersBefore = completed.slice(0, i);
+ const conflict = checkFilterConflict(completed[i], filtersBefore);
+ if (conflict) {
+ errors.push(conflict);
+ }
+ }
+
+ return errors;
+ });
+
+ // Check if there are any incomplete filters
+ const hasIncompleteFilters = createMemo(() =>
+ filters.some((f) => !isFilterComplete(f.data))
+ );
+
+ // Notify parent when incomplete filter state changes
+ createEffect(() => {
+ props.onIncompleteFiltersChange?.(hasIncompleteFilters());
+ });
+
+ // Show loading if we have saved filters but properties haven't loaded yet
+ const isLoading = () =>
+ filters.some((f) => f.data !== null) && allProperties().length === 0;
+
+ return (
+ <div class="flex flex-col gap-1">
+ {/* Conflict warnings */}
+ <Show when={conflictErrors().length > 0}>
+ <div class="text-xs text-failure bg-failure/10 border border-failure px-2 py-1 mb-1">
+ <For each={conflictErrors()}>{(error) => <div>{error}</div>}</For>
+ </div>
+ </Show>
+
+ <Show
+ when={!isLoading()}
+ fallback={
+ <div class="text-xs text-ink-muted px-2 py-1">Loading filters...</div>
+ }
+ >
+ {/* TODO: Add controlled editing state (editingPropertyId) so only one
+ dropdown is open at a time. */}
+ <For each={filters}>
+ {(filter, index) => (
+ <>
+ <FilterPropertyPill
+ id={filter.id}
+ savedData={filter.data}
+ initialProperty={
+ filter.data?.propertyId
+ ? getPropertyById(filter.data.propertyId)
+ : undefined
+ }
+ onSave={(data) => updateFilter(filter.id, data)}
+ onCancel={() => removeFilter(filter.id)}
+ />
+ <Show when={index() < filters.length - 1}>
+ <span class="text-[10px] text-ink-muted font-mono pl-3 pt-0.25 leading-none">
+ AND
+ </span>
+ </Show>
+ </>
+ )}
+ </For>
+ </Show>
+
+ {/* Add filter button */}
+ <button
+ type="button"
+ onClick={addFilter}
+ class={`px-2 py-0.75 ${filters.length > 0 ? 'mt-2' : ''} text-xs text-ink border border-edge hover:bg-hover w-full`}
+ >
+ + Add filter
+ </button>
+ </div>
+ );
+};
+
+export default PropertyFilterControl;
diff --git a/js/app/packages/app/component/PropertyFilterTypes.ts b/js/app/packages/app/component/PropertyFilterTypes.ts
new file mode 100644
index 0000000000..b51d74d086
--- /dev/null
+++ b/js/app/packages/app/component/PropertyFilterTypes.ts
@@ -0,0 +1,260 @@
+import { DataType } from '@service-properties/generated/schemas/dataType';
+import type { EntityType } from '@service-properties/generated/schemas/entityType';
+
+// ============================================
+// Property Filter Models
+// ============================================
+
+/** Data types that support filtering */
+export const FILTERABLE_DATA_TYPES = [
+ DataType.BOOLEAN,
+ DataType.DATE,
+ DataType.NUMBER,
+ DataType.SELECT_NUMBER,
+ DataType.SELECT_STRING,
+ DataType.ENTITY,
+] as const;
+
+/** Equality actions - matches against one or more values (OR logic for multiple) */
+export const EqualityAction = {
+ EQUAL: 'equal',
+ NOT_EQUAL: 'not_equal',
+} as const;
+export type EqualityAction =
+ (typeof EqualityAction)[keyof typeof EqualityAction];
+
+/** Comparison actions - available for DATE, NUMBER, SELECT_NUMBER, SELECT_STRING (single value only) */
+export const ComparisonAction = {
+ GREATER_THAN: 'greater_than',
+ GREATER_THAN_OR_EQUAL: 'greater_than_or_equal',
+ LESS_THAN: 'less_than',
+ LESS_THAN_OR_EQUAL: 'less_than_or_equal',
+} as const;
+export type ComparisonAction =
+ (typeof ComparisonAction)[keyof typeof ComparisonAction];
+
+/** Contains actions - available for multi-value properties (SELECT_NUMBER, SELECT_STRING, ENTITY) */
+export const ContainsAction = {
+ HAS_ANY: 'has_any',
+ HAS_ALL: 'has_all',
+ DOES_NOT_HAVE: 'does_not_have',
+} as const;
+export type ContainsAction =
+ (typeof ContainsAction)[keyof typeof ContainsAction];
+
+/** All possible filter actions */
+export type FilterAction = EqualityAction | ComparisonAction | ContainsAction;
+
+/** Symbols for filter actions (shown in pill) */
+export const ACTION_SYMBOLS: Record<FilterAction, string> = {
+ [EqualityAction.EQUAL]: '=',
+ [EqualityAction.NOT_EQUAL]: '≠',
+ [ComparisonAction.GREATER_THAN]: '>',
+ [ComparisonAction.GREATER_THAN_OR_EQUAL]: '≥',
+ [ComparisonAction.LESS_THAN]: '<',
+ [ComparisonAction.LESS_THAN_OR_EQUAL]: '≤',
+ [ContainsAction.HAS_ANY]: '∈',
+ [ContainsAction.HAS_ALL]: '⊇',
+ [ContainsAction.DOES_NOT_HAVE]: '∉',
+};
+
+/** Display names for filter actions (shown in dropdown: text + symbol) */
+export const ACTION_DISPLAY_NAMES: Record<FilterAction, string> = {
+ [EqualityAction.EQUAL]: 'is =',
+ [EqualityAction.NOT_EQUAL]: 'is not ≠',
+ [ComparisonAction.GREATER_THAN]: 'greater than >',
+ [ComparisonAction.GREATER_THAN_OR_EQUAL]: 'at least ≥',
+ [ComparisonAction.LESS_THAN]: 'less than <',
+ [ComparisonAction.LESS_THAN_OR_EQUAL]: 'at most ≤',
+ [ContainsAction.HAS_ANY]: 'has any ∈',
+ [ContainsAction.HAS_ALL]: 'has all ⊇',
+ [ContainsAction.DOES_NOT_HAVE]: 'has none ∉',
+};
+
+/** Entity reference for ENTITY filter values */
+export type EntityFilterValue = {
+ entityType: EntityType;
+ entityId: string;
+};
+
+/** Property filter - discriminated union by dataType */
+export type PropertyFilter =
+ // BOOLEAN - equality only (single value)
+ | {
+ propertyId: string;
+ dataType: 'BOOLEAN';
+ action: EqualityAction;
+ value: boolean;
+ }
+ // DATE - equality (multiple) or comparison (single)
+ | {
+ propertyId: string;
+ dataType: 'DATE';
+ action: EqualityAction;
+ values: string[]; // ISO date strings
+ }
+ | {
+ propertyId: string;
+ dataType: 'DATE';
+ action: ComparisonAction;
+ value: string; // ISO date string
+ }
+ // NUMBER - equality (multiple) or comparison (single)
+ | {
+ propertyId: string;
+ dataType: 'NUMBER';
+ action: EqualityAction;
+ values: number[];
+ }
+ | {
+ propertyId: string;
+ dataType: 'NUMBER';
+ action: ComparisonAction;
+ value: number;
+ }
+ // SELECT_NUMBER | SELECT_STRING (single-value) - equality or comparison
+ | {
+ propertyId: string;
+ dataType: 'SELECT_NUMBER' | 'SELECT_STRING';
+ action: EqualityAction;
+ values: string[]; // option ids
+ }
+ | {
+ propertyId: string;
+ dataType: 'SELECT_NUMBER' | 'SELECT_STRING';
+ action: ComparisonAction;
+ value: string; // option id
+ }
+ // SELECT_NUMBER | SELECT_STRING (multi-value) - contains only
+ | {
+ propertyId: string;
+ dataType: 'SELECT_NUMBER' | 'SELECT_STRING';
+ action: ContainsAction;
+ values: string[]; // option ids
+ }
+ // ENTITY (single-value) - equality only
+ | {
+ propertyId: string;
+ dataType: 'ENTITY';
+ action: EqualityAction;
+ values: EntityFilterValue[];
+ }
+ // ENTITY (multi-value) - contains only
+ | {
+ propertyId: string;
+ dataType: 'ENTITY';
+ action: ContainsAction;
+ values: EntityFilterValue[];
+ };
+
+/** Helper: Check if a data type is filterable */
+export const isFilterableDataType = (dataType: DataType): boolean => {
+ return (FILTERABLE_DATA_TYPES as readonly DataType[]).includes(dataType);
+};
+
+/** Helper: Get valid filter actions for a property based on data type and multi-select */
+export const getValidFilterActions = (
+ dataType: DataType,
+ isMultiSelect: boolean
+): FilterAction[] => {
+ const actions: FilterAction[] = [];
+
+ // Multi-select properties only support contains actions
+ if (isMultiSelect) {
+ actions.push(ContainsAction.HAS_ANY);
+ actions.push(ContainsAction.HAS_ALL);
+ actions.push(ContainsAction.DOES_NOT_HAVE);
+ return actions;
+ }
+
+ // BOOLEAN: only equality
+ if (dataType === DataType.BOOLEAN) {
+ return [EqualityAction.EQUAL, EqualityAction.NOT_EQUAL];
+ }
+
+ // ENTITY (single-value): only equality
+ if (dataType === DataType.ENTITY) {
+ return [EqualityAction.EQUAL, EqualityAction.NOT_EQUAL];
+ }
+
+ // DATE, NUMBER, SELECT_NUMBER, SELECT_STRING: equality + comparison
+ actions.push(EqualityAction.EQUAL);
+ actions.push(EqualityAction.NOT_EQUAL);
+ actions.push(ComparisonAction.GREATER_THAN);
+ actions.push(ComparisonAction.GREATER_THAN_OR_EQUAL);
+ actions.push(ComparisonAction.LESS_THAN);
+ actions.push(ComparisonAction.LESS_THAN_OR_EQUAL);
+
+ return actions;
+};
+
+/** Helper: Check if a new filter conflicts with existing filters */
+export const checkFilterConflict = (
+ newFilter: PropertyFilter,
+ existingFilters: PropertyFilter[]
+): string | null => {
+ const filtersForProperty = existingFilters.filter(
+ (f) => f.propertyId === newFilter.propertyId
+ );
+
+ if (filtersForProperty.length === 0) return null;
+
+ const existingActions = new Set(filtersForProperty.map((f) => f.action));
+ const newAction = newFilter.action;
+
+ // BOOLEAN: only one filter allowed per property
+ if (newFilter.dataType === 'BOOLEAN' && filtersForProperty.length > 0) {
+ return 'Redundant: boolean already filtered';
+ }
+
+ // Duplicate action (except has_any which can be repeated)
+ if (existingActions.has(newAction) && newAction !== ContainsAction.HAS_ANY) {
+ return `Redundant: duplicate "${ACTION_DISPLAY_NAMES[newAction]}" filter`;
+ }
+
+ // Equal conflicts with comparisons
+ if (newAction === EqualityAction.EQUAL) {
+ const hasComparison =
+ existingActions.has(ComparisonAction.GREATER_THAN) ||
+ existingActions.has(ComparisonAction.GREATER_THAN_OR_EQUAL) ||
+ existingActions.has(ComparisonAction.LESS_THAN) ||
+ existingActions.has(ComparisonAction.LESS_THAN_OR_EQUAL);
+ if (hasComparison) {
+ return 'Conflicting: "is" + comparison';
+ }
+ }
+
+ // Comparisons conflict with equal
+ const isComparison =
+ newAction === ComparisonAction.GREATER_THAN ||
+ newAction === ComparisonAction.GREATER_THAN_OR_EQUAL ||
+ newAction === ComparisonAction.LESS_THAN ||
+ newAction === ComparisonAction.LESS_THAN_OR_EQUAL;
+ if (isComparison && existingActions.has(EqualityAction.EQUAL)) {
+ return 'Conflicting: comparison + "is"';
+ }
+
+ // Lower bound conflicts
+ const isLowerBound =
+ newAction === ComparisonAction.GREATER_THAN ||
+ newAction === ComparisonAction.GREATER_THAN_OR_EQUAL;
+ const hasLowerBound =
+ existingActions.has(ComparisonAction.GREATER_THAN) ||
+ existingActions.has(ComparisonAction.GREATER_THAN_OR_EQUAL);
+ if (isLowerBound && hasLowerBound) {
+ return 'Redundant: multiple lower bounds';
+ }
+
+ // Upper bound conflicts
+ const isUpperBound =
+ newAction === ComparisonAction.LESS_THAN ||
+ newAction === ComparisonAction.LESS_THAN_OR_EQUAL;
+ const hasUpperBound =
+ existingActions.has(ComparisonAction.LESS_THAN) ||
+ existingActions.has(ComparisonAction.LESS_THAN_OR_EQUAL);
+ if (isUpperBound && hasUpperBound) {
+ return 'Redundant: multiple upper bounds';
+ }
+
+ return null;
+};
diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsx
index 934b1baca5..091bd5cae1 100644
--- a/js/app/packages/app/component/SoupContext.tsx
+++ b/js/app/packages/app/component/SoupContext.tsx
@@ -210,6 +210,10 @@ function createViewData(
viewProps?.filters?.focusFilters ??
VIEWCONFIG_BASE.filters.focusFilters ??
[],
+ propertyFilters:
+ viewProps?.filters?.propertyFilters ??
+ VIEWCONFIG_BASE.filters.propertyFilters ??
+ [],
},
display: {
layout: viewProps?.display?.layout ?? VIEWCONFIG_BASE.display.layout,
diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsx
index 01f1bfb53f..e7a4b975c3 100644
--- a/js/app/packages/app/component/UnifiedListView.tsx
+++ b/js/app/packages/app/component/UnifiedListView.tsx
@@ -15,6 +15,7 @@ import { ContextMenuContent, MenuSeparator } from '@core/component/Menu';
import { useTaskProperties } from '@core/component/Properties/hooks';
import { getSuggestedProperties } from '@core/component/Properties/utils';
import { RecipientSelector } from '@core/component/RecipientSelector';
+import { toast } from '@core/component/Toast/Toast';
import {
blockAcceptsFileExtension,
fileTypeToBlockName,
@@ -22,6 +23,7 @@ import {
import {
ENABLE_FRECENCY,
ENABLE_PROPERTY_DISPLAY,
+ ENABLE_PROPERTY_FILTER,
ENABLE_SOUP_FROM_FILTER,
ENABLE_TASKS_TABS,
} from '@core/constant/featureFlags';
@@ -134,6 +136,8 @@ import { EntityModal } from './EntityModal/EntityModal';
import { EntitySelectionToolbarModal } from './EntitySelectionToolbarModal';
import { EntityRow, EntityRowProvider } from './mobile/EntityRow';
import { PropertyDisplayControl } from './PropertyDisplayControl';
+import { PropertyFilterControl } from './PropertyFilterControl';
+import type { PropertyFilter } from './PropertyFilterTypes';
import { useUpsertSavedViewMutation } from './Soup';
import { openEntityInSplitFromUnifiedList } from './soupContextHelpers';
import {
@@ -150,7 +154,6 @@ import {
type SortOptions,
type SystemSortOption,
VIEWCONFIG_BASE,
- VIEWCONFIG_DEFAULTS_IDS,
VIEWCONFIG_DEFAULTS_IDS_ENUM,
VIEWCONFIG_FILTER_DOCUMENT_TYPE_FILTER,
type ViewConfigBase,
@@ -404,6 +407,19 @@ export function UnifiedListView(props: UnifiedListViewProps) {
setViewDataStore(selectedView(), 'filters', 'fromFilter', ...args);
};
+ // Property filters
+ const propertyFilters = createMemo(
+ () => view()?.filters.propertyFilters ?? []
+ );
+ const setPropertyFilters = (filters: PropertyFilter[]) => {
+ setViewDataStore(selectedView(), 'filters', 'propertyFilters', filters);
+ };
+ // Track incomplete property filters for toast warning on save
+ const [hasIncompletePropertyFilters, setHasIncompletePropertyFilters] =
+ createSignal(false);
+ // Store clear handler from PropertyFilterControl
+ let clearPropertyFilters: (() => void) | undefined;
+
const getSystemSortOption = (
sort: SortOptions | undefined
): SystemSortOption => {
@@ -536,9 +552,12 @@ export function UnifiedListView(props: UnifiedListViewProps) {
const propertyId = sort?.propertyId ?? null;
const sortOrder = sort?.sortOrder ?? null;
+ // Spread filters with propertyFilters explicitly accessed to ensure reactivity tracking
+ const filters = viewsData[viewKey]?.filters;
+
return {
display: viewsData[viewKey]?.display,
- filters: viewsData[viewKey]?.filters,
+ filters: { ...filters, propertyFilters: filters.propertyFilters },
sort: {
type: sortType,
sortBy,
@@ -1252,23 +1271,27 @@ export function UnifiedListView(props: UnifiedListViewProps) {
}
});
- const onClickSaveViewConfigChanges = () => {
+ const onClickSaveViewConfigChanges = async () => {
const view_ = view();
const config = currentViewConfigBase();
if (!view_ || !config) return;
- saveViewMutation.mutate({
+ // Warn if there are incomplete property filters (they won't be saved)
+ if (hasIncompletePropertyFilters()) {
+ toast.alert('Incomplete property filters were not saved');
+ }
+
+ // Wait for mutation to complete (including query refetch) before updating initialConfig
+ await saveViewMutation.mutateAsync({
id: view_.id,
name: view_.view,
config,
});
- // only for default views
- if (VIEWCONFIG_DEFAULTS_IDS.includes(view_.id as any)) {
- // Reset initialConfigSignal to current config after save
- const currentConfig = stringifiedCurrentViewConfigBase();
- if (currentConfig !== null && currentConfig !== undefined) {
- setViewDataStore(selectedView(), 'initialConfig', currentConfig);
- }
+
+ // Reset initialConfig after save + refetch so isViewConfigChanged returns false
+ const currentConfig = stringifiedCurrentViewConfigBase();
+ if (currentConfig !== null && currentConfig !== undefined) {
+ setViewDataStore(selectedView(), 'initialConfig', currentConfig);
}
};
@@ -1286,6 +1309,8 @@ export function UnifiedListView(props: UnifiedListViewProps) {
setViewDataStore(selectedView(), 'sort', initialConfigObj.sort);
setViewDataStore(selectedView(), 'display', initialConfigObj.display);
});
+ // Clear property filter UI state
+ clearPropertyFilters?.();
};
// Set initialConfig when it's not present (on load or after save/refetch)
@@ -1598,6 +1623,21 @@ export function UnifiedListView(props: UnifiedListViewProps) {
/>
</section>
</Show>
+ <Show when={ENABLE_PROPERTY_FILTER}>
+ <section class="gap-1 grid p-2">
+ <span class="font-medium text-xs">Property</span>
+ <PropertyFilterControl
+ propertyFilters={propertyFilters}
+ setPropertyFilters={setPropertyFilters}
+ onIncompleteFiltersChange={
+ setHasIncompletePropertyFilters
+ }
+ registerClearHandler={(fn) => {
+ clearPropertyFilters = fn;
+ }}
+ />
+ </section>
+ </Show>
</div>
</div>
</DropdownMenu>
diff --git a/js/app/packages/app/component/ViewConfig.tsx b/js/app/packages/app/component/ViewConfig.tsx
index b4d1370b78..ff1a1247e4 100644
--- a/js/app/packages/app/component/ViewConfig.tsx
+++ b/js/app/packages/app/component/ViewConfig.tsx
@@ -23,6 +23,7 @@ import {
import { emailClient } from '@service-email/client';
import stringify from 'json-stable-stringify';
import { queryClient } from '../../macro-entity/src/queries/client';
+import type { PropertyFilter } from './PropertyFilterTypes';
import type { SoupContext } from './SoupContext';
import { noiseFilter, signalFilter } from './soupFilters';
@@ -68,6 +69,7 @@ export type FilterOptions = {
projectFilter?: string;
fromFilter?: WithCustomUserInput<'user' | 'contact'>[];
focusFilters?: ('signal' | 'noise')[];
+ propertyFilters?: PropertyFilter[];
};
export type SystemSortOption =
@@ -142,6 +144,7 @@ export const VIEWCONFIG_BASE: ViewConfigBase = {
documentTypeFilter: [],
projectFilter: undefined,
fromFilter: [],
+ propertyFilters: [],
},
display: {
layout: 'compact',
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 0a5b490cff..f0b243daca 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
@@ -3,7 +3,7 @@ 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, IUser } from '@core/user';
+import type { IUser } from '@core/user';
import { idToEmail, tryMacroId, useContacts, useDisplayName } from '@core/user';
import { createFreshSearch } from '@core/util/freshSort';
import CompanyIcon from '@icon/duotone/building-duotone.svg';
@@ -21,7 +21,6 @@ import {
} from '@macro-entity';
import { useUserId } from '@service-gql/client';
import type { EntityType } from '@service-properties/generated/schemas/entityType';
-import type { Item } from '@service-storage/generated/schemas/item';
import { useHistory } from '@service-storage/history';
import { debounce } from '@solid-primitives/scheduled';
import {
@@ -37,6 +36,15 @@ import {
import { usePropertiesContext } from '../../../context/PropertiesContext';
import type { Property } from '../../../types';
import { useSearchInputFocus } from '../../../utils';
+import {
+ type CombinedEntity,
+ ENTITY_SEARCH_CONFIG,
+ entityMapper,
+ getEntityName,
+ getEntitySearchText,
+ getEntityType,
+ threadMapper,
+} from './entityUtils';
import { OptionCheckBox } from './OptionCheckBox';
type EntityInputProps = {
@@ -78,82 +86,6 @@ function getEntityTypePluralLabel(
}
}
-type CombinedEntity =
- | { kind: 'item'; id: string; data: Item }
- | { kind: 'user'; id: string; data: IUser }
- | { kind: 'channel'; id: string; data: ChannelWithParticipants }
- | { kind: 'company'; id: string; data: null }
- | { kind: 'thread'; id: string; data: EmailEntity };
-
-function entityMapper(kind: 'item' | 'user' | 'channel') {
- return (data: Item | IUser | ChannelWithParticipants): CombinedEntity => {
- return { kind, data, id: (data as { id: string }).id } as CombinedEntity;
- };
-}
-
-function threadMapper(email: EmailEntity): CombinedEntity {
- return { kind: 'thread', id: email.id, data: email };
-}
-
-function getEntityName(entity: CombinedEntity): string {
- switch (entity.kind) {
- case 'item':
- return entity.data.name;
- case 'user': {
- const { name, email } = entity.data;
- if (name === email) return email;
- return `${name} | ${email}`;
- }
- case 'channel':
- return entity.data.name ?? '';
- case 'company':
- return entity.id;
- case 'thread':
- return entity.data.name ?? 'No Subject';
- }
-}
-
-function getEntitySearchText(entity: CombinedEntity): string {
- switch (entity.kind) {
- case 'item':
- return entity.data.name;
- case 'user': {
- const { name, email } = entity.data;
- if (name === email) return `${email} | ${email}`;
- return `${name} | ${email}`;
- }
- case 'channel':
- return entity.data.name ?? '';
- case 'company':
- return entity.id;
- case 'thread':
- return entity.data.name ?? '';
- }
-}
-
-function getEntityType(entity: CombinedEntity): string {
- switch (entity.kind) {
- case 'user':
- return 'USER';
- case 'channel':
- return 'CHANNEL';
- case 'item':
- if (
- entity.data.type === 'document' &&
- entity.data.subType !== null &&
- entity.data.subType !== undefined &&
- entity.data.subType.type === 'task'
- ) {
- return 'TASK';
- }
- return entity.data.type.toUpperCase();
- case 'company':
- return 'COMPANY';
- case 'thread':
- return 'THREAD';
- }
-}
-
function getEntityIcon(entity: CombinedEntity) {
switch (entity.kind) {
case 'user':
@@ -254,8 +186,13 @@ export function PropertyEntitySelector(props: EntityInputProps) {
});
// Fetch emails for browsing (only when THREAD type)
+ // Email queries for THREAD type or generic ENTITY (no specific type)
+ const needsEmailSearch = () =>
+ props.property.specificEntityType === 'THREAD' ||
+ !props.property.specificEntityType;
+
const emailsQuery = createEmailsInfiniteQuery(() => ({ view: 'all' }), {
- disabled: () => props.property.specificEntityType !== 'THREAD',
+ disabled: () => !needsEmailSearch(),
});
const emails = () => emailsQuery.data ?? [];
@@ -271,7 +208,7 @@ export function PropertyEntitySelector(props: EntityInputProps) {
},
}),
{
- disabled: () => props.property.specificEntityType !== 'THREAD',
+ disabled: () => !needsEmailSearch(),
}
);
@@ -286,7 +223,7 @@ export function PropertyEntitySelector(props: EntityInputProps) {
});
const isLoadingEntities = createMemo(() => {
- if (props.property.specificEntityType === 'THREAD') {
+ if (needsEmailSearch()) {
// Loading if initial emails query is loading OR search is fetching
return (
emailsQuery.isLoading ||
@@ -306,6 +243,7 @@ export function PropertyEntitySelector(props: EntityInputProps) {
...contactsWithCurrentUser().map(entityMapper('user')),
...history().map(entityMapper('item')),
...channels().map(entityMapper('channel')),
+ ...emails().map(threadMapper),
];
}
@@ -358,7 +296,7 @@ export function PropertyEntitySelector(props: EntityInputProps) {
});
const entitySearch = createFreshSearch<CombinedEntity>(
- { timeWeight: 0.1, brevityWeight: 0.3 },
+ ENTITY_SEARCH_CONFIG,
getEntitySearchText
);
@@ -385,8 +323,8 @@ export function PropertyEntitySelector(props: EntityInputProps) {
.filter(excludeFilter)
.slice(0, MAX_VISIBLE_ENTITIES_NO_SEARCH);
- // For THREAD: merge local + server results (local first, server appended, deduped)
- if (props.property.specificEntityType === 'THREAD' && term) {
+ // For THREAD or generic entity: merge local + server results (local first, server appended, deduped)
+ if (needsEmailSearch() && term) {
const localIds = new Set(localResults.map((e) => e.id));
const serverResults = serverEmails()
.filter((e) => !localIds.has(e.id))
diff --git a/js/app/packages/core/component/Properties/component/modal/shared/entityUtils.ts b/js/app/packages/core/component/Properties/component/modal/shared/entityUtils.ts
new file mode 100644
index 0000000000..6c1944c1f8
--- /dev/null
+++ b/js/app/packages/core/component/Properties/component/modal/shared/entityUtils.ts
@@ -0,0 +1,90 @@
+import type { ChannelWithParticipants, IUser } from '@core/user';
+import type { EmailEntity } from '@macro-entity';
+import type { EntityType } from '@service-properties/generated/schemas/entityType';
+import type { Item } from '@service-storage/generated/schemas/item';
+
+/** Combined entity type for unified handling across entity selectors */
+export type CombinedEntity =
+ | { kind: 'item'; id: string; data: Item }
+ | { kind: 'user'; id: string; data: IUser }
+ | { kind: 'channel'; id: string; data: ChannelWithParticipants }
+ | { kind: 'company'; id: string; data: null }
+ | { kind: 'thread'; id: string; data: EmailEntity };
+
+/** Creates a mapper function for a specific entity kind */
+export function entityMapper(kind: 'item' | 'user' | 'channel') {
+ return (data: Item | IUser | ChannelWithParticipants): CombinedEntity => {
+ return { kind, data, id: (data as { id: string }).id } as CombinedEntity;
+ };
+}
+
+/** Maps an email entity to a CombinedEntity */
+export function threadMapper(email: EmailEntity): CombinedEntity {
+ return { kind: 'thread', id: email.id, data: email };
+}
+
+/** Gets the display name for an entity */
+export function getEntityName(entity: CombinedEntity): string {
+ switch (entity.kind) {
+ case 'item':
+ return entity.data.name;
+ case 'user': {
+ const { name, email } = entity.data;
+ if (name === email) return email;
+ return name;
+ }
+ case 'channel':
+ return entity.data.name ?? '';
+ case 'company':
+ return entity.id;
+ case 'thread':
+ return entity.data.name ?? 'No Subject';
+ }
+}
+
+/** Gets searchable text for an entity (used with createFreshSearch) */
+export function getEntitySearchText(entity: CombinedEntity): string {
+ switch (entity.kind) {
+ case 'item':
+ return entity.data.name;
+ case 'user': {
+ const { name, email } = entity.data;
+ if (name === email) return `${email} | ${email}`;
+ return `${name} | ${email}`;
+ }
+ case 'channel':
+ return entity.data.name ?? '';
+ case 'company':
+ return entity.id;
+ case 'thread':
+ return entity.data.name ?? '';
+ }
+}
+
+/** Gets the EntityType string for an entity */
+export function getEntityType(entity: CombinedEntity): EntityType {
+ switch (entity.kind) {
+ case 'user':
+ return 'USER';
+ case 'channel':
+ return 'CHANNEL';
+ case 'item':
+ if (
+ entity.data.type === 'document' &&
+ entity.data.subType?.type === 'task'
+ ) {
+ return 'TASK';
+ }
+ return entity.data.type.toUpperCase() as EntityType;
+ case 'company':
+ return 'COMPANY';
+ case 'thread':
+ return 'THREAD';
+ }
+}
+
+/** Search config for createFreshSearch (consistent across entity selectors) */
+export const ENTITY_SEARCH_CONFIG = {
+ timeWeight: 0.1,
+ brevityWeight: 0.3,
+} as const;
diff --git a/js/app/packages/core/component/Properties/component/modal/shared/index.ts b/js/app/packages/core/component/Properties/component/modal/shared/index.ts
index 13a105111a..8f38f6da84 100644
--- a/js/app/packages/core/component/Properties/component/modal/shared/index.ts
+++ b/js/app/packages/core/component/Properties/component/modal/shared/index.ts
@@ -1,4 +1,13 @@
export type { DropdownOption } from './Dropdown';
export { Dropdown } from './Dropdown';
+export {
+ type CombinedEntity,
+ ENTITY_SEARCH_CONFIG,
+ entityMapper,
+ getEntityName,
+ getEntitySearchText,
+ getEntityType,
+ threadMapper,
+} from './entityUtils';
export { PropertyEntitySelector } from './PropertyEntitySelector';
export { PropertyOptionSelector } from './PropertyOptionSelector';
diff --git a/js/app/packages/core/component/Properties/utils/typeGuards.ts b/js/app/packages/core/component/Properties/utils/typeGuards.ts
index 6c11a40270..fa380f9b01 100644
--- a/js/app/packages/core/component/Properties/utils/typeGuards.ts
+++ b/js/app/packages/core/component/Properties/utils/typeGuards.ts
@@ -1,4 +1,9 @@
+import { isErr } from '@core/util/maybeResult';
+import { propertiesServiceClient } from '@service-properties/client';
import type { EntityReference } from '@service-properties/generated/schemas/entityReference';
+import type { PropertyDefinition } from '@service-properties/generated/schemas/propertyDefinition';
+import type { PropertyDefinitionResponse } from '@service-properties/generated/schemas/propertyDefinitionResponse';
+import type { PropertyScope } from '@service-properties/generated/schemas/propertyScope';
import type { Property } from '../types';
/**
@@ -93,3 +98,34 @@ export function isEntityReferenceArray(
'entity_type' in ref
);
}
+
+/**
+ * Type guard to narrow PropertyDefinitionResponse to PropertyDefinition
+ * PropertyDefinitionWithOptions has { definition, property_options } structure
+ * PropertyDefinition has { id, data_type, ... } directly
+ */
+export function isPropertyDefinition(
+ p: PropertyDefinitionResponse
+): p is PropertyDefinition {
+ return !('definition' in p);
+}
+
+/**
+ * Fetch property definitions without options (flat structure)
+ * Narrows the response type from PropertyDefinitionResponse[] to PropertyDefinition[]
+ */
+export async function listPropertiesFlat(
+ scope: PropertyScope
+): Promise<PropertyDefinition[]> {
+ const result = await propertiesServiceClient.listProperties({
+ scope,
+ include_options: false,
+ });
+
+ if (isErr(result)) {
+ return [];
+ }
+
+ const [, data] = result;
+ return (Array.isArray(data) ? data : []).filter(isPropertyDefinition);
+}