@@ -18,18 +18,20 @@ import {
1818 DeleteOutlined ,
1919 SettingOutlined ,
2020} from '@ant-design/icons' ;
21- import { Typography , theme , App , TablePaginationConfig } from 'antd' ;
21+ import { Typography , theme , App , TablePaginationConfig , Alert } from 'antd' ;
2222import type { ColumnType } from 'antd/lib/table' ;
2323import {
2424 filterOutEmpty ,
2525 filterOutNullAndUndefined ,
2626 BAITable ,
2727 BAITableProps ,
2828 BAINameActionCell ,
29+ BAIConfirmModalWithInput ,
30+ BAIFlex ,
2931} from 'backend.ai-ui' ;
3032import dayjs from 'dayjs' ;
3133import * as _ from 'lodash-es' ;
32- import React from 'react' ;
34+ import React , { useState } from 'react' ;
3335import { useTranslation } from 'react-i18next' ;
3436import { graphql , useFragment } from 'react-relay' ;
3537
@@ -73,10 +75,13 @@ const EndpointList: React.FC<EndpointListProps> = ({
7375} ) => {
7476 const { t } = useTranslation ( ) ;
7577 const { token } = theme . useToken ( ) ;
76- const { message, modal } = App . useApp ( ) ;
78+ const { message } = App . useApp ( ) ;
7779 const [ currentUser ] = useCurrentUserInfo ( ) ;
7880 const baiClient = useSuspendedBackendaiClient ( ) ;
7981 const webuiNavigate = useWebUINavigate ( ) ;
82+ const [ deletingEndpoint , setDeletingEndpoint ] = useState < Endpoint | null > (
83+ null ,
84+ ) ;
8085
8186 const endpoints = useFragment (
8287 graphql `
@@ -144,46 +149,7 @@ const EndpointList: React.FC<EndpointListProps> = ({
144149 type : 'danger' ,
145150 disabled : isEndpointInDestroyingCategory ( row ) ,
146151 onClick : ( ) => {
147- modal . confirm ( {
148- title : t ( 'dialog.ask.DoYouWantToDeleteSomething' , {
149- name : row . name ,
150- } ) ,
151- content : t ( 'dialog.warning.CannotBeUndone' ) ,
152- okText : t ( 'button.Delete' ) ,
153- okButtonProps : {
154- danger : true ,
155- type : 'primary' ,
156- } ,
157- onOk : ( ) => {
158- if ( row . endpoint_id ) {
159- return new Promise < void > ( ( resolve ) => {
160- terminateModelServiceMutation . mutate ( row . endpoint_id ! , {
161- onSuccess : ( res ) => {
162- onDeleted ?.( row ) ;
163- if ( res . success ) {
164- message . success (
165- t ( 'modelService.ServiceTerminated' , {
166- name : row ?. name ,
167- } ) ,
168- ) ;
169- } else {
170- message . error (
171- t ( 'modelService.FailedToTerminateService' ) ,
172- ) ;
173- }
174- resolve ( ) ;
175- } ,
176- onError : ( ) => {
177- message . error (
178- t ( 'modelService.FailedToTerminateService' ) ,
179- ) ;
180- resolve ( ) ;
181- } ,
182- } ) ;
183- } ) ;
184- }
185- } ,
186- } ) ;
152+ setDeletingEndpoint ( row ) ;
187153 } ,
188154 } ,
189155 ] }
@@ -267,16 +233,63 @@ const EndpointList: React.FC<EndpointListProps> = ({
267233 ] ) ;
268234
269235 return (
270- < BAITable
271- size = "small"
272- loading = { loading }
273- scroll = { { x : 'max-content' } }
274- rowKey = { 'endpoint_id' }
275- dataSource = { filterOutNullAndUndefined ( endpoints ) }
276- columns = { columns }
277- pagination = { pagination }
278- { ...tableProps }
279- />
236+ < >
237+ < BAITable
238+ size = "small"
239+ loading = { loading }
240+ scroll = { { x : 'max-content' } }
241+ rowKey = { 'endpoint_id' }
242+ dataSource = { filterOutNullAndUndefined ( endpoints ) }
243+ columns = { columns }
244+ pagination = { pagination }
245+ { ...tableProps }
246+ />
247+ < BAIConfirmModalWithInput
248+ open = { ! ! deletingEndpoint }
249+ title = { t ( 'dialog.ask.DoYouWantToDeleteSomething' , {
250+ name : deletingEndpoint ?. name ,
251+ } ) }
252+ content = {
253+ < BAIFlex direction = "column" gap = "md" align = "stretch" >
254+ < Alert type = "warning" title = { t ( 'dialog.warning.CannotBeUndone' ) } />
255+ < BAIFlex >
256+ < Typography . Text style = { { marginRight : token . marginXXS } } >
257+ { t ( 'dialog.TypeNameToConfirmDeletion' ) }
258+ </ Typography . Text >
259+ (< Typography . Text code > { deletingEndpoint ?. name } </ Typography . Text > )
260+ </ BAIFlex >
261+ </ BAIFlex >
262+ }
263+ confirmText = { deletingEndpoint ?. name ?? '' }
264+ inputProps = { { placeholder : deletingEndpoint ?. name ?? '' } }
265+ okText = { t ( 'button.Delete' ) }
266+ okButtonProps = { { loading : terminateModelServiceMutation . isPending } }
267+ onOk = { ( ) => {
268+ if ( deletingEndpoint ?. endpoint_id ) {
269+ terminateModelServiceMutation . mutate ( deletingEndpoint . endpoint_id , {
270+ onSuccess : ( res ) => {
271+ onDeleted ?.( deletingEndpoint ) ;
272+ if ( res . success ) {
273+ message . success (
274+ t ( 'modelService.ServiceTerminated' , {
275+ name : deletingEndpoint ?. name ,
276+ } ) ,
277+ ) ;
278+ } else {
279+ message . error ( t ( 'modelService.FailedToTerminateService' ) ) ;
280+ }
281+ setDeletingEndpoint ( null ) ;
282+ } ,
283+ onError : ( ) => {
284+ message . error ( t ( 'modelService.FailedToTerminateService' ) ) ;
285+ setDeletingEndpoint ( null ) ;
286+ } ,
287+ } ) ;
288+ }
289+ } }
290+ onCancel = { ( ) => setDeletingEndpoint ( null ) }
291+ />
292+ </ >
280293 ) ;
281294} ;
282295
0 commit comments