mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
fix: KEY pool adjustment order will fail
This commit is contained in:
@@ -27,6 +27,7 @@ const KeySettings: React.FC = () => {
|
||||
const [total, setTotal] = useState<number>(0)
|
||||
const modalRef = useRef<any>()
|
||||
const { accessData } = useGlobalContext()
|
||||
const [apiKeys, setApiKeys] = useState<APIKey[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
pageListRef.current?.reload()
|
||||
@@ -154,16 +155,30 @@ const KeySettings: React.FC = () => {
|
||||
}
|
||||
|
||||
const handleDragSortEnd = async (beforeIndex: number, afterIndex: number, newDataSource: APIKey[]) => {
|
||||
console.log(beforeIndex, afterIndex, newDataSource)
|
||||
try {
|
||||
let targetId
|
||||
let sortDirection
|
||||
|
||||
// Check if there's an item before afterIndex
|
||||
if (afterIndex > 0) {
|
||||
targetId = newDataSource[afterIndex - 1].id
|
||||
sortDirection = 'after'
|
||||
} else if (afterIndex < newDataSource.length - 1) {
|
||||
// If no item before, use the item after
|
||||
targetId = newDataSource[afterIndex + 1].id
|
||||
sortDirection = 'before'
|
||||
}
|
||||
|
||||
const response = await fetchData<BasicResponse<any>>('ai/resource/key/sort', {
|
||||
method: 'PUT',
|
||||
eoParams: {
|
||||
origin: newDataSource[beforeIndex].id,
|
||||
target: newDataSource[afterIndex].id,
|
||||
sort: afterIndex > beforeIndex ? 'before' : 'after'
|
||||
provider: selectedProvider
|
||||
},
|
||||
eoBody: {
|
||||
origin: apiKeys[beforeIndex].id,
|
||||
target: targetId,
|
||||
sort: sortDirection
|
||||
}
|
||||
// eoApiPrefix: 'http://uat.apikit.com:11204/mockApi/aoplatform/api/v1/'
|
||||
})
|
||||
|
||||
if (response.code === STATUS_CODE.SUCCESS) {
|
||||
@@ -171,9 +186,13 @@ const KeySettings: React.FC = () => {
|
||||
pageListRef.current?.reload()
|
||||
} else {
|
||||
message.error(response.msg || RESPONSE_TIPS.error)
|
||||
// Revert the UI if API call fails
|
||||
pageListRef.current?.reload()
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(RESPONSE_TIPS.error)
|
||||
// Revert the UI if API call fails
|
||||
pageListRef.current?.reload()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,6 +214,7 @@ const KeySettings: React.FC = () => {
|
||||
|
||||
if (response.code === STATUS_CODE.SUCCESS) {
|
||||
setTotal(response.data.total)
|
||||
setApiKeys(response.data.keys)
|
||||
return {
|
||||
data: response.data.keys,
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user