diff --git a/src/action/ActionType.ts b/src/action/ActionType.ts index 91fdd726..091f1f00 100644 --- a/src/action/ActionType.ts +++ b/src/action/ActionType.ts @@ -247,6 +247,7 @@ enum ActionType { DOES_USERNAME_EXISTS = "DOES_USERNAME_EXISTS", LONG_RUNNING_TASKS_UPDATE = "LONG_RUNNING_TASKS_UPDATE", + CLEAR_LONG_RUNNING_TASKS_QUEUE = "CLEAR_LONG_RUNNING_TASKS_QUEUE", } export default ActionType; diff --git a/src/action/AsyncActions.ts b/src/action/AsyncActions.ts index 03592ff0..5d75e79d 100644 --- a/src/action/AsyncActions.ts +++ b/src/action/AsyncActions.ts @@ -1234,6 +1234,29 @@ export function invalidateCaches() { }; } +export function clearLongRunningTasksQueue() { + const action = { type: ActionType.CLEAR_LONG_RUNNING_TASKS_QUEUE }; + return (dispatch: ThunkDispatch) => { + dispatch(asyncActionRequest(action)); + return Ajax.delete(`${Constants.API_PREFIX}/admin/long-running-tasks`) + .then(() => dispatch(asyncActionSuccess(action))) + .then(() => + dispatch( + publishMessage( + new Message( + { + messageId: + "administration.maintenance.clearLongRunningTasksQueue.success", + }, + MessageType.SUCCESS + ) + ) + ) + ) + .catch((error) => dispatch(asyncActionFailure(action, error))); + }; +} + export function loadConfiguration() { const action = { type: ActionType.LOAD_CONFIGURATION }; return (dispatch: ThunkDispatch) => { diff --git a/src/component/administration/Maintenance.tsx b/src/component/administration/Maintenance.tsx index 89b70413..c3ddd913 100644 --- a/src/component/administration/Maintenance.tsx +++ b/src/component/administration/Maintenance.tsx @@ -1,17 +1,17 @@ import * as React from "react"; import { Button, ButtonToolbar } from "reactstrap"; import PanelWithActions from "../misc/PanelWithActions"; -import { connect } from "react-redux"; -import { ThunkDispatch } from "../../util/Types"; -import { invalidateCaches } from "../../action/AsyncActions"; -import { useI18n } from "../hook/useI18n"; -interface MaintenanceProps { - invalidateCache: () => void; -} +import { useI18n } from "../hook/useI18n"; +import { + clearLongRunningTasksQueue, + invalidateCaches, +} from "../../action/AsyncActions"; +import { ThunkDispatch } from "../../util/Types"; +import { useDispatch } from "react-redux"; -export const Maintenance: React.FC = (props) => { - const { invalidateCache } = props; +export const Maintenance: React.FC = () => { + const dispatch: ThunkDispatch = useDispatch(); const { i18n } = useI18n(); return ( @@ -20,17 +20,23 @@ export const Maintenance: React.FC = (props) => { color="primary" size="sm" title={i18n("administration.maintenance.invalidateCaches.tooltip")} - onClick={invalidateCache} + onClick={() => dispatch(invalidateCaches())} > {i18n("administration.maintenance.invalidateCaches")} + ); }; -export default connect(undefined, (dispatch: ThunkDispatch) => { - return { - invalidateCache: () => dispatch(invalidateCaches()), - }; -})(Maintenance); +export default Maintenance; diff --git a/src/i18n/cs.ts b/src/i18n/cs.ts index a74b61f1..6f1104fb 100644 --- a/src/i18n/cs.ts +++ b/src/i18n/cs.ts @@ -228,6 +228,12 @@ const cs = { "Vyprázdnit interní cache systému", "administration.maintenance.invalidateCaches.success": "Cache úspěšně vyprázdněna.", + "administration.maintenance.clearLongRunningTasksQueue": + "Vyprádznit frontu procesů na pozadí", + "administration.maintenance.clearLongRunningTasksQueue.tooltip": + "Vyprázdnit frontu procesů čekajících na zpracování na pozadí", + "administration.maintenance.clearLongRunningTasksQueue.success": + "Fronta procesů na pozadí úspěšně vyprázdněna.", "administration.groups": "Uživatelské skupiny", "administration.groups.create": "Vytvořit skupinu", "administration.groups.create.tooltip": diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 264ae219..3a2e2b13 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -217,6 +217,12 @@ const en = { "Invalidate system's internal caches", "administration.maintenance.invalidateCaches.success": "Caches successfully cleared.", + "administration.maintenance.clearLongRunningTasksQueue": + "Clear background process queue", + "administration.maintenance.clearLongRunningTasksQueue.tooltip": + "Clears the queue of processes that are waiting to be executed in the background", + "administration.maintenance.clearLongRunningTasksQueue.success": + "Background process queue successfully cleared.", "administration.groups": "User groups", "administration.groups.create": "Create group", "administration.groups.create.tooltip": "Allows to create a new user group",