Skip to content

Commit

Permalink
Hide more stuff per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Jan 9, 2025
1 parent 5df20ca commit 24e02c9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 22 deletions.
1 change: 1 addition & 0 deletions lib/insights_cloud/async/insights_full_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
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 = ({
insightsSyncEnabled,
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 (
<div className="insights_settings">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<DropdownItem key="recommendation-url">
<a href={recommendationUrl} target="_blank" rel="noopener noreferrer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -34,6 +35,7 @@ export const modifySelectedRows = (
selected: selectedIds[id] || (disableCheckbox && showSelectAllAlert),
recommendationUrl: results_url,
accessRHUrl: solution_url,
isLocalInsightsAdvisor: is_local_insights_advisor,
};
}
);
Expand Down
11 changes: 9 additions & 2 deletions webpack/InsightsCloudSync/Components/ToolbarDropdown.js
Original file line number Diff line number Diff line change
@@ -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 = [
<DropdownItem
key="recommendation-manual-sync"
onClick={onRecommendationSync}
>
{__('Sync recommendations')}
</DropdownItem>,
];
const cloudItems = [
<DropdownItem key="cloud-advisor-systems-link">
<a
href={redHatAdvisorSystems()}
Expand All @@ -26,6 +30,9 @@ const ToolbarDropdown = ({ onRecommendationSync }) => {
</a>
</DropdownItem>,
];
const dropdownItems = isLocalInsightsAdvisor
? baseItems
: baseItems.concat(cloudItems);
return (
<Dropdown
className="title-dropdown"
Expand Down
31 changes: 19 additions & 12 deletions webpack/InsightsCloudSync/InsightsCloudSync.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import PageLayout from 'foremanReact/routes/common/PageLayout/PageLayout';
import InsightsHeader from './Components/InsightsHeader';
Expand All @@ -13,7 +13,10 @@ import Pagination from './Components/InsightsTable/Pagination';
import ToolbarDropdown from './Components/ToolbarDropdown';
import InsightsSettings from './Components/InsightsSettings';

export const InsightsConfigContext = React.createContext();

const InsightsCloudSync = ({ syncInsights, query, fetchInsights }) => {
const [isLocalInsightsAdvisor, setIsLocalInsightsAdvisor] = useState(false);
const onRecommendationSync = () => syncInsights(fetchInsights, query);
const toolbarButtons = (
<>
Expand All @@ -29,18 +32,22 @@ const InsightsCloudSync = ({ syncInsights, query, fetchInsights }) => {

return (
<div className="rh-cloud-insights">
<InsightsSettings />
<PageLayout
searchable
searchProps={INSIGHTS_SEARCH_PROPS}
onSearch={nextQuery => fetchInsights({ query: nextQuery, page: 1 })}
header={INSIGHTS_SYNC_PAGE_TITLE}
toolbarButtons={toolbarButtons}
searchQuery={query}
beforeToolbarComponent={<InsightsHeader />}
<InsightsConfigContext.Provider
value={{ isLocalInsightsAdvisor, setIsLocalInsightsAdvisor }}
>
<InsightsTable />
</PageLayout>
<InsightsSettings />
<PageLayout
searchable
searchProps={INSIGHTS_SEARCH_PROPS}
onSearch={nextQuery => fetchInsights({ query: nextQuery, page: 1 })}
header={INSIGHTS_SYNC_PAGE_TITLE}
toolbarButtons={toolbarButtons}
searchQuery={query}
beforeToolbarComponent={<InsightsHeader />}
>
<InsightsTable />
</PageLayout>
</InsightsConfigContext.Provider>
</div>
);
};
Expand Down
6 changes: 4 additions & 2 deletions webpack/InsightsHostDetailsTab/NewHostDetailsTab.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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]);

Expand All @@ -41,7 +43,7 @@ const NewHostDetailsTab = ({ hostName, router }) => {
</DropdownItem>,
];

if (hits.length) {
if (hits.length && !isLocalInsightsAdvisor) {
const { host_uuid: uuid } = hits[0];
dropdownItems.push(
<DropdownItem key="insights-advisor-link" ouiaId="insights-advisor-link">
Expand Down

0 comments on commit 24e02c9

Please sign in to comment.