apps.websight-package-manager.web-resources.components.modals.UploadPackageModal.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of websight-package-manager-view Show documentation
Show all versions of websight-package-manager-view Show documentation
Package Manager View module is responsible for view part of Package Manager.
The newest version!
import React from "/apps/websight-atlaskit-esm/web-resources/react.js";
import Button, { ButtonGroup } from "/apps/websight-atlaskit-esm/web-resources/@atlaskit/button.js";
import { Checkbox } from "/apps/websight-atlaskit-esm/web-resources/@atlaskit/checkbox.js";
import ModalDialog, { ModalTransition } from "/apps/websight-atlaskit-esm/web-resources/@atlaskit/modal-dialog.js";
import ConfirmationModal from "/apps/websight-admin/web-resources/ConfirmationModal.js";
import FilePicker from "/apps/websight-admin/web-resources/FilePicker.js";
import Form, { FormFooter } from "/apps/websight-rest-atlaskit-client/web-resources/js/Form.js";
import PackageService from "../../services/PackageService.js";
const ACTION_UPLOAD = 'upload';
const ACTION_UPLOAD_AND_INSTALL = 'upload-and-install';
export default class UploadPackageModal extends React.Component {
constructor(props) {
super(props);
this.state = {
isOpen: false,
fileName: null
};
this.open = this.open.bind(this);
this.close = this.close.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.onUploadFormSubmit = this.onUploadFormSubmit.bind(this);
this.onUploadAndInstallFormSubmit = this.onUploadAndInstallFormSubmit.bind(this);
this.onSubmitSuccess = this.onSubmitSuccess.bind(this);
}
open() {
this.setState({
isOpen: true
});
}
close() {
this.setState({
isOpen: false,
fileName: null
});
}
onSubmit(...submitArgs) {
if (this.actionClicked === ACTION_UPLOAD_AND_INSTALL) {
this.onUploadAndInstallFormSubmit(...submitArgs);
} else {
this.onUploadFormSubmit(...submitArgs);
}
}
onUploadAndInstallFormSubmit(requestData, onSuccess, onValidationFailure, onComplete) {
if (this.props.onUploadAndInstallSuccess) {
const originalOnSuccess = onSuccess;
onSuccess = data => {
originalOnSuccess(data);
this.props.onUploadAndInstallSuccess(data.entity.path);
};
}
const onFailure = data => {
onComplete(data);
if (data.entity && data.entity.firstActionDone) {
this.onSubmitSuccess();
if (this.props.onUploadSuccess) {
this.props.onUploadSuccess();
}
}
};
PackageService.uploadAndInstallPackage(requestData, onSuccess, onValidationFailure, onFailure, onComplete);
}
onUploadFormSubmit(requestData, onSuccess, onValidationFailure, onComplete) {
if (this.props.onUploadSuccess) {
const originalOnSuccess = onSuccess;
onSuccess = data => {
originalOnSuccess(data);
this.props.onUploadSuccess(data.entity.path);
};
}
PackageService.uploadPackage(requestData, onSuccess, onValidationFailure, onComplete);
}
onSubmitSuccess() {
this.close();
}
render() {
const form = /*#__PURE__*/React.createElement(Form, {
ref: element => this.form = element,
onSubmit: this.onSubmit,
onSuccess: this.onSubmitSuccess
}, ({
submitted
}) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FilePicker, {
name: "file",
placeholder: "Browse Package File",
onChange: event => {
const file = event.target.files[0];
const fileName = file ? file.name : null;
this.setState({
fileName: fileName
});
}
}), /*#__PURE__*/React.createElement(Checkbox, {
hideLabel: true,
label: "Overwrite existing package",
name: "force",
value: "true"
}), /*#__PURE__*/React.createElement(FormFooter, null, /*#__PURE__*/React.createElement(ButtonGroup, null, /*#__PURE__*/React.createElement(Button, {
appearance: "primary",
type: "submit",
isLoading: submitted && this.actionClicked === ACTION_UPLOAD_AND_INSTALL,
isDisabled: !this.state.fileName || submitted && this.actionClicked !== ACTION_UPLOAD_AND_INSTALL,
onClick: event => {
event.preventDefault();
this.uploadAndInstallConfirmationModal.open();
}
}, "Upload & Install"), /*#__PURE__*/React.createElement(Button, {
appearance: "default",
type: "submit",
isLoading: submitted && this.actionClicked === ACTION_UPLOAD,
isDisabled: !this.state.fileName || submitted && this.actionClicked !== ACTION_UPLOAD,
onClick: () => {
this.actionClicked = ACTION_UPLOAD;
}
}, "Upload"), /*#__PURE__*/React.createElement(Button, {
appearance: "subtle",
onClick: this.close,
isDisabled: submitted
}, "Cancel"))), /*#__PURE__*/React.createElement(ConfirmationModal, {
buttonText: "Upload & Install",
heading: "Upload & Install package",
message: "Do you really want to upload and install this package?",
onConfirm: () => {
this.actionClicked = ACTION_UPLOAD_AND_INSTALL;
this.form.submit();
this.uploadAndInstallConfirmationModal.close();
},
ref: element => this.uploadAndInstallConfirmationModal = element
})));
return /*#__PURE__*/React.createElement(ModalTransition, null, this.state.isOpen && /*#__PURE__*/React.createElement(ModalDialog, {
heading: "Upload Package",
onClose: this.close
}, form));
}
}