From 9672ed05d5818779685a6688449b99bea6482b41 Mon Sep 17 00:00:00 2001 From: Adonis Puente Date: Tue, 17 Oct 2023 16:07:38 -0400 Subject: [PATCH] fix(Staleness): Update RBAC for staleness page + tab conditional #2062 --- src/api/api.js | 5 + .../HostStalenessCard.js | 165 ++++++++++-------- .../InventoryHostStaleness/constants.js | 55 +++--- src/routes/InventoryHostStaleness.js | 6 +- 4 files changed, 134 insertions(+), 97 deletions(-) diff --git a/src/api/api.js b/src/api/api.js index 9f2668e46..74191b81e 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -1,5 +1,6 @@ import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'; export const INVENTORY_API_BASE = '/api/inventory/v1'; +export const EDGE_API_BASE = '/api/edge/v1'; import flatMap from 'lodash/flatMap'; import instance from '@redhat-cloud-services/frontend-components-utilities/interceptors'; @@ -390,3 +391,7 @@ export const postStalenessData = (data) => { export const patchStalenessData = (data) => { return instance.patch(`${INVENTORY_API_BASE}/account/staleness`, data); }; + +export const fetchEdgeSystem = () => { + return instance.get(`${EDGE_API_BASE}/devices/devicesview?limit=1`); +}; diff --git a/src/components/InventoryHostStaleness/HostStalenessCard.js b/src/components/InventoryHostStaleness/HostStalenessCard.js index 0af33e956..366ed23e5 100644 --- a/src/components/InventoryHostStaleness/HostStalenessCard.js +++ b/src/components/InventoryHostStaleness/HostStalenessCard.js @@ -20,6 +20,7 @@ import TabCard from './TabCard'; import { CONVENTIONAL_TAB_TOOLTIP, IMMUTABLE_TAB_TOOLTIP, + conventionalApiKeys, daysToSecondsConversion, hostStalenessApiKeys, secondsToDaysConversion, @@ -27,6 +28,7 @@ import { import { InventoryHostStalenessPopover } from './constants'; import { fetchDefaultStalenessValues, + fetchEdgeSystem, fetchStalenessData, patchStalenessData, postStalenessData, @@ -42,6 +44,7 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => { const [activeTabKey, setActiveTabKey] = useState(0); const [isModalOpen, setIsModalOpen] = useState(false); const [isFormValid, setIsFormValid] = useState(true); + const [hasEdgeSystems, setHasEdgeSystems] = useState(true); const [hostStalenessImmutableDefaults, setHostStalenessImmutableDefaults] = useState({}); const [ @@ -68,7 +71,8 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => { //On save Button const saveHostData = async () => { let apiData = {}; - hostStalenessApiKeys.forEach( + let apiKeys = hasEdgeSystems ? hostStalenessApiKeys : conventionalApiKeys; + apiKeys.forEach( (filterKey) => filterKey !== 'id' && (apiData[filterKey] = daysToSecondsConversion(newFormValues[filterKey])) @@ -167,6 +171,7 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => { }; const batchedApi = async () => { + fetchEdgeSystem().then((res) => setHasEdgeSystems(res.data.total > 0)); fetchApiStalenessData(); fetchDefaultValues(); setIsLoading(false); @@ -184,7 +189,7 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => { Organization level system staleness and deletion - +

@@ -200,12 +205,11 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => { onClick={() => { setIsEditing(!isEditing); }} - ouiaId="edit-staleness-setting" > Edit ) : ( - +

} - bodyContent={
{CONVENTIONAL_TAB_TOOLTIP}
} - > - - - - } + {hasEdgeSystems ? ( + - + Conventional (RPM-DNF){' '} + Conventional systems (RPM-DNF) + } + bodyContent={
{CONVENTIONAL_TAB_TOOLTIP}
} + > + +
+ } - hostStalenessConventionalDefaults={ - hostStalenessConventionalDefaults + > + + + + Immutable (OSTree){' '} + Immutable (OSTree)} + bodyContent={
{IMMUTABLE_TAB_TOOLTIP}
} + > + +
+ } - /> -
- - Immutable (OSTree){' '} - Immutable (OSTree)} - bodyContent={
{IMMUTABLE_TAB_TOOLTIP}
} - > - -
- + > + +
+
+ ) : ( + - - - + /> + )} {isEditing && (