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.

feat: search tab filter selection (#2453)

gbirman8c20b6bb389b
diff --git a/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts b/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts
index 7399af8ce1..2ac15be1a3 100644
--- a/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts
+++ b/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts
@@ -298,23 +298,14 @@ export const VIEW_TAB_PRESETS: Record<ListView, ViewTabConfig> = {
if (!ctx.userId) return undefined;
return {
queryFilters: {
- channel_filters: { channel_ids: EXCLUDE },
- chat_filters: { chat_ids: EXCLUDE },
- email_filters: { recipients: EXCLUDE },
- document_filters: { document_ids: EXCLUDE },
+ ...QUERY_FILTERS.folders,
project_filters: { owners: [ctx.userId] },
},
clientFilters: { and: ['folders'] },
};
},
all: () => ({
- queryFilters: {
- channel_filters: { channel_ids: EXCLUDE },
- chat_filters: { chat_ids: EXCLUDE },
- email_filters: { recipients: EXCLUDE },
- document_filters: { document_ids: EXCLUDE },
- project_filters: {},
- },
+ queryFilters: QUERY_FILTERS.folders,
clientFilters: { and: ['folders'] },
}),
},
diff --git a/js/app/packages/app/component/next-soup/filters/query-filters.ts b/js/app/packages/app/component/next-soup/filters/query-filters.ts
index 6f6c6bf422..c8f6bd638b 100644
--- a/js/app/packages/app/component/next-soup/filters/query-filters.ts
+++ b/js/app/packages/app/component/next-soup/filters/query-filters.ts
@@ -131,6 +131,7 @@ export const QUERY_FILTERS = {
channel_filters: { channel_ids: EXCLUDE },
chat_filters: { chat_ids: EXCLUDE },
email_filters: { recipients: EXCLUDE },
+ project_filters: { project_ids: EXCLUDE },
document_filters: { file_types: getFileAssociations() },
},
@@ -138,6 +139,7 @@ export const QUERY_FILTERS = {
channel_filters: { channel_ids: EXCLUDE },
chat_filters: { chat_ids: EXCLUDE },
email_filters: { recipients: EXCLUDE },
+ project_filters: { project_ids: EXCLUDE },
document_filters: {
file_types: ['md', 'canvas', 'docx', ...getFileAssociations()],
},
@@ -151,5 +153,13 @@ export const QUERY_FILTERS = {
channel_filters: {},
},
+ folders: {
+ channel_filters: { channel_ids: EXCLUDE },
+ chat_filters: { chat_ids: EXCLUDE },
+ email_filters: { recipients: EXCLUDE },
+ document_filters: { document_ids: EXCLUDE },
+ project_filters: {},
+ },
+
default: {},
} satisfies Record<string, SoupItemsQueryFilters>;
diff --git a/js/app/packages/app/component/next-soup/soup-view/create-search-state.ts b/js/app/packages/app/component/next-soup/soup-view/create-search-state.ts
index c96dc8cb75..97d62650b3 100644
--- a/js/app/packages/app/component/next-soup/soup-view/create-search-state.ts
+++ b/js/app/packages/app/component/next-soup/soup-view/create-search-state.ts
@@ -116,8 +116,15 @@ export const createSearchState = ({
return filterToResultMap;
});
+ // we will hide local results if there are channel filters because we only want message results
+ const hasChannelQueryFilters = () => {
+ const cf = queryFilters().channel_filters;
+ return !!(cf?.channel_ids?.length || cf?.sender_ids?.length);
+ };
+
const filteredLocalFuzzyResults = createMemo(() => {
if (!localFuzzyResults()) return [];
+ if (hasChannelQueryFilters()) return [];
const activeFilters = getValidSearchFilters(soup.filters.active());
const results =
activeFilters.length === 0
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/filter-primitives.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/filter-primitives.tsx
index 13773d518f..12c4632d83 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/filter-primitives.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/filter-primitives.tsx
@@ -35,7 +35,12 @@ export const FilterSelect = (props: FilterSelectProps) => {
item={itemProps.item}
class="w-full flex items-center gap-2.5 p-2 rounded-xs text-left text-xs hover:bg-ink/5 group"
>
- <span class="size-4 flex items-center justify-center shrink-0 rounded-xs border border-edge-muted group-data-[selected]:bg-accent group-data-[selected]:border-accent">
+ <span
+ class={cn(
+ 'size-4 flex items-center justify-center shrink-0 border border-edge-muted group-data-[selected]:bg-accent group-data-[selected]:border-accent',
+ multiple() ? 'rounded-xs' : 'rounded-full'
+ )}
+ >
<KSelect.ItemIndicator>
<CheckIcon class="size-2.5 text-page" />
</KSelect.ItemIndicator>
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/parse-search-operators.ts b/js/app/packages/app/component/next-soup/soup-view/filters-bar/parse-search-operators.ts
new file mode 100644
index 0000000000..40b19f3226
--- /dev/null
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/parse-search-operators.ts
@@ -0,0 +1,34 @@
+export type OperatorType = 'index' | 'in' | 'from';
+
+export type ActiveOperator = {
+ type: OperatorType;
+ partial: string;
+ startIndex: number;
+ endIndex: number;
+};
+
+export function detectActiveOperator(
+ text: string,
+ cursorPosition: number
+): ActiveOperator | null {
+ const before = text.slice(0, cursorPosition);
+ const match = before.match(/(^|\s)(index|in|from):(\S*)$/);
+ if (!match) return null;
+
+ const type = match[2] as OperatorType;
+ const partial = match[3];
+ const startIndex = match.index! + match[1].length;
+ const endIndex = cursorPosition;
+
+ return { type, partial, startIndex, endIndex };
+}
+
+export function stripOperatorAtRange(
+ text: string,
+ startIndex: number,
+ endIndex: number
+): string {
+ const before = text.slice(0, startIndex);
+ const after = text.slice(endIndex);
+ return (before + after).replace(/\s{2,}/g, ' ').trim();
+}
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx
new file mode 100644
index 0000000000..edae1c9afd
--- /dev/null
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx
@@ -0,0 +1,269 @@
+import XIcon from '@icon/regular/x.svg';
+import { EntityIcon } from '@core/component/EntityIcon';
+import { UserIcon } from '@core/component/UserIcon';
+import { useQuickAccess } from '@core/context/quickAccess';
+import { useUserId } from '@core/context/user';
+import { QUERY_FILTERS } from '@app/component/next-soup/filters/query-filters';
+import { useSoupView } from '@app/component/next-soup/soup-view/soup-view-context';
+import type { SoupBody } from '@queries/soup/items';
+import { batch, createMemo, Show } from 'solid-js';
+import { FilterCombobox, FilterSelect, type Option } from './filter-primitives';
+import type { FilterID } from '@app/component/next-soup/filters/configs';
+
+export const INDEX_OPTIONS: (Option & { queryFilters: SoupBody })[] = [
+ {
+ value: 'channels',
+ label: 'Channels',
+ icon: () => <EntityIcon targetType="channel" size="xs" />,
+ queryFilters: QUERY_FILTERS.channels,
+ },
+ {
+ value: 'document',
+ label: 'Documents',
+ icon: () => <EntityIcon targetType="md" size="xs" />,
+ queryFilters: QUERY_FILTERS.documentAndFile,
+ },
+ {
+ value: 'task',
+ label: 'Tasks',
+ icon: () => <EntityIcon targetType="task" size="xs" />,
+ queryFilters: QUERY_FILTERS.task,
+ },
+ {
+ value: 'email',
+ label: 'Email',
+ icon: () => <EntityIcon targetType="email" size="xs" />,
+ queryFilters: QUERY_FILTERS.email,
+ },
+ {
+ value: 'folders',
+ label: 'Folders',
+ icon: () => <EntityIcon targetType="project" size="xs" />,
+ queryFilters: QUERY_FILTERS.folders,
+ },
+ {
+ value: 'agent',
+ label: 'Agents',
+ icon: () => <EntityIcon targetType="chat" size="xs" />,
+ queryFilters: QUERY_FILTERS.agent,
+ },
+];
+
+const INDEX_SELECT_OPTIONS: Option[] = INDEX_OPTIONS.map((o) => ({
+ value: o.value,
+ label: o.label,
+ icon: o.icon,
+}));
+
+export const SearchIndexFilter = () => {
+ const { soup, queryFilters, setQueryFilters } = useSoupView();
+
+ const activeIndex = createMemo((): Option[] => {
+ const found = INDEX_OPTIONS.find((opt) => soup.filters.isActive(opt.value));
+ return found
+ ? [{ value: found.value, label: found.label, icon: found.icon }]
+ : [];
+ });
+
+ const handleChange = (selected: Option[]) => {
+ batch(() => {
+ for (const opt of INDEX_OPTIONS) {
+ if (soup.filters.isActive(opt.value)) {
+ soup.filters.toggle({ or: [opt.value as FilterID] });
+ }
+ }
+
+ const prevChannelFilters = queryFilters().channel_filters;
+ const channelSubFilters = {
+ channel_ids: prevChannelFilters?.channel_ids,
+ sender_ids: prevChannelFilters?.sender_ids,
+ };
+
+ if (selected.length > 0) {
+ const opt = INDEX_OPTIONS.find((o) => o.value === selected[0].value);
+ if (opt) {
+ soup.filters.toggle({ or: [opt.value as FilterID] });
+ setQueryFilters({
+ ...opt.queryFilters,
+ channel_filters: {
+ ...opt.queryFilters.channel_filters,
+ ...channelSubFilters,
+ },
+ });
+ }
+ } else {
+ setQueryFilters({
+ ...QUERY_FILTERS.default,
+ channel_filters: {
+ ...channelSubFilters,
+ },
+ });
+ }
+ });
+ };
+
+ const indexLabel = createMemo(() => {
+ const active = activeIndex();
+ return active.length > 0 ? active[0].label : 'All';
+ });
+
+ const isChannelsActive = () =>
+ activeIndex().some((o) => o.value === 'channels');
+
+ return (
+ <div class="flex items-center gap-1.5">
+ <FilterSelect
+ label={indexLabel()}
+ options={INDEX_SELECT_OPTIONS}
+ active={activeIndex()}
+ onChange={handleChange}
+ multiple={false}
+ />
+ <Show when={isChannelsActive()}>
+ <InChannelFilter />
+ <FromSenderFilter />
+ </Show>
+ </div>
+ );
+};
+
+const InChannelFilter = () => {
+ const { setQueryFilters, queryFilters } = useSoupView();
+ const { useList } = useQuickAccess();
+ const channels = useList('channel', 'dm');
+
+ const channelOptions = createMemo((): Option[] =>
+ channels()
+ .filter((ch) => ch.data.name)
+ .map((ch) => ({
+ value: ch.id,
+ label: ch.data.name,
+ icon: () => (
+ <EntityIcon targetType={ch.data.channelType || 'channel'} size="xs" />
+ ),
+ }))
+ );
+
+ const activeChannelFilter = createMemo((): Option[] => {
+ const ids = queryFilters().channel_filters?.channel_ids;
+ if (!ids?.length) return [];
+ return channelOptions().filter((opt) => ids.includes(opt.value));
+ });
+
+ const inLabel = createMemo(() => {
+ const active = activeChannelFilter();
+ if (active.length === 0) return 'In';
+ if (active.length === 1) return `In: ${active[0].label}`;
+ return `In: ${active.length} channels`;
+ });
+
+ const handleChange = (selected: Option[]) => {
+ const ids = selected.map((opt) => opt.value);
+ setQueryFilters((prev) => ({
+ ...prev,
+ channel_filters: {
+ ...prev.channel_filters,
+ channel_ids: ids.length > 0 ? ids : undefined,
+ },
+ }));
+ };
+
+ return (
+ <div class="flex items-stretch">
+ <FilterCombobox
+ label={inLabel()}
+ options={channelOptions()}
+ active={activeChannelFilter()}
+ onChange={handleChange}
+ placeholder="Search channels..."
+ virtualized
+ />
+ <Show when={activeChannelFilter().length > 0}>
+ <button
+ type="button"
+ class="flex items-center ml-[-1px] px-1 border border-accent/30 bg-accent/15 text-accent rounded-r-xs hover:bg-accent/25"
+ onClick={() => handleChange([])}
+ >
+ <XIcon class="size-3" />
+ </button>
+ </Show>
+ </div>
+ );
+};
+
+const FromSenderFilter = () => {
+ const { setQueryFilters, queryFilters } = useSoupView();
+ const { useList } = useQuickAccess();
+ const contacts = useList('person');
+ const userId = useUserId();
+
+ const senderOptions = createMemo((): Option[] => {
+ const currentUserId = userId();
+ let me: Option | undefined;
+ const others: Option[] = [];
+ for (const c of contacts()) {
+ const opt: Option = {
+ value: c.id,
+ label:
+ c.id === currentUserId
+ ? `${c.data.name || 'Me'} (me)`
+ : c.data.name || c.id,
+ icon: () => (
+ <UserIcon id={c.id} size="xs" suppressClick showTooltip={false} />
+ ),
+ };
+ if (c.id === currentUserId) {
+ me = opt;
+ } else {
+ others.push(opt);
+ }
+ }
+ return [...(me ? [me] : []), ...others];
+ });
+
+ const activeSenderFilter = createMemo((): Option[] => {
+ const ids = queryFilters().channel_filters?.sender_ids;
+ if (!ids?.length) return [];
+ return senderOptions().filter((opt) => ids.includes(opt.value));
+ });
+
+ const fromLabel = createMemo(() => {
+ const active = activeSenderFilter();
+ if (active.length === 0) return 'From';
+ if (active.length === 1) return `From: ${active[0].label}`;
+ return `From: ${active.length} people`;
+ });
+
+ const handleChange = (selected: Option[]) => {
+ const ids = selected.map((opt) => opt.value);
+ setQueryFilters((prev) => ({
+ ...prev,
+ channel_filters: {
+ ...prev.channel_filters,
+ sender_ids: ids.length > 0 ? ids : undefined,
+ },
+ }));
+ };
+
+ return (
+ <div class="flex items-stretch">
+ <FilterCombobox
+ label={fromLabel()}
+ options={senderOptions()}
+ active={activeSenderFilter()}
+ onChange={handleChange}
+ placeholder="Search senders..."
+ virtualized
+ />
+ <Show when={activeSenderFilter().length > 0}>
+ <button
+ type="button"
+ class="flex items-center ml-[-1px] px-1 border border-accent/30 bg-accent/15 text-accent rounded-r-xs hover:bg-accent/25"
+ onClick={() => handleChange([])}
+ >
+ <XIcon class="size-3" />
+ </button>
+ </Show>
+ </div>
+ );
+};
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-operator-autocomplete.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-operator-autocomplete.tsx
new file mode 100644
index 0000000000..292f6f913c
--- /dev/null
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-operator-autocomplete.tsx
@@ -0,0 +1,135 @@
+import { cn } from '@ui/utils/classname';
+import { EntityIcon } from '@core/component/EntityIcon';
+import { UserIcon } from '@core/component/UserIcon';
+import { useQuickAccess } from '@core/context/quickAccess';
+import { useUserId } from '@core/context/user';
+import { createMemo, For, type JSX, Show } from 'solid-js';
+import type { ActiveOperator, OperatorType } from './parse-search-operators';
+import { INDEX_OPTIONS as INDEX_OPTIONS_SOURCE } from './search-filter-controls';
+
+export type AutocompleteOption = {
+ id: string;
+ label: string;
+ icon?: () => JSX.Element;
+};
+
+export const INDEX_OPTIONS: AutocompleteOption[] = INDEX_OPTIONS_SOURCE.map(
+ (o) => ({ id: o.value, label: o.label, icon: o.icon })
+);
+
+interface SearchOperatorAutocompleteProps {
+ activeOperator: ActiveOperator;
+ onSelect: (type: OperatorType, option: AutocompleteOption) => void;
+ onDismiss: () => void;
+ highlightedIndex: () => number;
+ setHighlightedIndex: (index: number) => void;
+}
+
+export const SearchOperatorAutocomplete = (
+ props: SearchOperatorAutocompleteProps
+) => {
+ const { useList } = useQuickAccess();
+ const channels = useList('channel', 'dm');
+ const contacts = useList('person');
+ const userId = useUserId();
+
+ const channelOptions = createMemo((): AutocompleteOption[] =>
+ channels()
+ .filter((ch) => ch.data.name)
+ .map((ch) => ({
+ id: ch.id,
+ label: ch.data.name,
+ icon: () => (
+ <EntityIcon targetType={ch.data.channelType || 'channel'} size="xs" />
+ ),
+ }))
+ );
+
+ const contactOptions = createMemo((): AutocompleteOption[] => {
+ const currentUserId = userId();
+ let me: AutocompleteOption | undefined;
+ const others: AutocompleteOption[] = [];
+ for (const c of contacts()) {
+ const opt: AutocompleteOption = {
+ id: c.id,
+ label:
+ c.id === currentUserId
+ ? `${c.data.name || 'Me'} (me)`
+ : c.data.name || c.id,
+ icon: () => (
+ <UserIcon id={c.id} size="xs" suppressClick showTooltip={false} />
+ ),
+ };
+ if (c.id === currentUserId) {
+ me = opt;
+ } else {
+ others.push(opt);
+ }
+ }
+ return [...(me ? [me] : []), ...others];
+ });
+
+ const baseOptions = createMemo((): AutocompleteOption[] => {
+ switch (props.activeOperator.type) {
+ case 'index':
+ return INDEX_OPTIONS;
+ case 'in':
+ return channelOptions();
+ case 'from':
+ return contactOptions();
+ }
+ });
+
+ const filteredOptions = createMemo((): AutocompleteOption[] => {
+ const partial = props.activeOperator.partial.toLowerCase();
+ if (!partial) return baseOptions();
+ return baseOptions().filter((opt) =>
+ opt.label.toLowerCase().includes(partial)
+ );
+ });
+
+ return (
+ <Show when={filteredOptions().length > 0}>
+ <div
+ data-operator-dropdown
+ class="absolute left-0 top-full mt-1 z-action-menu bg-surface-0 border border-edge-muted rounded-sm shadow-md min-w-[200px] max-w-[320px] max-h-[240px] overflow-y-auto p-1"
+ onMouseDown={(e) => e.preventDefault()}
+ >
+ <div class="px-2 py-1 text-[10px] text-ink-faint uppercase tracking-wider">
+ {props.activeOperator.type === 'index' && 'Filter by type'}
+ {props.activeOperator.type === 'in' && 'Filter by channel'}
+ {props.activeOperator.type === 'from' && 'Filter by sender'}
+ </div>
+ <For each={filteredOptions()}>
+ {(option, index) => {
+ const highlighted = () => props.highlightedIndex() === index();
+ return (
+ <button
+ type="button"
+ class={cn(
+ 'w-full flex items-center gap-2.5 px-3 py-1.5 rounded-xs text-left text-xs transition-colors',
+ highlighted() ? 'bg-hover' : 'hover:bg-hover'
+ )}
+ onClick={() =>
+ props.onSelect(props.activeOperator.type, option)
+ }
+ onMouseEnter={() => props.setHighlightedIndex(index())}
+ >
+ <Show when={option.icon}>
+ {(icon) => (
+ <span class="size-4 flex items-center justify-center shrink-0">
+ {icon()()}
+ </span>
+ )}
+ </Show>
+ <span class="flex-1 truncate text-ink-muted">
+ {option.label}
+ </span>
+ </button>
+ );
+ }}
+ </For>
+ </div>
+ </Show>
+ );
+};
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx
index 3f33b12e32..d000975e91 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx
@@ -6,6 +6,7 @@ import type { ListView } from '@app/constants/list-views';
import { createMemo, createSignal, Match, Show, Switch } from 'solid-js';
import { UnifiedFilterDropdown } from '@app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown';
import { ActiveFilterChips } from '@app/component/next-soup/soup-view/filters-bar/active-filter-chips';
+import { SearchIndexFilter } from '@app/component/next-soup/soup-view/filters-bar/search-filter-controls';
import { isMobile } from '@core/mobile/isMobile';
import { LabelAndHotKey, Tooltip } from '@core/component/Tooltip';
import { Button } from './button';
@@ -72,6 +73,7 @@ export const SoupFiltersBar = () => {
<Match when={isComponentListView('search')}>
<div class="w-full flex flex-col gap-2 p-2 border-b border-edge-muted/50">
<SoupSearchbar autoFocus />
+ <SearchIndexFilter />
</div>
</Match>
<Match when={true}>
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx
index 3505748679..dc75048ceb 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx
@@ -5,8 +5,31 @@ import { useSoupView } from '@app/component/next-soup/soup-view/soup-view-contex
import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';
import { Hotkey } from '@core/component/Hotkey';
import { LabelAndHotKey, Tooltip } from '@core/component/Tooltip';
+import { ENABLE_SEARCH_QUERY_OPERATORS } from '@core/constant/featureFlags';
import { registerHotkey } from '@core/hotkey/hotkeys';
-import { createSignal, createEffect, onCleanup, Show } from 'solid-js';
+import {
+ createSignal,
+ createEffect,
+ onCleanup,
+ Show,
+ createMemo,
+} from 'solid-js';
+import { QUERY_FILTERS } from '@app/component/next-soup/filters/query-filters';
+import {
+ detectActiveOperator,
+ stripOperatorAtRange,
+} from './parse-search-operators';
+import {
+ INDEX_OPTIONS,
+ SearchOperatorAutocomplete,
+ type AutocompleteOption,
+} from './search-operator-autocomplete';
+import { INDEX_OPTIONS as INDEX_OPTIONS_SOURCE } from './search-filter-controls';
+import type { OperatorType } from './parse-search-operators';
+
+const INDEX_QUERY_FILTERS = Object.fromEntries(
+ INDEX_OPTIONS_SOURCE.map((o) => [o.value, o.queryFilters])
+);
type SearchbarVariant = 'filled' | 'secondary';
@@ -24,7 +47,7 @@ const variantStyles: Record<SearchbarVariant, string> = {
};
export const SoupSearchbar = (props: SoupSearchbarProps) => {
- const { searchText, setSearchText } = useSoupView();
+ const { searchText, setSearchText, soup, setQueryFilters } = useSoupView();
const panel = useSplitPanelOrThrow();
const [ref, setRef] = createSignal<HTMLInputElement | undefined>();
@@ -32,6 +55,25 @@ export const SoupSearchbar = (props: SoupSearchbarProps) => {
const [searchFocused, setSearchFocused] = createSignal(false);
const [measuredWidth, setMeasuredWidth] = createSignal(0);
+ const [cursorPos, setCursorPos] = createSignal(0);
+ const [highlightedIndex, setHighlightedIndex] = createSignal(0);
+
+ const activeOperator = createMemo(() => {
+ if (!ENABLE_SEARCH_QUERY_OPERATORS) return null;
+ if (!searchFocused()) return null;
+ return detectActiveOperator(searchText(), cursorPos());
+ });
+
+ createEffect(() => {
+ if (activeOperator()) {
+ setHighlightedIndex(0);
+ }
+ });
+
+ const updateCursorPos = () => {
+ const el = ref();
+ if (el) setCursorPos(el.selectionStart ?? el.value.length);
+ };
createEffect(() => {
if (measureSpan) {
@@ -68,8 +110,141 @@ export const SoupSearchbar = (props: SoupSearchbarProps) => {
return Math.max(MIN_INPUT_WIDTH, measuredWidth());
};
+ const handleSelect = (type: OperatorType, option: AutocompleteOption) => {
+ const op = activeOperator();
+ if (!op) return;
+
+ const newText = stripOperatorAtRange(
+ searchText(),
+ op.startIndex,
+ op.endIndex
+ );
+ setSearchText(newText);
+
+ switch (type) {
+ case 'index': {
+ for (const opt of INDEX_OPTIONS) {
+ if (soup.filters.isActive(opt.id)) {
+ soup.filters.toggle({ or: [opt.id] });
+ }
+ }
+ soup.filters.toggle({ or: [option.id] });
+ const qf = INDEX_QUERY_FILTERS[option.id];
+ if (qf) setQueryFilters(qf);
+ break;
+ }
+ case 'in': {
+ if (!soup.filters.isActive('channels')) {
+ for (const opt of INDEX_OPTIONS) {
+ if (soup.filters.isActive(opt.id)) {
+ soup.filters.toggle({ or: [opt.id] });
+ }
+ }
+ soup.filters.toggle({ or: ['channels'] });
+ setQueryFilters({
+ ...QUERY_FILTERS.channels,
+ channel_filters: {
+ ...QUERY_FILTERS.channels.channel_filters,
+ channel_ids: [option.id],
+ },
+ });
+ } else {
+ setQueryFilters((prev) => ({
+ ...prev,
+ channel_filters: {
+ ...prev.channel_filters,
+ channel_ids: [
+ ...(prev.channel_filters?.channel_ids ?? []),
+ option.id,
+ ],
+ },
+ }));
+ }
+ break;
+ }
+ case 'from': {
+ if (!soup.filters.isActive('channels')) {
+ for (const opt of INDEX_OPTIONS) {
+ if (soup.filters.isActive(opt.id)) {
+ soup.filters.toggle({ or: [opt.id] });
+ }
+ }
+ soup.filters.toggle({ or: ['channels'] });
+ setQueryFilters({
+ ...QUERY_FILTERS.channels,
+ channel_filters: {
+ ...QUERY_FILTERS.channels.channel_filters,
+ sender_ids: [option.id],
+ },
+ });
+ } else {
+ setQueryFilters((prev) => ({
+ ...prev,
+ channel_filters: {
+ ...prev.channel_filters,
+ sender_ids: [
+ ...(prev.channel_filters?.sender_ids ?? []),
+ option.id,
+ ],
+ },
+ }));
+ }
+ break;
+ }
+ }
+
+ queueMicrotask(() => ref()?.focus());
+ };
+
+ const handleKeyDown = (e: KeyboardEvent) => {
+ const input = e.currentTarget as HTMLInputElement | null;
+ const op = activeOperator();
+
+ if (op) {
+ if (e.key === 'ArrowDown') {
+ e.preventDefault();
+ setHighlightedIndex((i) => i + 1);
+ return;
+ }
+ if (e.key === 'ArrowUp') {
+ e.preventDefault();
+ setHighlightedIndex((i) => Math.max(0, i - 1));
+ return;
+ }
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ const dropdownEl = ref()
+ ?.closest('[data-search-bar-wrapper]')
+ ?.querySelector('[data-operator-dropdown]');
+ if (dropdownEl) {
+ const buttons = dropdownEl.querySelectorAll('button');
+ const idx = highlightedIndex();
+ if (buttons[idx]) {
+ (buttons[idx] as HTMLButtonElement).click();
+ }
+ }
+ return;
+ }
+ if (e.key === 'Escape') {
+ e.preventDefault();
+ input?.blur();
+ props.onDismiss?.();
+ return;
+ }
+ } else {
+ if (e.key === 'Escape' || e.key === 'Enter' || e.key === 'ArrowDown') {
+ e.preventDefault();
+ input?.blur();
+ if (e.key === 'Escape') props.onDismiss?.();
+ }
+ }
+ };
+
return (
- <div class="w-full flex items-center shrink-0 grow min-w-0 mobile:-order-2">
+ <div
+ class="w-full flex items-center shrink-0 grow min-w-0 mobile:-order-2"
+ data-search-bar-wrapper
+ >
<Tooltip
class="w-full"
placement="bottom-start"
@@ -100,20 +275,17 @@ export const SoupSearchbar = (props: SoupSearchbarProps) => {
data-soup-search
type="text"
value={searchText()}
- onInput={(e) => setSearchText(e.currentTarget.value)}
- onFocus={() => setSearchFocused(true)}
- onBlur={() => setSearchFocused(false)}
- onKeyDown={(e) => {
- if (
- e.key === 'Escape' ||
- e.key === 'Enter' ||
- e.key === 'ArrowDown'
- ) {
- e.preventDefault();
- e.currentTarget.blur();
- if (e.key === 'Escape') props.onDismiss?.();
- }
+ onInput={(e) => {
+ setSearchText(e.currentTarget.value);
+ queueMicrotask(updateCursorPos);
}}
+ onClick={updateCursorPos}
+ onFocus={() => {
+ setSearchFocused(true);
+ queueMicrotask(updateCursorPos);
+ }}
+ onBlur={() => setSearchFocused(false)}
+ onKeyDown={handleKeyDown}
class="peer p-0 bg-transparent border-none outline-none ring-0 focus:outline-none focus:ring-0 cursor-default w-full"
style={{ width: `${inputWidth()}px` }}
/>
@@ -141,6 +313,17 @@ export const SoupSearchbar = (props: SoupSearchbarProps) => {
<XIcon class="size-4 mobile:size-6" />
</button>
</Show>
+ <Show when={activeOperator()}>
+ {(op) => (
+ <SearchOperatorAutocomplete
+ activeOperator={op()}
+ onSelect={handleSelect}
+ onDismiss={() => ref()?.blur()}
+ highlightedIndex={highlightedIndex}
+ setHighlightedIndex={setHighlightedIndex}
+ />
+ )}
+ </Show>
</div>
</Tooltip>
</div>
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/use-filter-refinements.ts b/js/app/packages/app/component/next-soup/soup-view/filters-bar/use-filter-refinements.ts
index ac24be601a..1fdaf341d3 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/use-filter-refinements.ts
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/use-filter-refinements.ts
@@ -3,16 +3,22 @@ import {
type PresetContext,
} from '@app/component/app-sidebar/soup-filter-presets';
import type { FilterID } from '@app/component/next-soup/filters/configs';
+import {
+ NIL_UUID,
+ QUERY_FILTERS,
+} from '@app/component/next-soup/filters/query-filters';
import { NO_ASSIGNEE } from '@app/component/next-soup/soup-view/task-sub-filter-matcher';
import { useSoupView } from '@app/component/next-soup/soup-view/soup-view-context';
import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';
import type { ListView } from '@app/constants/list-views';
import { isListViewID } from '@app/constants/list-views';
+import { useQuickAccess } from '@core/context/quickAccess';
import { useUserContext, useUserId } from '@core/context/user';
import { deepEqual } from '@core/util/compareUtils';
import { useContacts } from '@queries/contacts/contacts';
import { batch, createMemo } from 'solid-js';
import type { ActiveFilter } from './active-filter-chips';
+import { INDEX_OPTIONS } from './search-operator-autocomplete';
import {
buildContactLabel,
VIEW_FILTER_CATEGORIES,
@@ -50,6 +56,7 @@ export function useFilterRefinements() {
const user = useUserContext();
const contacts = useContacts();
const currentUserId = useUserId();
+ const quickAccess = useQuickAccess();
const getPresetContext = (): PresetContext => ({
userId: user.userId(),
@@ -154,6 +161,32 @@ export function useFilterRefinements() {
}
}
+ // Search operator filters: index: (entity type toggles)
+ const coveredByView = new Set(
+ viewCategories().flatMap((c) => c.options.map((o) => o.id))
+ );
+ for (const option of INDEX_OPTIONS) {
+ const optionId = option.id as FilterID;
+ if (
+ !soup.filters.isActive(optionId) ||
+ coveredByView.has(optionId) ||
+ presetFilterIds.has(optionId)
+ ) {
+ continue;
+ }
+ filters.push({
+ categoryLabel: 'Index',
+ optionId: option.id,
+ optionLabel: option.label,
+ icon: option.icon,
+ categoryOptions: INDEX_OPTIONS as ActiveFilter['categoryOptions'],
+ onRemove: () => {
+ soup.filters.toggle({ or: [optionId] });
+ setQueryFilters(QUERY_FILTERS.default);
+ },
+ });
+ }
+
// Sub-filters: assignee
const optionsMap = assigneeOptionsMap();
for (const id of assigneeFilter()) {
@@ -167,6 +200,60 @@ export function useFilterRefinements() {
});
}
+ // Search operator filters: in: (channel_ids)
+ const channelIds = (
+ queryFilters().channel_filters?.channel_ids ?? []
+ ).filter((id) => id !== NIL_UUID);
+ for (const channelId of channelIds) {
+ const item = quickAccess.getById(channelId);
+ const label =
+ item && 'data' in item && item.data?.name ? item.data.name : channelId;
+ filters.push({
+ categoryLabel: 'In',
+ optionId: `in:${channelId}`,
+ optionLabel: label,
+ onRemove: () =>
+ setQueryFilters((prev) => {
+ const ids = (prev.channel_filters?.channel_ids ?? []).filter(
+ (id) => id !== channelId
+ );
+ return {
+ ...prev,
+ channel_filters: {
+ ...prev.channel_filters,
+ channel_ids: ids.length > 0 ? ids : undefined,
+ },
+ };
+ }),
+ });
+ }
+
+ // Search operator filters: from: (sender_ids)
+ const senderIds = queryFilters().channel_filters?.sender_ids ?? [];
+ for (const senderId of senderIds) {
+ const item = quickAccess.getById(senderId);
+ const label =
+ item && 'data' in item && item.data?.name ? item.data.name : senderId;
+ filters.push({
+ categoryLabel: 'From',
+ optionId: `from:${senderId}`,
+ optionLabel: label,
+ onRemove: () =>
+ setQueryFilters((prev) => {
+ const ids = (prev.channel_filters?.sender_ids ?? []).filter(
+ (id) => id !== senderId
+ );
+ return {
+ ...prev,
+ channel_filters: {
+ ...prev.channel_filters,
+ sender_ids: ids.length > 0 ? ids : undefined,
+ },
+ };
+ }),
+ });
+ }
+
return filters;
});
diff --git a/js/app/packages/core/constant/featureFlags.ts b/js/app/packages/core/constant/featureFlags.ts
index df0499fc7d..5394f63c8a 100644
--- a/js/app/packages/core/constant/featureFlags.ts
+++ b/js/app/packages/core/constant/featureFlags.ts
@@ -280,6 +280,11 @@ export const ENABLE_FEATURED_SEARCH_RESULTS = resolveFeatureFlag(
true
);
+export const ENABLE_SEARCH_QUERY_OPERATORS = resolveFeatureFlag(
+ 'ENABLE_SEARCH_QUERY_OPERATORS',
+ false
+);
+
const ENABLE_NEW_CHANNELS_OVERRIDE = true;
export function ENABLE_NEW_CHANNELS(): boolean {