11import { BAIHuggingFaceRegistrySettingModalFragment$key } from '../../__generated__/BAIHuggingFaceRegistrySettingModalFragment.graphql' ;
2+ import { UpdateHuggingFaceRegistryInput } from '../../__generated__/BAIHuggingFaceRegistrySettingModalMutation.graphql' ;
23import { toLocalId } from '../../helper' ;
4+ import { useErrorMessageResolver } from '../../hooks' ;
35import BAIFlex from '../BAIFlex' ;
46import BAIModal , { BAIModalProps } from '../BAIModal' ;
57import BAIUnmountAfterClose from '../BAIUnmountAfterClose' ;
@@ -14,17 +16,17 @@ export type BAIHuggingFaceRegistrySettingModalFragmentKey =
1416
1517export interface BAIHuggingFaceRegistrySettingModalProps extends BAIModalProps {
1618 huggingFaceRegistryFragment ?: BAIHuggingFaceRegistrySettingModalFragmentKey ;
17- onRequestClose ?: ( success ?: boolean ) => void ;
1819}
1920
2021const BAIHuggingFaceRegistrySettingModal = ( {
2122 huggingFaceRegistryFragment,
22- onRequestClose,
2323 ...baiModalProps
2424} : BAIHuggingFaceRegistrySettingModalProps ) => {
2525 'use memo' ;
2626 const { t } = useTranslation ( ) ;
2727 const { message, modal } = App . useApp ( ) ;
28+ const { getErrorMessage } = useErrorMessageResolver ( ) ;
29+
2830 const formRef = useRef < FormInstance > ( null ) ;
2931
3032 const huggingFaceRegistry = useFragment (
@@ -56,34 +58,26 @@ const BAIHuggingFaceRegistrySettingModal = ({
5658
5759 const hasToken = initialToken && initialToken . length > 0 ;
5860
59- const executeUpdate = ( values : any ) => {
61+ const executeUpdate = ( values : UpdateHuggingFaceRegistryInput ) => {
6062 updateHuggingFaceRegistry ( {
6163 variables : {
6264 input : {
6365 id : toLocalId ( huggingFaceRegistry ! . id ) ,
64- token : values . token ,
66+ token : values . token ?? '' ,
6567 } ,
6668 } ,
6769 onCompleted : ( _res , errors ) => {
6870 if ( errors && errors . length > 0 ) {
69- errors . forEach ( ( err ) =>
70- message . error (
71- err . message ??
72- t ( 'comp:HuggingFaceRegistrySettingModal.FailedToUpdateToken' ) ,
73- ) ,
74- ) ;
71+ errors . forEach ( ( err ) => message . error ( getErrorMessage ( err ) ) ) ;
7572 return ;
7673 }
7774 message . success (
7875 t ( 'comp:HuggingFaceRegistrySettingModal.TokenUpdatedSuccessfully' ) ,
7976 ) ;
80- onRequestClose ?.( true ) ;
77+ baiModalProps . onOk ?.( { } as React . MouseEvent < HTMLButtonElement > ) ;
8178 } ,
8279 onError : ( err ) => {
83- message . error (
84- err . message ??
85- t ( 'comp:HuggingFaceRegistrySettingModal.FailedToUpdateToken' ) ,
86- ) ;
80+ message . error ( getErrorMessage ( err ) ) ;
8781 } ,
8882 } ) ;
8983 } ;
@@ -96,11 +90,19 @@ const BAIHuggingFaceRegistrySettingModal = ({
9690 return ;
9791 }
9892
93+ if ( hasToken && ! isEditing ) {
94+ // If not editing, no need to update
95+ message . success (
96+ t ( 'comp:HuggingFaceRegistrySettingModal.NoChangesToSave' ) ,
97+ ) ;
98+ baiModalProps . onOk ?.( { } as React . MouseEvent < HTMLButtonElement > ) ;
99+ return ;
100+ }
101+
99102 formRef . current
100103 ?. validateFields ( )
101104 . then ( ( values ) => {
102105 // Check if current token exists and is empty string, but new token is not empty
103-
104106 if ( hasToken && ! values . token ) {
105107 modal . confirm ( {
106108 title : t ( 'comp:HuggingFaceRegistrySettingModal.ResetTokenConfirm' ) ,
@@ -114,7 +116,7 @@ const BAIHuggingFaceRegistrySettingModal = ({
114116 // Don't proceed with update
115117 } ,
116118 okButtonProps : { danger : true } ,
117- okText : t ( 'button.Reset' ) ,
119+ okText : t ( 'general. button.Reset' ) ,
118120 } ) ;
119121 } else {
120122 executeUpdate ( values ) ;
@@ -128,15 +130,14 @@ const BAIHuggingFaceRegistrySettingModal = ({
128130 < BAIModal
129131 destroyOnHidden
130132 afterClose = { ( ) => setIsEditing ( false ) }
133+ { ...baiModalProps }
131134 title = { t ( 'comp:HuggingFaceRegistrySettingModal.HuggingFaceSettings' ) }
132135 centered
133- okText = { t ( 'button.Save' ) }
136+ okText = { t ( 'general. button.Save' ) }
134137 onOk = { handleOk }
135- onCancel = { ( ) => onRequestClose ?.( false ) }
136138 okButtonProps = { {
137139 loading : isInflightUpdateHuggingFaceRegistry ,
138140 } }
139- { ...baiModalProps }
140141 >
141142 < Form ref = { formRef } layout = "vertical" >
142143 < Form . Item
0 commit comments