-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve SR table jobs overview (#923)
- Loading branch information
1 parent
95f0f05
commit 1d3b3a4
Showing
10 changed files
with
181 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { Button } from "@/components/ui/button"; | ||
import { RefreshCw } from "lucide-react"; | ||
import { getJobs } from "@/api/scanreports"; | ||
import { toast } from "sonner"; | ||
|
||
interface RefreshButtonProps { | ||
scanReportId: string; | ||
onJobsRefresh: (updatedJobs: Job[]) => void; | ||
} | ||
|
||
export function RefreshButton({ | ||
scanReportId, | ||
onJobsRefresh, | ||
}: RefreshButtonProps) { | ||
const [isRefreshing, setIsRefreshing] = useState(false); | ||
|
||
const handleRefresh = async () => { | ||
try { | ||
setIsRefreshing(true); | ||
// Fetch jobs data | ||
const updatedJobs = await getJobs(scanReportId); | ||
if (updatedJobs) { | ||
onJobsRefresh(updatedJobs); | ||
} | ||
} catch (error: any) { | ||
toast.error("Failed to refresh jobs:", error); | ||
} finally { | ||
setIsRefreshing(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button | ||
variant="outline" | ||
onClick={handleRefresh} | ||
disabled={isRefreshing} | ||
className="ml-2" | ||
> | ||
{isRefreshing ? ( | ||
<>Refreshing...</> | ||
) : ( | ||
<> | ||
<RefreshCw className="mr-2 h-4 w-4" /> | ||
Refresh Jobs Progress | ||
</> | ||
)} | ||
</Button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
app/next-client-app/components/scanreports/ScanReportsTableClient.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
|
||
import { DataTable } from "@/components/data-table"; | ||
import { RefreshButton } from "../jobs/RefreshButton"; | ||
import { columns } from "@/app/(protected)/scanreports/[id]/columns"; | ||
|
||
export default function ScanReportsTableClient({ | ||
initialScanReportsResult, | ||
scanReportId, | ||
Filter, | ||
count, | ||
}: { | ||
initialScanReportsResult: ScanReportTable[]; | ||
scanReportId: string; | ||
Filter: JSX.Element; | ||
count: number; | ||
}) { | ||
const [scanReportsResult, setScanReportsResult] = useState( | ||
initialScanReportsResult | ||
); | ||
|
||
useEffect(() => { | ||
setScanReportsResult(initialScanReportsResult); | ||
}, [initialScanReportsResult]); | ||
|
||
const handleJobsRefresh = (updatedJobs: Job[]) => { | ||
// Update the jobs for each table row | ||
const updatedScanReportsResult = scanReportsResult.map((table) => ({ | ||
...table, | ||
jobs: updatedJobs, | ||
})); | ||
|
||
setScanReportsResult(updatedScanReportsResult); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<DataTable | ||
columns={columns} | ||
data={scanReportsResult} | ||
count={count} | ||
RefreshButton={ | ||
<RefreshButton | ||
scanReportId={scanReportId} | ||
onJobsRefresh={handleJobsRefresh} | ||
/> | ||
} | ||
linkPrefix="tables/" | ||
Filter={Filter} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters