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-5.0.39 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.38 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.35 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.37 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.36 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.35 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.34 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.33 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-3.0.32 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.32 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.32 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.31 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.31 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.30 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.30 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-3.0.29 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-4.0.29 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.29 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-3.0.28 webpack/InsightsCloudSync/InsightsCloudSyncActions.js
foreman_rh_cloud-5.0.28 webpack/InsightsCloudSync/InsightsCloudSyncActions.js