{"size": 1985, "ext": "js", "max_stars_repo_path": "awx/ui/src/screens/ManagementJob/ManagementJobList/LaunchManagementPrompt.js", "max_stars_repo_name": "DamoR25/awxnew", "max_stars_repo_stars_event_min_datetime": "2017-09-07T04:56:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T13:56:17.000Z", "max_issues_repo_path": "awx/ui/src/screens/ManagementJob/ManagementJobList/LaunchManagementPrompt.js", "max_issues_repo_name": "DamoR25/awxnew", "max_issues_repo_issues_event_min_datetime": "2017-09-07T09:30:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T20:28:01.000Z", "max_forks_repo_path": "awx/ui_next/src/screens/ManagementJob/ManagementJobList/LaunchManagementPrompt.js", "max_forks_repo_name": "TinLe/awx", "max_forks_repo_forks_event_min_datetime": "2017-09-07T04:14:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T23:53:09.000Z"}
{"max_stars_count": 11396, "max_issues_count": 11046, "max_forks_count": 3592, "avg_line_length": 23.9156626506, "max_line_length": 80, "alphanum_fraction": 0.5435768262}
import React, { useState } from 'react';

import { t } from '@lingui/macro';
import { Button, TextInput, Tooltip } from '@patternfly/react-core';
import { RocketIcon } from '@patternfly/react-icons';

import AlertModal from 'components/AlertModal';

const MAX_RETENTION = 99999;

const clamp = (val, min, max) => {
  if (val < min) {
    return min;
  }
  if (val > max) {
    return max;
  }
  return val;
};

function LaunchManagementPrompt({
  isOpen,
  isLoading,
  onClick,
  onClose,
  onConfirm,
  defaultDays,
}) {
  const [dataRetention, setDataRetention] = useState(defaultDays);
  return (
    <>
      <Tooltip content={t`Launch management job`} position="top">
        <Button
          aria-label={t`Launch management job`}
          variant="plain"
          onClick={onClick}
          isDisabled={isLoading}
        >
          <RocketIcon />
        </Button>
      </Tooltip>
      <AlertModal
        isOpen={isOpen}
        variant="info"
        onClose={onClose}
        title={t`Launch management job`}
        label={t`Launch management job`}
        actions={[
          <Button
            id="launch-job-confirm-button"
            key="delete"
            variant="primary"
            isDisabled={isLoading}
            aria-label={t`Launch`}
            onClick={() => onConfirm(dataRetention)}
          >
            {t`Launch`}
          </Button>,
          <Button
            id="launch-job-cancel-button"
            key="cancel"
            variant="link"
            aria-label={t`Cancel`}
            onClick={onClose}
          >
            {t`Cancel`}
          </Button>,
        ]}
      >
        {t`Set how many days of data should be retained.`}
        <TextInput
          value={dataRetention}
          type="number"
          onChange={(value) => setDataRetention(clamp(value, 0, MAX_RETENTION))}
          aria-label={t`Data retention period`}
        />
      </AlertModal>
    </>
  );
}

export default LaunchManagementPrompt;
