Sha256: 0f1de6e742e145488f45e3e1753473201664a819846cfc0e3b13f55e9ab8ae2d

Contents?: true

Size: 1.49 KB

Versions: 26

Compression:

Stored size: 1.49 KB

Contents

import React from 'react';
import { post } from 'foremanReact/redux/API';
import { addToast } from 'foremanReact/redux/actions/toasts';
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

26 entries across 26 versions & 1 rubygems

Version Path
foreman_rh_cloud-4.0.36 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.33 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-4.0.35 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.32 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-4.0.32 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-4.0.31 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-4.0.30 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.29 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-4.0.29 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-5.0.29 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.28 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-5.0.28 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-4.0.27 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.26 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-4.0.26 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-4.0.25.1 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.25 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-4.0.25 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.24.1 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-4.0.24.1 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js