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

feat: show confirm modal instead of popconfirm when deleting endpoint #2678

Merged
Merged
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
120 changes: 60 additions & 60 deletions react/src/pages/EndpointListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '@ant-design/icons';
import { useRafInterval } from 'ahooks';
import { useLocalStorageState } from 'ahooks';
import { Button, Table, Typography, theme, message, Popconfirm } from 'antd';
import { Button, Table, Typography, theme, App } from 'antd';
import { ColumnsType } from 'antd/es/table';
import graphql from 'babel-plugin-relay/macro';
import { default as dayjs } from 'dayjs';
Expand All @@ -51,13 +51,12 @@ export type Endpoint = NonNullable<

const EndpointListPage: React.FC<PropsWithChildren> = ({ children }) => {
const { t } = useTranslation();
const { message, modal } = App.useApp();
const baiClient = useSuspendedBackendaiClient();
const webuiNavigate = useWebUINavigate();
const { token } = theme.useToken();
const curProject = useCurrentProjectValue();
const [isOpenColumnsSetting, setIsOpenColumnsSetting] = useState(false);
const [terminatingModelService, setTerminatingModelService] =
useState<Endpoint | null>(null);

// const [paginationState, setPaginationState] = useState<{
const [paginationState] = useState<{
Expand Down Expand Up @@ -143,65 +142,66 @@ const EndpointListPage: React.FC<PropsWithChildren> = ({ children }) => {
webuiNavigate('/service/update/' + row.endpoint_id);
}}
/>
<Popconfirm
title={t('dialog.ask.DoYouWantToDeleteSomething', {
name: row.name,
})}
description={t('dialog.warning.CannotBeUndone')}
okType="danger"
okText={t('button.Delete')}
onConfirm={() => {
setOptimisticDeletingId(row.endpoint_id);
// FIXME: any better idea for handling result?
terminateModelServiceMutation.mutate(
terminatingModelService?.endpoint_id || '',
{
onSuccess: (res) => {
startRefetchTransition(() => {
updateServicesFetchKey();
});
// FIXME: temporally refer to mutate input to message
message.success(
t('modelService.ServiceTerminated', {
name: terminatingModelService?.name,
}),
);
},
onError: (err) => {
console.log(err);
message.error(t('modelService.FailedToTerminateService'));
},
<Button
type="text"
icon={
<DeleteOutlined
style={
row.desired_session_count < 0 ||
row.status?.toLowerCase() === 'destroying'
? undefined
: {
color: token.colorError,
}
}
/>
}
loading={
terminateModelServiceMutation.isPending &&
optimisticDeletingId === row.endpoint_id
}
disabled={
row.desired_session_count < 0 ||
row.status?.toLowerCase() === 'destroying'
}
onClick={() => {
modal.confirm({
title: t('dialog.ask.DoYouWantToDeleteSomething', {
name: row.name,
}),
content: t('dialog.warning.CannotBeUndone'),
okText: t('button.Delete'),
okButtonProps: {
danger: true,
type: 'primary',
},
);
onOk: () => {
setOptimisticDeletingId(row.endpoint_id);
// FIXME: any better idea for handling result?
row.endpoint_id && terminateModelServiceMutation.mutate(row.endpoint_id, {
onSuccess: (res) => {
startRefetchTransition(() => {
updateServicesFetchKey();
});
// FIXME: temporally refer to mutate input to message
if(res.success) {
message.success(
t('modelService.ServiceTerminated', {
name: row?.name,
}),
);
} else {
message.error(t('modelService.FailedToTerminateService'));
}
},
onError: (err) => {
message.error(t('modelService.FailedToTerminateService'));
},
});
},
});
}}
>
<Button
type="text"
icon={
<DeleteOutlined
style={
row.desired_session_count < 0 ||
row.status?.toLowerCase() === 'destroying'
? undefined
: {
color: token.colorError,
}
}
/>
}
loading={
terminateModelServiceMutation.isPending &&
optimisticDeletingId === row.endpoint_id
}
disabled={
row.desired_session_count < 0 ||
row.status?.toLowerCase() === 'destroying'
}
onClick={() => {
setTerminatingModelService(row);
}}
/>
</Popconfirm>
/>
</Flex>
),
},
Expand Down
Loading