From 1ab89459abb4edc20be72b7659bc9e9d3330478d Mon Sep 17 00:00:00 2001 From: amirrr <6696894+amirrr@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:44:31 +0100 Subject: [PATCH] converted widgets EditFileWidgetControl Signed-off-by: iripiri --- .../edit-widget/edit-widget-file-control.js | 73 ------------------- .../edit-widget/edit-widget-file-control.jsx | 72 ++++++++++++++++++ 2 files changed, 72 insertions(+), 73 deletions(-) delete mode 100644 src/widget/edit-widget/edit-widget-file-control.js create mode 100644 src/widget/edit-widget/edit-widget-file-control.jsx diff --git a/src/widget/edit-widget/edit-widget-file-control.js b/src/widget/edit-widget/edit-widget-file-control.js deleted file mode 100644 index 6f7c35d..0000000 --- a/src/widget/edit-widget/edit-widget-file-control.js +++ /dev/null @@ -1,73 +0,0 @@ -/** - * This file is part of VILLASweb. - * - * VILLASweb is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * VILLASweb is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with VILLASweb. If not, see . - ******************************************************************************/ - -import React from 'react'; -import { Form } from 'react-bootstrap'; - -class EditFileWidgetControl extends React.Component { - - constructor(props) { - super(props); - - this.state = { - files: [], - }; - } - - static getDerivedStateFromProps(props, state){ - return { - files: props.files.filter(file => file.type.includes(props.type)) - }; - } - - handleFileChange(e){ - this.props.handleChange({ target: { id: this.props.controlId, value: e.target.value } }); - } - - render() { - - let parts = this.props.controlId.split('.'); - let isCustomProperty = true; - if(parts.length === 1){ - isCustomProperty = false; - } - - let fileOptions = []; - if (this.state.files.length > 0){ - fileOptions.push( - - ) - fileOptions.push(this.state.files.map((file, index) => ( - - ))) - } else { - fileOptions = - } - - return
- - File - this.handleFileChange(e)}>{fileOptions} - -
; - } -} - -export default EditFileWidgetControl; diff --git a/src/widget/edit-widget/edit-widget-file-control.jsx b/src/widget/edit-widget/edit-widget-file-control.jsx new file mode 100644 index 0000000..a9af8dd --- /dev/null +++ b/src/widget/edit-widget/edit-widget-file-control.jsx @@ -0,0 +1,72 @@ +/** + * This file is part of VILLASweb. + * + * VILLASweb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VILLASweb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VILLASweb. If not, see . + ******************************************************************************/ +import React, { useState, useEffect } from "react"; +import { Form } from "react-bootstrap"; + +const EditFileWidgetControl = (props) => { + const [files, setFiles] = useState([]); + + useEffect(() => { + setFiles(props.files.filter((file) => file.type.includes(props.type))); + }, [props.files, props.type]); + + const handleFileChange = (e) => { + props.handleChange({ + target: { id: props.controlId, value: e.target.value }, + }); + }; + + const parts = props.controlId.split("."); + const isCustomProperty = parts.length !== 1; + + let fileOptions; + if (files.length > 0) { + fileOptions = [ + , + ...files.map((file, index) => ( + + )), + ]; + } else { + fileOptions = ; + } + + return ( +
+ + File + + {fileOptions} + + +
+ ); +}; + +export default EditFileWidgetControl;