feat: model list add stop and start button

This commit is contained in:
jialin
2024-12-18 16:13:58 +08:00
parent 57a1af9392
commit f44aee0af4
7 changed files with 54 additions and 69 deletions
@@ -8,8 +8,8 @@ import {
ListItem as WorkerListItem
} from '@/pages/resources/config/types';
import {
DeleteOutlined,
FieldTimeOutlined,
FileSyncOutlined,
InfoCircleOutlined
} from '@ant-design/icons';
import { useIntl } from '@umijs/max';
@@ -71,12 +71,12 @@ const InstanceItem: React.FC<InstanceItemProps> = ({
icon: <FieldTimeOutlined />
},
{
label: 'common.button.delete',
label: 'common.button.recreate',
key: 'delete',
props: {
danger: true
danger: false
},
icon: <DeleteOutlined />
icon: <FileSyncOutlined />
}
];
@@ -240,6 +240,16 @@ const Models: React.FC<ModelsProps> = ({
key: 'edit',
icon: <EditOutlined />
},
{
label: 'common.button.stop',
key: 'stop',
icon: <IconFont type="icon-stop1"></IconFont>
},
{
label: 'common.button.start',
key: 'start',
icon: <IconFont type="icon-playcircle"></IconFont>
},
{
label: 'models.openinplayground',
key: 'chat',
@@ -260,6 +270,13 @@ const Models: React.FC<ModelsProps> = ({
if (action.key === 'chat') {
return record.ready_replicas > 0;
}
if (action.key === 'start') {
return record.replicas === 0;
}
if (action.key === 'stop') {
return record.replicas > 0;
}
return true;
});
@@ -284,6 +301,27 @@ const Models: React.FC<ModelsProps> = ({
message.success(intl.formatMessage({ id: 'common.message.success' }));
};
const handleToggleStart = async (row: ListItem, action: string) => {
try {
await updateModel({
id: row.id,
data: {
..._.omit(row, [
'id',
'ready_replicas',
'created_at',
'updated_at',
'rowIndex'
]),
replicas: action === 'start' ? 1 : 0
}
});
message.success(intl.formatMessage({ id: 'common.message.success' }));
} catch (error) {
// ingore
}
};
const handleModalOk = useCallback(
async (data: FormData) => {
try {
@@ -448,6 +486,9 @@ const Models: React.FC<ModelsProps> = ({
if (val === 'delete') {
handleDelete(row);
}
if (val === 'start' || val === 'stop') {
handleToggleStart(row, val);
}
},
[handleEdit, handleOpenPlayGround, handleDelete]
);