Skip to content

Commit

Permalink
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.
  • Loading branch information
Arnei committed Dec 4, 2024
1 parent 5e5a850 commit 6d9e5a4
Show file tree
Hide file tree
Showing 28 changed files with 3,233 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
Expand Up @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions src/components/events/LifeCyclePolicies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down Expand Up @@ -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} />

Expand Down Expand Up @@ -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}>
Expand Down
37 changes: 36 additions & 1 deletion src/components/events/partials/LifeCyclePolicyActionCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));

Expand All @@ -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 */}
Expand All @@ -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}
/>
)}
</>
);
};
Expand Down
Loading

0 comments on commit 6d9e5a4

Please sign in to comment.