Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize redux #214

Merged
merged 29 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
43b0fdd
Modernize redux store
Arnei Oct 13, 2023
c6bf0d2
Replace "ACLs" actions, reducer with slice
Arnei Oct 16, 2023
47d775e
Add basic typescript to redux store
Arnei Oct 16, 2023
3142ce1
Add typescript to aclSlice
Arnei Oct 16, 2023
140ad69
Modernize Acls.tsx
Arnei Oct 19, 2023
5581170
Use createAsyncThunk in slice
Arnei Oct 20, 2023
0598e65
indentation app/src/components/shared/MainNav.tsx
Arnei Nov 20, 2023
1f6b69a
indentation app/src/components/shared/MainNav.tsx
Arnei Nov 20, 2023
ab63fce
indentation app/src/components/users/Acls.tsx
Arnei Nov 20, 2023
243f4d8
indentation app/src/components/users/Groups.tsx
Arnei Nov 20, 2023
1b55d30
indentation app/src/components/users/Users.tsx
Arnei Nov 20, 2023
6dc91cc
Semicolon app/src/components/users/Acls.tsx
Arnei Nov 20, 2023
40d90ca
Semicolon app/src/slices/aclSlice.ts
Arnei Nov 20, 2023
eeb4583
Semicolon app/src/store.ts
Arnei Nov 20, 2023
03d1423
Semicolon app/src/components/users/Acls.tsx
Arnei Nov 20, 2023
0ea139c
Semicolon app/src/slices/aclSlice.ts
Arnei Nov 20, 2023
37ca2d7
Semicolon app/src/slices/aclSlice.ts
Arnei Nov 20, 2023
9cea00c
Semicolon app/src/slices/aclSlice.ts
Arnei Nov 20, 2023
1533ba0
Update app/src/slices/aclSlice.ts
Arnei Nov 20, 2023
a564994
Semicolon app/src/slices/aclSlice.ts
Arnei Nov 20, 2023
e22dc91
Semicolon app/src/slices/aclSlice.ts
Arnei Nov 20, 2023
ca5e5fa
Semicolon app/src/slices/aclSlice.ts
Arnei Nov 20, 2023
57662f1
Fair enough
Arnei Nov 20, 2023
f617e88
Indentation app/src/thunks/tableThunks.ts
Arnei Nov 20, 2023
79896ed
Indentation app/src/thunks/tableThunks.ts
Arnei Nov 20, 2023
f0d45d1
Semicolon app/src/slices/aclSlice.ts
Arnei Nov 20, 2023
6d243e5
Semicolon app/src/store.ts
Arnei Nov 20, 2023
54276df
Replaces double spaces with tabs
Arnei Nov 20, 2023
a0b0c3f
Replace "ACL" with "Acl"
Arnei Nov 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@edorivai/react-smooth-dnd": "^0.11.2",
"@material-ui/core": "^4.12.4",
"@material-ui/pickers": "^3.3.10",
"@reduxjs/toolkit": "^1.9.7",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@types/react-router-dom": "^5.3.3",
Expand Down
35 changes: 0 additions & 35 deletions app/src/actions/aclActions.ts

This file was deleted.

9 changes: 4 additions & 5 deletions app/src/components/shared/MainNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import { fetchSeries } from "../../thunks/seriesThunks";
import { fetchServers } from "../../thunks/serverThunks";
import { fetchServices } from "../../thunks/serviceThunks";
import { fetchGroups } from "../../thunks/groupThunks";
import { fetchAcls } from "../../thunks/aclThunks";
import { GlobalHotKeys } from "react-hotkeys";
import { availableHotkeys } from "../../configs/hotkeysConfig";
import { fetchAcls } from "../../slices/aclSlice";
import { useAppDispatch } from "../../store";

