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.

fix(reviews): keep pull requests in date order after live updates (#8454)

Jacob Beckerman52869750e66e
diff --git a/apps/web/src/features/reviews-view/reviews-filter.test.ts b/apps/web/src/features/reviews-view/reviews-filter.test.ts
index 085ca09056..3910a64bb9 100644
--- a/apps/web/src/features/reviews-view/reviews-filter.test.ts
+++ b/apps/web/src/features/reviews-view/reviews-filter.test.ts
@@ -9,6 +9,7 @@ import {
import {
EMPTY_REVIEWS_FILTERS,
type ReviewsFilterSelection,
+ type ReviewsSortId,
} from './reviews-types';
describe('effective review filters', () => {
@@ -76,12 +77,41 @@ describe('review link filters and priority sort', () => {
).toEqual(['urgent', 'low', 'pending', 'none']);
});
- it('leaves the order alone for other sorts', () => {
+ it('keeps the server order for rows without timestamps', () => {
expect(
ids(applyReviewLinks(reviews, linksFor, EMPTY_REVIEWS_FILTERS, 'newest'))
).toEqual(['low', 'pending', 'none', 'urgent']);
});
+ describe('date sorts', () => {
+ const dated = (id: string, updatedAt: string, createdAt: string) =>
+ ({
+ id,
+ updatedAt,
+ createdAt,
+ metadata: { labels: [] },
+ }) as unknown as GithubPullRequestEntity;
+ // `live` was updated after the page loaded, so it arrives in its old slot.
+ const fetched = [
+ dated('a', '2026-10-20T10:00:00Z', '2026-10-01T00:00:00Z'),
+ dated('live', '2026-10-21T16:30:00Z', '2026-10-02T00:00:00Z'),
+ dated('b', '2026-10-19T10:00:00Z', '2026-10-03T00:00:00Z'),
+ ];
+ const sorted = (sort: ReviewsSortId) =>
+ ids(applyReviewLinks(fetched, linksFor, EMPTY_REVIEWS_FILTERS, sort));
+
+ it('orders rows by the timestamp they are sorted on', () => {
+ expect(sorted('recently_updated')).toEqual(['live', 'a', 'b']);
+ expect(sorted('least_recently_updated')).toEqual(['b', 'a', 'live']);
+ expect(sorted('newest')).toEqual(['b', 'live', 'a']);
+ expect(sorted('oldest')).toEqual(['a', 'live', 'b']);
+ });
+
+ it('orders equal priorities by recency', () => {
+ expect(sorted('priority')).toEqual(['live', 'a', 'b']);
+ });
+ });
+
it('matches any selected priority or link and holds back unloaded rows', () => {
expect(
ids(
diff --git a/apps/web/src/features/reviews-view/reviews-filter.ts b/apps/web/src/features/reviews-view/reviews-filter.ts
index dbec7efd50..0304534b92 100644
--- a/apps/web/src/features/reviews-view/reviews-filter.ts
+++ b/apps/web/src/features/reviews-view/reviews-filter.ts
@@ -59,10 +59,33 @@ export const hasLinkFilters = (filters: ReviewsFilterSelection) =>
/** The origin filter option for pull requests nothing identifies. */
export const UNKNOWN_ORIGIN = 'unknown';
+const SORT_ORDER: Record<
+ ReviewsSortId,
+ { timestamp: 'updatedAt' | 'createdAt'; descending: boolean }
+> = {
+ priority: { timestamp: 'updatedAt', descending: true },
+ recently_updated: { timestamp: 'updatedAt', descending: true },
+ least_recently_updated: { timestamp: 'updatedAt', descending: false },
+ newest: { timestamp: 'createdAt', descending: true },
+ oldest: { timestamp: 'createdAt', descending: false },
+};
+
+const timestampMs = (value: unknown) => {
+ const ms =
+ typeof value === 'string' || typeof value === 'number'
+ ? new Date(value).getTime()
+ : Number.NaN;
+ return Number.isNaN(ms) ? Number.NEGATIVE_INFINITY : ms;
+};
+
/**
* Priority and linked-to filters, and the priority sort, which read each pull
* request's links. Rows whose links have not loaded yet are held back while
* a link filter is active, since they cannot be matched.
+ *
+ * Rows are re-sorted by their current timestamp: the local cache keeps a pull
+ * request at its fetched position after a live update changes its
+ * `updatedAt`, which would split the list's date headings.
*/
export function applyReviewLinks(
reviews: readonly GithubPullRequestEntity[],
@@ -92,10 +115,19 @@ export function applyReviewLinks(
);
});
}
+ const order = SORT_ORDER[sort];
+ const time = (review: GithubPullRequestEntity) =>
+ timestampMs(review[order.timestamp]);
+ result.sort((a, b) => {
+ const [first, second] = order.descending
+ ? [time(b), time(a)]
+ : [time(a), time(b)];
+ return first === second ? 0 : first < second ? -1 : 1;
+ });
if (sort === 'priority') {
const priority = (review: GithubPullRequestEntity): PrPriorityId =>
linksFor(review)?.priority.id ?? 'none';
- // Array sort is stable, so equal priorities keep the server's recency order.
+ // Array sort is stable, so equal priorities keep their recency order.
result.sort((a, b) => comparePriority(priority(a), priority(b)));
}
return result;