浏览代码

fix(web): enhance API test page experience by adding loading state for test button (#21091)

tags/1.5.0
Kerwin Bryant 4 个月前
父节点
当前提交
4e701b1efd
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5
    1
      web/app/components/tools/edit-custom-collection-modal/test-api.tsx

+ 5
- 1
web/app/components/tools/edit-custom-collection-modal/test-api.tsx 查看文件

const language = getLanguage(locale) const language = getLanguage(locale)
const [credentialsModalShow, setCredentialsModalShow] = useState(false) const [credentialsModalShow, setCredentialsModalShow] = useState(false)
const [tempCredential, setTempCredential] = React.useState<Credential>(customCollection.credentials) const [tempCredential, setTempCredential] = React.useState<Credential>(customCollection.credentials)
const [testing, setTesting] = useState(false)
const [result, setResult] = useState<string>('') const [result, setResult] = useState<string>('')
const { operation_id: toolName, parameters } = tool const { operation_id: toolName, parameters } = tool
const [parametersValue, setParametersValue] = useState<Record<string, string>>({}) const [parametersValue, setParametersValue] = useState<Record<string, string>>({})
const handleTest = async () => { const handleTest = async () => {
if (testing) return
setTesting(true)
// clone test schema // clone test schema
const credentials = JSON.parse(JSON.stringify(tempCredential)) as Credential const credentials = JSON.parse(JSON.stringify(tempCredential)) as Credential
if (credentials.auth_type === AuthType.none) { if (credentials.auth_type === AuthType.none) {
} }
const res = await testAPIAvailable(data) as any const res = await testAPIAvailable(data) as any
setResult(res.error || res.result) setResult(res.error || res.result)
setTesting(false)
} }


return ( return (
</div> </div>


</div> </div>
<Button variant='primary' className=' mt-4 h-10 w-full' onClick={handleTest}>{t('tools.test.title')}</Button>
<Button variant='primary' className=' mt-4 h-10 w-full' loading={testing} disabled={testing} onClick={handleTest}>{t('tools.test.title')}</Button>
<div className='mt-6'> <div className='mt-6'>
<div className='flex items-center space-x-3'> <div className='flex items-center space-x-3'>
<div className='system-xs-semibold text-text-tertiary'>{t('tools.test.testResult')}</div> <div className='system-xs-semibold text-text-tertiary'>{t('tools.test.testResult')}</div>

正在加载...
取消
保存