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: global sort order locally (#827)
gbirmanaf97f28f94bf
diff --git a/js/app/packages/macro-entity/src/components/UnifiedInfiniteList.tsx b/js/app/packages/macro-entity/src/components/UnifiedInfiniteList.tsxindex ccae4aa8c3..a865c2197e 100644--- a/js/app/packages/macro-entity/src/components/UnifiedInfiniteList.tsx+++ b/js/app/packages/macro-entity/src/components/UnifiedInfiniteList.tsx@@ -42,6 +42,11 @@ import type {import type { WithSearch } from '../types/search';import { Entity } from './Entity';+const DEBOUNCE_FETCH_MORE_MS = 50;++// note that this must be greater than DEBOUNCE_FETCH_MORE_MS+const DEBOUNCE_LOADING_STATE_MS = 100;+const cacheMap = new Map<string,{@@ -171,6 +176,12 @@ const deduplicateEntities = <T extends EntityData>(entities: T[]): T[] => {* Sorts entities for search mode*/const sortEntitiesForSearch = <T extends EntityData>(a: T, b: T): number => {+ if (!isSearchEntity(a) || !isSearchEntity(b)) {+ if (isSearchEntity(a)) return -1;+ if (isSearchEntity(b)) return 1;+ return 0;+ }+const channelsWithNameMatchesFirst = (a: WithSearch<T>, b: WithSearch<T>) => {if (a.type === 'channel' && b.type !== 'channel' && a.search.nameHighlight)return -1;@@ -179,24 +190,18 @@ const sortEntitiesForSearch = <T extends EntityData>(a: T, b: T): number => {return 0;};- const localFirst = (a: WithSearch<T>, b: WithSearch<T>) => {- if (a.search.source === 'local' && b.search.source !== 'local') return -1;- if (a.search.source !== 'local' && b.search.source === 'local') return 1;+ // NOTE: backend returns items in descending order of updatedAt so we match that here+ const updatedAtFirst = (a: WithSearch<T>, b: WithSearch<T>) => {+ if (a.updatedAt && b.updatedAt) return b.updatedAt - a.updatedAt;+ if (a.updatedAt) return -1;+ if (b.updatedAt) return 1;return 0;};- if (isSearchEntity(a) && isSearchEntity(b)) {- return channelsWithNameMatchesFirst(a, b) || localFirst(a, b);- }-- return 0;+ // TODO: we may want to sort exact name matches first for other items too+ return channelsWithNameMatchesFirst(a, b) || updatedAtFirst(a, b);};-const DEBOUNCE_FETCH_MORE_MS = 50;--// note that this must be greater than DEBOUNCE_FETCH_MORE_MS-const DEBOUNCE_LOADING_STATE_MS = 100;-const getGroupKey = (operations?: EntityQueryOperations): PropertyKey => {if (!operations) return 0;let key = 0;@@ -494,7 +499,6 @@ export function createUnifiedInfiniteList<T extends EntityData>({onCleanup(() => debouncedFetchMore.clear());- // const cacheKey = createMemo(() => (id ? `list-cache-${id}` : null));const cacheKey = `list-cache-${id}`;// compose method to cache scroll position when called