All Downloads are FREE. Search and download functionalities are using the official Maven repository.

apps.websight-package-manager.web-resources.components.PackageActions.js Maven / Gradle / Ivy

The newest version!
import React from "/apps/websight-atlaskit-esm/web-resources/react.js";
import DropdownMenu, { DropdownItem } from "/apps/websight-atlaskit-esm/web-resources/@atlaskit/dropdown-menu.js";
import { TableRowActionButton } from "/apps/websight-admin/web-resources/Buttons.js";
import ConfirmationModal from "/apps/websight-admin/web-resources/ConfirmationModal.js";
import { TableRowActionButtonsContainer } from "/apps/websight-admin/web-resources/Containers.js";
import PackageService from "../services/PackageService.js";
import * as PackageUtil from "../utils/PackageUtil.js";
import { Filters } from "./ActivityLog.js";
import EditPackageModal from "./modals/EditPackageModal.js";
import InstallPackageModal from "./modals/InstallPackageModal.js";
import SchedulePackageActionsModal from "./modals/SchedulePackageActionsModal.js";
import { fetchApplicableActions } from "/apps/websight-admin/web-resources/utils/ExtraActionsUtil.js";

const getSuggestedAction = packageData => {
  const isBuilt = PackageUtil.isPackageBuilt(packageData);
  const isNotInstalled = !PackageUtil.isPackageInstalled(packageData);
  const isModified = PackageUtil.isPackageModified(packageData);

  if (isBuilt && isNotInstalled && !isModified) {
    return 'install';
  } else if (isModified || !isBuilt) {
    return 'build';
  }
};

