Add jail control actions to useJailDetail hook
Implement TASK F-2: Wrap JailDetailPage jail-control API calls in a hook. Changes: - Add start(), stop(), reload(), and setIdle() methods to useJailDetail hook - Update JailDetailPage to use hook control methods instead of direct API imports - Update error handling to remove dependency on ApiError type - Add comprehensive tests for new control methods (8 tests) - Update existing test to include new hook methods in mock The control methods handle refetching jail data after each operation, consistent with the pattern used in useJails hook.
This commit is contained in:
@@ -153,6 +153,14 @@ export interface UseJailDetailResult {
|
||||
removeIp: (ip: string) => Promise<void>;
|
||||
/** Enable or disable the ignoreself option for this jail. */
|
||||
toggleIgnoreSelf: (on: boolean) => Promise<void>;
|
||||
/** Start the jail. */
|
||||
start: () => Promise<void>;
|
||||
/** Stop the jail. */
|
||||
stop: () => Promise<void>;
|
||||
/** Reload jail configuration. */
|
||||
reload: () => Promise<void>;
|
||||
/** Toggle idle mode on/off for the jail. */
|
||||
setIdle: (on: boolean) => Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,6 +224,26 @@ export function useJailDetail(name: string): UseJailDetailResult {
|
||||
load();
|
||||
};
|
||||
|
||||
const doStart = async (): Promise<void> => {
|
||||
await startJail(name);
|
||||
load();
|
||||
};
|
||||
|
||||
const doStop = async (): Promise<void> => {
|
||||
await stopJail(name);
|
||||
load();
|
||||
};
|
||||
|
||||
const doReload = async (): Promise<void> => {
|
||||
await reloadJail(name);
|
||||
load();
|
||||
};
|
||||
|
||||
const doSetIdle = async (on: boolean): Promise<void> => {
|
||||
await setJailIdle(name, on);
|
||||
load();
|
||||
};
|
||||
|
||||
return {
|
||||
jail,
|
||||
ignoreList,
|
||||
@@ -226,6 +254,10 @@ export function useJailDetail(name: string): UseJailDetailResult {
|
||||
addIp,
|
||||
removeIp,
|
||||
toggleIgnoreSelf,
|
||||
start: doStart,
|
||||
stop: doStop,
|
||||
reload: doReload,
|
||||
setIdle: doSetIdle,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user