Skip to content

Commit

Permalink
Merge branch 'to-redux-toolkit-job' of Arnei/opencast-admin-interface…
Browse files Browse the repository at this point in the history
… into admin-ui-picard

Pull request #255

  Modernize redux: jobSlice
  • Loading branch information
gregorydlogan committed Feb 16, 2024
2 parents 45121d9 + 18d19ae commit 2e41bec
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 163 deletions.
35 changes: 0 additions & 35 deletions app/src/actions/jobActions.ts

This file was deleted.

7 changes: 2 additions & 5 deletions app/src/components/shared/MainNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from "../../thunks/tableThunks";
import { fetchEvents } from "../../slices/eventSlice";
import { fetchRecordings } from "../../thunks/recordingThunks";
import { fetchJobs } from "../../thunks/jobThunks";
import { fetchUsers } from "../../thunks/userThunks";
import { fetchThemes } from "../../thunks/themeThunks";
import { fetchFilters, fetchStats } from "../../thunks/tableFilterThunks";
Expand All @@ -31,6 +30,7 @@ import { GlobalHotKeys } from "react-hotkeys";
import { availableHotkeys } from "../../configs/hotkeysConfig";
import { fetchAcls } from "../../slices/aclSlice";
import { useAppDispatch } from "../../store";
import { fetchJobs } from "../../slices/jobSlice";

