Skip to content

Commit

Permalink
Refresh workflow operations in event details
Browse files Browse the repository at this point in the history
In the old admin ui, the status of workflow operations in the event
details was updated in real-time, allowing you to "watch" your
workflow running. This updates our admin ui to do the same by
re-fetching workflow operations every 5 seconds.

Unfortunately, this is causing rerenders even if the response
from the Opencast backend has not changed between calls.
We could probably memoize this somehow, but I can't find a
straightforward way, at least not one that is more straightfoward
than switching to redux toolkit (like in opencast#214).
  • Loading branch information
Arnei committed Nov 2, 2023
1 parent 390953b commit dcdf7d5
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { connect } from "react-redux";
import React from "react";
import React, { useEffect } from "react";
import Notifications from "../../../shared/Notifications";
import {
getWorkflow,
getWorkflowOperations,
isFetchingWorkflowOperations,
} from "../../../../selectors/eventDetailsSelectors";
import { fetchWorkflowOperationDetails } from "../../../../thunks/eventDetailsThunks";
import { fetchWorkflowOperationDetails, fetchWorkflowOperations } from "../../../../thunks/eventDetailsThunks";
import { removeNotificationWizardForm } from "../../../../actions/notificationActions";
import EventDetailsTabHierarchyNavigation from "./EventDetailsTabHierarchyNavigation";

Expand All @@ -26,9 +26,26 @@ const EventDetailsWorkflowOperations = ({
operations,
// @ts-expect-error TS(7031): Binding element 'isFetching' implicitly has an 'an... Remove this comment to see the full error message
isFetching,
// @ts-expect-error TS(7031): Binding element 'fetchOperationDetails' implicitly... Remove this comment to see the full error message
fetchOperations,
// @ts-expect-error TS(7031): Binding element 'fetchOperationDetails' implicitly... Remove this comment to see the full error message
fetchOperationDetails,
}) => {

const loadWorkflowOperations = async () => {
// Fetching workflow operations from server
await fetchOperations(eventId, workflowId);
};

useEffect(() => {
// Fetch workflow operations every 5 seconds
let fetchWorkflowOperationsInterval = setInterval(loadWorkflowOperations, 5000);

// Unmount interval
return () => clearInterval(fetchWorkflowOperationsInterval);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

// @ts-expect-error TS(7006): Parameter 'tabType' implicitly has an 'any' type.
const openSubTab = (tabType, operationId = null) => {
removeNotificationWizardForm();
Expand Down Expand Up @@ -146,6 +163,8 @@ const mapStateToProps = (state) => ({
// Mapping actions to dispatch
// @ts-expect-error TS(7006): Parameter 'dispatch' implicitly has an 'any' type.
const mapDispatchToProps = (dispatch) => ({
fetchOperations: (eventId: string, workflowId: string) =>
dispatch(fetchWorkflowOperations(eventId, workflowId)),
// @ts-expect-error TS(7006): Parameter 'eventId' implicitly has an 'any' type.
fetchOperationDetails: (eventId, workflowId, operationId) =>
dispatch(fetchWorkflowOperationDetails(eventId, workflowId, operationId)),
Expand Down

0 comments on commit dcdf7d5

Please sign in to comment.