Skip to content

Commit

Permalink
fix(Staleness): Update RBAC for staleness page + tab conditional RedH…
Browse files Browse the repository at this point in the history
  • Loading branch information
adonispuente committed Oct 17, 2023
1 parent d00fa9e commit 9672ed0
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 97 deletions.
5 changes: 5 additions & 0 deletions src/api/api.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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`);
};
165 changes: 94 additions & 71 deletions src/components/InventoryHostStaleness/HostStalenessCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import TabCard from './TabCard';
import {
CONVENTIONAL_TAB_TOOLTIP,
IMMUTABLE_TAB_TOOLTIP,
conventionalApiKeys,
daysToSecondsConversion,
hostStalenessApiKeys,
secondsToDaysConversion,
} from './constants';
import { InventoryHostStalenessPopover } from './constants';
import {
fetchDefaultStalenessValues,
fetchEdgeSystem,
fetchStalenessData,
patchStalenessData,
postStalenessData,
Expand All @@ -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 [
Expand All @@ -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]))
Expand Down Expand Up @@ -167,6 +171,7 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => {
};

const batchedApi = async () => {
fetchEdgeSystem().then((res) => setHasEdgeSystems(res.data.total > 0));
fetchApiStalenessData();
fetchDefaultValues();
setIsLoading(false);
Expand All @@ -184,7 +189,7 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => {
<Title headingLevel="h4" size="xl" id="HostTitle">
Organization level system staleness and deletion
</Title>
<InventoryHostStalenessPopover />
<InventoryHostStalenessPopover hasEdgeSystems={hasEdgeSystems} />
</CardHeader>
<CardBody>
<p>
Expand All @@ -200,12 +205,11 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => {
onClick={() => {
setIsEditing(!isEditing);
}}
ouiaId="edit-staleness-setting"
>
Edit
</Button>
) : (
<Tooltip content="You do not have the Inventory staleness and deletion viewer role required to perform this action. Contact your org admin for access.">
<Tooltip content="You do not have the Staleness and deletion admin role and/or Inventory Hosts Administrator role required to perform this action. Contact your org admin for access.">
<div>
<Button
variant="link"
Expand All @@ -218,77 +222,96 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => {
</Tooltip>
)}
</Flex>
<Tabs
id={'HostTabs'}
className="pf-m-light pf-c-table pf-u-mb-lg pf-u-mt-lg"
activeKey={activeTabKey}
onSelect={handleTabClick}
>
<Tab
eventKey={0}
title={
<TabTitleText>
Conventional (RPM-DNF){' '}
<Popover
aria-label="Basic popover"
headerContent={<div>Conventional systems (RPM-DNF)</div>}
bodyContent={<div>{CONVENTIONAL_TAB_TOOLTIP}</div>}
>
<OutlinedQuestionCircleIcon className="pf-u-ml-md" />
</Popover>
</TabTitleText>
}
{hasEdgeSystems ? (
<Tabs
id={'HostTabs'}
className="pf-m-light pf-c-table pf-u-mb-lg pf-u-mt-lg"
activeKey={activeTabKey}
onSelect={handleTabClick}
>
<TabCard
isEditing={isEditing}
filter={filter}
setFilter={setFilter}
activeTabKey={0}
newFormValues={newFormValues}
setNewFormValues={setNewFormValues}
isFormValid={isFormValid}
setIsFormValid={setIsFormValid}
hostStalenessImmutableDefaults={
hostStalenessImmutableDefaults
<Tab
eventKey={0}
title={
<TabTitleText>
Conventional (RPM-DNF){' '}
<Popover
aria-label="Basic popover"
headerContent={
<div>Conventional systems (RPM-DNF)</div>
}
bodyContent={<div>{CONVENTIONAL_TAB_TOOLTIP}</div>}
>
<OutlinedQuestionCircleIcon className="pf-u-ml-md" />
</Popover>
</TabTitleText>
}
hostStalenessConventionalDefaults={
hostStalenessConventionalDefaults
>
<TabCard
isEditing={isEditing}
filter={filter}
setFilter={setFilter}
activeTabKey={0}
newFormValues={newFormValues}
setNewFormValues={setNewFormValues}
isFormValid={isFormValid}
setIsFormValid={setIsFormValid}
hostStalenessImmutableDefaults={
hostStalenessImmutableDefaults
}
hostStalenessConventionalDefaults={
hostStalenessConventionalDefaults
}
/>
</Tab>
<Tab
eventKey={1}
title={
<TabTitleText>
Immutable (OSTree){' '}
<Popover
aria-label="Basic popover"
headerContent={<div>Immutable (OSTree)</div>}
bodyContent={<div>{IMMUTABLE_TAB_TOOLTIP}</div>}
>
<OutlinedQuestionCircleIcon className="pf-u-ml-md" />
</Popover>
</TabTitleText>
}
/>
</Tab>
<Tab
eventKey={1}
title={
<TabTitleText>
Immutable (OSTree){' '}
<Popover
aria-label="Basic popover"
headerContent={<div>Immutable (OSTree)</div>}
bodyContent={<div>{IMMUTABLE_TAB_TOOLTIP}</div>}
>
<OutlinedQuestionCircleIcon className="pf-u-ml-md" />
</Popover>
</TabTitleText>
>
<TabCard
isEditing={isEditing}
filter={filter}
setFilter={setFilter}
activeTabKey={1}
newFormValues={newFormValues}
setNewFormValues={setNewFormValues}
isFormValid={isFormValid}
setIsFormValid={setIsFormValid}
hostStalenessImmutableDefaults={
hostStalenessImmutableDefaults
}
hostStalenessConventionalDefaults={
hostStalenessConventionalDefaults
}
/>
</Tab>
</Tabs>
) : (
<TabCard
isEditing={isEditing}
filter={filter}
setFilter={setFilter}
activeTabKey={0}
newFormValues={newFormValues}
setNewFormValues={setNewFormValues}
isFormValid={isFormValid}
setIsFormValid={setIsFormValid}
hostStalenessImmutableDefaults={hostStalenessImmutableDefaults}
hostStalenessConventionalDefaults={
hostStalenessConventionalDefaults
}
>
<TabCard
isEditing={isEditing}
filter={filter}
setFilter={setFilter}
activeTabKey={1}
newFormValues={newFormValues}
setNewFormValues={setNewFormValues}
isFormValid={isFormValid}
setIsFormValid={setIsFormValid}
hostStalenessImmutableDefaults={
hostStalenessImmutableDefaults
}
hostStalenessConventionalDefaults={
hostStalenessConventionalDefaults
}
/>
</Tab>
</Tabs>
/>
)}
{isEditing && (
<Flex justifyContent={{ default: 'justifyContentFlexStart' }}>
<Button
Expand Down
55 changes: 34 additions & 21 deletions src/components/InventoryHostStaleness/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export const hostStalenessApiKeys = [
'immutable_culling_delta',
];

export const conventionalApiKeys = [
'conventional_staleness_delta',
'conventional_stale_warning_delta',
'conventional_culling_delta',
];

export const daysToSecondsConversion = (days) => {
return days * 86400;
};
Expand Down Expand Up @@ -258,7 +264,7 @@ export const HostStalenessResetDefaultPopover = ({ activeTabKey }) => {
);
};

export const InventoryHostStalenessPopover = () => {
export const InventoryHostStalenessPopover = ({ hasEdgeSystems }) => {
return (
<Popover
aria-label="Orginization level popover"
Expand Down Expand Up @@ -293,26 +299,29 @@ export const InventoryHostStalenessPopover = () => {
- Systems are deleted after 14 days since last check-in.
</span>
</Flex>
<Flex
direction={{ default: 'column' }}
spaceItems={{ default: 'spaceItemsNone' }}
>
<span className="pf-u-font-size-sm">
Default for Immutable systems (OSTree):
</span>
<span className="pf-u-font-size-sm">
<p>
- Systems are marked as stale after 2 days since last check-in.
</p>
</span>
<span className="pf-u-font-size-sm">
- Systems are marked as stale warning after 120 days since last
check-in.
</span>
<span className="pf-u-font-size-sm">
- Systems are deleted after 180 days since last check-in.
</span>
</Flex>
{hasEdgeSystems && (
<Flex
direction={{ default: 'column' }}
spaceItems={{ default: 'spaceItemsNone' }}
>
<span className="pf-u-font-size-sm">
Default for Immutable systems (OSTree):
</span>
<span className="pf-u-font-size-sm">
<p>
- Systems are marked as stale after 2 days since last
check-in.
</p>
</span>
<span className="pf-u-font-size-sm">
- Systems are marked as stale warning after 120 days since last
check-in.
</span>
<span className="pf-u-font-size-sm">
- Systems are deleted after 180 days since last check-in.
</span>
</Flex>
)}
</Flex>
}
>
Expand Down Expand Up @@ -574,3 +583,7 @@ export const formValidation = async (newFormValues, setIsFormValid) => {
HostStalenessResetDefaultPopover.propTypes = {
activeTabKey: PropTypes.number,
};

InventoryHostStalenessPopover.propTypes = {
hasEdgeSystems: PropTypes.bool,
};
6 changes: 1 addition & 5 deletions src/routes/InventoryHostStaleness.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import { usePermissionsWithContext } from '@redhat-cloud-services/frontend-compo
import { GENERAL_HOST_STALENESS_READ_PERMISSION } from '../components/InventoryHostStaleness/constants';
import { Page, PageSection } from '@patternfly/react-core';
import HostStalenessNoAccess from '../components/InventoryHostStaleness/HostStalenessNoAccess';
import { GENERAL_HOSTS_READ_PERMISSIONS } from '../constants';

const REQUIRED_PERMISSIONS = [
GENERAL_HOST_STALENESS_READ_PERMISSION,
GENERAL_HOSTS_READ_PERMISSIONS,
];
const REQUIRED_PERMISSIONS = [GENERAL_HOST_STALENESS_READ_PERMISSION];

const HostStaleness = () => {
const chrome = useChrome();
Expand Down

0 comments on commit 9672ed0

Please sign in to comment.