Skip to content

Commit

Permalink
Merge branch 'to-redux-toolkit-table' of Arnei/opencast-admin-interfa…
Browse files Browse the repository at this point in the history
…ce into main

Pull request #695

  Modernize redux: tableSlice
  • Loading branch information
gregorydlogan committed Jul 15, 2024
2 parents 19e0efe + e918fc6 commit 0d7e74f
Show file tree
Hide file tree
Showing 72 changed files with 907 additions and 1,513 deletions.
106 changes: 0 additions & 106 deletions src/actions/tableActions.ts

This file was deleted.

21 changes: 3 additions & 18 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { Link } from "react-router-dom";
import i18n from "../i18n/i18n";
import languages from "../i18n/languages";
Expand Down Expand Up @@ -45,10 +44,7 @@ function logout() {
/**
* Component that renders the header and the navigation in the upper right corner.
*/
const Header = ({
// @ts-expect-error TS(7031): Binding element 'loadingServicesIntoTable' implici... Remove this comment to see the full error message
loadingServicesIntoTable,
}) => {
const Header = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
// State for opening (true) and closing (false) the dropdown menus for language, notification, help and user
Expand Down Expand Up @@ -82,7 +78,7 @@ const Header = ({

const redirectToServices = async () => {
// Load services into table
await loadingServicesIntoTable();
await dispatch(loadServicesIntoTable());

// set the action filter value of services to true
await dispatch(setSpecificServiceFilter({ filter: "actions", filterValue: "true" }));
Expand Down Expand Up @@ -437,15 +433,4 @@ const MenuUser = () => {
);
};

// Getting state data out of redux store
// @ts-expect-error TS(7006): Parameter 'state' implicitly has an 'any' type.
const mapStateToProps = (state) => ({
});

// Mapping actions to dispatch
// @ts-expect-error TS(7006): Parameter 'dispatch' implicitly has an 'any' type.
const mapDispatchToProps = (dispatch) => ({
loadingServicesIntoTable: () => dispatch(loadServicesIntoTable()),
});

export default connect(mapStateToProps, mapDispatchToProps)(Header);
export default Header;
30 changes: 5 additions & 25 deletions src/components/configuration/Themes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import cn from "classnames";
import TableFilters from "../shared/TableFilters";
import Table from "../shared/Table";
import { fetchFilters, editTextFilter } from "../../slices/tableFilterSlice";
import { connect } from "react-redux";
import { themesTemplateMap } from "../../configs/tableConfigs/themesTableMap";
import { getTotalThemes } from "../../selectors/themeSelectors";
import { loadThemesIntoTable } from "../../thunks/tableThunks";
Expand All @@ -25,10 +24,7 @@ import { fetchThemes } from "../../slices/themeSlice";
/**
* This component renders the table view of events
*/
const Themes = ({
// @ts-expect-error TS(7031): Binding element 'loadingThemesIntoTable' implicitl... Remove this comment to see the full error message
loadingThemesIntoTable,
}) => {
const Themes = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();

Expand All @@ -40,17 +36,12 @@ const Themes = ({
const user = useAppSelector(state => getUserInformation(state));
const themes = useAppSelector(state => getTotalThemes(state));

// TODO: Get rid of the wrappers when modernizing redux is done
const fetchThemesWrapper = async () => {
await dispatch(fetchThemes())
}

const loadThemes = async () => {
// Fetching themes from server
await dispatch(fetchThemes());

// Load users into table
loadingThemesIntoTable();
dispatch(loadThemesIntoTable());
};

useEffect(() => {
Expand Down Expand Up @@ -128,8 +119,8 @@ const Themes = ({
<div className="controls-container">
{/* Include filters component */}
<TableFilters
loadResource={fetchThemesWrapper}
loadResourceIntoTable={loadingThemesIntoTable}
loadResource={fetchThemes}
loadResourceIntoTable={loadThemesIntoTable}
resource={"themes"}
/>
<h1>{t("CONFIGURATION.THEMES.TABLE.CAPTION")}</h1>
Expand All @@ -143,15 +134,4 @@ const Themes = ({
);
};

// Getting state data out of redux store
// @ts-expect-error TS(7006): Parameter 'state' implicitly has an 'any' type.
const mapStateToProps = (state) => ({
});

// Mapping actions to dispatch
// @ts-expect-error TS(7006): Parameter 'dispatch' implicitly has an 'any' type.
const mapDispatchToProps = (dispatch) => ({
loadingThemesIntoTable: () => dispatch(loadThemesIntoTable()),
});

export default connect(mapStateToProps, mapDispatchToProps)(Themes);
export default Themes;
42 changes: 8 additions & 34 deletions src/components/events/Events.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import cn from "classnames";
import { connect } from "react-redux";
import { Link, useLocation } from "react-router-dom";
import TableFilters from "../shared/TableFilters";
import MainNav from "../shared/MainNav";
Expand All @@ -24,7 +23,7 @@ import {
isFetchingAssetUploadOptions as getIsFetchingAssetUploadOptions,
isShowActions,
} from "../../selectors/eventSelectors";
import { setOffset } from "../../actions/tableActions";
import { setOffset } from "../../slices/tableSlice";
import Header from "../Header";
import NavBar from "../NavBar";
import MainView from "../MainView";
Expand All @@ -49,14 +48,7 @@ const containerAction = React.createRef<HTMLDivElement>();
/**
* This component renders the table view of events
*/
const Events = ({
// @ts-expect-error TS(7031): Binding element 'loadingEventsIntoTable' implicitl... Remove this comment to see the full error message
loadingEventsIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingSeriesIntoTable' implicitl... Remove this comment to see the full error message
loadingSeriesIntoTable,
// @ts-expect-error TS(7031): Binding element 'resetOffset' implicitly has an 'a... Remove this comment to see the full error message
resetOffset,
}) => {
const Events = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();

Expand All @@ -82,11 +74,6 @@ const Events = ({

let location = useLocation();

// TODO: Get rid of the wrappers when modernizing redux is done
const fetchEventsWrapper = async () => {
await dispatch(fetchEvents())
}

const loadEvents = async () => {
// Fetching stats from server
dispatch(fetchStats());
Expand All @@ -95,18 +82,18 @@ const Events = ({
await dispatch(fetchEvents());

// Load events into table
loadingEventsIntoTable();
dispatch(loadEventsIntoTable());
};

const loadSeries = () => {
// Reset the current page to first page
resetOffset();
dispatch(setOffset(0));

//fetching series from server
dispatch(fetchSeries());

//load series into table
loadingSeriesIntoTable();
dispatch(loadSeriesIntoTable());
};

useEffect(() => {
Expand Down Expand Up @@ -309,8 +296,8 @@ const Events = ({

{/* Include filters component*/}
<TableFilters
loadResource={fetchEventsWrapper}
loadResourceIntoTable={loadingEventsIntoTable}
loadResource={fetchEvents}
loadResourceIntoTable={loadEventsIntoTable}
resource={"events"}
/>
</div>
Expand All @@ -326,17 +313,4 @@ const Events = ({
);
};

// Getting state data out of redux store
// @ts-expect-error TS(7006): Parameter 'state' implicitly has an 'any' type.
const mapStateToProps = (state) => ({
});

// Mapping actions to dispatch
// @ts-expect-error TS(7006): Parameter 'dispatch' implicitly has an 'any' type.
const mapDispatchToProps = (dispatch) => ({
loadingEventsIntoTable: () => dispatch(loadEventsIntoTable()),
loadingSeriesIntoTable: () => dispatch(loadSeriesIntoTable()),
resetOffset: () => dispatch(setOffset(0)),
});

export default connect(mapStateToProps, mapDispatchToProps)(Events);
export default Events;
Loading

0 comments on commit 0d7e74f

Please sign in to comment.