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 26c93d7 commit e7b3c5f
Show file tree
Hide file tree
Showing 28 changed files with 2,625 additions and 242 deletions.
1,254 changes: 1,149 additions & 105 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.4.4",
"react-i18next": "^15.0.1",
"react-icons": "^5.2.1",
"react-js-cron": "^5.0.1",
"react-redux": "^7.2.9",
"react-router-dom": "^6.26.1",
"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 e7b3c5f

Please sign in to comment.