diff --git a/package.json b/package.json index 65dc3fe..3b53434 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "@fortawesome/fontawesome-svg-core": "^1.2.35", "@fortawesome/free-solid-svg-icons": "^5.15.3", "@fortawesome/react-fontawesome": "^0.1.14", + "@rjsf/core": "^2.5.1", "babel-runtime": "^6.26.0", "bootstrap": "^4.6.0", "classnames": "^2.3.1", diff --git a/src/common/dialogs/new-dialog.js b/src/common/dialogs/new-dialog.js index 8c7b44f..461f9ac 100644 --- a/src/common/dialogs/new-dialog.js +++ b/src/common/dialogs/new-dialog.js @@ -38,8 +38,6 @@ class NewDialog extends React.Component { } handleChange(e) { - console.log(e) - this.setState({ [e.target.id]: e.target.value }); } diff --git a/src/componentconfig/edit-config.js b/src/componentconfig/edit-config.js index 2ee19ec..63d9ded 100644 --- a/src/componentconfig/edit-config.js +++ b/src/componentconfig/edit-config.js @@ -16,11 +16,14 @@ ******************************************************************************/ import React from 'react'; -import { Form } from 'react-bootstrap'; +import Form from "@rjsf/core"; + +import { Form as BForm } from 'react-bootstrap'; import { Multiselect } from 'multiselect-react-dropdown' import Dialog from '../common/dialogs/dialog'; import ParametersEditor from '../common/parameters-editor'; + class EditConfigDialog extends React.Component { valid = false; @@ -30,6 +33,8 @@ class EditConfigDialog extends React.Component { name: '', icID: '', startParameters: {}, + formData: {}, + startparamTemplate: null, selectedFiles: [] // list of selected files {name, id}, this is not the fileIDs list of the config! }; } @@ -44,21 +49,21 @@ class EditConfigDialog extends React.Component { if (this.state.icID !== '' && this.props.config.icID !== parseInt(this.state.icID)) { data.icID = parseInt(this.state.icID, 10); } - if(this.state.startParameters !== {} && - JSON.stringify(this.props.config.startParameters) !== JSON.stringify(this.state.startParameters)){ + if (this.state.startParameters !== {} && + JSON.stringify(this.props.config.startParameters) !== JSON.stringify(this.state.startParameters)) { data.startParameters = this.state.startParameters; } let IDs = [] - for(let e of this.state.selectedFiles){ + for (let e of this.state.selectedFiles) { IDs.push(e.id) } - if(this.props.config.fileIDs !== null && this.props.config.fileIDs !== undefined) { + if (this.props.config.fileIDs !== null && this.props.config.fileIDs !== undefined) { if (JSON.stringify(IDs) !== JSON.stringify(this.props.config.fileIDs)) { data.fileIDs = IDs; } } - else{ + else { data.fileIDs = IDs } @@ -68,6 +73,9 @@ class EditConfigDialog extends React.Component { } else { this.props.onClose(); } + + this.setState({ startparamTemplate: null }) + this.valid = false } handleChange(e) { @@ -75,9 +83,28 @@ class EditConfigDialog extends React.Component { this.valid = this.isValid() } + changeIC(id) { + let schema = null; + if (this.props.ics) { + let currentIC = this.props.ics.find(ic => ic.id === parseInt(id, 10)); + if (currentIC) { + if (currentIC.startparameterschema.hasOwnProperty('type')) { + schema = currentIC.startparameterschema; + } + } + } + + this.setState({ + icID: id, + startparamTemplate: schema, + }); + + this.valid = this.isValid() + } + handleParameterChange(data) { if (data) { - this.setState({startParameters: data}); + this.setState({ startParameters: data }); } this.valid = this.isValid() } @@ -101,24 +128,39 @@ class EditConfigDialog extends React.Component { // determine list of selected files incl id and filename let selectedFiles = [] - if(this.props.config.fileIDs !== null && this.props.config.fileIDs !== undefined) { + if (this.props.config.fileIDs !== null && this.props.config.fileIDs !== undefined) { for (let selectedFileID of this.props.config.fileIDs) { for (let file of this.props.files) { if (file.id === selectedFileID) { - selectedFiles.push({name: file.name, id: file.id}) + selectedFiles.push({ name: file.name, id: file.id }) } } } } + let schema = null; + if (this.props.ics && this.props.config.icID) { + let currentIC = this.props.ics.find(ic => ic.id === parseInt(this.props.config.icID, 10)); + if (currentIC) { + if (currentIC.startparameterschema.hasOwnProperty('type')) { + schema = currentIC.startparameterschema; + } + } + } + this.setState({ name: this.props.config.name, icID: this.props.config.icID, startParameters: this.props.config.startParameters, selectedFiles: selectedFiles, + startparamTemplate: schema, }); } + handleFormChange({formData}) { + this.setState({formData: formData, startParameters: formData}) + this.valid = this.isValid() + } render() { const ICOptions = this.props.ics.map(s => @@ -126,9 +168,9 @@ class EditConfigDialog extends React.Component { ); let configFileOptions = []; - for(let file of this.props.files) { + for (let file of this.props.files) { configFileOptions.push( - {name: file.name, id: file.id} + { name: file.name, id: file.id } ); } @@ -141,29 +183,29 @@ class EditConfigDialog extends React.Component { onReset={() => this.resetState()} valid={this.valid} > -