Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Create, Edit, Delete for LifeCycle Policies
Browse files Browse the repository at this point in the history
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.
Arnei committed Dec 4, 2024
1 parent 5e5a850 commit c2d1c40
Showing 29 changed files with 3,240 additions and 828 deletions.
2,448 changes: 1,757 additions & 691 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
"react-hotkeys-hook": "^4.5.1",
"react-i18next": "^15.1.0",
"react-icons": "^5.3.0",
"react-js-cron": "^5.0.1",
"react-redux": "^9.1.2",
"react-router-dom": "^6.27.0",
"react-select": "^5.8.0",
39 changes: 39 additions & 0 deletions src/components/events/LifeCyclePolicies.tsx
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@ import { lifeCyclePoliciesTemplateMap } from "../../configs/tableConfigs/lifeCyc
import { fetchEvents } from "../../slices/eventSlice";
import { setOffset } from "../../slices/tableSlice";
import { fetchSeries } from "../../slices/seriesSlice";
import NewResourceModal from "../shared/NewResourceModal";
import { fetchLifeCyclePolicyActions, fetchLifeCyclePolicyTargetTypes, fetchLifeCyclePolicyTimings } from "../../slices/lifeCycleDetailsSlice";

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

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

// Load policies on mount
loadLifeCyclePolicies().then((r) => console.info(r));

// Fetch policies repeatedly
let fetchInterval = setInterval(loadLifeCyclePolicies, 5000);

return () => clearInterval(fetchInterval);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const toggleNavigation = () => {
setNavigation(!displayNavigation);
};

const showNewPolicyModal = async () => {
await dispatch(fetchLifeCyclePolicyActions());
await dispatch(fetchLifeCyclePolicyTargetTypes());
await dispatch(fetchLifeCyclePolicyTimings());

setNewPolicyModal(true);
};

const hideNewPolicyModal = () => {
setNewPolicyModal(false);
};

return (
<>
<Header />
<NavBar>
{
/* Display modal for new event if add event button is clicked */
displayNewPolicyModal && (
<NewResourceModal
handleClose={hideNewPolicyModal}
resource={"lifecyclepolicy"}
/>
)
}

{/* Include Burger-button menu*/}
<MainNav isOpen={displayNavigation} toggleMenu={toggleNavigation} />

@@ -120,6 +150,15 @@ const LifeCyclePolicies = () => {
</Link>
)}
</nav>

<div className="btn-group">
{hasAccess("ROLE_UI_EVENTS_CREATE", user) && (
<button className="add" onClick={() => showNewPolicyModal()}>
<i className="fa fa-plus" />
<span>{t("LIFECYCLE.POLICIES.TABLE.ADD_POLICY")}</span>
</button>
)}
</div>
</NavBar>

<MainView open={displayNavigation}>
37 changes: 36 additions & 1 deletion src/components/events/partials/LifeCyclePolicyActionCell.tsx
Original file line number Diff line number Diff line change
@@ -2,12 +2,13 @@ import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { useAppDispatch, useAppSelector } from "../../../store";
import { Tooltip } from "../../shared/Tooltip";
import { LifeCyclePolicy } from "../../../slices/lifeCycleSlice";
import { deleteLifeCyclePolicy, LifeCyclePolicy } from "../../../slices/lifeCycleSlice";
import DetailsModal from "../../shared/modals/DetailsModal";
import LifeCyclePolicyDetails from "./modals/LifeCyclePolicyDetails";
import { hasAccess } from "../../../utils/utils";
import { getUserInformation } from "../../../selectors/userInfoSelectors";
import { fetchLifeCyclePolicyDetails } from "../../../slices/lifeCycleDetailsSlice";
import ConfirmModal from "../../shared/ConfirmModal";

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

const [displayLifeCyclePolicyDetails, setLifeCyclePolicyDetails] = useState(false);
const [displayDeleteConfirmation, setDeleteConfirmation] = useState(false);

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

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

const hideDeleteConfirmation = () => {
setDeleteConfirmation(false);
};

const showDeleteConfirmation = async () => {
setDeleteConfirmation(true);
};

const deletingPolicy = (id: string) => {
dispatch(deleteLifeCyclePolicy(id));
};

return (
<>
{/* view details location/recording */}
@@ -55,6 +69,27 @@ const LifeCyclePolicyActionCell = ({
<LifeCyclePolicyDetails />
</DetailsModal>
)}

{/* delete policy */}
{hasAccess("ROLE_UI_LIFECYCLEPOLICY_DELETE", user) && (
<Tooltip title={t("LIFECYCLE.POLICIES.TABLE.TOOLTIP.DELETE")}>
<button
onClick={() => showDeleteConfirmation()}
className="button-like-anchor remove"

/>
</Tooltip>
)}

{displayDeleteConfirmation && (
<ConfirmModal
close={hideDeleteConfirmation}
resourceName={row.title}
resourceType="LIFECYCLE_POLICY"
resourceId={row.id}
deleteMethod={deletingPolicy}
/>
)}
</>
);
};
Original file line number Diff line number Diff line change
@@ -39,6 +39,8 @@ const LifeCyclePolicyDetailsAccessTab = ({
descriptionText={t("LIFECYCLE.POLICIES.DETAILS.ACCESS.DESCRIPTION")}
policies={acl}
fetchAccessPolicies={fetchLifeCyclePolicyDetailsAcls}
// TODO: Figure out why typescript is being funky here
// @ts-ignore
saveNewAccessPolicies={updateLifeCyclePolicyAccess}
editAccessRole={"ROLE_UI_LIFECYCLEPOLICY_DETAILS_ACL_EDIT"}
policyChanged={policyChanged}
Loading

0 comments on commit c2d1c40

Please sign in to comment.