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(soup): date range filters (#2982)
dev-rb2e11343b542f
diff --git a/js/app/packages/app/component/next-soup/filters/filter-store/compile.ts b/js/app/packages/app/component/next-soup/filters/filter-store/compile.tsindex 0402f34e32..6c71bf5951 100644--- a/js/app/packages/app/component/next-soup/filters/filter-store/compile.ts+++ b/js/app/packages/app/component/next-soup/filters/filter-store/compile.ts@@ -1,4 +1,5 @@import type {+ DateRangeFilter,EmailView,FieldFilters,FieldName,@@ -23,7 +24,15 @@ export type TargetAstMap = {emailView?: EmailView;};-type CompiledFieldName = Exclude<FieldName, 'properties'>;+type DateRangeFieldName =+ | 'documentCreatedAt'+ | 'documentUpdatedAt'+ | 'chatCreatedAt'+ | 'chatUpdatedAt'+ | 'folderCreatedAt'+ | 'folderUpdatedAt';++type CompiledFieldName = Exclude<FieldName, 'properties' | DateRangeFieldName>;const AST = {or(asts: BackendAst[]): BackendAst {@@ -94,6 +103,30 @@ const FIELD_CONFIG: Record<callAttended: { target: 'callf', field: 'Attended' },};+const DATE_RANGE_FIELDS: Record<+ string,+ { target: QueryTarget; field: string }+> = {+ documentCreatedAt: { target: 'df', field: 'ca' },+ documentUpdatedAt: { target: 'df', field: 'ua' },+ chatCreatedAt: { target: 'cf', field: 'ca' },+ chatUpdatedAt: { target: 'cf', field: 'ua' },+ folderCreatedAt: { target: 'pf', field: 'ca' },+ folderUpdatedAt: { target: 'pf', field: 'ua' },+};++const expandDateRange = (+ field: string,+ range: DateRangeFilter+): BackendAst[] => {+ const asts: BackendAst[] = [];+ if (range.gt) asts.push(AST.literal(field, { gt: range.gt }));+ if (range.gte) asts.push(AST.literal(field, { gte: range.gte }));+ if (range.lt) asts.push(AST.literal(field, { lt: range.lt }));+ if (range.lte) asts.push(AST.literal(field, { lte: range.lte }));+ return asts;+};+const propertyToAst = (p: PropertyFilter): BackendAst =>p.type === 'select'? { l: { pd: p.propertyId, v: { so: p.value } } }@@ -201,6 +234,27 @@ export function compileToAst(state: QueryState): TargetAstMap {}}+ for (const [fieldName, config] of Object.entries(DATE_RANGE_FIELDS)) {+ const includeVal = state.include[fieldName as FieldName] as+ | DateRangeFilter+ | undefined;+ const excludeVal = state.exclude[fieldName as FieldName] as+ | DateRangeFilter+ | undefined;++ if (includeVal) {+ byTarget[config.target].push(+ ...expandDateRange(config.field, includeVal)+ );+ }+ if (excludeVal) {+ const expanded = expandDateRange(config.field, excludeVal);+ if (expanded.length) {+ byTarget[config.target].push(AST.not(AST.and(expanded)));+ }+ }+ }+const result: TargetAstMap = {};for (const [target, asts] of Object.entries(byTarget)) {if (asts.length > 0) {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.tsindex 226d5f64ca..38c366a88e 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,9 @@export { defineQueryFilters } from './compile';-export type { PropertyFilter, Query, QueryState } from './types';+export type {+ DateRangeFilter,+ PropertyFilter,+ Query,+ QueryState,+} from './types';export const NIL_UUID = '00000000-0000-0000-0000-000000000000';diff --git a/js/app/packages/app/component/next-soup/filters/filter-store/types.ts b/js/app/packages/app/component/next-soup/filters/filter-store/types.tsindex a2c9ff2d42..95d37c83be 100644--- a/js/app/packages/app/component/next-soup/filters/filter-store/types.ts+++ b/js/app/packages/app/component/next-soup/filters/filter-store/types.ts@@ -1,5 +1,12 @@export type EmailView = 'inbox' | 'drafts' | 'sent' | 'all';+export type DateRangeFilter = {+ gt?: string;+ gte?: string;+ lt?: string;+ lte?: string;+};+export type PropertyFilter = {propertyId: string;type: 'select' | 'entity';@@ -47,6 +54,12 @@ export type ScalarFieldFilters = {folderSeen?: boolean;folderDone?: boolean;callAttended?: boolean;+ documentCreatedAt?: DateRangeFilter;+ documentUpdatedAt?: DateRangeFilter;+ chatCreatedAt?: DateRangeFilter;+ chatUpdatedAt?: DateRangeFilter;+ folderCreatedAt?: DateRangeFilter;+ folderUpdatedAt?: DateRangeFilter;};export type FieldFilters = ArrayFieldFilters & ScalarFieldFilters;