Skip to content

Commit

Permalink
Merge pull request #269 from Arnei/to-redux-toolkit-eventDetails
Browse files Browse the repository at this point in the history
Modernize redux: eventDetailsSlice
  • Loading branch information
Arnei authored Mar 4, 2024
2 parents cf21b57 + 9cfd190 commit 46c95ec
Show file tree
Hide file tree
Showing 30 changed files with 2,710 additions and 4,064 deletions.
606 changes: 0 additions & 606 deletions app/src/actions/eventDetailsActions.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from "react";
import { connect } from "react-redux";
import { getPolicies } from "../../../../selectors/eventDetailsSelectors";
import ResourceDetailsAccessPolicyTab from "../../../shared/modals/ResourceDetailsAccessPolicyTab";
import { useAppDispatch, useAppSelector } from "../../../../store";
import {
fetchAccessPolicies,
fetchHasActiveTransactions,
saveAccessPolicies,
} from "../../../../thunks/eventDetailsThunks";
import { getPolicies } from "../../../../selectors/eventDetailsSelectors";
import ResourceDetailsAccessPolicyTab from "../../../shared/modals/ResourceDetailsAccessPolicyTab";
} from "../../../../slices/eventDetailsSlice";
import { unwrapResult } from "@reduxjs/toolkit";

