Sha256: ce3a61f6228fe662e66c3a86187432c50733f597e0b1ce15b4c0d45f4a60c321

Contents?: true

Size: 1.96 KB

Versions: 62

Compression:

Stored size: 1.96 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 = ({
  canEdit,
  id,
  name,
  availableActions: { resumable, cancellable, stoppable },
  taskActions,
}) => {
  const buttons = [];
  const isTitle = canEdit && !(resumable || cancellable || stoppable);
  const title = isTitle ? __('Task cannot be canceled') : undefined;
  if (canEdit) {
    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 = {
  canEdit: PropTypes.bool,
  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,
};

ActionButton.defaultProps = {
  canEdit: false,
};

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-10.0.1 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-10.0.0 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-9.2.3 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-9.2.2 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-9.2.1 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-9.2.0 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-9.1.1 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-9.0.4 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-9.1.0 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-9.0.2 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-9.0.1 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-8.3.3 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-9.0.0 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-8.2.1 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-8.1.4 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-8.3.2 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-8.3.1 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-8.1.3 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js
foreman-tasks-8.3.0 webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js