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(email): add inbox selector to scope the mail list (#3774)

gbirmanee6bec9be734
diff --git a/js/app/packages/app/component/next-soup/filters/filter-store/index.ts b/js/app/packages/app/component/next-soup/filters/filter-store/index.ts
index ab343b1dcf..847423067d 100644
--- a/js/app/packages/app/component/next-soup/filters/filter-store/index.ts
+++ b/js/app/packages/app/component/next-soup/filters/filter-store/index.ts
@@ -1,4 +1,8 @@
-export { defineQueryFilters, queryStateFrom } from './compile';
+export {
+ compileToAst,
+ defineQueryFilters,
+ queryStateFrom,
+} from './compile';
export type {
PropertyFilter,
Query,
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/inbox-selector.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/inbox-selector.tsx
new file mode 100644
index 0000000000..e6485344ed
--- /dev/null
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/inbox-selector.tsx
@@ -0,0 +1,82 @@
+import { useSoupView } from '@app/component/next-soup/soup-view/soup-view-context';
+import { inboxIconProps } from '@core/component/inboxIcon';
+import { UserIcon } from '@core/component/UserIcon';
+import { Combobox } from '@kobalte/core/combobox';
+import CaretDownIcon from '@phosphor/caret-down.svg';
+import TrayIcon from '@phosphor/tray.svg';
+import { useEmailLinksQuery } from '@queries/email/link';
+import { Button } from '@ui';
+import { createMemo, Show } from 'solid-js';
+import type { SearchableOption } from './search-filter-controls';
+import { SearchableMultiSelect } from './searchable-multi-select';
+
+/**
+ * Scopes the list to a subset of the user's linked inboxes. Multi-select,
+ * default = all (no clause). Hidden entirely for single-inbox users so they
+ * see no change. Selection is held in soup-view's `inboxFilter` and compiled
+ * into `Owner` email literals.
+ */
+export function InboxSelector() {
+ const linksQuery = useEmailLinksQuery();
+ const links = () => linksQuery.data?.links ?? [];
+ const { inboxFilter, setInboxFilter } = useSoupView();
+
+ const options = createMemo((): SearchableOption[] =>
+ links()
+ .map((link) => ({
+ id: link.id,
+ label: link.email_address,
+ icon: () => (
+ <UserIcon
+ {...inboxIconProps(link.email_address)}
+ photoUrl={link.photo_url ?? undefined}
+ size="sm"
+ suppressClick
+ showTooltip={false}
+ />
+ ),
+ }))
+ .sort((a, b) => a.label.localeCompare(b.label))
+ );
+
+ const activeIds = createMemo(() => {
+ const selected = inboxFilter();
+ return selected === undefined ? links().map((l) => l.id) : selected;
+ });
+
+ const onChange = (ids: string[]) =>
+ setInboxFilter(ids.length === links().length ? undefined : ids);
+
+ const label = () => {
+ const ids = inboxFilter();
+ if (ids === undefined) return 'All inboxes';
+ if (ids.length === 0) return 'No inboxes';
+ if (ids.length === 1)
+ return links().find((l) => l.id === ids[0])?.email_address ?? '1 inbox';
+ return `${ids.length} inboxes`;
+ };
+
+ return (
+ <Show when={links().length > 1}>
+ <SearchableMultiSelect
+ options={options}
+ activeIds={activeIds}
+ onChange={onChange}
+ placeholder="Search inboxes..."
+ preserveOrder
+ >
+ <Combobox.Trigger
+ as={Button}
+ variant="base"
+ size="sm"
+ depth={2}
+ class="bg-surface gap-1 max-w-50"
+ >
+ <TrayIcon />
+ <span class="truncate">{label()}</span>
+ <CaretDownIcon class="size-3 shrink-0" />
+ </Combobox.Trigger>
+ </SearchableMultiSelect>
+ </Show>
+ );
+}
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/searchable-multi-select.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/searchable-multi-select.tsx
index 349be22125..2c7ff22e9a 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/searchable-multi-select.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/searchable-multi-select.tsx
@@ -32,6 +32,8 @@ type SearchableMultiSelectProps = {
gutter?: number;
contentClass?: string;
listboxClass?: string;
+ /** Keep `options` in their given order instead of pinning selected first. */
+ preserveOrder?: boolean;
open?: Accessor<boolean>;
onOpenChange?: (open: boolean) => void;
children: JSX.Element;
@@ -140,13 +142,15 @@ export const SearchableMultiSelect = (props: SearchableMultiSelectProps) => {
const activeOptions = useActiveOptions(props.options, props.activeIds);
const hasMatches = useHasMatches(props.options, searchQuery);
- const sortedOptions = useSelectedFirst({
+ const selectedFirstOptions = useSelectedFirst({
items: props.options,
selectedIds: props.activeIds,
searchQuery,
getId: getOptionId,
sortDeps: [isOpen],
});
+ const sortedOptions = () =>
+ props.preserveOrder ? props.options() : selectedFirstOptions();
const handleChange = (selected: SearchableOption[]) => {
props.onChange(selected.map((o) => o.id));
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 46fa0d62ac..d8ab66166f 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
@@ -7,6 +7,10 @@ import {
type SoupState,
} from '@app/component/next-soup/create-soup-state';
import type { FilterContext } from '@app/component/next-soup/filters/configs/';
+import {
+ compileToAst,
+ NIL_UUID,
+} from '@app/component/next-soup/filters/filter-store';
import type { SetPredicatesInput } from '@app/component/next-soup/filters/filter-store/predicates-store';
import {
createQueryStore,
@@ -84,6 +88,8 @@ interface SoupViewContextValues {
queryFilters: QueryStore;
assigneeFilter: Accessor<string[]>;
setAssigneeFilter: Setter<string[]>;
+ inboxFilter: Accessor<string[] | undefined>;
+ setInboxFilter: Setter<string[] | undefined>;
activeTab: Accessor<string | undefined>;
setActiveTab: Setter<string | undefined>;
groupByField: Accessor<GroupByField | undefined>;
@@ -223,6 +229,10 @@ export const SoupViewContextProvider: FlowComponent<
'soup.assigneeFilter',
{ default: [] }
);
+ const [inboxFilter, setInboxFilter] = useEntryState<string[] | undefined>(
+ 'soup.inboxFilter',
+ { default: undefined }
+ );
const [activeTab, setActiveTab] = useEntryState<string | undefined>(
'soup.tab',
{ default: undefined }
@@ -250,8 +260,18 @@ export const SoupViewContextProvider: FlowComponent<
}
});
- // soupBody is derived from the query filter store's compiled AST
- const soupBody = createMemo(() => queryFilters.compile());
+ const soupBody = createMemo(() => {
+ const inboxes = inboxFilter();
+ if (inboxes === undefined) return queryFilters.compile();
+ const state = queryFilters.state;
+ return compileToAst({
+ ...state,
+ include: {
+ ...state.include,
+ emailLinkId: inboxes.length ? inboxes : [NIL_UUID],
+ },
+ });
+ });
const [searchText, setSearchText] = useEntryState<string>('search.text', {
default: props.initialSearchText ?? '',
@@ -605,6 +625,8 @@ export const SoupViewContextProvider: FlowComponent<
queryFilters,
assigneeFilter,
setAssigneeFilter,
+ inboxFilter,
+ setInboxFilter,
activeTab,
setActiveTab,
groupByField,
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 93b1e3cc5f..e498223e74 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
@@ -17,6 +17,7 @@ import type { QueryState } from '@app/component/next-soup/filters/filter-store';
import type { SetPredicatesInput } from '@app/component/next-soup/filters/filter-store/predicates-store';
import { useSoup } from '@app/component/next-soup/soup-context';
import { EmptyState } from '@app/component/next-soup/soup-view/empty-states';
+import { InboxSelector } from '@app/component/next-soup/soup-view/filters-bar/inbox-selector';
import { SoupFiltersBar } from '@app/component/next-soup/soup-view/filters-bar/soup-filters-bar';
import { SoupSearchbar } from '@app/component/next-soup/soup-view/filters-bar/soup-view-search-bar';
import { useFilterRefinements } from '@app/component/next-soup/soup-view/filters-bar/use-filter-refinements';
@@ -436,6 +437,15 @@ export const SoupView = (props: SoupViewProps) => {
/>
</Show>
</Show>
+ <Show
+ when={
+ !isMobile() &&
+ !narrowSearchExpanded() &&
+ isComponentListView('mail')
+ }
+ >
+ <InboxSelector />
+ </Show>
</div>
</SplitHeaderLeft>
<Show when={!isMobile()}>
diff --git a/js/app/packages/block-email/component/FromInboxSelector.tsx b/js/app/packages/block-email/component/FromInboxSelector.tsx
index 4202e6e356..d5d2c4ea8c 100644
--- a/js/app/packages/block-email/component/FromInboxSelector.tsx
+++ b/js/app/packages/block-email/component/FromInboxSelector.tsx
@@ -45,6 +45,10 @@ export function FromInboxSelector(props: {
}) {
const activeInbox = () =>
props.links.find((l) => l.id === props.activeLinkId) ?? props.links[0];
+ const sortedLinks = () =>
+ [...props.links].sort((a, b) =>
+ a.email_address.localeCompare(b.email_address)
+ );
return (
<Show when={activeInbox()}>
{(active) => (
@@ -67,7 +71,7 @@ export function FromInboxSelector(props: {
</Dropdown.Trigger>
<Dropdown.Content>
<Dropdown.Group>
- <For each={props.links}>
+ <For each={sortedLinks()}>
{(inbox) => (
<Dropdown.Item onSelect={() => props.onSelect(inbox.id)}>
<FromInboxOption inbox={inbox} />