From 13858025f892609ff1a800847f9cf5febb62076c Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Mon, 23 Dec 2024 13:08:09 -0500 Subject: [PATCH] Hide more stuff per comments --- .../async/insights_full_sync.rb | 1 + .../InsightsSettings/InsightsSettings.js | 13 +++++--- .../InsightsTable/InsightsTableConstants.js | 3 +- .../InsightsTable/InsightsTableHelpers.js | 2 ++ .../Components/ToolbarDropdown.js | 11 +++++-- .../InsightsCloudSync/InsightsCloudSync.js | 31 ++++++++++++------- .../NewHostDetailsTab.js | 6 ++-- 7 files changed, 45 insertions(+), 22 deletions(-) diff --git a/lib/insights_cloud/async/insights_full_sync.rb b/lib/insights_cloud/async/insights_full_sync.rb index 829ac873..e1ab0099 100644 --- a/lib/insights_cloud/async/insights_full_sync.rb +++ b/lib/insights_cloud/async/insights_full_sync.rb @@ -121,6 +121,7 @@ def to_model_hash(hit_hash) likelihood: hit_hash['likelihood'].to_i, results_url: hit_hash['results_url'], rule_id: to_rule_id(hit_hash['results_url']), + is_local_insights_advisor: ::ForemanRhCloud.use_insights_on_premise?, } end diff --git a/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js b/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js index 587857e0..bf663124 100644 --- a/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +++ b/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js @@ -1,7 +1,8 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useContext } from 'react'; import PropTypes from 'prop-types'; import { translate as __ } from 'foremanReact/common/I18n'; import SwitcherPF4 from '../../../common/Switcher/SwitcherPF4'; +import { InsightsConfigContext } from '../../InsightsCloudSync'; import './insightsSettings.scss'; const InsightsSettings = ({ @@ -9,23 +10,25 @@ const InsightsSettings = ({ getInsightsSyncSettings, setInsightsSyncEnabled, }) => { - const [isOnPrem, setIsOnPrem] = useState(false); + const { isLocalInsightsAdvisor, setIsLocalInsightsAdvisor } = useContext( + InsightsConfigContext + ); useEffect(() => { async function fetchData() { try { await getInsightsSyncSettings(); } catch (err) { if (err.cause?.response?.status === 422) { - setIsOnPrem(true); + setIsLocalInsightsAdvisor(true); } else { throw err; } } } fetchData(); - }, [getInsightsSyncSettings, setInsightsSyncEnabled]); + }, [getInsightsSyncSettings, setIsLocalInsightsAdvisor]); - if (isOnPrem) return null; + if (isLocalInsightsAdvisor) return null; return (
diff --git a/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js b/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js index 946462bb..c782566e 100644 --- a/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +++ b/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js @@ -31,10 +31,11 @@ export const hasPlaybookFormatter = ({ title: hasPlaybook }) => ({ }); export const actionsFormatter = (props, { rowData = {} }) => { - const { recommendationUrl, accessRHUrl } = rowData; + const { recommendationUrl, accessRHUrl, isLocalInsightsAdvisor } = rowData; const dropdownItems = []; recommendationUrl && + !isLocalInsightsAdvisor && dropdownItems.push( diff --git a/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js b/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js index 14e4dc83..023f52c1 100644 --- a/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js +++ b/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js @@ -21,6 +21,7 @@ export const modifySelectedRows = ( has_playbook, results_url, solution_url, + is_local_insights_advisor, }) => { const disableCheckbox = !has_playbook; const cells = [hostname, title, total_risk, has_playbook, results_url]; @@ -34,6 +35,7 @@ export const modifySelectedRows = ( selected: selectedIds[id] || (disableCheckbox && showSelectAllAlert), recommendationUrl: results_url, accessRHUrl: solution_url, + isLocalInsightsAdvisor: is_local_insights_advisor, }; } ); diff --git a/webpack/InsightsCloudSync/Components/ToolbarDropdown.js b/webpack/InsightsCloudSync/Components/ToolbarDropdown.js index f6c82ad5..8d78d4cf 100644 --- a/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +++ b/webpack/InsightsCloudSync/Components/ToolbarDropdown.js @@ -1,19 +1,23 @@ -import React, { useState } from 'react'; +import React, { useState, useContext } from 'react'; import PropTypes from 'prop-types'; import { translate as __ } from 'foremanReact/common/I18n'; import { Dropdown, DropdownItem, KebabToggle } from '@patternfly/react-core'; import { ExternalLinkAltIcon } from '@patternfly/react-icons'; import { redHatAdvisorSystems } from '../InsightsCloudSyncHelpers'; +import { InsightsConfigContext } from '../InsightsCloudSync'; const ToolbarDropdown = ({ onRecommendationSync }) => { const [isDropdownOpen, setIsDropdownOpen] = useState(false); - const dropdownItems = [ + const { isLocalInsightsAdvisor } = useContext(InsightsConfigContext); + const baseItems = [ {__('Sync recommendations')} , + ]; + const cloudItems = [ { , ]; + const dropdownItems = isLocalInsightsAdvisor + ? baseItems + : baseItems.concat(cloudItems); return ( { + const [isLocalInsightsAdvisor, setIsLocalInsightsAdvisor] = useState(false); const onRecommendationSync = () => syncInsights(fetchInsights, query); const toolbarButtons = ( <> @@ -29,18 +32,22 @@ const InsightsCloudSync = ({ syncInsights, query, fetchInsights }) => { return (
- - fetchInsights({ query: nextQuery, page: 1 })} - header={INSIGHTS_SYNC_PAGE_TITLE} - toolbarButtons={toolbarButtons} - searchQuery={query} - beforeToolbarComponent={} + - - + + fetchInsights({ query: nextQuery, page: 1 })} + header={INSIGHTS_SYNC_PAGE_TITLE} + toolbarButtons={toolbarButtons} + searchQuery={query} + beforeToolbarComponent={} + > + + +
); }; diff --git a/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js b/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js index 68919726..d3c88cca 100644 --- a/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +++ b/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useContext } from 'react'; import PropTypes from 'prop-types'; import { useDispatch, useSelector } from 'react-redux'; import SearchBar from 'foremanReact/components/SearchBar'; @@ -21,11 +21,13 @@ import { selectHits, } from '../InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors'; import { redHatAdvisorSystems } from '../InsightsCloudSync/InsightsCloudSyncHelpers'; +import { InsightsConfigContext } from '../InsightsCloudSync/InsightsCloudSync'; const NewHostDetailsTab = ({ hostName, router }) => { const dispatch = useDispatch(); const query = useSelector(selectSearch); const hits = useSelector(selectHits); + const { isLocalInsightsAdvisor } = useContext(InsightsConfigContext); useEffect(() => () => router.replace({ search: null }), [router]); @@ -41,7 +43,7 @@ const NewHostDetailsTab = ({ hostName, router }) => { , ]; - if (hits.length) { + if (hits.length && !isLocalInsightsAdvisor) { const { host_uuid: uuid } = hits[0]; dropdownItems.push(