Skip to content

Commit f0dbf10

Browse files
committed
feat(FR-1694): Create a new agent page using the agent_nodes query
1 parent 72f49f9 commit f0dbf10

File tree

10 files changed

+1479
-73
lines changed

10 files changed

+1479
-73
lines changed

packages/backend.ai-ui/src/helper/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,38 @@ export const omitNullAndUndefinedFields = <T extends Record<string, any>>(
386386
) as Partial<T>;
387387
};
388388

389+
/**
390+
* Safely parses an unknown input into a plain object record.
391+
*
392+
* Accepts either:
393+
* - a non-null object (not an array) returned as-is
394+
* - a JSON string starting with '{' which will be parsed
395+
* Otherwise returns an empty object.
396+
*
397+
*
398+
* @param raw - Unknown input value that may be an object or JSON string
399+
* @returns A record object or an empty object if parsing fails
400+
*/
401+
export function parseObjectMap<T = any>(raw: unknown): Record<string, T> {
402+
if (!raw) return {};
403+
if (typeof raw === 'object' && raw !== null && !Array.isArray(raw)) {
404+
return raw as Record<string, T>;
405+
}
406+
if (typeof raw === 'string') {
407+
const s = raw.trim();
408+
if (!s.startsWith('{')) return {};
409+
try {
410+
const parsed = JSON.parse(s);
411+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
412+
return parsed as Record<string, T>;
413+
}
414+
} catch {
415+
return {};
416+
}
417+
}
418+
return {};
419+
}
420+
389421
/**
390422
* Generates a random string of alphabetic characters.
391423
*

react/src/components/AgentList.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
AgentListQuery,
44
AgentListQuery$data,
55
} from '../__generated__/AgentListQuery.graphql';
6-
import { AgentSettingModalFragment$key } from '../__generated__/AgentSettingModalFragment.graphql';
76
import {
87
convertToBinaryUnit,
98
convertToDecimalUnit,
@@ -16,7 +15,7 @@ import { useBAIPaginationOptionStateOnSearchParamLegacy } from '../hooks/reactPa
1615
import { useHiddenColumnKeysSetting } from '../hooks/useHiddenColumnKeysSetting';
1716
import { useThemeMode } from '../hooks/useThemeMode';
1817
import AgentDetailModal from './AgentDetailModal';
19-
import AgentSettingModal from './AgentSettingModal';
18+
import AgentSettingModalLegacy from './AgentSettingModalLegacy';
2019
import BAIIntervalView from './BAIIntervalView';
2120
import BAIProgressWithLabel from './BAIProgressWithLabel';
2221
import BAIRadioGroup from './BAIRadioGroup';
@@ -47,6 +46,7 @@ import _ from 'lodash';
4746
import React, { useState, useDeferredValue } from 'react';
4847
import { useTranslation } from 'react-i18next';
4948
import { graphql, useLazyLoadQuery } from 'react-relay';
49+
import { AgentSettingModalLegacyFragment$key } from 'src/__generated__/AgentSettingModalLegacyFragment.graphql';
5050
import { StringParam, useQueryParams, withDefault } from 'use-query-params';
5151

5252
type Agent = NonNullable<AgentListQuery$data['agent_list']>['items'][number];
@@ -71,7 +71,7 @@ const AgentList: React.FC<AgentListProps> = ({
7171
const [currentAgentInfo, setCurrentAgentInfo] =
7272
useState<AgentDetailModalFragment$key | null>();
7373
const [currentSettingAgent, setCurrentSettingAgent] =
74-
useState<AgentSettingModalFragment$key | null>();
74+
useState<AgentSettingModalLegacyFragment$key | null>();
7575
const [visibleColumnSettingModal, { toggle: toggleColumnSettingModal }] =
7676
useToggle();
7777
const baiClient = useSuspendedBackendaiClient();
@@ -146,7 +146,7 @@ const AgentList: React.FC<AgentListProps> = ({
146146
scaling_group
147147
schedulable
148148
...AgentDetailModalFragment
149-
...AgentSettingModalFragment
149+
...AgentSettingModalLegacyFragment
150150
}
151151
total_count
152152
}
@@ -960,8 +960,8 @@ const AgentList: React.FC<AgentListProps> = ({
960960
open={!!currentAgentInfo}
961961
onRequestClose={() => setCurrentAgentInfo(null)}
962962
/>
963-
<AgentSettingModal
964-
agentSettingModalFrgmt={currentSettingAgent}
963+
<AgentSettingModalLegacy
964+
agentSettingModalLegacyFrgmt={currentSettingAgent}
965965
open={!!currentSettingAgent}
966966
onRequestClose={(success) => {
967967
if (success) {

0 commit comments

Comments
 (0)