fix: model list duplicate
This commit is contained in:
@@ -12,18 +12,24 @@ import { ModelInstanceListItem } from '../config/types';
|
||||
|
||||
interface InstanceItemProps {
|
||||
list: ModelInstanceListItem[];
|
||||
handleChildSelect: (val: string, item: ModelInstanceListItem) => void;
|
||||
handleChildSelect: (
|
||||
val: string,
|
||||
item: ModelInstanceListItem,
|
||||
list: ModelInstanceListItem[]
|
||||
) => void;
|
||||
}
|
||||
|
||||
const InstanceItem: React.FC<InstanceItemProps> = ({
|
||||
list,
|
||||
handleChildSelect
|
||||
}) => {
|
||||
console.log('instance item====');
|
||||
const intl = useIntl();
|
||||
const childActionList = [
|
||||
{
|
||||
label: intl.formatMessage({ id: 'common.button.viewlog' }),
|
||||
key: 'viewlog',
|
||||
status: [InstanceStatusMap.Running, InstanceStatusMap.Error],
|
||||
icon: <FieldTimeOutlined />
|
||||
},
|
||||
{
|
||||
@@ -33,9 +39,16 @@ const InstanceItem: React.FC<InstanceItemProps> = ({
|
||||
icon: <DeleteOutlined />
|
||||
}
|
||||
];
|
||||
const testStatus = {
|
||||
state: InstanceStatusMap.Scheduled
|
||||
|
||||
const setChildActionList = (item: ModelInstanceListItem) => {
|
||||
return _.filter(childActionList, (action: any) => {
|
||||
if (action.key === 'viewlog') {
|
||||
return InstanceStatusMap.Running.includes(item.state);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
const getWorkerIp = (item: ModelInstanceListItem) => {
|
||||
if (item.worker_ip) {
|
||||
return item.port ? `${item.worker_ip}:${item.port}` : item.worker_ip;
|
||||
@@ -90,8 +103,10 @@ const InstanceItem: React.FC<InstanceItemProps> = ({
|
||||
<Col span={5}>
|
||||
<div style={{ paddingLeft: 39 }}>
|
||||
<DropdownButtons
|
||||
items={childActionList}
|
||||
onSelect={(val: string) => handleChildSelect(val, item)}
|
||||
items={setChildActionList(item)}
|
||||
onSelect={(val: string) =>
|
||||
handleChildSelect(val, item, list)
|
||||
}
|
||||
></DropdownButtons>
|
||||
</div>
|
||||
</Col>
|
||||
|
||||
@@ -4,6 +4,7 @@ import SealTable from '@/components/seal-table';
|
||||
import SealColumn from '@/components/seal-table/components/seal-column';
|
||||
import { PageAction } from '@/config';
|
||||
import type { PageActionType } from '@/config/types';
|
||||
import useExpandedRowKeys from '@/hooks/use-expanded-row-keys';
|
||||
import useTableRowSelection from '@/hooks/use-table-row-selection';
|
||||
import useTableSort from '@/hooks/use-table-sort';
|
||||
import { handleBatchRequest } from '@/utils';
|
||||
@@ -18,7 +19,7 @@ import { PageContainer } from '@ant-design/pro-components';
|
||||
import { Access, useAccess, useIntl, useNavigate } from '@umijs/max';
|
||||
import { Button, Input, Modal, Space, message } from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import { memo, useCallback, useEffect, useState } from 'react';
|
||||
import { memo, useCallback, useState } from 'react';
|
||||
import {
|
||||
MODELS_API,
|
||||
MODEL_INSTANCE_API,
|
||||
@@ -57,11 +58,9 @@ const Models: React.FC<ModelsProps> = ({
|
||||
handleSearch,
|
||||
handleShowSizeChange,
|
||||
handlePageChange,
|
||||
createModelsChunkRequest,
|
||||
queryParams,
|
||||
loading,
|
||||
total,
|
||||
fetchData
|
||||
total
|
||||
}) => {
|
||||
// const { modal } = App.useApp();
|
||||
console.log('model list====2');
|
||||
@@ -69,6 +68,8 @@ const Models: React.FC<ModelsProps> = ({
|
||||
const intl = useIntl();
|
||||
const navigate = useNavigate();
|
||||
const rowSelection = useTableRowSelection();
|
||||
const { handleExpandChange, updateExpandedRowKeys, expandedRowKeys } =
|
||||
useExpandedRowKeys();
|
||||
const { sortOrder, setSortOrder } = useTableSort({
|
||||
defaultSortOrder: 'descend'
|
||||
});
|
||||
@@ -145,6 +146,7 @@ const Models: React.FC<ModelsProps> = ({
|
||||
async onOk() {
|
||||
await deleteModel(row.id);
|
||||
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
||||
updateExpandedRowKeys([row.id]);
|
||||
},
|
||||
onCancel() {
|
||||
console.log('Cancel');
|
||||
@@ -162,6 +164,7 @@ const Models: React.FC<ModelsProps> = ({
|
||||
await handleBatchRequest(rowSelection.selectedRowKeys, deleteModel);
|
||||
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
||||
rowSelection.clearSelections();
|
||||
updateExpandedRowKeys(rowSelection.selectedRowKeys);
|
||||
},
|
||||
onCancel() {
|
||||
console.log('Cancel');
|
||||
@@ -181,7 +184,7 @@ const Models: React.FC<ModelsProps> = ({
|
||||
console.log('error:', error);
|
||||
}
|
||||
};
|
||||
const handleDeleteInstace = (row: any) => {
|
||||
const handleDeleteInstace = (row: any, list: ModelInstanceListItem[]) => {
|
||||
Modal.confirm({
|
||||
title: '',
|
||||
content: intl.formatMessage(
|
||||
@@ -191,6 +194,9 @@ const Models: React.FC<ModelsProps> = ({
|
||||
async onOk() {
|
||||
await deleteModelInstance(row.id);
|
||||
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
||||
if (list.length === 1) {
|
||||
updateExpandedRowKeys([row.model_id]);
|
||||
}
|
||||
},
|
||||
onCancel() {
|
||||
console.log('Cancel');
|
||||
@@ -232,9 +238,9 @@ const Models: React.FC<ModelsProps> = ({
|
||||
}, []);
|
||||
|
||||
const handleChildSelect = useCallback(
|
||||
(val: any, row: ModelInstanceListItem) => {
|
||||
(val: any, row: ModelInstanceListItem, list: ModelInstanceListItem[]) => {
|
||||
if (val === 'delete') {
|
||||
handleDeleteInstace(row);
|
||||
handleDeleteInstace(row, list);
|
||||
}
|
||||
if (val === 'viewlog') {
|
||||
handleViewLogs(row);
|
||||
@@ -252,10 +258,6 @@ const Models: React.FC<ModelsProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
createModelsChunkRequest();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageContainer
|
||||
@@ -309,6 +311,8 @@ const Models: React.FC<ModelsProps> = ({
|
||||
<SealTable
|
||||
dataSource={dataSource}
|
||||
rowSelection={rowSelection}
|
||||
expandedRowKeys={expandedRowKeys}
|
||||
onExpand={handleExpandChange}
|
||||
loading={loading}
|
||||
rowKey="id"
|
||||
expandable={true}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import LogsViewer from '@/components/logs-viewer';
|
||||
import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { Modal } from 'antd';
|
||||
import React from 'react';
|
||||
import { Button, Modal } from 'antd';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
type ViewModalProps = {
|
||||
open: boolean;
|
||||
@@ -12,14 +13,36 @@ type ViewModalProps = {
|
||||
const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
|
||||
console.log('viewlogs======');
|
||||
const { open, url, onCancel } = props || {};
|
||||
const [modalSize, setModalSize] = useState<any>({
|
||||
width: 600,
|
||||
height: 450
|
||||
});
|
||||
const isFullScreenRef = React.useRef(false);
|
||||
const intl = useIntl();
|
||||
if (!open) {
|
||||
return null;
|
||||
}
|
||||
const handleFullscreenToggle = () => {
|
||||
isFullScreenRef.current = !isFullScreenRef.current;
|
||||
setModalSize((size: any) => {
|
||||
return {
|
||||
width: size.width === 600 ? '100%' : 600,
|
||||
height: size.height === 450 ? 'calc(100vh - 100px)' : 450
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={intl.formatMessage({ id: 'common.button.viewlog' })}
|
||||
title={
|
||||
<span className="flex flex-center">
|
||||
<span> {intl.formatMessage({ id: 'common.button.viewlog' })}</span>
|
||||
<Button size="middle" type="text" onClick={handleFullscreenToggle}>
|
||||
{isFullScreenRef.current ? (
|
||||
<FullscreenExitOutlined />
|
||||
) : (
|
||||
<FullscreenOutlined />
|
||||
)}
|
||||
</Button>
|
||||
</span>
|
||||
}
|
||||
open={open}
|
||||
centered={true}
|
||||
onCancel={onCancel}
|
||||
@@ -27,11 +50,11 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
|
||||
closeIcon={true}
|
||||
maskClosable={false}
|
||||
keyboard={false}
|
||||
width={600}
|
||||
width={modalSize.width}
|
||||
footer={null}
|
||||
>
|
||||
<LogsViewer
|
||||
height={500}
|
||||
height={modalSize.height}
|
||||
url={url}
|
||||
params={{
|
||||
follow: true
|
||||
|
||||
Reference in New Issue
Block a user