Skip to content

Commit e7b3c5f

Browse files
committed
Add Create, Edit, Delete for LifeCycle Policies
Instead of only being able to view lifecycle policies, this commit lets you edit them, create new ones and even delete them. Depends on changes to the backend.
1 parent 26c93d7 commit e7b3c5f

28 files changed

+2625
-242
lines changed

package-lock.json

+1,149-105
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"react-hotkeys-hook": "^4.4.4",
3434
"react-i18next": "^15.0.1",
3535
"react-icons": "^5.2.1",
36+
"react-js-cron": "^5.0.1",
3637
"react-redux": "^7.2.9",
3738
"react-router-dom": "^6.26.1",
3839
"react-select": "^5.8.0",

src/components/events/LifeCyclePolicies.tsx

+39
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { lifeCyclePoliciesTemplateMap } from "../../configs/tableConfigs/lifeCyc
2424
import { fetchEvents } from "../../slices/eventSlice";
2525
import { setOffset } from "../../slices/tableSlice";
2626
import { fetchSeries } from "../../slices/seriesSlice";
27+
import NewResourceModal from "../shared/NewResourceModal";
28+
import { fetchLifeCyclePolicyActions, fetchLifeCyclePolicyTargetTypes, fetchLifeCyclePolicyTimings } from "../../slices/lifeCycleDetailsSlice";
2729

2830
/**
2931
* This component renders the table view of policies
@@ -32,6 +34,7 @@ const LifeCyclePolicies = () => {
3234
const { t } = useTranslation();
3335
const dispatch = useAppDispatch();
3436
const [displayNavigation, setNavigation] = useState(false);
37+
const [displayNewPolicyModal, setNewPolicyModal] = useState(false);
3538

3639
const user = useAppSelector(state => getUserInformation(state));
3740
const policiesTotal = useAppSelector(state => getTotalLifeCyclePolicies(state));
@@ -77,17 +80,44 @@ const LifeCyclePolicies = () => {
7780

7881
// Load policies on mount
7982
loadLifeCyclePolicies().then((r) => console.info(r));
83+
84+
// Fetch policies repeatedly
85+
let fetchInterval = setInterval(loadLifeCyclePolicies, 5000);
86+
87+
return () => clearInterval(fetchInterval);
8088
// eslint-disable-next-line react-hooks/exhaustive-deps
8189
}, []);
8290

8391
const toggleNavigation = () => {
8492
setNavigation(!displayNavigation);
8593
};
8694

95+
const showNewPolicyModal = async () => {
96+
await dispatch(fetchLifeCyclePolicyActions());
97+
await dispatch(fetchLifeCyclePolicyTargetTypes());
98+
await dispatch(fetchLifeCyclePolicyTimings());
99+
100+
setNewPolicyModal(true);
101+
};
102+
103+
const hideNewPolicyModal = () => {
104+
setNewPolicyModal(false);
105+
};
106+
87107
return (
88108
<>
89109
<Header />
90110
<NavBar>
111+
{
112+
/* Display modal for new event if add event button is clicked */
113+
displayNewPolicyModal && (
114+
<NewResourceModal
115+
handleClose={hideNewPolicyModal}
116+
resource={"lifecyclepolicy"}
117+
/>
118+
)
119+
}
120+
91121
{/* Include Burger-button menu*/}
92122
<MainNav isOpen={displayNavigation} toggleMenu={toggleNavigation} />
93123

@@ -120,6 +150,15 @@ const LifeCyclePolicies = () => {
120150
</Link>
121151
)}
122152
</nav>
153+
154+
<div className="btn-group">
155+
{hasAccess("ROLE_UI_EVENTS_CREATE", user) && (
156+
<button className="add" onClick={() => showNewPolicyModal()}>
157+
<i className="fa fa-plus" />
158+
<span>{t("LIFECYCLE.POLICIES.TABLE.ADD_POLICY")}</span>
159+
</button>
160+
)}
161+
</div>
123162
</NavBar>
124163

125164
<MainView open={displayNavigation}>

src/components/events/partials/LifeCyclePolicyActionCell.tsx

+36-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import React, { useState } from "react";
22
import { useTranslation } from "react-i18next";
33
import { useAppDispatch, useAppSelector } from "../../../store";
44
import { Tooltip } from "../../shared/Tooltip";
5-
import { LifeCyclePolicy } from "../../../slices/lifeCycleSlice";
5+
import { deleteLifeCyclePolicy, LifeCyclePolicy } from "../../../slices/lifeCycleSlice";
66
import DetailsModal from "../../shared/modals/DetailsModal";
77
import LifeCyclePolicyDetails from "./modals/LifeCyclePolicyDetails";
88
import { hasAccess } from "../../../utils/utils";
99
import { getUserInformation } from "../../../selectors/userInfoSelectors";
1010
import { fetchLifeCyclePolicyDetails } from "../../../slices/lifeCycleDetailsSlice";
11+
import ConfirmModal from "../../shared/ConfirmModal";
1112

1213
/**
1314
* This component renders the title cells of series in the table view
@@ -21,6 +22,7 @@ const LifeCyclePolicyActionCell = ({
2122
const dispatch = useAppDispatch();
2223

2324
const [displayLifeCyclePolicyDetails, setLifeCyclePolicyDetails] = useState(false);
25+
const [displayDeleteConfirmation, setDeleteConfirmation] = useState(false);
2426

2527
const user = useAppSelector(state => getUserInformation(state));
2628

@@ -34,6 +36,18 @@ const LifeCyclePolicyActionCell = ({
3436
setLifeCyclePolicyDetails(false);
3537
};
3638

39+
const hideDeleteConfirmation = () => {
40+
setDeleteConfirmation(false);
41+
};
42+
43+
const showDeleteConfirmation = async () => {
44+
setDeleteConfirmation(true);
45+
};
46+
47+
const deletingPolicy = (id: string) => {
48+
dispatch(deleteLifeCyclePolicy(id));
49+
};
50+
3751
return (
3852
<>
3953
{/* view details location/recording */}
@@ -55,6 +69,27 @@ const LifeCyclePolicyActionCell = ({
5569
<LifeCyclePolicyDetails />
5670
</DetailsModal>
5771
)}
72+
73+
{/* delete policy */}
74+
{hasAccess("ROLE_UI_LIFECYCLEPOLICY_DELETE", user) && (
75+
<Tooltip title={t("LIFECYCLE.POLICIES.TABLE.TOOLTIP.DELETE")}>
76+
<button
77+
onClick={() => showDeleteConfirmation()}
78+
className="button-like-anchor remove"
79+
80+
/>
81+
</Tooltip>
82+
)}
83+
84+
{displayDeleteConfirmation && (
85+
<ConfirmModal
86+
close={hideDeleteConfirmation}
87+
resourceName={row.title}
88+
resourceType="LIFECYCLE_POLICY"
89+
resourceId={row.id}
90+
deleteMethod={deletingPolicy}
91+
/>
92+
)}
5893
</>
5994
);
6095
};

0 commit comments

Comments
 (0)