Sha256: 1e4fa333bcfa35414de937f9ca22385fa50b24b0acff02861ca5e51b5f7861ec

Contents?: true

Size: 1.78 KB

Versions: 3

Compression:

Stored size: 1.78 KB

Contents

import React from 'react';
import PropTypes from 'prop-types';
import { translate as __ } from 'foremanReact/common/I18n';
import { ActionButtons } from 'foremanReact/components/common/ActionButtons/ActionButtons';

export const ActionButton = ({
  id,
  name,
  availableActions: { resumable, cancellable, stoppable },
  taskActions,
}) => {
  const buttons = [];
  const isTitle = !(resumable || cancellable || stoppable);
  const title = isTitle ? __('Task cannot be canceled') : undefined;
  if (resumable) {
    buttons.push({
      title: __('Resume'),
      action: {
        disabled: !resumable,
        onClick: () => taskActions.resumeTask(id, name),
        id: `task-resume-button-${id}`,
      },
    });
  }
  if (cancellable || (!stoppable && !resumable)) {
    // Cancel is the default button that should be shown if no task action can be done
    buttons.push({
      title: __('Cancel'),
      action: {
        disabled: !cancellable,
        onClick: () => taskActions.cancelTask(id, name),
        id: `task-cancel-button-${id}`,
      },
    });
  }

  if (stoppable) {
    buttons.push({
      title: __('Force Cancel'),
      action: {
        disabled: !stoppable,
        onClick: () => taskActions.forceCancelTask(id, name),
        id: `task-force-cancel-button-${id}`,
      },
    });
  }
  return (
    <span title={title}>
      <ActionButtons buttons={buttons} />
    </span>
  );
};

ActionButton.propTypes = {
  id: PropTypes.string.isRequired,
  name: PropTypes.string.isRequired,
  availableActions: PropTypes.shape({
    cancellable: PropTypes.bool,
    resumable: PropTypes.bool,
    stoppable: PropTypes.bool,
  }).isRequired,
  taskActions: PropTypes.shape({
    cancelTask: PropTypes.func,
    resumeTask: PropTypes.func,
    forceCancelTask: PropTypes.func,
  }).isRequired,
};

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman-tasks-2.0.1 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-2.0.0 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-1.2.0 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js