Skip to content

Commit d39497a

Browse files
committed
feat(FR-1425): implement BAISessionAgentIds component to improve agent display (#4219)
Resolves #4218 ([FR-1425](https://lablup.atlassian.net/browse/FR-1425)) # Add BAISessionAgentIds component for better agent ID display This PR adds a new `BAISessionAgentIds` component to improve the display of agent IDs in session details. The component: - Shows a limited number of agent IDs inline (default: 3) - Displays remaining IDs in a popover when clicked - Includes a "Copy All" button for easy copying of all agent IDs - Handles empty states gracefully The component is integrated in both the session detail view and session nodes table, replacing the previous simple string display. **Checklist:** - [x] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after [FR-1425]: https://lablup.atlassian.net/browse/FR-1425?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 8cfe73a commit d39497a

File tree

27 files changed

+263
-6
lines changed

27 files changed

+263
-6
lines changed

packages/backend.ai-ui/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
"import/no-duplicates": "error"
5454
}
5555
},
56+
"dependencies": {
57+
"react-copy-to-clipboard": "^5.1.0"
58+
},
5659
"peerDependencies": {
5760
"@ant-design/icons": "^5.6.1",
5861
"antd": "^5.24.5",
@@ -91,6 +94,7 @@
9194
"@types/big.js": "^6.2.2",
9295
"@types/lodash": "^4.17.13",
9396
"@types/react": "^19.0.0",
97+
"@types/react-copy-to-clipboard": "^5.0.7",
9498
"@types/react-dom": "^19.0.3",
9599
"@types/react-relay": "^18.2.1",
96100
"@types/react-resizable": "^3.0.8",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { BAISessionAgentIdsFragment$key } from '../../__generated__/BAISessionAgentIdsFragment.graphql';
2+
import BAIFlex from '../BAIFlex';
3+
import { CopyOutlined } from '@ant-design/icons';
4+
import { Popover, Typography, Button, theme } from 'antd';
5+
import _ from 'lodash';
6+
import React, { useMemo } from 'react';
7+
import { CopyToClipboard } from 'react-copy-to-clipboard';
8+
import { useTranslation } from 'react-i18next';
9+
import { graphql, useFragment } from 'react-relay';
10+
11+
interface BAISessionAgentIdsProps {
12+
sessionFrgmt: BAISessionAgentIdsFragment$key;
13+
maxInline?: number; // New prop to control max inline display
14+
emptyText?: string; // New prop for empty state text
15+
}
16+
export const BAISessionAgentIds: React.FC<BAISessionAgentIdsProps> = ({
17+
sessionFrgmt,
18+
maxInline = 3,
19+
emptyText = '-',
20+
}) => {
21+
const { t } = useTranslation();
22+
const { token } = theme.useToken();
23+
const session = useFragment(
24+
graphql`
25+
fragment BAISessionAgentIdsFragment on ComputeSessionNode {
26+
agent_ids
27+
}
28+
`,
29+
sessionFrgmt,
30+
);
31+
32+
const agents = useMemo(
33+
() => _.uniq(session.agent_ids ?? []),
34+
[session.agent_ids],
35+
);
36+
37+
const inline = agents.slice(0, maxInline).join(', ');
38+
const rest = agents.slice(maxInline);
39+
const restCount = _.max([agents.length - maxInline, 0]) || 0;
40+
41+
return agents.length === 0 ? (
42+
emptyText
43+
) : (
44+
<span>
45+
<Typography.Text>{inline}</Typography.Text>
46+
{restCount > 0 && (
47+
<>
48+
&nbsp;
49+
<Popover
50+
trigger="click"
51+
title={
52+
<BAIFlex justify="between">
53+
<span>
54+
{t('comp:BAISessionAgentIds.Agent')} ({agents.length})
55+
</span>
56+
<CopyToClipboard text={agents.join(', ')}>
57+
<Button size="small" type="text" icon={<CopyOutlined />}>
58+
{t('general.button.CopyAll')}
59+
</Button>
60+
</CopyToClipboard>
61+
</BAIFlex>
62+
}
63+
content={
64+
<div style={{ maxHeight: 240, overflow: 'auto', minWidth: 260 }}>
65+
<ul style={{ paddingLeft: token.padding, margin: 0 }}>
66+
{rest.map((id) => (
67+
<li key={id} style={{ listStyle: 'disc' }}>
68+
<Typography.Text>{id}</Typography.Text>
69+
</li>
70+
))}
71+
</ul>
72+
</div>
73+
}
74+
>
75+
<Typography.Link>+{restCount}</Typography.Link>
76+
</Popover>
77+
</>
78+
)}
79+
</span>
80+
);
81+
};

packages/backend.ai-ui/src/locale/de.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@
1717
},
1818
"comp:BAIResourceWithSteppedProgress": {
1919
"Unlimited": "Unbegrenzt"
20+
},
21+
"comp:BAISessionAgentIds": {
22+
"Agent": "Agent"
23+
},
24+
"general": {
25+
"button": {
26+
"CopyAll": "Alle kopieren"
27+
}
2028
}
2129
}

