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.

refactor(soup): refactor query filter setting (#1464)

dev-rb848b7982d6d3
diff --git a/js/app/packages/app/component/mobile/MobileDock.tsx b/js/app/packages/app/component/mobile/MobileDock.tsx
index 904006e95d..3470eed194 100644
--- a/js/app/packages/app/component/mobile/MobileDock.tsx
+++ b/js/app/packages/app/component/mobile/MobileDock.tsx
@@ -60,7 +60,7 @@ export function MobileDock() {
const isInboxActive = () =>
soup.filters.isActive('signal') && splitIsUnifiedList();
const isPeopleTeamsActive = () =>
- soup.filters.isActive('teams-and-people') && splitIsUnifiedList();
+ soup.filters.isActive('channels') && splitIsUnifiedList();
const isTasksActive = () =>
soup.filters.isActive('task') && splitIsUnifiedList();
const isAllActive = () =>
@@ -120,7 +120,7 @@ export function MobileDock() {
ensureUnifiedList();
batch(() => {
toggleSignalFilter(false);
- activateFilter('teams-and-people');
+ activateFilter('channels');
});
}}
/>
diff --git a/js/app/packages/app/component/next-soup/filters/filters.ts b/js/app/packages/app/component/next-soup/filters/filters.ts
index e6ceda6f4a..7e34207187 100644
--- a/js/app/packages/app/component/next-soup/filters/filters.ts
+++ b/js/app/packages/app/component/next-soup/filters/filters.ts
@@ -8,11 +8,9 @@ import {
type EntityWithValidIcon,
getIconConfig,
} from '@core/component/EntityIcon';
-import type {
- SoupItemsQueryArgs,
- SoupItemsQueryFilters,
-} from '@queries/soup/items';
+import type { SoupItemsQueryFilters } from '@queries/soup/items';
import { codeFileExtensions } from '@block-code/util/languageSupport';
+import type { FilterConfig } from './create-filter-state';
import type { Component } from 'solid-js';
import { AnimatedChannelIcon } from '@macro-icons/wide/animating/channel';
import { AnimatedChatIcon } from '@macro-icons/wide/animating/chat';
@@ -22,6 +20,22 @@ import { AnimatedFolderIcon } from '@macro-icons/wide/animating/folder';
import { AnimatedStarIcon } from '@macro-icons/wide/animating/star';
import { AnimatedTaskIcon } from '@macro-icons/wide/animating/task';
+export const NIL_UUID = '00000000-0000-0000-0000-000000000000';
+
+/**
+ * Array containing NIL_UUID, used to exclude an entity type from query results.
+ *
+ * @example
+ * ```ts
+ * filters.set({
+ * query: {
+ * chat_filters: { chat_ids: EXCLUDE }, // Exclude all chats
+ * }
+ * });
+ * ```
+ */
+export const EXCLUDE: string[] = [NIL_UUID];
+
/**
* Unread filter - entity has unread content.
*
@@ -53,17 +67,6 @@ export function notDoneFilter(entity: WithNotification<EntityData>) {
);
}
-/** Filter predicate function */
-export type FilterPredicate<T> = (entity: T) => boolean;
-
-/** Filter configuration */
-export type FilterConfig<T> = {
- readonly id: string;
- readonly label: string;
- readonly predicate: FilterPredicate<T>;
- readonly group?: string;
-};
-
/** Filter group configuration */
export type FilterGroup = {
readonly id: string;
@@ -123,10 +126,8 @@ export function fileFilter(entity: EntityData): boolean {
return !['md', 'canvas'].includes(fileType);
}
-export function teamsAndPeopleFilter(entity: EntityData): boolean {
- if (entity.type !== 'channel') return false;
-
- return true;
+export function channelsFilter(entity: EntityData): boolean {
+ return entity.type === 'channel';
}
export const SOUP_FILTERS = [
@@ -206,9 +207,9 @@ export const SOUP_FILTERS = [
group: 'type',
},
{
- id: 'teams-and-people',
- label: 'Groups',
- predicate: teamsAndPeopleFilter,
+ id: 'channels',
+ label: 'Channels',
+ predicate: channelsFilter,
group: 'type',
},
] as const;
@@ -298,77 +299,80 @@ export const getFolderFileTypes = (type: 'soup' | 'search') => {
});
};
-export const NIL_UUID = '00000000-0000-0000-0000-000000000000';
+export const QUERY_FILTERS = {
+ /** Docs filter - markdown and canvas documents (excludes tasks) */
+ document: {
+ 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'] },
+ },
-const buildDefaultValue = (entityTypes: string[], required: string[]) => {
- const hasNoEntityTypes = entityTypes.length === 0;
+ /** Tasks filter - markdown documents with task subType */
+ task: {
+ channel_filters: { channel_ids: EXCLUDE },
+ chat_filters: { chat_ids: EXCLUDE },
+ email_filters: { recipients: EXCLUDE },
+ project_filters: { project_ids: EXCLUDE },
+ document_filters: { file_types: ['md'] },
+ },
- const hasSomeRequiredType = required.some((t) => entityTypes.includes(t));
+ /** Mail filter - emails */
+ email: {
+ channel_filters: { channel_ids: EXCLUDE },
+ chat_filters: { chat_ids: EXCLUDE },
+ document_filters: { document_ids: EXCLUDE },
+ project_filters: { project_ids: EXCLUDE },
+ email_filters: {},
+ },
- if (hasSomeRequiredType || hasNoEntityTypes) {
- return [];
- }
+ /** People filter - direct message channels */
+ people: {
+ chat_filters: { chat_ids: EXCLUDE },
+ document_filters: { document_ids: EXCLUDE },
+ email_filters: { recipients: EXCLUDE },
+ project_filters: { project_ids: EXCLUDE },
+ channel_filters: {},
+ },
- return [NIL_UUID];
-};
+ /** Teams filter - group channels (non-DM) */
+ teams: {
+ chat_filters: { chat_ids: EXCLUDE },
+ document_filters: { document_ids: EXCLUDE },
+ email_filters: { recipients: EXCLUDE },
+ project_filters: { project_ids: EXCLUDE },
+ channel_filters: {},
+ },
-export const buildDssFiltersRequest = (
- filters: FilterConfig<EntityData>[],
- context?: {
- extra?: SoupItemsQueryFilters;
- isSearchActive?: boolean;
- emailActive?: boolean;
- }
-): SoupItemsQueryArgs['body'] => {
- const entityTypes = filters
- .filter((f) => ENTITY_TYPE_FILTERS.includes(f.id as EntityTypeFilters))
- .map((f) => f.id);
-
- const {
- channel_filters,
- document_filters,
- chat_filters,
- email_filters,
- project_filters,
- } = context?.extra ?? {};
-
- return {
- channel_filters: {
- ...channel_filters,
- channel_ids:
- channel_filters?.channel_ids ??
- buildDefaultValue(entityTypes, ['teams', 'people']),
- },
- document_filters: {
- ...document_filters,
- document_ids:
- document_filters?.document_ids ??
- buildDefaultValue(entityTypes, ['file', 'document', 'task']),
- project_ids: document_filters?.project_ids ?? [],
- file_types: document_filters?.file_types ?? [],
- },
- chat_filters: {
- ...chat_filters,
- chat_ids:
- chat_filters?.chat_ids ?? buildDefaultValue(entityTypes, ['agent']),
- project_ids: chat_filters?.project_ids ?? [],
- },
- email_filters: {
- ...email_filters,
- recipients:
- email_filters?.recipients ??
- (context?.emailActive &&
- !context.isSearchActive &&
- (entityTypes.includes('email') || entityTypes.length === 0)
- ? []
- : [NIL_UUID]),
- },
- project_filters: {
- ...project_filters,
- project_ids:
- project_filters?.project_ids ??
- buildDefaultValue(entityTypes, ['file']),
- },
- emailView: 'all',
- };
-};
+ /** Agents filter - chats */
+ agent: {
+ channel_filters: { channel_ids: EXCLUDE },
+ document_filters: { document_ids: EXCLUDE },
+ email_filters: { recipients: EXCLUDE },
+ project_filters: { project_ids: EXCLUDE },
+ chat_filters: {},
+ },
+
+ /** Files filter - non-markdown documents (code, images, pdfs, etc.) */
+ file: {
+ channel_filters: { channel_ids: EXCLUDE },
+ chat_filters: { chat_ids: EXCLUDE },
+ email_filters: { recipients: EXCLUDE },
+ document_filters: { file_types: getFolderFileTypes('soup') },
+ },
+
+ /** Channels filter - all channels (teams and people) */
+ channels: {
+ chat_filters: { chat_ids: EXCLUDE },
+ document_filters: { document_ids: EXCLUDE },
+ email_filters: { recipients: EXCLUDE },
+ project_filters: { project_ids: EXCLUDE },
+ channel_filters: {},
+ },
+
+ /** Default - include all entity types (no filter active) */
+ default: {},
+} satisfies Record<string, SoupItemsQueryFilters>;
+
+export type QueryFilterKey = keyof typeof QUERY_FILTERS;
diff --git a/js/app/packages/app/component/next-soup/filters/index.ts b/js/app/packages/app/component/next-soup/filters/index.ts
index c002766876..80c153114b 100644
--- a/js/app/packages/app/component/next-soup/filters/index.ts
+++ b/js/app/packages/app/component/next-soup/filters/index.ts
@@ -4,15 +4,14 @@ export {
emailFilter,
fileFilter,
FILTER_GROUPS,
- type FilterConfig,
type FilterGroup,
- type FilterPredicate,
notDoneFilter,
peopleFilter,
projectFilter,
taskFilter,
teamsFilter,
unreadFilter,
+ SOUP_FILTERS,
} from './filters';
export {
@@ -21,4 +20,8 @@ export {
explicitNoiseFilter,
} from './signal-filters';
-export { createFilterState } from './create-filter-state';
+export {
+ createFilterState,
+ type FilterConfig,
+ type FilterPredicate,
+} from './create-filter-state';
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-toolbar.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-toolbar.tsx
index b15d189b1e..4bd1f6aa8b 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-toolbar.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-toolbar.tsx
@@ -21,17 +21,20 @@ import {
createSignal,
onMount,
createEffect,
+ batch,
type Component,
} from 'solid-js';
import {
ANIMATED_ICONS,
ENTITY_TYPE_FILTER_CONFIGS,
- type FilterID,
+ EXCLUDE,
getEntityTypeFilterIcon,
+ QUERY_FILTERS,
} from '@app/component/next-soup/filters/filters';
import { ENABLE_ANIMATED_ICONS } from '@core/constant/featureFlags';
import { registerHotkey } from '@core/hotkey/hotkeys';
import { useSoupView } from '@app/component/next-soup/soup-view/soup-view-context';
+import { useEmailLinksStatus } from '@core/email-link';
import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';
import type { ValidHotkey } from '@core/hotkey/types';
import { createElementSize } from '@solid-primitives/resize-observer';
@@ -59,12 +62,19 @@ const ENTITY_TYPE_SHORTCUTS: Record<
};
export const SoupToolbar = () => {
- const { soup } = useSoupView();
+ const { soup, setQueryFilters } = useSoupView();
const [scrollContainerRef, setScrollContainerRef] = createSignal<
HTMLDivElement | undefined
>(undefined);
+ const handleClear = () => {
+ batch(() => {
+ soup.filters.clear();
+ setQueryFilters(QUERY_FILTERS.default);
+ });
+ };
+
return (
<>
<SplitHeaderLeft>
@@ -89,7 +99,7 @@ export const SoupToolbar = () => {
<button
type="button"
class="flex items-center gap-1.5 px-2.5 rounded-full text-ink-muted hover:text-accent hover:bg-accent/20 active:bg-accent active:text-panel"
- onClick={soup.filters.clear}
+ onClick={handleClear}
>
<XIcon class="size-4.5" />
<span class="text-xs touch:mobile-width:text-sm leading-none">
@@ -106,38 +116,74 @@ export const SoupToolbar = () => {
);
};
+type EntityTypeFilterId =
+ | 'document'
+ | 'task'
+ | 'people'
+ | 'teams'
+ | 'agent'
+ | 'file';
+
const SoupFilters = () => {
- const { soup, setSearchText } = useSoupView();
+ const { soup, setSearchText, isSearchDisabled, setQueryFilters } =
+ useSoupView();
const panel = useSplitPanelOrThrow();
+ const emailActive = useEmailLinksStatus();
const [sortDropdownOpen, setSortDropdownOpen] = createSignal(false);
- const toggleFilter = (filter: FilterID) => {
- soup.filters.toggle(filter);
- };
-
- const toggleSignalFilter = () => {
- // If we're going to be removing the signal filter,
- // we should replace it with the explicit-noise filter
- if (soup.filters.isActive('signal')) {
- toggleFilter('explicit-noise');
+ const toggleFocus = (id: 'signal' | 'noise') => {
+ if (soup.filters.isActive(id)) {
+ soup.filters.toggle('explicit-noise');
soup.filters.deactivate('not-done');
} else {
- toggleFilter('signal');
+ soup.filters.toggle(id);
soup.filters.activate('not-done');
}
};
- const toggleNoiseFilter = () => {
- // If we're going to be removing the noise filter,
- // we should replace it with the explicit-noise filter
- if (soup.filters.isActive('noise')) {
- toggleFilter('explicit-noise');
- soup.filters.deactivate('not-done');
- } else {
- toggleFilter('noise');
- soup.filters.activate('not-done');
- }
+ const toggleUnread = () => {
+ soup.filters.toggle('unread');
+ };
+
+ const toggleEntityType = (id: EntityTypeFilterId) => {
+ const willBeActive = !soup.filters.isActive(id);
+ batch(() => {
+ soup.filters.toggle(id);
+ setQueryFilters(willBeActive ? QUERY_FILTERS[id] : QUERY_FILTERS.default);
+ });
+ };
+
+ // Email has special handling for email integration status
+ const toggleEmail = () => {
+ const willBeActive = !soup.filters.isActive('email');
+ batch(() => {
+ soup.filters.toggle('email');
+ if (willBeActive) {
+ const shouldIncludeEmails = emailActive() && isSearchDisabled();
+ setQueryFilters({
+ ...QUERY_FILTERS.email,
+ email_filters: {
+ recipients: shouldIncludeEmails ? [] : EXCLUDE,
+ },
+ });
+ } else {
+ setQueryFilters(QUERY_FILTERS.default);
+ }
+ });
+ };
+
+ const entityTypeToggleHandlers: Record<
+ (typeof ENTITY_TYPE_FILTER_CONFIGS)[number]['id'],
+ () => void
+ > = {
+ document: () => toggleEntityType('document'),
+ task: () => toggleEntityType('task'),
+ email: toggleEmail,
+ people: () => toggleEntityType('people'),
+ teams: () => toggleEntityType('teams'),
+ agent: () => toggleEntityType('agent'),
+ file: () => toggleEntityType('file'),
};
const togglePreview = () => {
@@ -162,53 +208,53 @@ const SoupFilters = () => {
{
hotkey: 'i',
description: 'Toggle Inbox',
- handler: toggleSignalFilter,
+ handler: () => toggleFocus('signal'),
},
{
hotkey: 'o',
description: 'Toggle Other',
- handler: toggleNoiseFilter,
+ handler: () => toggleFocus('noise'),
},
// Entity type filter hotkeys
{
hotkey: ENTITY_TYPE_SHORTCUTS.document,
description: 'Filter by Docs',
- handler: () => toggleFilter('document'),
+ handler: () => toggleEntityType('document'),
},
{
hotkey: ENTITY_TYPE_SHORTCUTS.task,
description: 'Filter by Tasks',
- handler: () => toggleFilter('task'),
+ handler: () => toggleEntityType('task'),
},
{
hotkey: ENTITY_TYPE_SHORTCUTS.email,
description: 'Filter by Mail',
- handler: () => toggleFilter('email'),
+ handler: toggleEmail,
},
{
hotkey: ENTITY_TYPE_SHORTCUTS.people,
description: 'Filter by People',
- handler: () => toggleFilter('people'),
+ handler: () => toggleEntityType('people'),
},
{
hotkey: ENTITY_TYPE_SHORTCUTS.teams,
description: 'Filter by Teams',
- handler: () => toggleFilter('teams'),
+ handler: () => toggleEntityType('teams'),
},
{
hotkey: ENTITY_TYPE_SHORTCUTS.agent,
description: 'Filter by Agents',
- handler: () => toggleFilter('agent'),
+ handler: () => toggleEntityType('agent'),
},
{
hotkey: ENTITY_TYPE_SHORTCUTS.file,
description: 'Filter by Files',
- handler: () => toggleFilter('file'),
+ handler: () => toggleEntityType('file'),
},
{
hotkey: 'u',
description: 'Filter by Unread',
- handler: () => toggleFilter('unread'),
+ handler: toggleUnread,
},
{
hotkey: 's',
@@ -219,8 +265,11 @@ const SoupFilters = () => {
hotkey: '/',
description: 'Clear filters',
handler: () => {
- soup.filters.clear();
- setSearchText('');
+ batch(() => {
+ soup.filters.clear();
+ setQueryFilters(QUERY_FILTERS.default);
+ setSearchText('');
+ });
},
},
{
@@ -257,7 +306,7 @@ const SoupFilters = () => {
label="Inbox"
shortcut="i"
isActive={soup.filters.isActive('signal')}
- onClick={toggleSignalFilter}
+ onClick={() => toggleFocus('signal')}
/>
{/* Other toggle */}
<FilterButton
@@ -266,7 +315,7 @@ const SoupFilters = () => {
label="Other"
shortcut="o"
isActive={soup.filters.isActive('noise')}
- onClick={toggleNoiseFilter}
+ onClick={() => toggleFocus('noise')}
/>
<FilterDivider />
{/* Unread filter */}
@@ -280,7 +329,7 @@ const SoupFilters = () => {
'text-ink-muted hover:text-accent hover:bg-accent/20':
!soup.filters.isActive('unread'),
}}
- onClick={() => soup.filters.toggle('unread')}
+ onClick={toggleUnread}
>
<svg
class="size-4"
@@ -313,7 +362,7 @@ const SoupFilters = () => {
label={filter.label ?? ''}
shortcut={shortcut}
isActive={() => soup.filters.isActive(filter.id)}
- onClick={() => toggleFilter(filter.id)}
+ onClick={entityTypeToggleHandlers[filter.id]}
paddingClass="px-2.5"
/>
);
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 042b7eabf0..0d83ce476a 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
@@ -3,13 +3,9 @@ import {
createSoupState,
type SoupState,
} from '@app/component/next-soup/create-soup-state';
-import {
- buildDssFiltersRequest,
- getFolderFileTypes,
-} from '@app/component/next-soup/filters/filters';
+import { getFolderFileTypes } from '@app/component/next-soup/filters/filters';
import { sortEntitiesForSearch } from '@app/component/next-soup/soup-view/sort-options';
import { deduplicateEntities } from '@app/component/next-soup/utils';
-import { useEmailLinksStatus } from '@core/email-link';
import { arrayEquals } from '@core/util/compareUtils';
import { debouncedDependent } from '@core/util/debounce';
import { fuzzyMatch } from '@core/util/fuzzy';
@@ -30,6 +26,7 @@ import {
createSignal,
type FlowComponent,
on,
+ type Setter,
Suspense,
useContext,
} from 'solid-js';
@@ -70,6 +67,7 @@ interface SoupViewContextValues {
setSearchText: (value: string) => void;
isSearchDisabled: Accessor<boolean>;
rows: Accessor<SoupRow[]>;
+ setQueryFilters: Setter<SoupItemsQueryFilters>;
}
export const SoupViewContext = createContext<SoupViewContextValues>();
@@ -98,9 +96,9 @@ export const SoupViewContextProvider: FlowComponent<
> = (props) => {
const soup = props.soup ?? createSoupState();
- const emailActive = useEmailLinksStatus();
-
const [searchText, setSearchText] = createSignal('');
+ const [internalQueryFilters, setQueryFilters] =
+ createSignal<SoupItemsQueryFilters>({});
const debouncedSearchForLocal = debouncedDependent(
searchText,
@@ -173,25 +171,33 @@ export const SoupViewContextProvider: FlowComponent<
);
const queryFilters = createMemo(() => {
- const base = buildDssFiltersRequest(soup.filters.active(), {
- extra: props.queryFilters,
- isSearchActive: !isSearchDisabled(),
- emailActive: emailActive(),
- });
+ const base = internalQueryFilters();
- if (soup.filters.isActive('file')) {
- if (base.document_filters?.file_types) {
- base.document_filters.file_types = getFolderFileTypes('soup');
- }
- }
-
- if (soup.filters.isActive('task')) {
- if (base.document_filters?.file_types) {
- base.document_filters.file_types = ['md'];
- }
- }
-
- return base;
+ return {
+ ...base,
+ ...props.queryFilters,
+ // Deep merge individual filter objects if both exist
+ channel_filters: {
+ ...base.channel_filters,
+ ...props.queryFilters?.channel_filters,
+ },
+ chat_filters: {
+ ...base.chat_filters,
+ ...props.queryFilters?.chat_filters,
+ },
+ document_filters: {
+ ...base.document_filters,
+ ...props.queryFilters?.document_filters,
+ },
+ email_filters: {
+ ...base.email_filters,
+ ...props.queryFilters?.email_filters,
+ },
+ project_filters: {
+ ...base.project_filters,
+ ...props.queryFilters?.project_filters,
+ },
+ };
});
const searchFilters = createMemo(() => {
@@ -411,6 +417,7 @@ export const SoupViewContextProvider: FlowComponent<
searchText,
setSearchText,
isSearchDisabled,
+ setQueryFilters,
};
return (
diff --git a/js/app/packages/block-project/component/Block.tsx b/js/app/packages/block-project/component/Block.tsx
index e7124d90de..cddb416948 100644
--- a/js/app/packages/block-project/component/Block.tsx
+++ b/js/app/packages/block-project/component/Block.tsx
@@ -110,7 +110,6 @@ const Block: Component = () => {
filterConfigs: [
{
id: 'project-content',
- label: 'Project content',
predicate: (entity) => PROJECT_ENTITY_TYPES.includes(entity.type),
},
],