Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ interface SearchResult {
const searchResultsTableColumns: NonNullable<TableProps<SearchResult>["columns"]> = [
{
dataIndex: "timestamp",
defaultSortOrder: "ascend",
defaultSortOrder: "descend",
key: "timestamp",
render: (timestamp: number) => dayjs(timestamp).format(DATETIME_FORMAT_TEMPLATE),
sorter: (a, b) => a.timestamp - b.timestamp,
sorter: (a, b) => {
const timestampDiff = a.timestamp - b.timestamp;
if (0 !== timestampDiff) {
return timestampDiff;
}

return a._id.localeCompare(b._id);
},
Comment on lines +37 to +43

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Comparator returns ascending order; verify this aligns with intended “descend” default

defaultSortOrder is set to "descend", yet the comparator returns a.timestamp - b.timestamp, which produces an ascending result set that Ant Design will then invert to achieve descending order.
If someone later removes/changes defaultSortOrder, the implicit coupling may break. Consider returning the inverted difference to make the comparator self-contained and future-proof:

-const timestampDiff = a.timestamp - b.timestamp;
+const timestampDiff = b.timestamp - a.timestamp;

Same reasoning applies to the _id fallback:

-return a._id.localeCompare(b._id);
+return b._id.localeCompare(a._id);

This keeps the comparator’s semantics clear and avoids relying on external props for direction.


🏁 Script executed:

#!/bin/bash
# Search for defaultSortOrder occurrences across the codebase
rg -n "defaultSortOrder" -A3 -B3

echo "----"
# Search for sorter definitions in SearchResultsTable directory
rg -n "sorter" -A5 -B5 components/log-viewer-webui/client/src/pages/SearchPage/SearchResults

Length of output: 2691


Make the sorter self-contained by flipping to descending

The current comparator (a.timestamp - b.timestamp) produces an ascending sort that Ant Design then reverses due to defaultSortOrder: "descend". To avoid this implicit coupling—so changing or removing defaultSortOrder won’t silently break the order—flip both parts of the comparator to sort descending by default:

• File:
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx
• Around lines 36–43

-        sorter: (a, b) => {
-            const timestampDiff = a.timestamp - b.timestamp;
+        sorter: (a, b) => {
+            const timestampDiff = b.timestamp - a.timestamp;
             if (0 !== timestampDiff) {
                 return timestampDiff;
             }
-
-            return a._id.localeCompare(b._id);
+            return b._id.localeCompare(a._id);
         },

This change makes the comparator’s intent explicit and decoupled from the defaultSortOrder prop.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const timestampDiff = a.timestamp - b.timestamp;
if (0 !== timestampDiff) {
return timestampDiff;
}
return a._id.localeCompare(b._id);
},
sorter: (a, b) => {
const timestampDiff = b.timestamp - a.timestamp;
if (0 !== timestampDiff) {
return timestampDiff;
}
return b._id.localeCompare(a._id);
},
🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx
around lines 36 to 43, the comparator currently returns ascending order by
subtracting timestamps (a.timestamp - b.timestamp) and using localeCompare on
_id, which relies on the external defaultSortOrder "descend" to invert the
order. To make the comparator self-contained and explicitly descending, invert
the subtraction to (b.timestamp - a.timestamp) and reverse the localeCompare to
b._id.localeCompare(a._id). This ensures the comparator inherently sorts in
descending order without depending on external props.


// Specifying a third sort direction removes ability for user to cancel sorting.
sortDirections: [
Expand Down Expand Up @@ -68,8 +75,15 @@ const searchResultsTableColumns: NonNullable<TableProps<SearchResult>["columns"]
*/
const TABLE_BOTTOM_PADDING = 75;

/**
* The maximum number of results to retrieve for a search.
*/
const SEARCH_MAX_NUM_RESULTS = 1000;

Comment on lines +78 to +82

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Duplicate definition of SEARCH_MAX_NUM_RESULTS across client & server

A constant with the same value already lives in server/src/fastify-v2/routes/api/search/typings.ts. Maintaining two sources invites drift.
Recommend moving the value to a shared package (e.g., shared/consts.ts) and importing it in both places, or piping it from the server to the client via an API/ENV.

🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx
around lines 78 to 82, the constant SEARCH_MAX_NUM_RESULTS is duplicated from
the server code, risking value drift. To fix this, move the constant definition
to a shared module like shared/consts.ts, then import it in both the client and
server files. Alternatively, expose the value from the server via an API or
environment variable and consume it in the client to maintain a single source of
truth.


export type {SearchResult};
export {
searchResultsTableColumns, TABLE_BOTTOM_PADDING,
SEARCH_MAX_NUM_RESULTS,
searchResultsTableColumns,
TABLE_BOTTOM_PADDING,
};
Comment on lines +86 to 89

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Re-export order nit

Minor: exporting the new constant before the column configs would better match the declaration order above.

🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx
around lines 86 to 89, the export order is inconsistent with the declaration
order. Move the export of SEARCH_MAX_NUM_RESULTS to appear before the export of
searchResultsTableColumns and TABLE_BOTTOM_PADDING to match the order in which
they are declared above.

Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import MongoCollectionSocket from "../../../../api/socket/MongoCollectionSocket";
import {useCursor} from "../../../../api/socket/useCursor";
import useSearchStore, {SEARCH_STATE_DEFAULT} from "../../SearchState/index";
import {SearchResult} from "./typings";
import {
SEARCH_MAX_NUM_RESULTS,
SearchResult,
} from "./typings";


/**
Expand All @@ -20,8 +23,23 @@ const useSearchResults = () => {
return null;
}

// Retrieve 1k most recent results.
const options = {
sort: [
[
"timestamp",
"desc",
],
[
"_id",
"desc",
],
],
limit: SEARCH_MAX_NUM_RESULTS,
};

const collection = new MongoCollectionSocket(searchJobId.toString());
return collection.find({}, {});
return collection.find({}, options);
},
[searchJobId]
);
Expand Down