packages/backend.ai-ui/src/locale/el.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@
1717
},
1818
"comp:BAIResourceWithSteppedProgress": {
1919
"Unlimited": "Απεριόριστος"
20+
},
21+
"comp:BAISessionAgentIds": {
22+
"Agent": "Μέσο"
23+
},
24+
"general": {
25+
"button": {
26+
"CopyAll": "Αντιγράψτε όλα"
27+
}
2028
}
2129
}

packages/backend.ai-ui/src/locale/en.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@
1717
},
1818
"comp:BAIResourceWithSteppedProgress": {
1919
"Unlimited": "Unlimited"
20+
},
21+
"comp:BAISessionAgentIds": {
22+
"Agent": "Agent"
23+
},
24+
"general": {
25+
"button": {
26+
"CopyAll": "Copy All"
27+
}
2028
}
2129
}

packages/backend.ai-ui/src/locale/es.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@
1717
},
1818
"comp:BAIResourceWithSteppedProgress": {
1919
"Unlimited": "Ilimitado"
20+
},
21+
"comp:BAISessionAgentIds": {
22+
"Agent": "Agente"
23+
},
24+
"general": {
25+
"button": {
26+
"CopyAll": "Copiar todo"
27+
}
2028
}
2129
}

packages/backend.ai-ui/src/locale/fi.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@
1717
},
1818
"comp:BAIResourceWithSteppedProgress": {
1919
"Unlimited": "Rajoittamaton"
20+
},
21+
"comp:BAISessionAgentIds": {
22+
"Agent": "Agentti"
23+
},
24+
"general": {
25+
"button": {
26+
"CopyAll": "Kopioida kaikki"
27+
}
2028
}
2129
}

packages/backend.ai-ui/src/locale/fr.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@
1717
},
1818
"comp:BAIResourceWithSteppedProgress": {
1919
"Unlimited": "Illimité"
20+
},
21+
"comp:BAISessionAgentIds": {
22+
"Agent": "Agent"
23+
},
24+
"general": {
25+
"button": {
26+
"CopyAll": "Copier tout"
27+
}
2028
}
2129
}

packages/backend.ai-ui/src/locale/id.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@
1717
},
1818
"comp:BAIResourceWithSteppedProgress": {
1919
"Unlimited": "Tak terbatas"
20+
},
21+
"comp:BAISessionAgentIds": {
22+
"Agent": "Agen"
23+
},
24+
"general": {
25+
"button": {
26+
"CopyAll": "Salin semua"
27+
}
2028
}
2129
}

packages/backend.ai-ui/src/locale/it.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@
1717
},
1818
"comp:BAIResourceWithSteppedProgress": {
1919
"Unlimited": "Illimitato"
20+
},
21+
"comp:BAISessionAgentIds": {
22+
"Agent": "Agente"
23+
},
24+
"general": {
25+
"button": {
26+
"CopyAll": "Copia tutto"
27+
}
2028
}
2129
}

0 commit comments

Comments
 (0)