-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableRow, | ||
CircularProgress, | ||
} from '@mui/material'; | ||
|
||
interface Worker { | ||
name: string; | ||
id: string; | ||
queue_name: string; | ||
last_seen: string; // Assuming 'last_seen' is a string for simplicity | ||
} | ||
|
||
interface WorkerTableProps { | ||
token: string; | ||
setShowJobTable: React.Dispatch<React.SetStateAction<boolean>>; | ||
} | ||
|
||
const WorkersTable: React.FC<WorkerTableProps> = ({ token, setShowJobTable }) => { | ||
const [workers, setWorkers] = useState<Worker[]>([]); | ||
const [loading, setLoading] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
const fetchWorkers = async () => { | ||
try { | ||
setLoading(true); | ||
const response = await axios.get('/api/v1/workers', | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
setWorkers(response.data); | ||
} catch (error) { | ||
console.error('Error fetching workers:', error); | ||
setShowJobTable(false); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
fetchWorkers(); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<Table> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>Name</TableCell> | ||
<TableCell>ID</TableCell> | ||
<TableCell>Queue Name</TableCell> | ||
<TableCell>Last Seen</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{workers.map((worker) => ( | ||
<TableRow key={worker.id}> | ||
<TableCell>{worker.name}</TableCell> | ||
<TableCell>{worker.id}</TableCell> | ||
<TableCell>{worker.queue_name}</TableCell> | ||
<TableCell>{worker.last_seen}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
{loading && <CircularProgress />} | ||
</div> | ||
); | ||
}; | ||
|
||
export default WorkersTable; |
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