/**
* This component manages the access policy tab of the event details modal
Expand All @@ -18,19 +19,26 @@ const EventDetailsAccessPolicyTab = ({
header,
// @ts-expect-error TS(7031): Binding element 't' implicitly has an 'any' type.
t,
// @ts-expect-error TS(7031): Binding element 'policies' implicitly has an 'any'... Remove this comment to see the full error message
policies,
// @ts-expect-error TS(7031): Binding element 'fetchAccessPolicies' implicitly h... Remove this comment to see the full error message
fetchAccessPolicies,
// @ts-expect-error TS(7031): Binding element 'fetchHasActiveTransactions' impli... Remove this comment to see the full error message
fetchHasActiveTransactions,
// @ts-expect-error TS(7031): Binding element 'saveNewAccessPolicies' implicitly... Remove this comment to see the full error message
saveNewAccessPolicies,
// @ts-expect-error TS(7031): Binding element 'policyChanged' implicitly has an ... Remove this comment to see the full error message
policyChanged,
// @ts-expect-error TS(7031): Binding element 'setPolicyChanged' implicitly has ... Remove this comment to see the full error message
setPolicyChanged,
}) => {
const dispatch = useAppDispatch();

// TODO: Get rid of the wrappers when modernizing redux is done
const fetchAccessPoliciesWrapper = (eventId: any) => {
dispatch(fetchAccessPolicies(eventId));
}
const fetchHasActiveTransactionsWrapper = async(eventId: any) => {
return await dispatch(fetchHasActiveTransactions(eventId)).then(unwrapResult);
}
const saveNewAccessPoliciesWrapper = async(eventId: any, policies: any) => {
dispatch(saveAccessPolicies({eventId, policies}));
}

const policies = useAppSelector(state => getPolicies(state));

return (
<ResourceDetailsAccessPolicyTab
resourceId={eventId}
Expand All @@ -39,9 +47,9 @@ const EventDetailsAccessPolicyTab = ({
saveButtonText={"SAVE"}
t={t}
policies={policies}
fetchAccessPolicies={fetchAccessPolicies}
fetchHasActiveTransactions={fetchHasActiveTransactions}
saveNewAccessPolicies={saveNewAccessPolicies}
fetchAccessPolicies={fetchAccessPoliciesWrapper}
fetchHasActiveTransactions={fetchHasActiveTransactionsWrapper}
saveNewAccessPolicies={saveNewAccessPoliciesWrapper}
descriptionText={t("EVENTS.SERIES.NEW.ACCESS.ACCESS_POLICY.DESCRIPTION")}
editAccessRole={"ROLE_UI_EVENTS_DETAILS_ACL_EDIT"}
policyChanged={policyChanged}
Expand All @@ -50,26 +58,4 @@ const EventDetailsAccessPolicyTab = ({
);
};

// Getting state data out of redux store
// @ts-expect-error TS(7006): Parameter 'state' implicitly has an 'any' type.
const mapStateToProps = (state) => ({
policies: getPolicies(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 'eventId' implicitly has an 'any' type.
fetchAccessPolicies: (eventId) => dispatch(fetchAccessPolicies(eventId)),
// @ts-expect-error TS(7006): Parameter 'eventId' implicitly has an 'any' type.
fetchHasActiveTransactions: (eventId) =>
dispatch(fetchHasActiveTransactions(eventId)),
// @ts-expect-error TS(7006): Parameter 'eventId' implicitly has an 'any' type.
saveNewAccessPolicies: (eventId, policies) =>
dispatch(saveAccessPolicies(eventId, policies)),
});

export default connect(
mapStateToProps,
mapDispatchToProps
)(EventDetailsAccessPolicyTab);
export default EventDetailsAccessPolicyTab;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import { connect } from "react-redux";
import EventDetailsTabHierarchyNavigation from "./EventDetailsTabHierarchyNavigation";
import Notifications from "../../../shared/Notifications";
import {
getAssetAttachmentDetails,
isFetchingAssets,
isFetchingAssetAttachmentDetails,
} from "../../../../selectors/eventDetailsSelectors";
import { humanReadableBytesFilter } from "../../../../utils/eventDetailsUtils";
import { useAppSelector } from "../../../../store";

/**
* This component manages the attachment details sub-tab for assets tab of event details modal
Expand All @@ -18,11 +18,10 @@ const EventDetailsAssetAttachmentDetails = ({
t,
// @ts-expect-error TS(7031): Binding element 'setHierarchy' implicitly has an '... Remove this comment to see the full error message
setHierarchy,
// @ts-expect-error TS(7031): Binding element 'attachment' implicitly has an 'an... Remove this comment to see the full error message
attachment,
// @ts-expect-error TS(7031): Binding element 'isFetching' implicitly has an 'an... Remove this comment to see the full error message
isFetching,
}) => {
const attachment = useAppSelector(state => getAssetAttachmentDetails(state));
const isFetching = useAppSelector(state => isFetchingAssetAttachmentDetails(state));

// @ts-expect-error TS(7006): Parameter 'subTabName' implicitly has an 'any' typ... Remove this comment to see the full error message
const openSubTab = (subTabName) => {
setHierarchy(subTabName);
Expand Down Expand Up @@ -162,11 +161,4 @@ const EventDetailsAssetAttachmentDetails = ({
);
};

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

export default connect(mapStateToProps)(EventDetailsAssetAttachmentDetails);
export default EventDetailsAssetAttachmentDetails;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import { connect } from "react-redux";
import EventDetailsTabHierarchyNavigation from "./EventDetailsTabHierarchyNavigation";
import Notifications from "../../../shared/Notifications";
import {
getAssetAttachments,
isFetchingAssets,
isFetchingAssetAttachments,
} from "../../../../selectors/eventDetailsSelectors";
import { fetchAssetAttachmentDetails } from "../../../../thunks/eventDetailsThunks";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { fetchAssetAttachmentDetails } from "../../../../slices/eventDetailsSlice";

/**
* This component manages the attachments sub-tab for assets tab of event details modal
Expand All @@ -18,18 +18,16 @@ const EventDetailsAssetAttachments = ({
t,
// @ts-expect-error TS(7031): Binding element 'setHierarchy' implicitly has an '... Remove this comment to see the full error message
setHierarchy,
// @ts-expect-error TS(7031): Binding element 'attachments' implicitly has an 'a... Remove this comment to see the full error message
attachments,
// @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 'loadAttachmentDetails' implicitly... Remove this comment to see the full error message
loadAttachmentDetails,
}) => {
const dispatch = useAppDispatch();

const attachments = useAppSelector(state => getAssetAttachments(state));
const isFetching = useAppSelector(state => isFetchingAssetAttachments(state));

// @ts-expect-error TS(7006): Parameter 'subTabName' implicitly has an 'any' typ... Remove this comment to see the full error message
const openSubTab = (subTabName, attachmentId = "") => {
if (subTabName === "attachment-details") {
// @ts-expect-error TS(7006): Parameter 'r' implicitly has an 'any' type.
loadAttachmentDetails(eventId, attachmentId).then((r) => {});
dispatch(fetchAssetAttachmentDetails({eventId, attachmentId})).then();
}
setHierarchy(subTabName);
};
Expand Down Expand Up @@ -95,7 +93,6 @@ const EventDetailsAssetAttachments = ({
</thead>
<tbody>
{isFetching ||
// @ts-expect-error TS(7006): Parameter 'item' implicitly has an 'any' type.
attachments.map((item, key) => (
<tr key={key}>
<td>{item.id}</td>
Expand Down Expand Up @@ -132,22 +129,4 @@ const EventDetailsAssetAttachments = ({
);
};

// Getting state data out of redux store
// @ts-expect-error TS(7006): Parameter 'state' implicitly has an 'any' type.
const mapStateToProps = (state) => ({
isFetching: isFetchingAssets(state),
attachments: getAssetAttachments(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 'eventId' implicitly has an 'any' type.
loadAttachmentDetails: (eventId, attachmentId) =>
dispatch(fetchAssetAttachmentDetails(eventId, attachmentId)),
});

export default connect(
mapStateToProps,
mapDispatchToProps
)(EventDetailsAssetAttachments);
export default EventDetailsAssetAttachments;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import { connect } from "react-redux";
import EventDetailsTabHierarchyNavigation from "./EventDetailsTabHierarchyNavigation";
import Notifications from "../../../shared/Notifications";
import {
getAssetCatalogDetails,
isFetchingAssets,
isFetchingAssetCatalogDetails,
} from "../../../../selectors/eventDetailsSelectors";
import { humanReadableBytesFilter } from "../../../../utils/eventDetailsUtils";
import { useAppSelector } from "../../../../store";

/**
* This component manages the catalog details sub-tab for assets tab of event details modal
Expand All @@ -18,11 +18,10 @@ const EventDetailsAssetCatalogDetails = ({
t,
// @ts-expect-error TS(7031): Binding element 'setHierarchy' implicitly has an '... Remove this comment to see the full error message
setHierarchy,
// @ts-expect-error TS(7031): Binding element 'catalog' implicitly has an 'any' ... Remove this comment to see the full error message
catalog,
// @ts-expect-error TS(7031): Binding element 'isFetching' implicitly has an 'an... Remove this comment to see the full error message
isFetching,
}) => {
const catalog = useAppSelector(state => getAssetCatalogDetails(state));
const isFetching = useAppSelector(state => isFetchingAssetCatalogDetails(state));

// @ts-expect-error TS(7006): Parameter 'subTabName' implicitly has an 'any' typ... Remove this comment to see the full error message
const openSubTab = (subTabName) => {
setHierarchy(subTabName);
Expand Down Expand Up @@ -157,11 +156,4 @@ const EventDetailsAssetCatalogDetails = ({
);
};

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

export default connect(mapStateToProps)(EventDetailsAssetCatalogDetails);
export default EventDetailsAssetCatalogDetails;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import { connect } from "react-redux";
import EventDetailsTabHierarchyNavigation from "./EventDetailsTabHierarchyNavigation";
import Notifications from "../../../shared/Notifications";
import {
getAssetCatalogs,
isFetchingAssets,
isFetchingAssetCatalogs,
} from "../../../../selectors/eventDetailsSelectors";
import { fetchAssetCatalogDetails } from "../../../../thunks/eventDetailsThunks";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { fetchAssetCatalogDetails } from "../../../../slices/eventDetailsSlice";

/**
* This component manages the catalogs sub-tab for assets tab of event details modal
Expand All @@ -18,18 +18,16 @@ const EventDetailsAssetCatalogs = ({
t,
// @ts-expect-error TS(7031): Binding element 'setHierarchy' implicitly has an '... Remove this comment to see the full error message
setHierarchy,
// @ts-expect-error TS(7031): Binding element 'catalogs' implicitly has an 'any'... Remove this comment to see the full error message
catalogs,
// @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 'loadCatalogDetails' implicitly ha... Remove this comment to see the full error message
loadCatalogDetails,
}) => {
const dispatch = useAppDispatch();

const catalogs = useAppSelector(state => getAssetCatalogs(state));
const isFetching = useAppSelector(state => isFetchingAssetCatalogs(state));

// @ts-expect-error TS(7006): Parameter 'subTabName' implicitly has an 'any' typ... Remove this comment to see the full error message
const openSubTab = (subTabName, catalogId = "") => {
if (subTabName === "catalog-details") {
// @ts-expect-error TS(7006): Parameter 'r' implicitly has an 'any' type.
loadCatalogDetails(eventId, catalogId).then((r) => {});
dispatch(fetchAssetCatalogDetails({eventId, catalogId})).then();
}
setHierarchy(subTabName);
};
Expand Down Expand Up @@ -91,7 +89,6 @@ const EventDetailsAssetCatalogs = ({
</thead>
<tbody>
{isFetching ||
// @ts-expect-error TS(7006): Parameter 'item' implicitly has an 'any' type.
catalogs.map((item, key) => (
<tr key={key}>
<td>{item.id}</td>
Expand Down Expand Up @@ -128,22 +125,4 @@ const EventDetailsAssetCatalogs = ({
);
};

// Getting state data out of redux store
// @ts-expect-error TS(7006): Parameter 'state' implicitly has an 'any' type.
const mapStateToProps = (state) => ({
isFetching: isFetchingAssets(state),
catalogs: getAssetCatalogs(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 'eventId' implicitly has an 'any' type.
loadCatalogDetails: (eventId, catalogId) =>
dispatch(fetchAssetCatalogDetails(eventId, catalogId)),
});

export default connect(
mapStateToProps,
mapDispatchToProps
)(EventDetailsAssetCatalogs);
export default EventDetailsAssetCatalogs;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import { connect } from "react-redux";
import EventDetailsTabHierarchyNavigation from "./EventDetailsTabHierarchyNavigation";
import Notifications from "../../../shared/Notifications";
import {
getAssetMedia,
isFetchingAssets,
isFetchingAssetMedia,
} from "../../../../selectors/eventDetailsSelectors";
import { fetchAssetMediaDetails } from "../../../../thunks/eventDetailsThunks";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { fetchAssetMediaDetails } from "../../../../slices/eventDetailsSlice";

/**
* This component manages the media sub-tab for assets tab of event details modal
Expand All @@ -18,18 +18,16 @@ const EventDetailsAssetMedia = ({
t,
// @ts-expect-error TS(7031): Binding element 'setHierarchy' implicitly has an '... Remove this comment to see the full error message
setHierarchy,
// @ts-expect-error TS(7031): Binding element 'media' implicitly has an 'any' ty... Remove this comment to see the full error message
media,
// @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 'loadMediaDetails' implicitly has ... Remove this comment to see the full error message
loadMediaDetails,
}) => {
const dispatch = useAppDispatch();

const media = useAppSelector(state => getAssetMedia(state));
const isFetching = useAppSelector(state => isFetchingAssetMedia(state));

// @ts-expect-error TS(7006): Parameter 'subTabName' implicitly has an 'any' typ... Remove this comment to see the full error message
const openSubTab = (subTabName, mediaId = "") => {
if (subTabName === "media-details") {
// @ts-expect-error TS(7006): Parameter 'r' implicitly has an 'any' type.
loadMediaDetails(eventId, mediaId).then((r) => {});
dispatch(fetchAssetMediaDetails({eventId, mediaId})).then();
}
setHierarchy(subTabName);
};
Expand Down Expand Up @@ -79,7 +77,6 @@ const EventDetailsAssetMedia = ({
</thead>
<tbody>
{isFetching ||
// @ts-expect-error TS(7006): Parameter 'item' implicitly has an 'any' type.
media.map((item, key) => (
<tr key={key}>
<td>
Expand Down Expand Up @@ -116,22 +113,4 @@ const EventDetailsAssetMedia = ({
);
};

// Getting state data out of redux store
// @ts-expect-error TS(7006): Parameter 'state' implicitly has an 'any' type.
const mapStateToProps = (state) => ({
isFetching: isFetchingAssets(state),
media: getAssetMedia(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 'eventId' implicitly has an 'any' type.
loadMediaDetails: (eventId, mediaId) =>
dispatch(fetchAssetMediaDetails(eventId, mediaId)),
});

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

0 comments on commit 46c95ec

Please sign in to comment.