Add admin endpoint to delete bundle backtest requests and implement related UI functionality + Add job resilient
This commit is contained in:
@@ -486,6 +486,49 @@ export class AdminClient extends AuthorizedApiBase {
|
||||
}
|
||||
return Promise.resolve<BundleBacktestRequestSummaryResponse>(null as any);
|
||||
}
|
||||
|
||||
admin_DeleteBundleBacktestRequest(id: string): Promise<FileResponse> {
|
||||
let url_ = this.baseUrl + "/Admin/BundleBacktestRequests/{id}";
|
||||
if (id === undefined || id === null)
|
||||
throw new Error("The parameter 'id' must be defined.");
|
||||
url_ = url_.replace("{id}", encodeURIComponent("" + id));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Accept": "application/octet-stream"
|
||||
}
|
||||
};
|
||||
|
||||
return this.transformOptions(options_).then(transformedOptions_ => {
|
||||
return this.http.fetch(url_, transformedOptions_);
|
||||
}).then((_response: Response) => {
|
||||
return this.processAdmin_DeleteBundleBacktestRequest(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processAdmin_DeleteBundleBacktestRequest(response: Response): Promise<FileResponse> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200 || status === 206) {
|
||||
const contentDisposition = response.headers ? response.headers.get("content-disposition") : undefined;
|
||||
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
|
||||
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
|
||||
if (fileName) {
|
||||
fileName = decodeURIComponent(fileName);
|
||||
} else {
|
||||
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
|
||||
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
|
||||
}
|
||||
return response.blob().then(blob => { return { fileName: fileName, data: blob, status: status, headers: _headers }; });
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<FileResponse>(null as any);
|
||||
}
|
||||
}
|
||||
|
||||
export class BacktestClient extends AuthorizedApiBase {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {useState} from 'react'
|
||||
import {useQuery} from '@tanstack/react-query'
|
||||
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import useApiUrlStore from '../../../app/store/apiStore'
|
||||
import {
|
||||
@@ -28,8 +28,10 @@ const BundleBacktestRequestsSettings: React.FC = () => {
|
||||
const [progressPercentageMax, setProgressPercentageMax] = useState<string>('')
|
||||
const [filtersOpen, setFiltersOpen] = useState<boolean>(false)
|
||||
const [showTable, setShowTable] = useState<boolean>(true)
|
||||
const [deleteConfirmRequestId, setDeleteConfirmRequestId] = useState<string | null>(null)
|
||||
|
||||
const adminClient = new AdminClient({}, apiUrl)
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
// Fetch bundle backtest requests summary statistics
|
||||
const {
|
||||
@@ -83,6 +85,33 @@ const BundleBacktestRequestsSettings: React.FC = () => {
|
||||
const totalPages = bundleRequestsData?.totalPages || 0
|
||||
const currentPage = bundleRequestsData?.currentPage || 1
|
||||
|
||||
// Delete mutation
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: async (requestId: string) => {
|
||||
return await adminClient.admin_DeleteBundleBacktestRequest(requestId)
|
||||
},
|
||||
onSuccess: () => {
|
||||
// Invalidate and refetch queries
|
||||
queryClient.invalidateQueries({ queryKey: ['bundleBacktestRequests'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['bundleBacktestRequestsSummary'] })
|
||||
setDeleteConfirmRequestId(null)
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Failed to delete bundle request:', error)
|
||||
alert(error.message || 'Failed to delete bundle request')
|
||||
}
|
||||
})
|
||||
|
||||
const handleDelete = (requestId: string) => {
|
||||
setDeleteConfirmRequestId(requestId)
|
||||
}
|
||||
|
||||
const confirmDelete = () => {
|
||||
if (deleteConfirmRequestId) {
|
||||
deleteMutation.mutate(deleteConfirmRequestId)
|
||||
}
|
||||
}
|
||||
|
||||
const handlePageChange = (newPage: number) => {
|
||||
setPage(newPage)
|
||||
}
|
||||
@@ -519,6 +548,7 @@ const BundleBacktestRequestsSettings: React.FC = () => {
|
||||
sortOrder={sortOrder}
|
||||
onPageChange={handlePageChange}
|
||||
onSortChange={handleSortChange}
|
||||
onDelete={handleDelete}
|
||||
/>
|
||||
|
||||
{error && (
|
||||
@@ -526,6 +556,34 @@ const BundleBacktestRequestsSettings: React.FC = () => {
|
||||
<span>Failed to load bundle backtest requests. Please try again.</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Delete Confirmation Modal */}
|
||||
{deleteConfirmRequestId && (
|
||||
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
|
||||
<div className="bg-base-100 p-6 rounded-lg shadow-xl max-w-md w-full mx-4">
|
||||
<h3 className="text-lg font-semibold mb-4">Confirm Delete</h3>
|
||||
<p className="text-base-content/70 mb-6">
|
||||
Are you sure you want to delete this bundle backtest request? This action cannot be undone and will also delete all related backtests.
|
||||
</p>
|
||||
<div className="flex gap-3 justify-end">
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
onClick={() => setDeleteConfirmRequestId(null)}
|
||||
disabled={deleteMutation.isPending}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-error"
|
||||
onClick={confirmDelete}
|
||||
disabled={deleteMutation.isPending}
|
||||
>
|
||||
{deleteMutation.isPending ? 'Deleting...' : 'Delete'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ interface IBundleBacktestRequestsTable {
|
||||
sortOrder: string
|
||||
onPageChange: (page: number) => void
|
||||
onSortChange: (sortBy: BundleBacktestRequestSortableColumn) => void
|
||||
onDelete?: (requestId: string) => void
|
||||
}
|
||||
|
||||
const BundleBacktestRequestsTable: React.FC<IBundleBacktestRequestsTable> = ({
|
||||
@@ -28,7 +29,8 @@ const BundleBacktestRequestsTable: React.FC<IBundleBacktestRequestsTable> = ({
|
||||
sortBy,
|
||||
sortOrder,
|
||||
onPageChange,
|
||||
onSortChange
|
||||
onSortChange,
|
||||
onDelete
|
||||
}) => {
|
||||
const getStatusBadge = (status: string | null | undefined) => {
|
||||
if (!status) return <span className="badge badge-sm">-</span>
|
||||
@@ -180,8 +182,24 @@ const BundleBacktestRequestsTable: React.FC<IBundleBacktestRequestsTable> = ({
|
||||
accessor: (row: BundleBacktestRequestListItemResponse) => (
|
||||
<span className="font-mono text-xs">{row.requestId?.substring(0, 8)}...</span>
|
||||
)
|
||||
}
|
||||
], [sortBy, sortOrder, onSortChange])
|
||||
},
|
||||
...(onDelete ? [{
|
||||
id: 'actions',
|
||||
Header: 'Actions',
|
||||
accessor: (row: BundleBacktestRequestListItemResponse) => (
|
||||
<button
|
||||
className="btn btn-sm btn-error btn-outline"
|
||||
onClick={() => onDelete(row.requestId || '')}
|
||||
disabled={!row.requestId}
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-4 h-4">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m-4.788 0L3.74 9m4.788-4.788L9.26 4.51m4.788 0L14.74 4.51M9.26 4.51l.346-1.5M14.74 4.51l-.346-1.5M3.74 9l4.788 0M14.74 9l4.788 0" />
|
||||
</svg>
|
||||
Delete
|
||||
</button>
|
||||
)
|
||||
}] : [])
|
||||
], [sortBy, sortOrder, onSortChange, onDelete])
|
||||
|
||||
const tableData = useMemo(() => {
|
||||
return bundleRequests.map((request) => ({
|
||||
|
||||
Reference in New Issue
Block a user