Sha256: d8da4b70e7554862e7e325d92c403eaf8afffda422fea5f6284b2e441792ac57

Contents?: true

Size: 1.44 KB

Versions: 74

Compression:

Stored size: 1.44 KB

Contents

import { post } from 'foremanReact/redux/API';
import { translate as __ } from 'foremanReact/common/I18n';
import { insightsCloudUrl } from './InsightsCloudSyncHelpers';
import {
  INSIGHTS_CLOUD_SYNC,
  INSIGHTS_CLOUD_SYNC_TASK,
} from './InsightsCloudSyncConstants';
import { setupTaskPolling, taskRelatedToast } from '../common/ForemanTasks';

export const syncInsights = (fetchInsights, query) => dispatch =>
  dispatch(
    post({
      key: INSIGHTS_CLOUD_SYNC,
      url: insightsCloudUrl('tasks'),
      handleSuccess: ({
        data: {
          task: { id },
        },
      }) => {
        dispatch(syncInsightsStartedToast(id));
        dispatch(setupInsightsTaskPolling(id, fetchInsights, query, dispatch));
      },
      errorToast: error => syncInsightsError(error),
    })
  );

const syncInsightsError = error =>
  `${__('Recommendation sync has failed: ')} ${error}`;

const syncInsightsStartedToast = taskId =>
  taskRelatedToast(taskId, 'info', __('Recommendation sync has started: '));

const setupInsightsTaskPolling = (taskId, fetchInsights, query, dispatch) =>
  setupTaskPolling({
    taskId,
    key: INSIGHTS_CLOUD_SYNC_TASK,
    onTaskSuccess: () => {
      fetchInsights({ query, page: 1 });
      dispatch(
        taskRelatedToast(
          taskId,
          'success',
          __('Recommendations synced successfully')
        )
      );
    },
    taskErrorMessage: data => syncInsightsError(data.humanized.errors),
    dispatch,
  });

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
foreman_rh_cloud-4.0.27 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-3.0.26 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.26 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.25.1 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-3.0.25 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.25 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-3.0.24.1 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.24.1 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-3.0.24 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.24 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-3.0.23 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.23 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-3.0.22 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.22 webpack/InsightsCloudSync/InsightsCloudSyncActions.js