Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat: use file type soup request filters (#790)
gbirman13c9756f5824
diff --git a/js/app/packages/app/component/UnifiedListEmptyState.tsx b/js/app/packages/app/component/UnifiedListEmptyState.tsxindex a0242a8e99..a48ea3a220 100644--- a/js/app/packages/app/component/UnifiedListEmptyState.tsx+++ b/js/app/packages/app/component/UnifiedListEmptyState.tsx@@ -117,10 +117,7 @@ export function EmptyState(props: {/></Match><Match when={props.viewId === 'all'}>- <EmptyStateHelpDrawer- message={'No items to show.'}- helpDrawer={'all'}- />+ <EmptyStateHelpDrawer helpDrawer={'all'} /></Match><Match when={true}><EmptyStateInner />diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsxindex 9853e7c2e1..d2e3a959b3 100644--- a/js/app/packages/app/component/UnifiedListView.tsx+++ b/js/app/packages/app/component/UnifiedListView.tsx@@ -5,6 +5,7 @@ import {import { noiseFilter, signalFilter } from '@app/component/soupFilters';import type { BlockChannelProps } from '@block-channel/component/Block';import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';+import { codeFileExtensions } from '@block-code/util/languageSupport';import { URL_PARAMS as EMAIL_PARAMS } from '@block-email/constants';import { URL_PARAMS as MD_PARAMS } from '@block-md/constants';import { URL_PARAMS as PDF_PARAMS } from '@block-pdf/signal/location';@@ -33,13 +34,13 @@ import { TOKENS } from '@core/hotkey/tokens';import { isTouchDevice } from '@core/mobile/isTouchDevice';import { isMobileWidth } from '@core/mobile/mobileWidth';import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';+import { arrayEquals } from '@core/util/compareUtils';import { debouncedDependent } from '@core/util/debounce';import { fuzzyMatch } from '@core/util/fuzzy';import SearchIcon from '@icon/regular/magnifying-glass.svg?component-solid';import LoadingSpinner from '@icon/regular/spinner.svg?component-solid';import XIcon from '@icon/regular/x.svg?component-solid';import { ContextMenu } from '@kobalte/core/context-menu';-import { supportedExtensions } from '@lexical-core/utils';import {createChannelsQuery,createDssInfiniteQuery,@@ -98,6 +99,7 @@ import {createRoot,createSelector,createSignal,+ For,mergeProps,on,onCleanup,@@ -150,6 +152,7 @@ import {VIEWCONFIG_BASE,VIEWCONFIG_DEFAULTS_IDS,VIEWCONFIG_DEFAULTS_IDS_ENUM,+ VIEWCONFIG_FILTER_DOCUMENT_TYPE_FILTER,type ViewConfigBase,type ViewData,} from './ViewConfig';@@ -157,6 +160,17 @@ import {const SEARCH_SERVICE_DEBOUNCE_MS = 200;const LOCAL_FUZZY_SEARCH_DEBOUNCE_MS = 20;+const NIL_UUID = '00000000-0000-0000-0000-000000000000';++const FILE_TYPE_DISPLAY_LABELS: Record<DocumentTypeFilter, string> = {+ md: 'NOTE',+ pdf: 'PDF',+ canvas: 'CANVAS',+ code: 'CODE',+ image: 'IMAGE',+ unknown: 'OTHER',+};+const sortOptions = [{value: 'viewed_at',@@ -681,46 +695,84 @@ export function UnifiedListView(props: UnifiedListViewProps) {setOptionalFilters(filterFns);});- const unifiedSearchIncludeArray = createMemo<UnifiedSearchIndex[]>(() => {- let types = entityTypeFilter();- // NOTE: empty array means search all- if (types.length === 0) types = [];- const includeArray: UnifiedSearchIndex[] = [];- for (const type of types) {- switch (type) {- case 'document':- case 'task':- includeArray.push('documents');- break;- case 'chat':- includeArray.push('chats');- break;- case 'channel':- includeArray.push('channels');- break;- case 'email':- includeArray.push('emails');- break;- case 'project':- includeArray.push('projects');- break;+ const unifiedSearchIncludeArray = createMemo<UnifiedSearchIndex[]>(+ () => {+ let types = entityTypeFilter();+ // NOTE: empty array means search all+ if (types.length === 0) types = [];+ const includeArray: UnifiedSearchIndex[] = [];+ for (const type of types) {+ switch (type) {+ case 'document':+ case 'task':+ includeArray.push('documents');+ break;+ case 'chat':+ includeArray.push('chats');+ break;+ case 'channel':+ includeArray.push('channels');+ break;+ case 'email':+ includeArray.push('emails');+ break;+ case 'project':+ includeArray.push('projects');+ break;+ }}- }- return includeArray;- });+ return Array.from(new Set(includeArray));+ },+ [],+ { equals: arrayEquals }+ );++ const createFileTypeFilterMemo = (type: 'soup' | 'search') =>+ createMemo<string[]>(+ () => {+ let fileTypes = [];+ if (entityTypeFilter().includes('task')) {+ fileTypes.push('md');+ }++ if (entityTypeFilter().includes('document')) {+ if (+ fileTypeFilter().length > 0 &&+ fileTypeFilter().length <+ VIEWCONFIG_FILTER_DOCUMENT_TYPE_FILTER.length+ ) {+ const documentFileTypes = fileTypeFilter().flatMap((fileType) => {+ if (fileType === 'code')+ return type === 'soup' ? ['assoc:code'] : codeFileExtensions;+ if (fileType === 'image')+ return type === 'soup' ? ['assoc:image'] : [NIL_UUID];+ if (fileType === 'unknown')+ return type === 'soup' ? ['assoc:other'] : [NIL_UUID];+ return [fileType];+ });+ fileTypes.push(...documentFileTypes);+ } else {+ // if we have task + document and no file type filter, we want to include all file types+ fileTypes = [];+ }+ }++ return Array.from(new Set(fileTypes));+ },+ [],+ {+ equals: arrayEquals,+ }+ );++ const joinedSoupFileTypeFilter = createFileTypeFilterMemo('soup');+ const joinedSearchFileTypeFilter = createFileTypeFilterMemo('search');const unifiedSearchFilters = createMemo<UnifiedSearchRequestFilters>(() => {let documentFilters: DocumentFilters | null = null;- if (fileTypeFilter().length > 0) {- const fileTypes = fileTypeFilter().flatMap((fileType) => {- // not ideal but it works for most cases- if (fileType === 'code') return supportedExtensions;- return [fileType];- });- documentFilters = {- file_types: fileTypes,- };- }+ documentFilters = {+ file_types: joinedSearchFileTypeFilter(),+ };let emailFilters: EmailFilters | null = null;if (shouldFilterEmails()) {@@ -794,11 +846,11 @@ export function UnifiedListView(props: UnifiedListViewProps) {sort_method: sortType(),}));- const GARBAGE_UUID = '00000000-0000-0000-0000-000000000000';+const dssQueryRequestBody = createMemo((): PostSoupRequest => ({channel_filters: {- channel_ids: [GARBAGE_UUID],+ channel_ids: [NIL_UUID],},document_filters: {document_ids:@@ -806,14 +858,15 @@ export function UnifiedListView(props: UnifiedListViewProps) {entityTypeFilter().includes('task') ||entityTypeFilter().length === 0? []- : [GARBAGE_UUID],+ : [NIL_UUID],project_ids: view().viewType === 'project' ? [view().id] : [],+ file_types: joinedSoupFileTypeFilter(),},chat_filters: {chat_ids:entityTypeFilter().includes('chat') || entityTypeFilter().length === 0? []- : [GARBAGE_UUID],+ : [NIL_UUID],project_ids: view().viewType === 'project' ? [view().id] : [],},email_filters: {@@ -824,7 +877,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {(entityTypeFilter().includes('email') ||entityTypeFilter().length === 0)? []- : [GARBAGE_UUID],+ : [NIL_UUID],},project_filters: {project_ids:@@ -833,7 +886,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {: entityTypeFilter().includes('project') ||entityTypeFilter().length === 0? []- : [GARBAGE_UUID],+ : [NIL_UUID],},limit: props.defaultDisplayOptions?.limit ?? 100,emailView: importantFilter()@@ -1374,48 +1427,17 @@ export function UnifiedListView(props: UnifiedListViewProps) {<section class="gap-1 p-2"><span class="font-medium text-xs">Filetype</span><div class="flex flex-row flex-wrap items-center gap-1">- <ToggleButton- size="SM"- pressed={fileTypeFilter().includes('md')}- onChange={() => toggleFileTypeFilter('md')}- >- NOTE- </ToggleButton>- <ToggleButton- size="SM"- pressed={fileTypeFilter().includes('pdf')}- onChange={() => toggleFileTypeFilter('pdf')}- >- </ToggleButton>- <ToggleButton- size="SM"- pressed={fileTypeFilter().includes('canvas')}- onChange={() => toggleFileTypeFilter('canvas')}- >- CANVAS- </ToggleButton>- <ToggleButton- size="SM"- pressed={fileTypeFilter().includes('code')}- onChange={() => toggleFileTypeFilter('code')}- >- CODE- </ToggleButton>- <ToggleButton- size="SM"- pressed={fileTypeFilter().includes('image')}- onChange={() => toggleFileTypeFilter('image')}- >- IMAGE- </ToggleButton>- <ToggleButton- size="SM"- pressed={fileTypeFilter().includes('unknown')}- onChange={() => toggleFileTypeFilter('unknown')}- >- Other- </ToggleButton>+ <For each={[...VIEWCONFIG_FILTER_DOCUMENT_TYPE_FILTER]}>+ {(fileType) => (+ <ToggleButton+ size="SM"+ pressed={fileTypeFilter().includes(fileType)}+ onChange={() => toggleFileTypeFilter(fileType)}+ >+ {FILE_TYPE_DISPLAY_LABELS[fileType]}+ </ToggleButton>+ )}+ </For></div></section><Show when={ENABLE_SOUP_FROM_FILTER && showFromFilter()}>diff --git a/js/app/packages/app/component/ViewConfig.tsx b/js/app/packages/app/component/ViewConfig.tsxindex 5d1f1bfd48..1cdb55bc06 100644--- a/js/app/packages/app/component/ViewConfig.tsx+++ b/js/app/packages/app/component/ViewConfig.tsx@@ -338,7 +338,7 @@ export const VIEWCONFIG_SORT_ORDER: readonly SortOptions['sortOrder'][] = ['descending',] as const;export const VIEWCONFIG_FILTER_DOCUMENT_TYPE_FILTER: readonly FilterOptions['documentTypeFilter'][number][] =- ['md', 'code', 'image', 'canvas', 'pdf', 'unknown'] as const;+ ['md', 'pdf', 'canvas', 'code', 'image', 'unknown'] as const;export const VIEWCONFIG_FILTER_ENTITY_TYPE: readonly FilterOptions['typeFilter'][number][] =['channel', 'chat', 'document', 'email', 'project', 'task'] as const;diff --git a/js/app/packages/block-code/util/languageSupport.ts b/js/app/packages/block-code/util/languageSupport.tsindex edad5927b3..8214c317d0 100644--- a/js/app/packages/block-code/util/languageSupport.ts+++ b/js/app/packages/block-code/util/languageSupport.ts@@ -112,7 +112,7 @@ const extensionToLanguage: Record<string, string> = {};// Build supported extensions from FileTypeMap where app === 'code'-const codeFileExtensions = Object.values(FileTypeMap)+export const codeFileExtensions = Object.values(FileTypeMap).filter((fileType) => fileType.app === 'code').map((fileType) => fileType.extension);diff --git a/js/app/packages/macro-entity/src/index.tsx b/js/app/packages/macro-entity/src/index.tsxindex 5acb9cb50f..de40001e7f 100644--- a/js/app/packages/macro-entity/src/index.tsx+++ b/js/app/packages/macro-entity/src/index.tsx@@ -16,7 +16,6 @@ export { useQueryClient } from './queries/client';export {createChatsInfiniteQuery,createDeleteDssItemMutation,- createDocumentsInfiniteQuery,createDssInfiniteQuery,} from './queries/dss';export { createEmailsInfiniteQuery } from './queries/email';diff --git a/js/app/packages/macro-entity/src/queries/dss.ts b/js/app/packages/macro-entity/src/queries/dss.tsindex a38e9f6f3e..8b8968c9a8 100644--- a/js/app/packages/macro-entity/src/queries/dss.ts+++ b/js/app/packages/macro-entity/src/queries/dss.ts@@ -272,62 +272,6 @@ const selectData: ();};-export function createDocumentsInfiniteQuery(- args?: GetItemsSoupParams | Accessor<GetItemsSoupParams>-) {- const params = () => {- const argParams = typeof args === 'function' ? args() : args;- const limit =- argParams?.limit && argParams.limit > 0 && argParams.limit <= 500- ? argParams.limit- : 500;- return {- ...argParams,- limit,- };- };-- const authQuery = createApiTokenQuery();- const instructionsIdQuery = useInstructionsMdIdQuery();-- return useInfiniteQuery(() => ({- queryKey: queryKeys.document({- infinite: true,- ...params(),- }),- queryHash: dssQueryKeyHashFn(- queryKeys.document({- infinite: true,- ...params(),- }) as DssQueryKey- ),- queryFn: ({ pageParam }) =>- fetchPaginatedDocumentsGet({ apiToken: authQuery.data, ...pageParam }),- initialPageParam: params(),- getNextPageParam: ({ next_cursor: cursor }) =>- cursor ? { ...params(), cursor } : undefined,- select: (data) =>- data.pages.flatMap(({ items }) =>- items- .filter((item) => item.tag === 'document')- .filter((item) => item.data.id !== instructionsIdQuery.data)- .map(- (item): DocumentEntity => ({- ...item.data,- type: item.tag,- frecencyScore: item.frecency_score,- viewedAt: item.data.viewedAt ?? undefined,- fileType: item.data.fileType ?? undefined,- projectId: item.data.projectId ?? undefined,- subType: item.data.subType ?? undefined,- name: resolveDocumentEntityName(item.data),- })- )- ),- enabled: authQuery.isSuccess,- }));-}-export function createChatsInfiniteQuery(args?: GetItemsSoupParams | Accessor<GetItemsSoupParams>) {