/**
* This component renders the main navigation that opens when the burger button is clicked
Expand Down Expand Up @@ -73,8 +74,6 @@ const MainNav = ({
loadingGroups,
// @ts-expect-error TS(7031): Binding element 'loadingGroupsIntoTable' implicitl... Remove this comment to see the full error message
loadingGroupsIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingAcls' implicitly has an 'a... Remove this comment to see the full error message
loadingAcls,
// @ts-expect-error TS(7031): Binding element 'loadingAclsIntoTable' implicitly ... Remove this comment to see the full error message
loadingAclsIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingThemes' implicitly has an ... Remove this comment to see the full error message
Expand All @@ -89,6 +88,7 @@ const MainNav = ({
loadingFilters,
}) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
let navigate = useNavigate();

const loadEvents = () => {
Expand Down Expand Up @@ -205,7 +205,7 @@ const MainNav = ({
resetOffset();

// Fetching acls from server
loadingAcls();
dispatch(fetchAcls());

// Load acls into table
loadingAclsIntoTable();
Expand Down Expand Up @@ -361,7 +361,6 @@ const mapDispatchToProps = (dispatch) => ({
loadingUsersIntoTable: () => dispatch(loadUsersIntoTable()),
loadingGroups: () => dispatch(fetchGroups()),
loadingGroupsIntoTable: () => dispatch(loadGroupsIntoTable()),
loadingAcls: () => dispatch(fetchAcls()),
loadingAclsIntoTable: () => dispatch(loadAclsIntoTable()),
loadingThemes: () => dispatch(fetchThemes()),
loadingThemesIntoTable: () => dispatch(loadThemesIntoTable()),
Expand Down
87 changes: 22 additions & 65 deletions app/src/components/users/Acls.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState } from "react";
import { connect } from "react-redux";
import { useTranslation } from "react-i18next";
import MainNav from "../shared/MainNav";
import { Link } from "react-router-dom";
Expand All @@ -17,7 +16,6 @@ import {
loadUsersIntoTable,
} from "../../thunks/tableThunks";
import { fetchGroups } from "../../thunks/groupThunks";
import { fetchAcls } from "../../thunks/aclThunks";
import { getTotalAcls } from "../../selectors/aclSelectors";
import { editTextFilter } from "../../actions/tableFilterActions";
import { setOffset } from "../../actions/tableActions";
Expand All @@ -27,81 +25,63 @@ import Footer from "../Footer";
import { hasAccess } from "../../utils/utils";
import { getUserInformation } from "../../selectors/userInfoSelectors";
import { getCurrentFilterResource } from "../../selectors/tableFilterSelectors";
import { useAppDispatch, useAppSelector } from "../../store";
import { fetchAcls } from "../../slices/aclSlice";

/**
* This component renders the table view of acls
*/
const Acls = ({
// @ts-expect-error TS(7031): Binding element 'loadingAcls' implicitly has an 'a... Remove this comment to see the full error message
loadingAcls,
// @ts-expect-error TS(7031): Binding element 'loadingAclsIntoTable' implicitly ... Remove this comment to see the full error message
loadingAclsIntoTable,
// @ts-expect-error TS(7031): Binding element 'acls' implicitly has an 'any' typ... Remove this comment to see the full error message
acls,
// @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 'loadingUsers' implicitly has an '... Remove this comment to see the full error message
loadingUsers,
// @ts-expect-error TS(7031): Binding element 'loadingUsersIntoTable' implicitly... Remove this comment to see the full error message
loadingUsersIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingGroups' implicitly has an ... Remove this comment to see the full error message
loadingGroups,
// @ts-expect-error TS(7031): Binding element 'loadingGroupsIntoTable' implicitl... Remove this comment to see the full error message
loadingGroupsIntoTable,
// @ts-expect-error TS(7031): Binding element 'resetTextFilter' implicitly has a... Remove this comment to see the full error message
resetTextFilter,
// @ts-expect-error TS(7031): Binding element 'resetOffset' implicitly has an 'a... Remove this comment to see the full error message
resetOffset,
// @ts-expect-error TS(7031): Binding element 'user' implicitly has an 'any' typ... Remove this comment to see the full error message
user,
// @ts-expect-error TS(7031): Binding element 'currentFilterType' implicitly has... Remove this comment to see the full error message
currentFilterType,
}) => {
const Acls: React.FC = () => {
const { t } = useTranslation();
const [displayNavigation, setNavigation] = useState(false);
const [displayNewAclModal, setNewAclModal] = useState(false);

const dispatch = useAppDispatch();
const acls = useAppSelector(state => getTotalAcls(state));
const user = useAppSelector(state => getUserInformation(state));
const currentFilterType = useAppSelector(state => getCurrentFilterResource(state));

const loadAcls = async () => {
// Fetching acls from server
await loadingAcls();
await dispatch(fetchAcls());

// Load acls into table
loadingAclsIntoTable();
dispatch(loadAclsIntoTable());
};

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

// Fetching users from server
loadingUsers();
dispatch(fetchUsers());

// Load users into table
loadingUsersIntoTable();
dispatch(loadUsersIntoTable());
};

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

// Fetching groups from server
loadingGroups();
dispatch(fetchGroups());

// Load groups into table
loadingGroupsIntoTable();
dispatch(loadGroupsIntoTable());
};

