@@ -8,17 +8,14 @@ import AutoScalingRuleEditorModalLegacy, {
88 COMPARATOR_LABELS ,
99} from './AutoScalingRuleEditorModalLegacy' ;
1010import { DeleteFilled , PlusOutlined , SettingOutlined } from '@ant-design/icons' ;
11+ import { App , Button , Tag , Tooltip , Typography , theme } from 'antd' ;
1112import {
12- App ,
13- Button ,
14- Card ,
15- Popconfirm ,
16- Tag ,
17- Tooltip ,
18- Typography ,
19- theme ,
20- } from 'antd' ;
21- import { BAIFlex , BAITable , BAIUnmountAfterClose } from 'backend.ai-ui' ;
13+ BAICard ,
14+ BAIConfirmModalWithInput ,
15+ BAIFlex ,
16+ BAITable ,
17+ BAIUnmountAfterClose ,
18+ } from 'backend.ai-ui' ;
2219import { default as dayjs } from 'dayjs' ;
2320import * as _ from 'lodash-es' ;
2421import { CircleArrowDownIcon , CircleArrowUpIcon } from 'lucide-react' ;
@@ -102,6 +99,9 @@ const AutoScalingRuleListLegacy: React.FC<AutoScalingRuleListLegacyProps> = ({
10299 useState < AutoScalingRuleEditorModalLegacyFragment$key | null > ( null ) ;
103100 const [ isOpenAutoScalingRuleModal , setIsOpenAutoScalingRuleModal ] =
104101 useState ( false ) ;
102+ const [ deletingRule , setDeletingRule ] = useState < Record < string , any > | null > (
103+ null ,
104+ ) ;
105105
106106 const [
107107 commitDeleteAutoScalingRuleMutation ,
@@ -117,7 +117,7 @@ const AutoScalingRuleListLegacy: React.FC<AutoScalingRuleListLegacyProps> = ({
117117
118118 return (
119119 < >
120- < Card
120+ < BAICard
121121 title = { t ( 'modelService.AutoScalingRules' ) }
122122 extra = {
123123 < Button
@@ -131,6 +131,7 @@ const AutoScalingRuleListLegacy: React.FC<AutoScalingRuleListLegacyProps> = ({
131131 { t ( 'modelService.AddRules' ) }
132132 </ Button >
133133 }
134+ styles = { { body : { paddingTop : 0 } } }
134135 >
135136 < BAITable
136137 scroll = { { x : 'max-content' } }
@@ -180,79 +181,26 @@ const AutoScalingRuleListLegacy: React.FC<AutoScalingRuleListLegacyProps> = ({
180181 }
181182 } }
182183 />
183- < Popconfirm
184- title = { t ( 'dialog.warning.CannotBeUndone' ) }
185- okText = { t ( 'button.Delete' ) }
186- okButtonProps = { {
187- danger : true ,
188- } }
189- disabled = { isInFlightDeleteAutoScalingRuleMutation }
190- onConfirm = { ( ) => {
191- if ( autoScalingRules ) {
192- commitDeleteAutoScalingRuleMutation ( {
193- variables : {
194- id : row ?. id as string ,
195- } ,
196- onCompleted : ( res , errors ) => {
197- if (
198- ! res ?. delete_endpoint_auto_scaling_rule_node ?. ok
199- ) {
200- message . error (
201- res ?. delete_endpoint_auto_scaling_rule_node
202- ?. msg ,
203- ) ;
204- } else if ( errors && errors . length > 0 ) {
205- const errorMsgList = _ . map (
206- errors ,
207- ( error ) =>
208- error . message || t ( 'dialog.ErrorOccurred' ) ,
209- ) ;
210- for ( const error of errorMsgList ) {
211- message . error ( error ) ;
184+ < Button
185+ type = "text"
186+ icon = {
187+ < DeleteFilled
188+ style = {
189+ isEndpointDestroying
190+ ? undefined
191+ : {
192+ color : token . colorError ,
212193 }
213- } else {
214- setEditingAutoScalingRule ( null ) ;
215- startRefetchTransition ( ( ) => {
216- onRefetch ( ) ;
217- } ) ;
218- message . success ( {
219- key : 'autoscaling-rule-deleted' ,
220- content : t (
221- 'autoScalingRule.SuccessfullyDeleted' ,
222- ) ,
223- } ) ;
224- }
225- } ,
226- onError : ( error ) => {
227- message . error (
228- error ?. message || t ( 'dialog.ErrorOccurred' ) ,
229- ) ;
230- } ,
231- } ) ;
194+ }
195+ />
196+ }
197+ disabled = { isEndpointDestroying || ! isOwnedByCurrentUser }
198+ onClick = { ( ) => {
199+ if ( row ) {
200+ setDeletingRule ( row ) ;
232201 }
233202 } }
234- >
235- < Button
236- type = "text"
237- icon = {
238- < DeleteFilled
239- style = {
240- isEndpointDestroying
241- ? undefined
242- : {
243- color : token . colorError ,
244- }
245- }
246- />
247- }
248- disabled = { false }
249- onClick = { ( ) => {
250- if ( row ) {
251- setEditingAutoScalingRule ( row ) ;
252- }
253- } }
254- />
255- </ Popconfirm >
203+ />
256204 </ BAIFlex >
257205 ) ,
258206 } ,
@@ -322,7 +270,7 @@ const AutoScalingRuleListLegacy: React.FC<AutoScalingRuleListLegacyProps> = ({
322270 showSorterTooltip = { false }
323271 dataSource = { autoScalingRules }
324272 > </ BAITable >
325- </ Card >
273+ </ BAICard >
326274 < BAIUnmountAfterClose >
327275 < AutoScalingRuleEditorModalLegacy
328276 open = { isOpenAutoScalingRuleModal }
@@ -339,6 +287,64 @@ const AutoScalingRuleListLegacy: React.FC<AutoScalingRuleListLegacyProps> = ({
339287 } }
340288 />
341289 </ BAIUnmountAfterClose >
290+ < BAIConfirmModalWithInput
291+ open = { ! ! deletingRule }
292+ title = { t ( 'autoScalingRule.ConfirmDeleteAutoScalingRule' , {
293+ autoScalingRule : deletingRule ?. metric_name ?? '' ,
294+ } ) }
295+ content = {
296+ < Typography . Text type = "danger" >
297+ { t ( 'dialog.warning.CannotBeUndone' ) }
298+ </ Typography . Text >
299+ }
300+ confirmText = { deletingRule ?. metric_name ?? '' }
301+ inputLabel = { t ( 'autoScalingRule.TypeMetricNameToDelete' , {
302+ metricName : deletingRule ?. metric_name ?? '' ,
303+ } ) }
304+ okText = { t ( 'button.Delete' ) }
305+ okButtonProps = { { loading : isInFlightDeleteAutoScalingRuleMutation } }
306+ onOk = { ( ) => {
307+ if ( deletingRule && autoScalingRules ) {
308+ commitDeleteAutoScalingRuleMutation ( {
309+ variables : {
310+ id : deletingRule . id as string ,
311+ } ,
312+ onCompleted : ( res , errors ) => {
313+ if ( ! res ?. delete_endpoint_auto_scaling_rule_node ?. ok ) {
314+ message . error (
315+ res ?. delete_endpoint_auto_scaling_rule_node ?. msg ,
316+ ) ;
317+ setDeletingRule ( null ) ;
318+ } else if ( errors && errors . length > 0 ) {
319+ const errorMsgList = _ . map (
320+ errors ,
321+ ( error ) => error . message || t ( 'dialog.ErrorOccurred' ) ,
322+ ) ;
323+ for ( const error of errorMsgList ) {
324+ message . error ( error ) ;
325+ }
326+ setDeletingRule ( null ) ;
327+ } else {
328+ setDeletingRule ( null ) ;
329+ setEditingAutoScalingRule ( null ) ;
330+ startRefetchTransition ( ( ) => {
331+ onRefetch ( ) ;
332+ } ) ;
333+ message . success ( {
334+ key : 'autoscaling-rule-deleted' ,
335+ content : t ( 'autoScalingRule.SuccessfullyDeleted' ) ,
336+ } ) ;
337+ }
338+ } ,
339+ onError : ( error ) => {
340+ message . error ( error ?. message || t ( 'dialog.ErrorOccurred' ) ) ;
341+ setDeletingRule ( null ) ;
342+ } ,
343+ } ) ;
344+ }
345+ } }
346+ onCancel = { ( ) => setDeletingRule ( null ) }
347+ />
342348 </ >
343349 ) ;
344350} ;
0 commit comments