diff --git a/packages/ketcher-react/src/script/ui/component/view/savebutton.jsx b/packages/ketcher-react/src/script/ui/component/view/savebutton.jsx index 2bf820eb36..872c924861 100644 --- a/packages/ketcher-react/src/script/ui/component/view/savebutton.jsx +++ b/packages/ketcher-react/src/script/ui/component/view/savebutton.jsx @@ -23,6 +23,7 @@ const SaveButton = props => { const { server, filename = 'unnamed', + outputFormat, data, type, mode = 'saveFile', @@ -59,7 +60,7 @@ const SaveButton = props => { const saveImage = () => { const ketcherInstance = getKetcherInstance() ketcherInstance - .generateImageAsync(data, { outputFormat: 'svg' }) + .generateImageAsync(data, { outputFormat }) .then(blob => { saveAs(blob, filename) onSave() diff --git a/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx b/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx index d30ee59f4c..b030fac3ce 100644 --- a/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx +++ b/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx @@ -21,6 +21,9 @@ import { getPropertiesByFormat, formatProperties } from 'ketcher-core' + +import { molfileManager } from '../../../../../../chem/molfile' +import smilesManager from '../../../../../../chem/smiles' import graphManager from '../../../../../../format/chemGraph' import * as structFormat from '../../../../../data/convert/structConverter' import { saveUserTmpl } from '../../../../../state/templates' @@ -29,6 +32,8 @@ import { check } from '../../../../../state/server' import { Dialog } from '../../../../components' import Form, { Field } from '../../../../../component/form/form' import SaveButton from '../../../../../component/view/savebutton' +import Tabs from '../../../../../component/view/Tabs' +import SaveImageTab from './SaveImageTab' import classes from './Save.module.less' @@ -60,9 +65,10 @@ const saveSchema = { class SaveDialog extends Component { constructor(props) { super(props) - this.state = { disableControls: false } + this.state = { imageFormat: 'svg', tabIndex: 0 } this.isRxn = this.props.struct.hasRxnArrow() this.textAreaRef = createRef() + this.formContainerRef = createRef() const formats = [this.isRxn ? 'rxn' : 'mol', 'smiles', 'graph'] if (this.props.server) formats.push( @@ -91,6 +97,13 @@ class SaveDialog extends Component { componentDidMount() { const { checkOptions } = this.props.checkState this.props.onCheck(checkOptions) + if (this.formContainerRef.current) { + const { + width, + height + } = this.formContainerRef.current.getBoundingClientRect() + this.setState({ dimensions: { width, height } }) + } } showStructWarningMessage = format => { @@ -99,35 +112,33 @@ class SaveDialog extends Component { } changeType = type => { - this.setState({ disableControls: true }) - const { struct, server, options, formState } = this.props - const factory = new FormatterFactory(server, graphManager) + const factory = new FormatterFactory( + server, + graphManager, + molfileManager, + smilesManager + ) const service = factory.create(type, options) - return service - .getStructureFromStructAsync(struct) - .then( - structStr => { - this.setState({ structStr }) - setTimeout(() => { - if (this.textAreaRef.current) { - this.textAreaRef.current.select() - } - }, 10) // TODO: remove hack - }, - e => { - //TODO: add error handler call - alert(e.message) - this.props.onResetForm(formState) - return e - } - ) - .finally(() => { - this.setState({ disableControls: false }) - }) + return service.getStructureFromStructAsync(struct).then( + structStr => { + this.setState({ structStr }) + setTimeout(() => { + if (this.textAreaRef.current) { + this.textAreaRef.current.select() + } + }, 10) // TODO: remove hack + }, + e => { + //TODO: add error handler call + alert(e.message) + this.props.onResetForm(formState) + return e + } + ) } getWarnings = format => { @@ -157,74 +168,118 @@ class SaveDialog extends Component { return warnings } - render() { - const { structStr, disableControls } = this.state + changeTab = tabIndex => { + this.setState({ tabIndex }) + } + + changeImageFormat = imageFormat => { + this.setState({ imageFormat }) + } + + renderSaveFile = () => { const formState = Object.assign({}, this.props.formState) delete formState.moleculeErrors const { filename, format } = formState.result const warnings = this.getWarnings(format) + const { structStr } = this.state + return ( +