useEffect(() => {
if ("acls" !== currentFilterType) {
loadingFilters("acls");
dispatch(fetchFilters("acls"));
}

resetTextFilter();
dispatch(editTextFilter(""));

// Load acls on mount
loadAcls().then((r) => console.info(r));

// Fetch ACLs every minute
// Fetch Acls every minute
let fetchAclInterval = setInterval(loadAcls, 5000);

return () => clearInterval(fetchAclInterval);
Expand Down Expand Up @@ -185,8 +165,8 @@ const Acls = ({
<div className="controls-container">
{/* Include filters component */}
<TableFilters
loadResource={loadingAcls}
loadResourceIntoTable={loadingAclsIntoTable}
loadResource={() => dispatch(fetchAcls())}
loadResourceIntoTable={() => dispatch(loadAclsIntoTable())}
resource={"acls"}
/>
<h1>{t("USERS.ACLS.TABLE.CAPTION")}</h1>
Expand All @@ -200,27 +180,4 @@ const Acls = ({
);
};

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

// Mapping actions to dispatch
// @ts-expect-error TS(7006): Parameter 'dispatch' implicitly has an 'any' type.
const mapDispatchToProps = (dispatch) => ({
// @ts-expect-error TS(7006): Parameter 'resource' implicitly has an 'any' type.
loadingFilters: (resource) => dispatch(fetchFilters(resource)),
loadingAcls: () => dispatch(fetchAcls()),
loadingAclsIntoTable: () => dispatch(loadAclsIntoTable()),
loadingUsers: () => dispatch(fetchUsers()),
loadingUsersIntoTable: () => dispatch(loadUsersIntoTable()),
loadingGroups: () => dispatch(fetchGroups()),
loadingGroupsIntoTable: () => dispatch(loadGroupsIntoTable()),
resetTextFilter: () => dispatch(editTextFilter("")),
resetOffset: () => dispatch(setOffset(0)),
});

export default connect(mapStateToProps, mapDispatchToProps)(Acls);
export default Acls;
9 changes: 4 additions & 5 deletions app/src/components/users/Groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
loadUsersIntoTable,
} from "../../thunks/tableThunks";
import { fetchGroups } from "../../thunks/groupThunks";
import { fetchAcls } from "../../thunks/aclThunks";
import { editTextFilter } from "../../actions/tableFilterActions";
import { setOffset } from "../../actions/tableActions";
import { styleNavClosed, styleNavOpen } from "../../utils/componentsUtils";
Expand All @@ -27,6 +26,8 @@ import Footer from "../Footer";
import { getUserInformation } from "../../selectors/userInfoSelectors";
import { hasAccess } from "../../utils/utils";
import { getCurrentFilterResource } from "../../selectors/tableFilterSelectors";
import { fetchAcls } from "../../slices/aclSlice";
import { useAppDispatch } from "../../store";

/**
* This component renders the table view of groups
Expand All @@ -44,8 +45,6 @@ const Groups = ({
loadingUsers,
// @ts-expect-error TS(7031): Binding element 'loadingUsersIntoTable' implicitly... Remove this comment to see the full error message
loadingUsersIntoTable,
// @ts-expect-error TS(7031): Binding element 'loadingAcls' implicitly has an 'a... Remove this comment to see the full error message
loadingAcls,
// @ts-expect-error TS(7031): Binding element 'loadingAclsIntoTable' implicitly ... Remove this comment to see the full error message
loadingAclsIntoTable,
// @ts-expect-error TS(7031): Binding element 'resetTextFilter' implicitly has a... Remove this comment to see the full error message
Expand All @@ -58,6 +57,7 @@ const Groups = ({
currentFilterType,
}) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const [displayNavigation, setNavigation] = useState(false);
const [displayNewGroupModal, setNewGroupModal] = useState(false);

Expand Down Expand Up @@ -85,7 +85,7 @@ const Groups = ({
resetOffset();

// Fetching acls from server
loadingAcls();
dispatch(fetchAcls());

// Load acls into table
loadingAclsIntoTable();
Expand Down Expand Up @@ -217,7 +217,6 @@ const mapDispatchToProps = (dispatch) => ({
loadingGroupsIntoTable: () => dispatch(loadGroupsIntoTable()),
loadingUsers: () => dispatch(fetchUsers()),
loadingUsersIntoTable: () => dispatch(loadUsersIntoTable()),
loadingAcls: () => dispatch(fetchAcls()),
loadingAclsIntoTable: () => dispatch(loadAclsIntoTable()),
resetTextFilter: () => dispatch(editTextFilter("")),
resetOffset: () => dispatch(setOffset(0)),
Expand Down
Loading