Skip to content

Commit

Permalink
Hide the sync recommendations toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Dec 16, 2024
1 parent f8751f0 commit 5dcaff6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 25 deletions.
6 changes: 6 additions & 0 deletions app/controllers/insights_cloud/settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module InsightsCloud
class SettingsController < ::ApplicationController
def show
if SETTINGS[:insights][:use_insights_on_premise]
render json: {
error: _('This Foreman is configured to use Insights on Premise. Syncing to Insights Cloud is disabled.'),
}, status: :unprocessable_entity
return
end
render_setting(:insightsSyncEnabled, :allow_auto_insights_sync)
end

Expand Down
8 changes: 7 additions & 1 deletion lib/foreman_rh_cloud/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ def self.register_scheduled_task(task_class, cronline)

# Adding a sub menu after hosts menu
divider :top_menu, caption: N_('Insights'), parent: :configure_menu
menu :top_menu, :inventory_upload, caption: N_('Inventory Upload'), url: '/foreman_rh_cloud/inventory_upload', url_hash: { controller: :react, action: :index }, parent: :configure_menu
menu :top_menu,
:inventory_upload,
caption: N_('Inventory Upload'),
url: '/foreman_rh_cloud/inventory_upload',
url_hash: { controller: :react, action: :index },
parent: :configure_menu,
if: lambda { !SETTINGS[:insights][:use_insights_on_premise] }

Check failure on line 116 in lib/foreman_rh_cloud/engine.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Style/Lambda: Use the `-> { ... }` lambda literal syntax for single line lambdas.
menu :top_menu, :insights_hits, caption: N_('Recommendations'), url: '/foreman_rh_cloud/insights_cloud', url_hash: { controller: :react, action: :index }, parent: :configure_menu

register_facet InsightsFacet, :insights do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
import React, { Component } from 'react';
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { translate as __ } from 'foremanReact/common/I18n';
import SwitcherPF4 from '../../../common/Switcher/SwitcherPF4';
import './insightsSettings.scss';

class InsightsSettings extends Component {
componentDidMount() {
const { getInsightsSyncSettings } = this.props;
getInsightsSyncSettings();
}
const InsightsSettings = ({
insightsSyncEnabled,
getInsightsSyncSettings,
setInsightsSyncEnabled,
}) => {
const [isOnPrem, setIsOnPrem] = useState(false);
useEffect(() => {
async function fetchData() {
try {
await getInsightsSyncSettings();
} catch (err) {
if (err.cause?.response?.status === 422) {
setIsOnPrem(true);
} else {
throw err;
}
}
}
fetchData();
}, [getInsightsSyncSettings, setInsightsSyncEnabled]);

render() {
const { insightsSyncEnabled, setInsightsSyncEnabled } = this.props;
return (
<div className="insights_settings">
<SwitcherPF4
id="insights_sync_switcher"
label={__('Sync automatically')}
tooltip={__(
'Enable automatic synchronization of Insights recommendations from the Red Hat cloud'
)}
isChecked={insightsSyncEnabled}
onChange={() => setInsightsSyncEnabled(!insightsSyncEnabled)}
/>
</div>
);
}
}
if (isOnPrem) return null;

return (
<div className="insights_settings">
<SwitcherPF4
id="insights_sync_switcher"
label={__('Sync automatically')}
tooltip={__(
'Enable automatic synchronization of Insights recommendations from the Red Hat cloud'
)}
isChecked={insightsSyncEnabled}
onChange={() => setInsightsSyncEnabled(!insightsSyncEnabled)}
/>
</div>
);
};

InsightsSettings.propTypes = {
insightsSyncEnabled: PropTypes.bool.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export const getInsightsSyncSettings = () => async dispatch => {
},
},
});
} catch ({ message }) {
} catch (err) {
const { message } = err;
if (err?.response?.status === 422) {
throw new Error(message, { cause: err });
}
dispatch(
addToast({
sticky: true,
Expand Down

0 comments on commit 5dcaff6

Please sign in to comment.