From 08b9eaaf8813a9a814a534e9448eff65b49efc34 Mon Sep 17 00:00:00 2001 From: Adonis Puente <60629070+adonispuente@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:33:25 -0400 Subject: [PATCH] feat(RHIN-447): Staleness page UX updates and Name changes (#2036) * Disable Global Filter * Reset button works with individual tabs * rename culling to deletion + QE button request * optimizations and route change * Popover changes, Never value replaces , current api Keys --- src/Routes.js | 4 +- .../HostStalenessCard.js | 53 ++++-- .../HostStalenessNoAccess.js | 2 +- .../InventoryHostStaleness/TabCard.js | 30 +++- .../InventoryHostStaleness/constants.js | 154 ++++++++++-------- src/routes/InventoryHostStaleness.js | 7 +- 6 files changed, 158 insertions(+), 92 deletions(-) diff --git a/src/Routes.js b/src/Routes.js index e4c8e7443..3afa18d37 100644 --- a/src/Routes.js +++ b/src/Routes.js @@ -29,7 +29,7 @@ export const routes = { groupDetail: '/groups/:groupId', update: '/:inventoryId/update', edgeInventory: '/manage-edge-inventory', - staleness: '/staleness-and-culling', + staleness: '/staleness-and-deletion', }; const INVENTORY_TOTAL_FETCH_URL = '/api/inventory/v1/hosts'; @@ -84,7 +84,7 @@ export const Routes = () => { element: , }, { - path: '/staleness-and-culling', + path: '/staleness-and-deletion', element: groupsEnabled ? : , }, ]); diff --git a/src/components/InventoryHostStaleness/HostStalenessCard.js b/src/components/InventoryHostStaleness/HostStalenessCard.js index 07dbe1f1f..67a7df30e 100644 --- a/src/components/InventoryHostStaleness/HostStalenessCard.js +++ b/src/components/InventoryHostStaleness/HostStalenessCard.js @@ -37,12 +37,18 @@ import PropTypes from 'prop-types'; const HostStalenessCard = ({ canModifyHostStaleness }) => { const [filter, setFilter] = useState({}); - const [defaultApiValues, setDefaultApiValues] = useState({}); const [newFormValues, setNewFormValues] = useState(filter); const [isEditing, setIsEditing] = useState(false); const [activeTabKey, setActiveTabKey] = useState(0); const [isModalOpen, setIsModalOpen] = useState(false); const [isFormValid, setIsFormValid] = useState(true); + const [hostStalenessImmutableDefaults, setHostStalenessImmutableDefaults] = + useState({}); + const [ + hostStalenessConventionalDefaults, + setHostStalenessConventionalDefaults, + ] = useState({}); + const [isLoading, setIsLoading] = useState(true); const dispatch = useDispatch(); @@ -139,12 +145,25 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => { //keeps track of what default the backend wants const fetchDefaultValues = async () => { let results = await fetchDefaultStalenessValues().catch((err) => err); - let newFilter = {}; - hostStalenessApiKeys.forEach( - (filterKey) => - (newFilter[filterKey] = secondsToDaysConversion(results[filterKey])) - ); - setDefaultApiValues(newFilter); + let conventionalFilter = {}; + let immutableFilter = {}; + + Object.keys(results).forEach((key) => { + if (key.includes('conventional')) { + conventionalFilter[key] = secondsToDaysConversion(results[key]); + } else if (key.includes('immutable')) { + immutableFilter[key] = secondsToDaysConversion(results[key]); + } + }); + + setHostStalenessConventionalDefaults({ + ...hostStalenessConventionalDefaults, + ...conventionalFilter, + }); + setHostStalenessImmutableDefaults({ + ...hostStalenessImmutableDefaults, + ...immutableFilter, + }); }; const batchedApi = async () => { @@ -163,7 +182,7 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => { - Organization level system staleness and culling + Organization level system staleness and deletion @@ -185,7 +204,7 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => { Edit ) : ( - + + ) : ( @@ -84,5 +94,7 @@ TabCard.propTypes = { isFormValid: PropTypes.any, setIsFormValid: PropTypes.any, defaultValues: PropTypes.object, + hostStalenessImmutableDefaults: PropTypes.object, + hostStalenessConventionalDefaults: PropTypes.object, }; export default TabCard; diff --git a/src/components/InventoryHostStaleness/constants.js b/src/components/InventoryHostStaleness/constants.js index a5c9fdc36..a27d3cd48 100644 --- a/src/components/InventoryHostStaleness/constants.js +++ b/src/components/InventoryHostStaleness/constants.js @@ -1,6 +1,7 @@ import React from 'react'; import { Button, Flex, Popover, Title } from '@patternfly/react-core'; import { OutlinedQuestionCircleIcon } from '@patternfly/react-icons'; +import PropTypes from 'prop-types'; export const CONVENTIONAL_TAB_TOOLTIP = 'With RPM-DNF, you can manage the system software by using the DNF package manager and updated RPM packages. This is a simple and adaptive method of managing and modifying the system over its lifecycle.'; @@ -18,16 +19,9 @@ export const HOST_STALENESS_ADMINISTRATOR_PERMISSIONS = [ GENERAL_HOST_STALENESS_WRITE_PERMISSION, ]; -//int for 'Never' value. POSTgreSQL max in is this -const maxSafeInt = 2147483647; - //86400 seconds in one day -> divide each by secodns in a day to get day values export const secondsToDaysConversion = (seconds) => { - if (seconds > 2000000000) { - return 'Never'; - } else { - return seconds / 86400; - } + return seconds / 86400; }; export const hostStalenessApiKeys = [ @@ -40,18 +34,13 @@ export const hostStalenessApiKeys = [ ]; export const daysToSecondsConversion = (days) => { - if (days === 'Never') { - return maxSafeInt; - } else { - return days * 86400; - } + return days * 86400; }; export const conditionalDropdownError = (newFormValues, dropdownItems) => { //this runs on every select every time let apiKey = dropdownItems[0].apiKey; - let formValue = - newFormValues[apiKey] === 'Never' ? maxSafeInt : newFormValues[apiKey]; + let formValue = newFormValues[apiKey]; if (apiKey === 'conventional_staleness_delta') { if (formValue > newFormValues['conventional_stale_warning_delta']) { @@ -69,7 +58,7 @@ export const conditionalDropdownError = (newFormValues, dropdownItems) => { className="pf-u-font-size-sm pf-v5-u-danger-color-100" style={{ width: '200px' }} > - Staleness must be before culling + Staleness must be before deletion

); } else { @@ -83,7 +72,7 @@ export const conditionalDropdownError = (newFormValues, dropdownItems) => { className="pf-u-font-size-sm pf-v5-u-danger-color-100" style={{ width: '200px' }} > - Stale warning must be before culling + Stale warning must be before deletion

); } else if (formValue < newFormValues['conventional_staleness_delta']) { @@ -110,7 +99,7 @@ export const conditionalDropdownError = (newFormValues, dropdownItems) => { className="pf-u-font-size-sm pf-v5-u-danger-color-100" style={{ width: '200px' }} > - Culling must be after staleness + Deletion must be after staleness

); } else if (formValue < newFormValues['conventional_staleness_delta']) { @@ -119,7 +108,7 @@ export const conditionalDropdownError = (newFormValues, dropdownItems) => { className="pf-u-font-size-sm pf-v5-u-danger-color-100" style={{ width: '200px' }} > - Culling must be after stale warning + Deletion must be after stale warning

); } else { @@ -143,7 +132,7 @@ export const conditionalDropdownError = (newFormValues, dropdownItems) => { className="pf-u-font-size-sm pf-v5-u-danger-color-100" style={{ width: '200px' }} > - Staleness must be before culling + Staleness must be before deletion

); } else { @@ -161,7 +150,7 @@ export const conditionalDropdownError = (newFormValues, dropdownItems) => { className="pf-u-font-size-sm pf-v5-u-danger-color-100 " style={{ width: '200px' }} > - Stale warning must be before culling + Stale warning must be before deletion

); } else if (formValue < newFormValues['immutable_staleness_delta']) { @@ -188,7 +177,7 @@ export const conditionalDropdownError = (newFormValues, dropdownItems) => { className="pf-u-font-size-sm pf-v5-u-danger-color-100" style={{ width: '200px' }} > - Culling must be after staleness + Deletion must be after staleness

); } else if (formValue < newFormValues['immutable_staleness_delta']) { @@ -197,7 +186,7 @@ export const conditionalDropdownError = (newFormValues, dropdownItems) => { className="pf-u-font-size-sm pf-v5-u-danger-color-100" style={{ width: '200px' }} > - Culling must be after stale warning + Deletion must be after stale warning

); } else { @@ -206,31 +195,48 @@ export const conditionalDropdownError = (newFormValues, dropdownItems) => { } }; -export const HostStalenessResetDefaultPopover = () => { +export const HostStalenessResetDefaultPopover = ({ activeTabKey }) => { return ( Orginization level setting - } + headerContent={Default settings} position="left" bodyContent={ - - - - Systems are marked as stale after 1 day since last check-in. - - - - Systems are marked as stale warning after 14 days since last - check-in. - + activeTabKey ? ( + + + - Systems are marked as stale after 2 day since last check-in. + + + - Systems are marked as stale warning after 120 days since last + check-in. + - - - Systems are culled after 30 days since last check-in. - - + + - Systems are culled after 2 years since last check-in. + + + ) : ( + + + - Systems are marked as stale after 1 day since last check-in. + + + - Systems are marked as stale warning after 14 days since last + check-in. + + + + - Systems are culled after 30 days since last check-in. + + + ) } >