Skip to content

Commit

Permalink
Merge pull request #263 from Arnei/to-redux-toolkit-service
Browse files Browse the repository at this point in the history
Modernize redux: serviceSlice
  • Loading branch information
Arnei authored Feb 28, 2024
2 parents 1a5203f + b5012df commit 4a95048
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 204 deletions.
35 changes: 0 additions & 35 deletions app/src/actions/serviceActions.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 @@ -23,7 +23,7 @@ import { setOffset } from "../../actions/tableActions";
import { getUserInformation } from "../../selectors/userInfoSelectors";
import { hasAccess } from "../../utils/utils";
import { fetchServers } from "../../thunks/serverThunks";
import { fetchServices } from "../../thunks/serviceThunks";
import { fetchServices } from "../../slices/serviceSlice";
import { fetchGroups } from "../../slices/groupSlice";
import { GlobalHotKeys } from "react-hotkeys";
import { availableHotkeys } from "../../configs/hotkeysConfig";
Expand Down Expand Up @@ -56,8 +56,6 @@ const MainNav = ({
loadingServers,
// @ts-expect-error TS(7031): Binding element 'loadingServersIntoTable' implicit... Remove this comment to see the full error message
loadingServersIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingServices' implicitly has a... Remove this comment to see the full error message
loadingServices,
// @ts-expect-error TS(7031): Binding element 'loadingServicesIntoTable' implici... Remove this comment to see the full error message
loadingServicesIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingUsers' implicitly has an '... Remove this comment to see the full error message
Expand Down Expand Up @@ -156,7 +154,7 @@ const MainNav = ({
resetOffset();

// Fetching services from server
loadingServices();
dispatch(fetchServices());

// Load services into table
loadingServicesIntoTable();
Expand Down Expand Up @@ -342,7 +340,6 @@ const mapDispatchToProps = (dispatch) => ({
loadingJobsIntoTable: () => dispatch(loadJobsIntoTable()),
loadingServers: () => dispatch(fetchServers()),
loadingServersIntoTable: () => dispatch(loadServersIntoTable()),
loadingServices: () => dispatch(fetchServices()),
loadingServicesIntoTable: () => dispatch(loadServicesIntoTable()),
loadingUsers: () => dispatch(fetchUsers()),
loadingUsersIntoTable: () => dispatch(loadUsersIntoTable()),
Expand Down
7 changes: 2 additions & 5 deletions app/src/components/systems/Jobs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
loadServicesIntoTable,
} from "../../thunks/tableThunks";
import { fetchServers } from "../../thunks/serverThunks";
import { fetchServices } from "../../thunks/serviceThunks";
import { editTextFilter } from "../../actions/tableFilterActions";
import { setOffset } from "../../actions/tableActions";
import { styleNavClosed, styleNavOpen } from "../../utils/componentsUtils";
Expand All @@ -27,6 +26,7 @@ import { hasAccess } from "../../utils/utils";
import { getCurrentFilterResource } from "../../selectors/tableFilterSelectors";
import { useAppDispatch, useAppSelector } from "../../store";
import { fetchJobs } from "../../slices/jobSlice";
import { fetchServices } from "../../slices/serviceSlice";

/**
* This component renders the table view of jobs
Expand All @@ -40,8 +40,6 @@ const Jobs = ({
loadingServers,
// @ts-expect-error TS(7031): Binding element 'loadingServersIntoTable' implicit... Remove this comment to see the full error message
loadingServersIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingServices' implicitly has a... Remove this comment to see the full error message
loadingServices,
// @ts-expect-error TS(7031): Binding element 'loadingServicesIntoTable' implici... Remove this comment to see the full error message
loadingServicesIntoTable,
// @ts-expect-error TS(7031): Binding element 'resetTextFilter' implicitly has a... Remove this comment to see the full error message
Expand Down Expand Up @@ -88,7 +86,7 @@ const Jobs = ({
resetOffset();

// Fetching services from server
loadingServices();
dispatch(fetchServices());

// Load services into table
loadingServicesIntoTable();
Expand Down Expand Up @@ -193,7 +191,6 @@ const mapDispatchToProps = (dispatch) => ({
loadingJobsIntoTable: () => dispatch(loadJobsIntoTable()),
loadingServers: () => dispatch(fetchServers()),
loadingServersIntoTable: () => dispatch(loadServersIntoTable()),
loadingServices: () => dispatch(fetchServices()),
loadingServicesIntoTable: () => dispatch(loadServicesIntoTable()),
resetTextFilter: () => dispatch(editTextFilter("")),
resetOffset: () => dispatch(setOffset(0)),
Expand Down
7 changes: 2 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 { fetchServices } from "../../thunks/serviceThunks";
import { editTextFilter } from "../../actions/tableFilterActions";
import { setOffset } from "../../actions/tableActions";
import { styleNavClosed, styleNavOpen } from "../../utils/componentsUtils";
Expand All @@ -26,6 +25,7 @@ import { getUserInformation } from "../../selectors/userInfoSelectors";
import { hasAccess } from "../../utils/utils";
import { getCurrentFilterResource } from "../../selectors/tableFilterSelectors";
import { useAppDispatch } from "../../store";
import { fetchServices } from "../../slices/serviceSlice";
import { fetchJobs } from "../../slices/jobSlice";

/**
Expand All @@ -42,8 +42,6 @@ const Servers = ({
loadingFilters,
// @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
loadingServices,
// @ts-expect-error TS(7031): Binding element 'loadingServicesIntoTable' implici... Remove this comment to see the full error message
loadingServicesIntoTable,
// @ts-expect-error TS(7031): Binding element 'resetTextFilter' implicitly has a... Remove this comment to see the full error message
Expand Down Expand Up @@ -83,7 +81,7 @@ const Servers = ({
resetOffset();

// Fetching services from server
loadingServices();
dispatch(fetchServices());

// Load services into table
loadingServicesIntoTable();
Expand Down Expand Up @@ -189,7 +187,6 @@ const mapDispatchToProps = (dispatch) => ({
loadingServers: () => dispatch(fetchServers()),
loadingServersIntoTable: () => dispatch(loadServersIntoTable()),
loadingJobsIntoTable: () => dispatch(loadJobsIntoTable()),
loadingServices: () => dispatch(fetchServices()),
loadingServicesIntoTable: () => dispatch(loadServicesIntoTable()),
resetTextFilter: () => dispatch(editTextFilter("")),
resetOffset: () => dispatch(setOffset(0)),
Expand Down
23 changes: 12 additions & 11 deletions app/src/components/systems/Services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import TableFilters from "../shared/TableFilters";
import Table from "../shared/Table";
import MainNav from "../shared/MainNav";
import Notifications from "../shared/Notifications";
import { servicesTemplateMap } from "../../configs/tableConfigs/servicesTableConfig";
import { servicesTemplateMap } from "../../configs/tableConfigs/servicesTableMap";
import { fetchFilters } from "../../thunks/tableFilterThunks";
import {
loadJobsIntoTable,
loadServersIntoTable,
loadServicesIntoTable,
} from "../../thunks/tableThunks";
import { fetchServices } from "../../thunks/serviceThunks";
import { fetchServers } from "../../thunks/serverThunks";
import { getTotalServices } from "../../selectors/serviceSelector";
import { editTextFilter } from "../../actions/tableFilterActions";
Expand All @@ -25,19 +24,16 @@ import Footer from "../Footer";
import { getUserInformation } from "../../selectors/userInfoSelectors";
import { hasAccess } from "../../utils/utils";
import { getCurrentFilterResource } from "../../selectors/tableFilterSelectors";
import { useAppDispatch } from "../../store";
import { useAppDispatch, useAppSelector } from "../../store";
import { fetchJobs } from "../../slices/jobSlice";
import { fetchServices } from "../../slices/serviceSlice";

/**
* This component renders the table view of services
*/
const Services = ({
// @ts-expect-error TS(7031): Binding element 'loadingServices' implicitly has a... Remove this comment to see the full error message
loadingServices,
// @ts-expect-error TS(7031): Binding element 'loadingServicesIntoTable' implici... Remove this comment to see the full error message
loadingServicesIntoTable,
// @ts-expect-error TS(7031): Binding element 'services' implicitly has an 'any'... Remove this comment to see the full error message
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 'loadingJobsIntoTable' implicitly ... Remove this comment to see the full error message
Expand All @@ -59,9 +55,16 @@ const Services = ({
const dispatch = useAppDispatch();
const [displayNavigation, setNavigation] = useState(false);

const services = useAppSelector(state => getTotalServices(state));

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

const loadServices = async () => {
// Fetching services from server
await loadingServices();
await dispatch(fetchServices());

// Load services into table
loadingServicesIntoTable();
Expand Down Expand Up @@ -158,7 +161,7 @@ const Services = ({
<div className="controls-container">
{/* Include filters component */}
<TableFilters
loadResource={loadingServices}
loadResource={fetchServicesWrapper}
loadResourceIntoTable={loadingServicesIntoTable}
resource={"services"}
/>
Expand All @@ -176,7 +179,6 @@ const Services = ({
// Getting state data out of redux store
// @ts-expect-error TS(7006): Parameter 'state' implicitly has an 'any' type.
const mapStateToProps = (state) => ({
services: getTotalServices(state),
user: getUserInformation(state),
currentFilterType: getCurrentFilterResource(state),
});
Expand All @@ -186,7 +188,6 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = (dispatch) => ({
// @ts-expect-error TS(7006): Parameter 'resource' implicitly has an 'any' type.
loadingFilters: (resource) => dispatch(fetchFilters(resource)),
loadingServices: () => dispatch(fetchServices()),
loadingServicesIntoTable: () => dispatch(loadServicesIntoTable()),
loadingJobsIntoTable: () => dispatch(loadJobsIntoTable()),
loadingServers: () => dispatch(fetchServers()),
Expand Down
9 changes: 5 additions & 4 deletions app/src/components/systems/partials/ServicesActionsCell.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { fetchServices, restartService } from "../../../thunks/serviceThunks";
import { loadServicesIntoTable } from "../../../thunks/tableThunks";
import { getUserInformation } from "../../../selectors/userInfoSelectors";
import { hasAccess } from "../../../utils/utils";
import { useAppDispatch } from "../../../store";
import { fetchServices, restartService } from "../../../slices/serviceSlice";

/**
* This component renders the action cells of services in the table view
Expand All @@ -20,10 +21,11 @@ const ServicesActionCell = ({
user,
}) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();

const onClickRestart = async () => {
await restartService(row.hostname, row.name);
await loadServices();
await dispatch(restartService({host: row.hostname, serviceType: row.name}));
await dispatch(fetchServices());
loadServicesIntoTable();
};

Expand All @@ -49,7 +51,6 @@ const mapStateToProps = (state) => ({
// mapping actions to dispatch
// @ts-expect-error TS(7006): Parameter 'dispatch' implicitly has an 'any' type.
const mapDispatchToProps = (dispatch) => ({
loadServices: () => dispatch(fetchServices()),
loadServicesIntoTable: () => dispatch(loadServicesIntoTable()),
});

Expand Down
15 changes: 0 additions & 15 deletions app/src/configs/tableConfigs/servicesTableConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import MeanRunTimeCell from "../../components/systems/partials/MeanRunTimeCell";
import MeanQueueTimeCell from "../../components/systems/partials/MeanQueueTimeCell";
import ServicesActionCell from "../../components/systems/partials/ServicesActionsCell";

/**
* Config that contains the columns and further information regarding services. These are the information that never or hardly changes.
* That's why it is hard coded here and not fetched from server.
Expand Down Expand Up @@ -73,14 +69,3 @@ export const servicesTableConfig = {
category: "systems",
multiSelect: false,
};

/**
* This map contains the mapping between the template strings above and the corresponding react component.
* This helps to render different templates of cells more dynamically. Even empty needed, because Table component
* uses template map.
*/
export const servicesTemplateMap = {
MeanRunTimeCell: MeanRunTimeCell,
MeanQueueTimeCell: MeanQueueTimeCell,
ServicesActionsCell: ServicesActionCell,
};
14 changes: 14 additions & 0 deletions app/src/configs/tableConfigs/servicesTableMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import MeanRunTimeCell from "../../components/systems/partials/MeanRunTimeCell";
import MeanQueueTimeCell from "../../components/systems/partials/MeanQueueTimeCell";
import ServicesActionCell from "../../components/systems/partials/ServicesActionsCell";

/**
* This map contains the mapping between the template strings above and the corresponding react component.
* This helps to render different templates of cells more dynamically. Even empty needed, because Table component
* uses template map.
*/
export const servicesTemplateMap = {
MeanRunTimeCell: MeanRunTimeCell,
MeanQueueTimeCell: MeanQueueTimeCell,
ServicesActionsCell: ServicesActionCell,
};
71 changes: 0 additions & 71 deletions app/src/reducers/serviceReducer.ts

This file was deleted.

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

/**
* This file contains selectors regarding services
*/

export const getServices = (state: any) => state.services.results;
export const getTotalServices = (state: any) => state.services.total;
export const getServices = (state: RootState) => state.services.results;
export const getTotalServices = (state: RootState) => state.services.total;
Loading

0 comments on commit 4a95048

Please sign in to comment.