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(kommand): full-text search row in command menu (#3000)

gbirmanc17cd780bbae
diff --git a/js/app/packages/app/component/command/CommandItem.tsx b/js/app/packages/app/component/command/CommandItem.tsx
index 6b250ec81c..3c7b46d30f 100644
--- a/js/app/packages/app/component/command/CommandItem.tsx
+++ b/js/app/packages/app/component/command/CommandItem.tsx
@@ -5,11 +5,14 @@ import { For, Match, Show, Switch } from 'solid-js';
import {
isCommandItem,
isEntityItem,
+ isSearchItem,
type CommandMenuItem,
+ type SearchItem,
} from './useCommandItems';
import { Entity, type EntityData } from '@entity';
import { cn } from '@ui/utils/classname';
import Terminal from '@phosphor-icons/core/regular/terminal.svg?component-solid';
+import SearchIcon from '@macro-icons/macro-magnifying-glass.svg';
import { Dynamic } from 'solid-js/web';
export interface CommandItemProps {
@@ -116,9 +119,25 @@ function EntityDisplay(props: { entity: EntityData }) {
);
}
+function SearchDisplay(props: { item: SearchItem }) {
+ return (
+ <div class="flex items-center gap-2 flex-1 min-w-0">
+ <div class="size-5 flex items-center justify-center text-ink-muted shrink-0">
+ <SearchIcon class="size-4" />
+ </div>
+ <span class="truncate text-ink">
+ Search for <span class="text-ink">“{props.item.query}”</span>
+ </span>
+ </div>
+ );
+}
+
function ItemDisplay(props: { item: CommandMenuItem }) {
return (
<Switch>
+ <Match when={isSearchItem(props.item) && props.item}>
+ {(item) => <SearchDisplay item={item()} />}
+ </Match>
<Match when={isCommandItem(props.item) && props.item}>
{(item) => <CommandDisplay item={item()} />}
</Match>
diff --git a/js/app/packages/app/component/command/CommandMenu.tsx b/js/app/packages/app/component/command/CommandMenu.tsx
index a47a5ed383..563c7a0652 100644
--- a/js/app/packages/app/component/command/CommandMenu.tsx
+++ b/js/app/packages/app/component/command/CommandMenu.tsx
@@ -2,6 +2,7 @@ import { DialogWrapper } from '@core/component/DialogWrapper';
import {
isCommandItem,
isEntityItem,
+ isSearchItem,
type CommandMenuItem,
} from './useCommandItems';
import { getActiveCommandsFromScope } from '@core/hotkey/getCommands';
@@ -15,9 +16,11 @@ import {
createSelector,
createSignal,
For,
+ Match,
on,
onMount,
Show,
+ Switch,
} from 'solid-js';
import { type VirtualizerHandle, VList } from 'virtua/solid';
import { useSplitLayout } from '../split-layout/layout';
@@ -36,6 +39,8 @@ import { InlineEntity, type EntityData } from '@entity';
import { globalSplitManager } from '@app/signal/splitLayout';
import { isListViewID } from '@app/constants/list-views';
import { useAnalytics } from '@app/component/analytics-context';
+import { getCategorySearchFilters } from './category-search-filters';
+import { getSearchSplit } from '@app/component/next-soup/soup-view/search-controllers';
const CATEGORIES: { id: CategoryFilter; label: string }[] = [
{ id: 'all', label: 'All' },
@@ -59,6 +64,8 @@ export function CommandMenu() {
? () => isListViewID(splitManager.activeSplit()?.content().id)
: () => true; // assume list mode
+ let suppressCloseAutoFocus = false;
+
createEffect(() => {
const open = CommandState.isOpen();
if (!isListMode()) {
@@ -66,16 +73,32 @@ export function CommandMenu() {
}
if (open) {
CommandState.onMenuOpen();
+ suppressCloseAutoFocus = false;
} else {
CommandState.onMenuClose();
}
});
+ const handleSelect = (item: CommandMenuItem) => {
+ if (isSearchItem(item)) suppressCloseAutoFocus = true;
+ };
+
return (
<Dialog open={CommandState.isOpen()} onOpenChange={CommandState.setIsOpen}>
<Dialog.Portal>
- <DialogWrapper contentRef={setCommandMenuRef}>
- <CommandMenuInner commandMenuRef={commandMenuRef} />
+ <DialogWrapper
+ contentRef={setCommandMenuRef}
+ onCloseAutoFocus={(event) => {
+ if (suppressCloseAutoFocus) {
+ event.preventDefault();
+ suppressCloseAutoFocus = false;
+ }
+ }}
+ >
+ <CommandMenuInner
+ commandMenuRef={commandMenuRef}
+ onSelect={handleSelect}
+ />
</DialogWrapper>
</Dialog.Portal>
</Dialog>
@@ -174,6 +197,52 @@ export function CommandMenuInner(props: {
return;
}
+ if (isSearchItem(item)) {
+ const overrides = getCategorySearchFilters(item.category);
+ const filters = overrides?.filters ?? {};
+ const clientFilters = overrides?.clientFilters ?? {};
+ const splitManager = globalSplitManager();
+ const active = splitManager?.activeSplit();
+ const activeContent = active?.content();
+ const activeIsSearch =
+ activeContent?.type === 'component' && activeContent.id === 'search';
+
+ if (!openInNewSplit && activeIsSearch && active) {
+ const controller = getSearchSplit(active.id);
+ if (controller) {
+ controller.applyOverrides({
+ query: item.query,
+ filters,
+ clientFilters,
+ });
+ active.activate();
+ CommandState.close();
+ CommandState.setQuery('');
+ return;
+ }
+ }
+
+ openWithSplit(
+ {
+ type: 'component',
+ id: 'search',
+ params: {
+ initialQuery: item.query,
+ initialFilters: filters,
+ initialClientFilters: clientFilters,
+ },
+ },
+ {
+ referredFrom: 'kommand-menu',
+ preferNewSplit: openInNewSplit,
+ allowDuplicate: true,
+ }
+ );
+ CommandState.close();
+ CommandState.setQuery('');
+ return;
+ }
+
CommandState.close();
CommandState.setQuery('');
}
@@ -550,6 +619,7 @@ function CommandMenuFooter(props: {
const isCommand = () =>
props.selectedItem && isCommandItem(props.selectedItem);
const isEntity = () => props.selectedItem && isEntityItem(props.selectedItem);
+ const isSearch = () => props.selectedItem && isSearchItem(props.selectedItem);
return (
<div class="flex items-center gap-4 px-4 py-2 bg-panel border-t border-edge-muted text-xs text-ink-extra-muted/80">
@@ -565,25 +635,23 @@ function CommandMenuFooter(props: {
Navigate
</span>
- <Show
- when={props.isInCommandScope}
- fallback={
- <Show
- when={isCommand() || props.isEntityActionMode}
- fallback={
- <Show when={isEntity()}>
- <HotkeyHint shortcut="enter" label="Open" />
- <HotkeyHint shortcut="shift+enter" label="Open in new split" />
- </Show>
- }
- >
- <HotkeyHint shortcut="enter" label="Run action" />
- </Show>
- }
- >
- <HotkeyHint shortcut="enter" label="Run action" />
- <HotkeyHint shortcut="escape" label="Back" />
- </Show>
+ <Switch>
+ <Match when={props.isInCommandScope}>
+ <HotkeyHint shortcut="enter" label="Run action" />
+ <HotkeyHint shortcut="escape" label="Back" />
+ </Match>
+ <Match when={isCommand() || props.isEntityActionMode}>
+ <HotkeyHint shortcut="enter" label="Run action" />
+ </Match>
+ <Match when={isSearch()}>
+ <HotkeyHint shortcut="enter" label="Search" />
+ <HotkeyHint shortcut="shift+enter" label="Search in new split" />
+ </Match>
+ <Match when={isEntity()}>
+ <HotkeyHint shortcut="enter" label="Open" />
+ <HotkeyHint shortcut="shift+enter" label="Open in new split" />
+ </Match>
+ </Switch>
<Show when={!props.isInCommandScope && !props.isEntityActionMode}>
<HotkeyHint shortcut="tab" label="Category" />
diff --git a/js/app/packages/app/component/command/category-search-filters.ts b/js/app/packages/app/component/command/category-search-filters.ts
new file mode 100644
index 0000000000..39b587834d
--- /dev/null
+++ b/js/app/packages/app/component/command/category-search-filters.ts
@@ -0,0 +1,37 @@
+import { INDEX_OPTIONS } from '@app/component/next-soup/soup-view/filters-bar/search-filter-controls';
+import type { Query } from '@app/component/next-soup/filters/filter-store/types';
+import type { SetPredicatesInput } from '@app/component/next-soup/filters/filter-store/predicates-store';
+import type { CategoryFilter } from './types';
+
+export type CategorySearchFilters = {
+ filters: Query;
+ clientFilters: SetPredicatesInput<string>;
+};
+
+// Each Cmd+K category maps to a search-view INDEX_OPTIONS value so the
+// resulting Type: chip behaves the same as one picked from the filter
+// dropdown. Cmd+K DMs maps to the same channels index as Channels for now;
+// channelType-based narrowing (DMs vs non-DMs) is left for a follow-up once
+// the search backend honors it.
+const CATEGORY_TO_INDEX: Partial<Record<CategoryFilter, string>> = {
+ channels: 'channels',
+ dms: 'channels',
+ documents: 'document-or-file',
+ tasks: 'task',
+ chats: 'agent',
+ projects: 'folders',
+};
+
+export function getCategorySearchFilters(
+ category: CategoryFilter
+): CategorySearchFilters | undefined {
+ const indexValue = CATEGORY_TO_INDEX[category];
+ if (!indexValue) return undefined;
+ const option = INDEX_OPTIONS.find((o) => o.value === indexValue);
+ if (!option) return undefined;
+
+ return {
+ filters: option.queryFilters,
+ clientFilters: { or: [indexValue] },
+ };
+}
diff --git a/js/app/packages/app/component/command/useCommandItems.ts b/js/app/packages/app/component/command/useCommandItems.ts
index b7de263d3b..af67d23304 100644
--- a/js/app/packages/app/component/command/useCommandItems.ts
+++ b/js/app/packages/app/component/command/useCommandItems.ts
@@ -39,8 +39,20 @@ type CommandItem = {
displayHotkeySequence?: HotkeySequenceStep[];
};
+/** Search item: triggers full-text search in the sidebar Search view */
+type SearchItem = {
+ id: string;
+ kind: 'search';
+ bucket: 'search';
+ searchText: string;
+ sortTimestamp: number;
+ timestamps: TimestampedItem;
+ query: string;
+ category: CategoryFilter;
+};
+
/** Combined item type for command menu (quickAccess items + commands) */
-type CommandMenuItem = QuickAccessItem | CommandItem;
+type CommandMenuItem = QuickAccessItem | CommandItem | SearchItem;
function isCommandItem(item: CommandMenuItem): item is CommandItem {
return item.kind === 'command';
@@ -54,6 +66,34 @@ function isUserItem(item: CommandMenuItem): item is UserItem {
return item.kind === 'user';
}
+function isSearchItem(item: CommandMenuItem): item is SearchItem {
+ return item.kind === 'search';
+}
+
+/** Categories that surface a "Search for [query]" row in the command menu */
+const SEARCHABLE_CATEGORIES: ReadonlySet<CategoryFilter> = new Set([
+ 'all',
+ 'channels',
+ 'dms',
+ 'documents',
+ 'tasks',
+ 'chats',
+ 'projects',
+]);
+
+function makeSearchItem(query: string, category: CategoryFilter): SearchItem {
+ return {
+ id: `search:${category}:${query}`,
+ kind: 'search',
+ bucket: 'search',
+ searchText: query,
+ sortTimestamp: 0,
+ timestamps: { viewedAt: undefined, updatedAt: undefined },
+ query,
+ category,
+ };
+}
+
function createSearchConfig(hasQuery: boolean): FreshSortConfig {
return {
useViewedAt: true,
@@ -235,19 +275,34 @@ export function useCommandItems(
});
});
+ const shouldShowSearchRow = (q: string) => {
+ if (!q.trim()) return false;
+ if (CommandState.commandScopeCommands().length > 0) return false;
+ if (CommandState.isEntityActionMode()) return false;
+ return SEARCHABLE_CATEGORIES.has(categoryFilter());
+ };
+
const filteredItems = createMemo(() => {
const q = query();
const items = categoryItems();
- if (!q) {
- return items;
+ const ranked = q ? search()(items, q).map((result) => result.item) : items;
+
+ if (shouldShowSearchRow(q)) {
+ return [makeSearchItem(q, categoryFilter()), ...ranked];
}
- return search()(items, q).map((result) => result.item);
+ return ranked;
});
return filteredItems;
}
-export { isEntityItem, isUserItem, isCommandItem };
-export type { QuickAccessItem, CommandMenuItem, CommandItem, Bucket };
+export { isEntityItem, isUserItem, isCommandItem, isSearchItem };
+export type {
+ QuickAccessItem,
+ CommandMenuItem,
+ CommandItem,
+ SearchItem,
+ Bucket,
+};
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 6c0bb0b0f8..9e9d48a3dc 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
@@ -121,6 +121,8 @@ interface CreateSearchStateArgs {
disableLocalSearch?: boolean;
searchPaused?: Accessor<boolean>;
searchMentions?: Accessor<string[]>;
+ /** Pre-populate searchText so the service request fires on mount (skips the debounce wait for the initial value). */
+ initialText?: string;
}
export const createSearchState = ({
@@ -130,8 +132,9 @@ export const createSearchState = ({
disableLocalSearch,
searchPaused,
searchMentions,
+ initialText,
}: CreateSearchStateArgs) => {
- const [searchText, setSearchText] = createSignal('');
+ const [searchText, setSearchText] = createSignal(initialText ?? '');
const notificationSource = useGlobalNotificationSource();
const userId = useUserId();
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 be24a462e4..6dfc46e7a8 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
@@ -14,7 +14,11 @@ import { useSoup } from '../../soup-context';
import { registerHotkey } from '@core/hotkey/hotkeys';
import { useAnalytics } from '@app/component/analytics-context';
-export const SoupFiltersBar = () => {
+interface SoupFiltersBarProps {
+ initialSearchText?: string;
+}
+
+export const SoupFiltersBar = (props: SoupFiltersBarProps = {}) => {
const {
resetToTabDefaults,
activeFiltersList,
@@ -71,7 +75,11 @@ export const SoupFiltersBar = () => {
<Switch>
<Match when={isComponentListView('search')}>
<div class="w-full flex flex-col gap-2 p-2 border-b border-edge-muted">
- <SoupSearchbar autoFocus placeholder="Search, @mention contacts" />
+ <SoupSearchbar
+ autoFocus={!props.initialSearchText}
+ placeholder="Search, @mention contacts"
+ initialValue={props.initialSearchText}
+ />
<div class="flex items-start gap-2">
<UnifiedFilterDropdown />
<ActiveFilterChips
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 1fab95505d..4f7054d12b 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
@@ -1,15 +1,29 @@
import XIcon from '@icon/regular/x.svg?component-solid';
import SearchIcon from '@macro-icons/macro-magnifying-glass.svg';
import { cn } from '@ui/utils/classname';
+import { useSoup } from '@app/component/next-soup/soup-context';
import { useSoupView } from '@app/component/next-soup/soup-view/soup-view-context';
+import { registerSearchSplit } from '@app/component/next-soup/soup-view/search-controllers';
import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';
import { Hotkey } from '@core/component/Hotkey';
import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';
import { markdownToPlainText } from '@lexical-core/utils/parsers';
import { registerHotkey } from '@core/hotkey/hotkeys';
-import { COMMAND_PRIORITY_HIGH, KEY_ARROW_DOWN_COMMAND } from 'lexical';
-import { createSignal, createEffect, on, onCleanup, Show } from 'solid-js';
+import { batch } from 'solid-js';
+import {
+ $getRoot,
+ COMMAND_PRIORITY_HIGH,
+ KEY_ARROW_DOWN_COMMAND,
+} from 'lexical';
+import {
+ createSignal,
+ createEffect,
+ on,
+ onCleanup,
+ onMount,
+ Show,
+} from 'solid-js';
type SearchbarVariant = 'filled' | 'secondary';
@@ -18,6 +32,7 @@ interface SoupSearchbarProps {
autoFocus?: boolean;
onDismiss?: () => void;
placeholder?: string;
+ initialValue?: string;
}
const variantStyles: Record<SearchbarVariant, string> = {
@@ -28,7 +43,9 @@ const variantStyles: Record<SearchbarVariant, string> = {
};
export const SoupSearchbar = (props: SoupSearchbarProps) => {
- const { setSearchText, setSearchPaused, setSearchMentions } = useSoupView();
+ const { setSearchText, setSearchPaused, setSearchMentions, queryFilters } =
+ useSoupView();
+ const soup = useSoup();
const panel = useSplitPanelOrThrow();
const [hasContent, setHasContent] = createSignal(false);
@@ -112,6 +129,29 @@ export const SoupSearchbar = (props: SoupSearchbarProps) => {
onCleanup(searchHotkey.dispose);
+ onMount(() => {
+ const content = panel.handle.content();
+ if (content.type !== 'component' || content.id !== 'search') return;
+ const dispose = registerSearchSplit(panel.handle.id, {
+ applyOverrides: ({ query, filters, clientFilters }) => {
+ batch(() => {
+ editor.controls.setMarkdown(query);
+ editor.controls.getLexical().update(() => {
+ $getRoot().selectEnd();
+ });
+ editor.controls.blur();
+ queryFilters.replace(filters);
+ soup.predicates.set(clientFilters);
+ });
+ // Restore focus to the split panel so hotkey navigation works. The
+ // command menu suppresses Kobalte's onCloseAutoFocus for search
+ // rows so this stays put without needing a delay.
+ queueMicrotask(() => panel.panelRef()?.focus({ preventScroll: true }));
+ },
+ });
+ onCleanup(dispose);
+ });
+
return (
<div
class="w-full flex items-center shrink-0 grow min-w-0 mobile:-order-2"
@@ -133,6 +173,7 @@ export const SoupSearchbar = (props: SoupSearchbarProps) => {
config={editor}
placeholder={props.placeholder ?? 'Search'}
autofocus={props.autoFocus}
+ initialValue={props.initialValue}
class="min-h-0! overflow-visible!"
/>
</div>
diff --git a/js/app/packages/app/component/next-soup/soup-view/search-controllers.ts b/js/app/packages/app/component/next-soup/soup-view/search-controllers.ts
new file mode 100644
index 0000000000..5d7cdd6da0
--- /dev/null
+++ b/js/app/packages/app/component/next-soup/soup-view/search-controllers.ts
@@ -0,0 +1,31 @@
+import type { SetPredicatesInput } from '@app/component/next-soup/filters/filter-store/predicates-store';
+import type { Query } from '@app/component/next-soup/filters/filter-store/types';
+import type { SplitId } from '@app/component/split-layout/layoutManager';
+
+export type SearchSplitOverrides = {
+ query: string;
+ filters: Query;
+ clientFilters: SetPredicatesInput<string>;
+};
+
+export type SearchSplitController = {
+ applyOverrides: (overrides: SearchSplitOverrides) => void;
+};
+
+const registry = new Map<SplitId, SearchSplitController>();
+
+export function registerSearchSplit(
+ splitId: SplitId,
+ controller: SearchSplitController
+): () => void {
+ registry.set(splitId, controller);
+ return () => {
+ if (registry.get(splitId) === controller) registry.delete(splitId);
+ };
+}
+
+export function getSearchSplit(
+ splitId: SplitId
+): SearchSplitController | undefined {
+ return registry.get(splitId);
+}
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
index b7cccbcff5..5c28c91e96 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
@@ -102,6 +102,7 @@ export const useMaybeSoupView = () => useContext(SoupViewContext);
interface SoupViewContextProviderProps {
soup?: SoupState;
initialQuery?: Query;
+ initialSearchText?: string;
disableLocalSearch?: boolean;
/**
* Additional client-side entities to merge into the soup item stream.
@@ -200,6 +201,7 @@ export const SoupViewContextProvider: FlowComponent<
disableLocalSearch: props.disableLocalSearch,
searchPaused,
searchMentions,
+ initialText: props.initialSearchText,
});
const notificationSource = useGlobalNotificationSource();
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
index 9dd78101ef..1aea564942 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
@@ -191,6 +191,9 @@ interface SoupViewProps {
viewName: string;
initialClientFilters?: SetPredicatesInput<string>;
initialFilters?: Partial<QueryState>;
+ initialSearchText?: string;
+ /** Ignore localStorage on mount and use the supplied `initial*` values. */
+ skipPersistedState?: boolean;
disableLocalSearch?: boolean;
/**
* Client-side entities to merge into the soup results. Useful for entity
@@ -271,6 +274,7 @@ export const SoupView = (props: SoupViewProps) => {
<SoupViewContextProvider
soup={soup}
initialQuery={props.initialFilters}
+ initialSearchText={props.initialSearchText}
disableLocalSearch={props.disableLocalSearch}
additionalEntities={props.additionalEntities}
>
@@ -310,6 +314,7 @@ export const SoupView = (props: SoupViewProps) => {
<SoupSearchbar
variant="secondary"
autoFocus
+ initialValue={props.initialSearchText}
onDismiss={() => setNarrowSearchExpanded(false)}
/>
</div>
@@ -330,7 +335,10 @@ export const SoupView = (props: SoupViewProps) => {
}}
expanded={() => (
<div class="w-52">
- <SoupSearchbar variant="secondary" />
+ <SoupSearchbar
+ variant="secondary"
+ initialValue={props.initialSearchText}
+ />
</div>
)}
collapsed={() => (
@@ -353,7 +361,7 @@ export const SoupView = (props: SoupViewProps) => {
/>
</Show>
</SplitHeaderRight>
- <SoupFiltersBar />
+ <SoupFiltersBar initialSearchText={props.initialSearchText} />
</div>
<Show when={hasLinkError()}>
<EmailPermissionsBanner />
@@ -368,6 +376,7 @@ export const SoupView = (props: SoupViewProps) => {
<SoupViewFileDropzone>
<SoupViewList
initialClientFilters={props.initialClientFilters}
+ skipPersistedState={props.skipPersistedState}
/>
</SoupViewFileDropzone>
</Suspense>
@@ -393,6 +402,7 @@ interface SoupViewListProps {
customScrollbarHidden?: boolean;
scopeId?: string;
initialClientFilters?: SetPredicatesInput<string>;
+ skipPersistedState?: boolean;
}
export const SoupViewList = (props: SoupViewListProps) => {
@@ -692,9 +702,10 @@ export const SoupViewList = (props: SoupViewListProps) => {
// Restore previewEntity synchronously so the first-render effect sees the
// correct value and avoids a transient window where previewEntity is undefined.
- const initialPersistedState = !persistenceDisabled
- ? untrack(persistedState)
- : null;
+ const initialPersistedState =
+ !persistenceDisabled && !props.skipPersistedState
+ ? untrack(persistedState)
+ : null;
soup.setPreviewEntity(initialPersistedState?.previewEntity);
// Set initial state
@@ -789,7 +800,9 @@ export const SoupViewList = (props: SoupViewListProps) => {
if (restored || isProjectList) return;
restored = true;
- const cached = listStateCache.get(cacheKey);
+ const cached = props.skipPersistedState
+ ? undefined
+ : listStateCache.get(cacheKey);
if (cached) {
setSearchText(cached.searchText);
soup.focus.set(cached.focus);
diff --git a/js/app/packages/app/component/split-layout/componentRegistry.tsx b/js/app/packages/app/component/split-layout/componentRegistry.tsx
index 0906b66ecd..405b26d2c0 100644
--- a/js/app/packages/app/component/split-layout/componentRegistry.tsx
+++ b/js/app/packages/app/component/split-layout/componentRegistry.tsx
@@ -13,6 +13,8 @@ import { useAutomationEntities } from '@queries/agent-schedule/entities';
import { type Component, type JSXElement, lazy, onMount, Show } from 'solid-js';
import { EmailCompose } from '../../../block-email/component/compose/Compose';
import { SettingsPanelComponentWrapper } from '../settings/Settings';
+import type { Query } from '@app/component/next-soup/filters/filter-store/types';
+import type { SetPredicatesInput } from '@app/component/next-soup/filters/filter-store/predicates-store';
import type { SplitContent } from './layoutManager';
import { useSplitPanelOrThrow } from './layoutUtils';
@@ -239,16 +241,30 @@ registerComponent(
})
);
+type SearchComponentParams = {
+ initialQuery?: string;
+ initialFilters?: Query;
+ initialClientFilters?: SetPredicatesInput<string>;
+};
+
registerComponent(
'search',
- withAuth(() => {
+ withAuth((params: SearchComponentParams = {}) => {
usePageViewTracking('search');
const preset = getViewPreset('search');
+ const hasExplicitParams =
+ params.initialQuery !== undefined ||
+ params.initialFilters !== undefined ||
+ params.initialClientFilters !== undefined;
return (
<SoupView
viewName="Search"
- initialFilters={preset?.filters}
- initialClientFilters={preset?.clientFilters}
+ initialFilters={params.initialFilters ?? preset?.filters}
+ initialClientFilters={
+ params.initialClientFilters ?? preset?.clientFilters
+ }
+ initialSearchText={params.initialQuery}
+ skipPersistedState={hasExplicitParams}
/>
);
})
diff --git a/js/app/packages/core/component/DialogWrapper.tsx b/js/app/packages/core/component/DialogWrapper.tsx
index 8eb7c69cd4..59f403e580 100644
--- a/js/app/packages/core/component/DialogWrapper.tsx
+++ b/js/app/packages/core/component/DialogWrapper.tsx
@@ -9,6 +9,7 @@ export interface DialogWrapperProps {
width?: string;
overlayRef?: Ref<HTMLDivElement>;
contentRef?: Ref<HTMLDivElement>;
+ onCloseAutoFocus?: (event: Event) => void;
}
/**
@@ -33,6 +34,7 @@ export function DialogWrapper(props: DialogWrapperProps) {
'max-w-[calc(100vw-16px)] mt-40 mx-auto overflow-hidden portal-scope'
)}
style={{ width: width }}
+ onCloseAutoFocus={props.onCloseAutoFocus}
>
<Panel depth={3} active>
<div
diff --git a/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx b/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx
index 9ca0d3c05e..f1f4e98cb7 100644
--- a/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx
@@ -66,6 +66,9 @@ export const MarkdownShell: Component<
});
}
+ const hasInitialContent =
+ props.initialState !== undefined || props.initialValue !== undefined;
+
if (props.initialState) {
initializeEditorWithState(editor, props.initialState);
} else if (props.initialValue) {
@@ -75,6 +78,12 @@ export const MarkdownShell: Component<
}
didInitializeContent = true;
+
+ // The deferred markdownState effect misses the synchronous change inside
+ // init, so push the initial value out to onChange manually.
+ if (hasInitialContent) {
+ builderConfig.handlers.onChange?.(markdownState());
+ }
};
// Track editable state