Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back model id column #318

Merged
merged 1 commit into from
Apr 23, 2024
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 @@ -157,8 +157,31 @@ describe('<DeployedModelTable />', () => {
expect(within(cells[2] as HTMLElement).getByText('Not responding')).toBeInTheDocument();
});

it('should render Action column and call onViewDetail with the model item of the current table row', async () => {
it('should render Model ID at fifth column and copy to clipboard after text clicked', async () => {
const execCommandOrigin = document.execCommand;
document.execCommand = jest.fn(() => true);

const columnIndex = 4;
setup();
const header = screen.getAllByRole('columnheader')[columnIndex];
const columnContent = header
.closest('table')
?.querySelectorAll(`tbody tr td:nth-child(${columnIndex + 1})`);
expect(within(header).getByText('Model ID')).toBeInTheDocument();
expect(columnContent?.length).toBe(3);
const cells = columnContent!;
expect(within(cells[0] as HTMLElement).getByText('model-1-id')).toBeInTheDocument();
expect(within(cells[1] as HTMLElement).getByText('model-2-id')).toBeInTheDocument();
expect(within(cells[2] as HTMLElement).getByText('model-3-id')).toBeInTheDocument();

await userEvent.click(within(cells[0] as HTMLElement).getByLabelText('Copy ID to clipboard'));
expect(document.execCommand).toHaveBeenCalledWith('copy');

document.execCommand = execCommandOrigin;
});

it('should render Action column and call onViewDetail with the model item of the current table row', async () => {
const columnIndex = 5;
const onViewDetailMock = jest.fn();
const { finalProps } = setup({
onViewDetail: onViewDetailMock,
Expand Down
38 changes: 34 additions & 4 deletions public/components/monitoring/model_deployment_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
EuiSpacer,
EuiLink,
EuiToolTip,
EuiCopy,
EuiText,
} from '@elastic/eui';

import { MODEL_STATE } from '../../../common';
Expand Down Expand Up @@ -76,14 +78,14 @@ export const ModelDeploymentTable = ({
{
field: 'name',
name: 'Name',
width: '23.84%',
width: '26.13%',
sortable: true,
truncateText: true,
},
{
field: 'id',
name: 'Source',
width: '23.84%',
width: '14%',
sortable: false,
truncateText: true,
render: (_id: string, modelDeploymentItem: ModelDeploymentItem) => {
Expand All @@ -93,7 +95,7 @@ export const ModelDeploymentTable = ({
{
field: 'id',
name: 'Connector name',
width: '22.61%',
width: '22%',
truncateText: true,
textOnly: true,
render: (_id: string, modelDeploymentItem: ModelDeploymentItem) => {
Expand All @@ -103,7 +105,7 @@ export const ModelDeploymentTable = ({
{
field: 'model_state',
name: 'Status',
width: '23.84%',
width: '14%',
sortable: true,
truncateText: true,
render: (
Expand Down Expand Up @@ -138,6 +140,34 @@ export const ModelDeploymentTable = ({
);
},
},
{
field: 'id',
name: 'Model ID',
width: '18%',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we let width self-adaptive or specific?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean self-adaptive by model id length? I think it's hard to do that. The percentage column width value will follow by the table width. It will shrink if window size reduced. The model id will be truncated.
image

sortable: true,
render: (id: string) => (
<>
<EuiCopy
className="ml-modelModelIdCellTextWrapper"
textToCopy={id}
beforeMessage="Copy model ID"
anchorClassName="ml-modelModelIdCell"
>
{(copy) => (
<EuiButtonIcon
aria-label="Copy ID to clipboard"
color="text"
iconType="copy"
onClick={copy}
/>
)}
</EuiCopy>
<EuiText className="eui-textTruncate ml-modelModelIdText" size="s">
{id}
</EuiText>
</>
),
},
{
field: 'id',
name: 'Action',
Expand Down
Loading