Sha256: 1353f796fdb5b6d7da445618254f6c18e40e9e257a5784a68ed64d900926e417

Contents?: true

Size: 1.49 KB

Versions: 50

Compression:

Stored size: 1.49 KB

Contents

import React from 'react';
import { post } from 'foremanReact/redux/API';
import { addToast } from 'foremanReact/components/ToastsList';
import { translate as __ } from 'foremanReact/common/I18n';
import { inventoryUrl } from '../../../../ForemanInventoryHelpers';
import Toast from './components/Toast';
import {
  INVENTORY_SYNC,
  INVENTORY_SYNC_TASK_UPDATE,
} from './SyncButtonConstants';
import {
  setupTaskPolling,
  taskRelatedToast,
} from '../../../../../common/ForemanTasks';

export const handleSync = () => dispatch => {
  dispatch(
    post({
      key: INVENTORY_SYNC,
      url: inventoryUrl('tasks'),
      handleSuccess: ({
        data: {
          task: { id },
        },
      }) => {
        dispatch(setupInventorySyncTaskPolling(id, dispatch));
        return dispatch(
          taskRelatedToast(id, 'info', __('Inventory sync has started:'))
        );
      },
      errorToast: inventorySyncErrorToast,
    })
  );
};

export const setupInventorySyncTaskPolling = (id, dispatch) =>
  setupTaskPolling({
    taskId: id,
    key: INVENTORY_SYNC_TASK_UPDATE,
    onTaskSuccess: ({
      output: {
        host_statuses: { sync, disconnect },
      },
    }) =>
      dispatch(
        addToast({
          sticky: true,
          type: 'success',
          message: <Toast syncHosts={sync} disconnectHosts={disconnect} />,
        })
      ),
    dispatch,
  });

const inventorySyncErrorToast = message =>
  `${__('Inventory sync has failed: ')} ${message.response?.data?.message ||
    message}`;

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
foreman_rh_cloud-11.1.0 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-10.0.3 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-11.0.3 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-9.0.59 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-11.0.2 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-11.0.1 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-11.0.0 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-9.0.58 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-10.0.2 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-9.0.57 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-10.0.1 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-9.0.56 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-9.0.55 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-9.0.54 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-9.0.53 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-9.0.52 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-8.0.52 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-9.0.51 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-8.0.51 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-7.0.48 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js