/**
* This component renders the main navigation that opens when the burger button is clicked
Expand All @@ -52,8 +52,6 @@ const MainNav = ({
loadingRecordings,
// @ts-expect-error TS(7031): Binding element 'loadingRecordingsIntoTable' impli... Remove this comment to see the full error message
loadingRecordingsIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingJobs' implicitly has an 'a... Remove this comment to see the full error message
loadingJobs,
// @ts-expect-error TS(7031): Binding element 'loadingJobsIntoTable' implicitly ... Remove this comment to see the full error message
loadingJobsIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingServers' implicitly has an... Remove this comment to see the full error message
Expand Down Expand Up @@ -138,7 +136,7 @@ const MainNav = ({
resetOffset();

// Fetching jobs from server
loadingJobs();
dispatch(fetchJobs());

// Load jobs into table
loadingJobsIntoTable();
Expand Down Expand Up @@ -348,7 +346,6 @@ const mapDispatchToProps = (dispatch) => ({
// @ts-expect-error TS(2554): Expected 1 arguments, but got 0.
loadingRecordings: () => dispatch(fetchRecordings()),
loadingRecordingsIntoTable: () => dispatch(loadRecordingsIntoTable()),
loadingJobs: () => dispatch(fetchJobs()),
loadingJobsIntoTable: () => dispatch(loadJobsIntoTable()),
loadingServers: () => dispatch(fetchServers()),
loadingServersIntoTable: () => dispatch(loadServersIntoTable()),
Expand Down
21 changes: 12 additions & 9 deletions app/src/components/systems/Jobs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Notifications from "../shared/Notifications";
import { jobsTemplateMap } from "../../configs/tableConfigs/jobsTableConfig";
import { getTotalJobs } from "../../selectors/jobSelectors";
import { fetchFilters } from "../../thunks/tableFilterThunks";
import { fetchJobs } from "../../thunks/jobThunks";
import {
loadJobsIntoTable,
loadServersIntoTable,
Expand All @@ -26,17 +25,15 @@ import Footer from "../Footer";
import { getUserInformation } from "../../selectors/userInfoSelectors";
import { hasAccess } from "../../utils/utils";
import { getCurrentFilterResource } from "../../selectors/tableFilterSelectors";
import { useAppDispatch, useAppSelector } from "../../store";
import { fetchJobs } from "../../slices/jobSlice";

/**
* This component renders the table view of jobs
*/
const Jobs = ({
// @ts-expect-error TS(7031): Binding element 'loadingJobs' implicitly has an 'a... Remove this comment to see the full error message
loadingJobs,
// @ts-expect-error TS(7031): Binding element 'loadingJobsIntoTable' implicitly ... Remove this comment to see the full error message
loadingJobsIntoTable,
// @ts-expect-error TS(7031): Binding element 'jobs' implicitly has an 'any' typ... Remove this comment to see the full error message
jobs,
// @ts-expect-error TS(7031): Binding element 'loadingFilters' implicitly has an... Remove this comment to see the full error message
loadingFilters,
// @ts-expect-error TS(7031): Binding element 'loadingServers' implicitly has an... Remove this comment to see the full error message
Expand All @@ -57,11 +54,19 @@ const Jobs = ({
currentFilterType,
}) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const [displayNavigation, setNavigation] = useState(false);

const jobs = useAppSelector(state => getTotalJobs(state));

// TODO: Get rid of the wrappers when modernizing redux is done
const fetchJobsWrapper = () => {
dispatch(fetchJobs())
}

const loadJobs = async () => {
// Fetching jobs from server
await loadingJobs();
await dispatch(fetchJobs());

// Load jobs into table
loadingJobsIntoTable();
Expand Down Expand Up @@ -158,7 +163,7 @@ const Jobs = ({
<div className="controls-container">
{/* Include filters component */}
<TableFilters
loadResource={loadingJobs}
loadResource={fetchJobsWrapper}
loadResourceIntoTable={loadingJobsIntoTable}
resource={"jobs"}
/>
Expand All @@ -176,7 +181,6 @@ const Jobs = ({
// Getting state data out of redux store
// @ts-expect-error TS(7006): Parameter 'state' implicitly has an 'any' type.
const mapStateToProps = (state) => ({
jobs: getTotalJobs(state),
user: getUserInformation(state),
currentFilterType: getCurrentFilterResource(state),
});
Expand All @@ -186,7 +190,6 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = (dispatch) => ({
// @ts-expect-error TS(7006): Parameter 'resource' implicitly has an 'any' type.
loadingFilters: (resource) => dispatch(fetchFilters(resource)),
loadingJobs: () => dispatch(fetchJobs()),
loadingJobsIntoTable: () => dispatch(loadJobsIntoTable()),
loadingServers: () => dispatch(fetchServers()),
loadingServersIntoTable: () => dispatch(loadServersIntoTable()),
Expand Down
9 changes: 4 additions & 5 deletions app/src/components/systems/Servers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
loadServersIntoTable,
loadServicesIntoTable,
} from "../../thunks/tableThunks";
import { fetchJobs } from "../../thunks/jobThunks";
import { fetchServices } from "../../thunks/serviceThunks";
import { editTextFilter } from "../../actions/tableFilterActions";
import { setOffset } from "../../actions/tableActions";
Expand All @@ -26,6 +25,8 @@ import Footer from "../Footer";
import { getUserInformation } from "../../selectors/userInfoSelectors";
import { hasAccess } from "../../utils/utils";
import { getCurrentFilterResource } from "../../selectors/tableFilterSelectors";
import { useAppDispatch } from "../../store";
import { fetchJobs } from "../../slices/jobSlice";

/**
* This component renders the table view of servers
Expand All @@ -39,8 +40,6 @@ const Servers = ({
servers,
// @ts-expect-error TS(7031): Binding element 'loadingFilters' implicitly has an... Remove this comment to see the full error message
loadingFilters,
// @ts-expect-error TS(7031): Binding element 'loadingJobs' implicitly has an 'a... Remove this comment to see the full error message
loadingJobs,
// @ts-expect-error TS(7031): Binding element 'loadingJobsIntoTable' implicitly ... Remove this comment to see the full error message
loadingJobsIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingServices' implicitly has a... Remove this comment to see the full error message
Expand All @@ -57,6 +56,7 @@ const Servers = ({
currentFilterType,
}) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const [displayNavigation, setNavigation] = useState(false);

const loadServers = async () => {
Expand All @@ -72,7 +72,7 @@ const Servers = ({
resetOffset();

// Fetching jobs from server
loadingJobs();
dispatch(fetchJobs());

// Load jobs into table
loadingJobsIntoTable();
Expand Down Expand Up @@ -188,7 +188,6 @@ const mapDispatchToProps = (dispatch) => ({
loadingFilters: (resource) => dispatch(fetchFilters(resource)),
loadingServers: () => dispatch(fetchServers()),
loadingServersIntoTable: () => dispatch(loadServersIntoTable()),
loadingJobs: () => dispatch(fetchJobs()),
loadingJobsIntoTable: () => dispatch(loadJobsIntoTable()),
loadingServices: () => dispatch(fetchServices()),
loadingServicesIntoTable: () => dispatch(loadServicesIntoTable()),
Expand Down
9 changes: 4 additions & 5 deletions app/src/components/systems/Services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import MainNav from "../shared/MainNav";
import Notifications from "../shared/Notifications";
import { servicesTemplateMap } from "../../configs/tableConfigs/servicesTableConfig";
import { fetchFilters } from "../../thunks/tableFilterThunks";
import { fetchJobs } from "../../thunks/jobThunks";
import {
loadJobsIntoTable,
loadServersIntoTable,
Expand All @@ -26,6 +25,8 @@ import Footer from "../Footer";
import { getUserInformation } from "../../selectors/userInfoSelectors";
import { hasAccess } from "../../utils/utils";
import { getCurrentFilterResource } from "../../selectors/tableFilterSelectors";
import { useAppDispatch } from "../../store";
import { fetchJobs } from "../../slices/jobSlice";

/**
* This component renders the table view of services
Expand All @@ -39,8 +40,6 @@ const Services = ({
services,
// @ts-expect-error TS(7031): Binding element 'loadingFilters' implicitly has an... Remove this comment to see the full error message
loadingFilters,
// @ts-expect-error TS(7031): Binding element 'loadingJobs' implicitly has an 'a... Remove this comment to see the full error message
loadingJobs,
// @ts-expect-error TS(7031): Binding element 'loadingJobsIntoTable' implicitly ... Remove this comment to see the full error message
loadingJobsIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingServers' implicitly has an... Remove this comment to see the full error message
Expand All @@ -57,6 +56,7 @@ const Services = ({
currentFilterType,
}) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const [displayNavigation, setNavigation] = useState(false);

const loadServices = async () => {
Expand All @@ -72,7 +72,7 @@ const Services = ({
resetOffset();

// Fetching jobs from server
loadingJobs();
dispatch(fetchJobs());

// Load jobs into table
loadingJobsIntoTable();
Expand Down Expand Up @@ -188,7 +188,6 @@ const mapDispatchToProps = (dispatch) => ({
loadingFilters: (resource) => dispatch(fetchFilters(resource)),
loadingServices: () => dispatch(fetchServices()),
loadingServicesIntoTable: () => dispatch(loadServicesIntoTable()),
loadingJobs: () => dispatch(fetchJobs()),
loadingJobsIntoTable: () => dispatch(loadJobsIntoTable()),
loadingServers: () => dispatch(fetchServers()),
loadingServersIntoTable: () => dispatch(loadServersIntoTable()),
Expand Down
71 changes: 0 additions & 71 deletions app/src/reducers/jobReducer.ts

This file was deleted.

7 changes: 4 additions & 3 deletions app/src/selectors/jobSelectors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RootState } from "../store";

/**
* This file contains selectors regarding jobs
*/

export const getJobs = (state: any) => state.jobs.results;
export const getTotalJobs = (state: any) => state.jobs.total;
export const getJobs = (state: RootState) => state.jobs.results;
export const getTotalJobs = (state: RootState) => state.jobs.total;
Loading

0 comments on commit 2e41bec

Please sign in to comment.