Skip to content

Commit 3e51f6d

Browse files
committed
Fix infinite render loop on retention policies settings page
1 parent 8a3d14b commit 3e51f6d

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

app/src/pages/settings/RetentionPoliciesTable.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import { css } from "@emotion/react";
1111

1212
import { Link } from "@phoenix/components";
1313
import { tableCSS } from "@phoenix/components/table/styles";
14-
import {
15-
useNotifySuccess,
16-
useViewerCanManageRetentionPolicy,
17-
} from "@phoenix/contexts";
14+
import { useNotifySuccess } from "@phoenix/contexts/NotificationContext";
15+
import { useViewerCanManageRetentionPolicy } from "@phoenix/contexts/ViewerContext";
1816
import { assertUnreachable } from "@phoenix/typeUtils";
1917
import { createPolicyScheduleSummaryText } from "@phoenix/utils/retentionPolicyUtils";
2018

@@ -87,14 +85,18 @@ export const RetentionPoliciesTable = ({
8785
);
8886

8987
const connectionId = data.projectTraceRetentionPolicies.__id;
90-
const tableData = data.projectTraceRetentionPolicies.edges.map((edge) => {
91-
const node = edge.node;
92-
const data = readInlineData<RetentionPoliciesTable_retentionPolicy$key>(
93-
RETENTION_POLICY_FRAGMENT,
94-
node
95-
);
96-
return data;
97-
});
88+
const tableData = useMemo(
89+
() =>
90+
data.projectTraceRetentionPolicies.edges.map((edge) => {
91+
const node = edge.node;
92+
const data = readInlineData<RetentionPoliciesTable_retentionPolicy$key>(
93+
RETENTION_POLICY_FRAGMENT,
94+
node
95+
);
96+
return data;
97+
}),
98+
[data]
99+
);
98100

99101
const columns: ColumnDef<(typeof tableData)[number]>[] = useMemo(() => {
100102
const columns: ColumnDef<(typeof tableData)[number]>[] = [
@@ -193,7 +195,7 @@ export const RetentionPoliciesTable = ({
193195
return columns;
194196
}, [canManageRetentionPolicy, notifySuccess, connectionId]);
195197

196-
const table = useReactTable<(typeof tableData)[number]>({
198+
const table = useReactTable({
197199
columns,
198200
data: tableData,
199201
getCoreRowModel: getCoreRowModel(),

app/src/pages/settings/SettingsPage.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useCallback } from "react";
2-
import { Key } from "react-aria-components";
1+
import { Suspense, useCallback } from "react";
2+
import { Collection, Key } from "react-aria-components";
33
import { Navigate, Outlet, useLocation, useNavigate } from "react-router";
44
import { css } from "@emotion/react";
55

6-
import { LazyTabPanel, Tab, TabList, Tabs } from "@phoenix/components";
6+
import { Loading, Tab, TabList, TabPanel, Tabs } from "@phoenix/components";
77

88
const settingsPageCSS = css`
99
overflow-y: auto;
@@ -20,6 +20,15 @@ const settingsPageInnerCSS = css`
2020
margin-right: auto;
2121
`;
2222

23+
const tabs: { id: string; label: string }[] = [
24+
{ id: "general", label: "General" },
25+
{ id: "providers", label: "AI Providers" },
26+
{ id: "models", label: "Models" },
27+
{ id: "annotations", label: "Annotations" },
28+
{ id: "prompts", label: "Prompts" },
29+
{ id: "data", label: "Data Retention" },
30+
];
31+
2332
export function SettingsPage() {
2433
const { pathname } = useLocation();
2534
const navigate = useNavigate();
@@ -47,24 +56,15 @@ export function SettingsPage() {
4756
<Tab id="prompts">Prompts</Tab>
4857
<Tab id="data">Data Retention</Tab>
4958
</TabList>
50-
<LazyTabPanel id="general" padded>
51-
<Outlet />
52-
</LazyTabPanel>
53-
<LazyTabPanel id="providers" padded>
54-
<Outlet />
55-
</LazyTabPanel>
56-
<LazyTabPanel id="models" padded>
57-
<Outlet />
58-
</LazyTabPanel>
59-
<LazyTabPanel id="annotations" padded>
60-
<Outlet />
61-
</LazyTabPanel>
62-
<LazyTabPanel id="prompts" padded>
63-
<Outlet />
64-
</LazyTabPanel>
65-
<LazyTabPanel id="data" padded>
66-
<Outlet />
67-
</LazyTabPanel>
59+
<Collection items={tabs}>
60+
{(item) => (
61+
<TabPanel id={item.id} padded>
62+
<Suspense fallback={<Loading />}>
63+
<Outlet />
64+
</Suspense>
65+
</TabPanel>
66+
)}
67+
</Collection>
6868
</Tabs>
6969
</div>
7070
</main>

0 commit comments

Comments
 (0)