Skip to content

Commit

Permalink
fix: Improve notification clearing (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
leSamo authored Dec 2, 2021
1 parent fbaaaf9 commit 0f98a25
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import GroupedCVELabels from '../../PresentationalComponents/Snippets/GroupedCVE
import ErrorHandler from '../../PresentationalComponents/ErrorHandler/ErrorHandler';
import { useRbac } from '../../../Helpers/Hooks';
import { NotAuthorized } from '../../PresentationalComponents/EmptyStates/EmptyStates';
import { clearNotifications } from '@redhat-cloud-services/frontend-components-notifications/redux';

export const CVEPageContext = React.createContext({ isLoading: true });

Expand Down Expand Up @@ -77,6 +78,7 @@ const CVEDetailsPage = ({ match }) => {
useEffect(() => {
return () => {
dispatch(clearCveStore());
dispatch(clearNotifications());
};
}, [dispatch]);

Expand Down
11 changes: 2 additions & 9 deletions src/Components/SmartComponents/Modals/BaseModal.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Button, FormGroup, FormSelect, FormSelectOption, Modal, TextArea } from '@patternfly/react-core';
import {
addNotification,
clearNotifications
addNotification
} from '@redhat-cloud-services/frontend-components-notifications/redux';
import propTypes from 'prop-types';
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import { ReadOnlyNotification, STATUS_OPTIONS } from '../../../Helpers/constants';
import messages from '../../../Messages';
Expand Down Expand Up @@ -64,12 +63,6 @@ export const BaseModal = ({ items, title, onSave, onSuccessNotification, onFailu
handleClose();
};

useEffect(() => {
return () => {
dispatch(clearNotifications());
};
}, [dispatch]);

return (
<Modal
variant="small"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Main } from '@redhat-cloud-services/frontend-components/Main';
import { addNotification } from '@redhat-cloud-services/frontend-components-notifications/redux';
import { addNotification, clearNotifications } from '@redhat-cloud-services/frontend-components-notifications/redux';
import propTypes from 'prop-types';
import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import { connect, useDispatch } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { fetchSystemDetails, optOutSystemsAction } from '../../../Store/Actions/Actions';
import { systemDetailsPageStore } from '../../../Store/Reducers/SystemDetailsPageStore';
Expand All @@ -15,12 +15,20 @@ import messages from '../../../Messages';
import { AppInfo, DetailWrapper, InventoryDetailHead } from '@redhat-cloud-services/frontend-components/Inventory';

const InventoryDetail = ({ fetchSystemDetails, systemDetails = {}, optOutSystem, match, addNotification, intl, errors }) => {
const dispatch = useDispatch();

const inventoryId = match.params.inventoryId;

useEffect(() => {
fetchSystemDetails(inventoryId);
}, [fetchSystemDetails, inventoryId]);

useEffect(() => {
return () => {
dispatch(clearNotifications());
};
}, [dispatch]);

const notifications = systemName => ({
exclude: {
success: {
Expand Down Expand Up @@ -67,6 +75,7 @@ const InventoryDetail = ({ fetchSystemDetails, systemDetails = {}, optOutSystem,
};

const { opt_out: isOptOut = false, entity, loaded } = systemDetails;

return (
<DetailWrapper>
<Header
Expand Down
2 changes: 2 additions & 0 deletions src/Components/SmartComponents/SystemsPage/SystemsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useGetEntities, useOptOutSystems } from '../../../Helpers/Hooks';
import * as APIHelper from '../../../Helpers/APIHelper';
import { EmptyStateNoSystems } from '../../PresentationalComponents/EmptyStates/EmptyStates';
import ColumnManagementModal from '../Modals/ColumnManagementModal';
import { clearNotifications } from '@redhat-cloud-services/frontend-components-notifications/redux';

const SystemsPage = () => {
const inventoryRef = React.createRef();
Expand Down Expand Up @@ -55,6 +56,7 @@ const SystemsPage = () => {
return () => {
dispatch(clearSystemStore());
dispatch(clearInventoryStore());
dispatch(clearNotifications());
};
}, [dispatch]);

Expand Down

0 comments on commit 0f98a25

Please sign in to comment.