feat(monitors): create bulk actions ui components and selection hooks
- Extracts generic table selection logic into useTableSelection hook - Creates BulkActionsBar component with Collapse animations - Implements useBulkMonitorActions to handle API logic and toasts - Adds i18n translation strings across all 16 locales Fixes #3602
This commit is contained in:
1 parent
094def117a
commit
6b9759e455
20 files changed
+279
-16
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { usePost } from "@/Hooks/UseApi";
|
||||
|
||||
interface BulkPauseBody {
|
||||
monitorIds: string[];
|
||||
pause: boolean;
|
||||
}
|
||||
|
||||
interface UseBulkMonitorActionsReturn {
|
||||
selectedRows: string[];
|
||||
setSelectedRows: (rows: string[]) => void;
|
||||
handleBulkPause: () => Promise<void>;
|
||||
handleBulkResume: () => Promise<void>;
|
||||
handleCancelSelection: () => void;
|
||||
}
|
||||
|
||||
export const useBulkMonitorActions = (
|
||||
refetch: () => void,
|
||||
page?: number
|
||||
): UseBulkMonitorActionsReturn => {
|
||||
const [selectedRows, setSelectedRows] = useState<string[]>([]);
|
||||
const { post: bulkPost } = usePost<BulkPauseBody>();
|
||||
|
||||
// Clear selection when page changes
|
||||
useEffect(() => {
|
||||
setSelectedRows([]);
|
||||
}, [page]);
|
||||
|
||||
const handleBulkPause = async () => {
|
||||
const result = await bulkPost("/monitors/bulk/pause", {
|
||||
monitorIds: selectedRows,
|
||||
pause: true,
|
||||
});
|
||||
if (result) {
|
||||
setSelectedRows([]);
|
||||
refetch();
|
||||
}
|
||||
};
|
||||
|
||||
const handleBulkResume = async () => {
|
||||
const result = await bulkPost("/monitors/bulk/pause", {
|
||||
monitorIds: selectedRows,
|
||||
pause: false,
|
||||
});
|
||||
if (result) {
|
||||
setSelectedRows([]);
|
||||
refetch();
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancelSelection = () => {
|
||||
setSelectedRows([]);
|
||||
};
|
||||
|
||||
return {
|
||||
selectedRows,
|
||||
setSelectedRows,
|
||||
handleBulkPause,
|
||||
handleBulkResume,
|
||||
handleCancelSelection,
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user