export default class PackageActions extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      extraActions: props.extraActions
    };
    this.buildPackage = this.buildPackage.bind(this);
    this.deletePackage = this.deletePackage.bind(this);
    this.dumpCoverage = this.dumpCoverage.bind(this);
    this.installPackage = this.installPackage.bind(this);
    this.showFilters = this.showFilters.bind(this);
    this.uninstallPackage = this.uninstallPackage.bind(this);
  }

  buildPackage(path) {
    PackageService.buildPackage(path, () => {
      this.buildConfirmationModal.close();
      this.props.updateActionState(path, {
        state: 'CHECKING',
        type: 'BUILD'
      }, true);
    }, () => this.buildConfirmationModal.close());
  }

  installPackage(path, advancedOptions, dryRun = false) {
    PackageService.installPackage(path, advancedOptions.acHandling ? advancedOptions.acHandling.value : '', advancedOptions.extractSubpackages, () => {
      this.installConfirmationModal.close();
      this.props.updateActionState(path, {
        state: 'CHECKING',
        type: 'INSTALL'
      }, true);
    }, () => this.installConfirmationModal.close(), dryRun);
  }

  uninstallPackage(path) {
    PackageService.uninstallPackage(path, () => {
      this.uninstallConfirmationModal.close();
      this.props.updateActionState(path, {
        state: 'CHECKING',
        type: 'UNINSTALL'
      }, true);
    }, () => this.uninstallConfirmationModal.close());
  }

  dumpCoverage(path) {
    PackageService.dumpCoverage(path, () => {
      this.props.updateActionState(path, {
        state: 'CHECKING',
        type: 'COVERAGE'
      }, true);
    });
  }

  showFilters() {
    const {
      packageData
    } = this.props;
    const showFiltersLogs = /*#__PURE__*/React.createElement(Filters, {
      name: packageData.name,
      path: packageData.path,
      filters: packageData.filters,
      date: new Date()
    });
    this.props.toggleConsole(packageData.path, true, showFiltersLogs);
  }

  deletePackage() {
    PackageService.deletePackage(this.props.packageData.path, () => {
      this.deleteConfirmationModal.close();
      this.props.refreshPage();
    }, () => this.deleteConfirmationModal.close());
  }

  render() {
    const {
      packageData
    } = this.props;
    const {
      extraActions
    } = this.state;
    const suggestedAction = getSuggestedAction(packageData);
    const isPackageInstalled = PackageUtil.isPackageInstalled(packageData);
    const isPackageBuilt = PackageUtil.isPackageBuilt(packageData);
    return /*#__PURE__*/React.createElement(TableRowActionButtonsContainer, null, /*#__PURE__*/React.createElement(TableRowActionButton, {
      tooltipContent: "Build",
      iconName: "gavel",
      appearance: suggestedAction === 'build' ? 'primary' : 'default',
      onClick: () => this.buildConfirmationModal.open()
    }), /*#__PURE__*/React.createElement(TableRowActionButton, {
      tooltipContent: isPackageInstalled ? 'Reinstall' : 'Install',
      iconName: "play_arrow",
      isDisabled: !isPackageBuilt,
      appearance: suggestedAction === 'install' ? 'primary' : 'default',
      onClick: () => this.installConfirmationModal.open()
    }), /*#__PURE__*/React.createElement(DropdownMenu, {
      trigger: "",
      triggerType: "button",
      appearance: "tall",
      onOpenChange: event => {
        if (event.isOpen) {
          fetchApplicableActions(this.props.extraActions, packageData.path, actions => {
            this.setState({
              extraActions: actions
            });
          });
        }
      }
    }, /*#__PURE__*/React.createElement(DropdownItem, {
      href: packageData.path + '?' + packageData.timestamp,
      isDisabled: !isPackageBuilt
    }, "Download"), /*#__PURE__*/React.createElement(DropdownItem, {
      onClick: () => this.editPackageModal.open()
    }, "Edit"), /*#__PURE__*/React.createElement(DropdownItem, {
      onClick: this.showFilters
    }, "Show Filters"), /*#__PURE__*/React.createElement(DropdownItem, {
      onClick: () => this.dumpCoverage(packageData.path)
    }, "Coverage"), /*#__PURE__*/React.createElement(DropdownItem, {
      isDisabled: !isPackageBuilt,
      onClick: () => this.installPackage(packageData.path, true)
    }, "Test Install"), /*#__PURE__*/React.createElement(DropdownItem, {
      onClick: () => this.uninstallConfirmationModal.open(),
      isDisabled: !isPackageInstalled
    }, "Uninstall"), /*#__PURE__*/React.createElement(DropdownItem, {
      onClick: () => this.deleteConfirmationModal.open()
    }, "Delete"), /*#__PURE__*/React.createElement(DropdownItem, {
      onClick: () => this.schedulePackageActionsModal.open()
    }, "Schedule"), extraActions && extraActions.map((action, index) => {
      return /*#__PURE__*/React.createElement(DropdownItem, {
        key: index,
        onClick: () => action.onClick()
      }, action.label);
    })), extraActions && extraActions.map(action => {
      return action.modal(packageData);
    }), /*#__PURE__*/React.createElement(ConfirmationModal, {
      buttonText: 'Build',
      heading: 'Build package',
      message: /*#__PURE__*/React.createElement(React.Fragment, null, "Do you really want to build this package?", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("b", null, packageData.downloadName)),
      onConfirm: () => this.buildPackage(packageData.path),
      ref: element => this.buildConfirmationModal = element
    }), /*#__PURE__*/React.createElement(InstallPackageModal, {
      packageData: packageData,
      isPackageInstalled: isPackageInstalled,
      onSubmit: this.installPackage,
      ref: element => this.installConfirmationModal = element
    }), /*#__PURE__*/React.createElement(EditPackageModal, {
      packageToEdit: packageData,
      groups: this.props.groups,
      onEditSuccess: () => this.props.refreshPage(),
      ref: element => this.editPackageModal = element
    }), /*#__PURE__*/React.createElement(ConfirmationModal, {
      buttonText: 'Delete',
      heading: 'Delete package',
      appearance: "danger",
      message: /*#__PURE__*/React.createElement(React.Fragment, null, "Are you sure you want to permanently delete package?", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("b", null, packageData.downloadName)),
      onConfirm: this.deletePackage,
      ref: element => this.deleteConfirmationModal = element
    }), /*#__PURE__*/React.createElement(ConfirmationModal, {
      buttonText: 'Uninstall',
      heading: 'Uninstall package',
      message: /*#__PURE__*/React.createElement(React.Fragment, null, "Do you really want to uninstall this package?", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("b", null, packageData.downloadName)),
      onConfirm: () => this.uninstallPackage(packageData.path),
      ref: element => this.uninstallConfirmationModal = element
    }), /*#__PURE__*/React.createElement(SchedulePackageActionsModal, {
      packagePath: packageData.path,
      packageName: packageData.downloadName,
      onScheduleSuccess: () => this.props.refreshPage(),
      ref: element => this.schedulePackageActionsModal = element
    }));
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy