Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(frontend): list trade symbols in code order

alex3fc42d7b6477
diff --git a/frontend/src/pages/RunDetail.tsx b/frontend/src/pages/RunDetail.tsx
index d5a1a3b37..ce521e34d 100644
--- a/frontend/src/pages/RunDetail.tsx
+++ b/frontend/src/pages/RunDetail.tsx
@@ -1026,7 +1026,9 @@ function TradesTab({ run }: { run: RunData }) {
), [source, sortDesc]);
if (trades.length === 0) return <div className="p-8 text-muted-foreground text-sm">{i18n.t("runDetail.noTrades")}</div>;
- const symbols = [...new Set(trades.map((tr) => tr.code).filter(Boolean))];
+ // Same code order as the Chart tab's symbol list, so a symbol sits in the
+ // same place on both tabs and does not move when the time order flips.
+ const symbols = [...new Set(trades.map((tr) => tr.code).filter(Boolean))].sort();
const hasPnl = trades.some((tr) => parseTradeNumber(tr.pnl) != null);
const hasReturnPct = trades.some((tr) => parseTradeNumber(tr.return_pct) != null);
const hasHoldingDays = trades.some((tr) => (tr.holding_days ?? "") !== "");
diff --git a/frontend/src/pages/__tests__/RunDetail.test.tsx b/frontend/src/pages/__tests__/RunDetail.test.tsx
index ec8674538..c9108fd5a 100644
--- a/frontend/src/pages/__tests__/RunDetail.test.tsx
+++ b/frontend/src/pages/__tests__/RunDetail.test.tsx
@@ -284,6 +284,36 @@ describe("RunDetail page", () => {
expect(firstRowTime()).toBe(allTrades[0].timestamp);
});
+ it("lists trade symbols in code order whichever way the trades are sorted", async () => {
+ apiMock.getRun.mockResolvedValue({
+ status: "success",
+ run_id: "multi",
+ prompt: "Multi symbol run",
+ artifacts_trades_csv: [
+ { timestamp: "2024-01-01", code: "00700.HK", side: "BUY" },
+ { timestamp: "2024-01-02", code: "02328.HK", side: "BUY" },
+ { timestamp: "2024-01-03", code: "00005.HK", side: "BUY" },
+ { timestamp: "2024-01-04", code: "00700.HK", side: "SELL" },
+ ],
+ });
+ apiMock.getRunCode.mockResolvedValue({});
+
+ renderRunDetail("/runs/multi");
+ await screen.findByText("Multi symbol run");
+ fireEvent.click(screen.getByRole("tab", { name: "Trades" }));
+
+ const symbolOptions = () => within(screen.getByRole("combobox", { name: "Symbol" }))
+ .getAllByRole("option")
+ .map((option) => option.textContent);
+ const expected = ["All symbols", "00005.HK", "00700.HK", "02328.HK"];
+ expect(symbolOptions()).toEqual(expected);
+
+ const timeHeader = screen.getByRole("columnheader", { name: "Time" });
+ fireEvent.click(within(timeHeader).getByRole("button"));
+
+ expect(symbolOptions()).toEqual(expected);
+ });
+
it("pads and scroll-wraps run-card key/value and artifact tables", async () => {
apiMock.getRun.mockResolvedValue({
status: "success",