From f8a4dd406b80930f734e761b7e6cb36ac4092017 Mon Sep 17 00:00:00 2001 From: Flaminia Cavallo Date: Mon, 14 Oct 2024 11:18:58 +0200 Subject: [PATCH] feat: add option to enter custom text to data sets --- src/config/field-overrides/dataSet.js | 134 ++++++++++++++++++++------ src/i18n/i18n_module_en.properties | 3 + webpack.config.js | 2 +- 3 files changed, 106 insertions(+), 33 deletions(-) diff --git a/src/config/field-overrides/dataSet.js b/src/config/field-overrides/dataSet.js index b43624c25..0a341b160 100644 --- a/src/config/field-overrides/dataSet.js +++ b/src/config/field-overrides/dataSet.js @@ -7,12 +7,13 @@ import Checkbox from '../../forms/form-fields/check-box'; import {RadioButton, RadioButtonGroup} from "material-ui/RadioButton"; import addD2Context from 'd2-ui/lib/component-helpers/addD2Context'; import log from "loglevel"; +import TextField from "material-ui/TextField/TextField"; class RenderAsTabsSettings extends React.Component { constructor(props, context) { super(props); this.state = { - displayOptions: this.parseDisplayOptions() + displayOptions: this.parseDisplayOptions(), }; this.translate = context.d2.i18n.getTranslation.bind( context.d2.i18n @@ -30,18 +31,18 @@ class RenderAsTabsSettings extends React.Component { } } - updateTabsDirection = (tabsDirection) => { - const newDisplayOptions = { - ...this.state.displayOptions, - tabsDirection - } + updateDisplayOption = (newDisplayOptions) => { this.setState({displayOptions: newDisplayOptions}); this.props.model.displayOptions = JSON.stringify(newDisplayOptions) } onDisplayOptionsChanged = (event) => { const tabsDirection = event.target.value - this.updateTabsDirection(tabsDirection) + const newDisplayOptions = { + ...this.state.displayOptions, + tabsDirection + } + this.updateDisplayOption(newDisplayOptions) } onRenderAsTabsChanged = (event) => { @@ -52,39 +53,108 @@ class RenderAsTabsSettings extends React.Component { : undefined this.props.onChange({ target: { value: renderAsTabs } }); - this.updateTabsDirection(tabsDirection) + const newDisplayOptions = { + ...this.state.displayOptions, + tabsDirection + } + this.updateDisplayOption(newDisplayOptions) + } + + onAddCustomTextChanged = (event) => { + const addCustomText = event.target.value + const customText = + addCustomText + ? {header: undefined, subheader: undefined} + : undefined + + const newDisplayOptions = { + ...this.state.displayOptions, + customText + } + this.updateDisplayOption(newDisplayOptions) + } + + + onCustomTextHeaderChanged = (event) => { + const customText = + {header: event.target.value, subheader: this.state.displayOptions.customText.subheader || undefined} + + const newDisplayOptions = { + ...this.state.displayOptions, + customText + } + this.updateDisplayOption(newDisplayOptions) + } + + onCustomTextSubheaderChanged = (event) => { + const customText = + {header: this.state.displayOptions.customText.header || undefined, subheader: event.target.value} + + const newDisplayOptions = { + ...this.state.displayOptions, + customText + } + this.updateDisplayOption(newDisplayOptions) } render() { const state = this.state; const props = this.props; + const cssStyles = { + display: 'flex', + flexDirection: 'column' + }; return
- - {props.value && - - - + - } + {props.value && + + + + } +
+ + {state.displayOptions && state.displayOptions.customText && +
+ + +
} } } diff --git a/src/i18n/i18n_module_en.properties b/src/i18n/i18n_module_en.properties index 2dc211e6f..e47630673 100644 --- a/src/i18n/i18n_module_en.properties +++ b/src/i18n/i18n_module_en.properties @@ -626,6 +626,9 @@ render_options_as_radio=Render options as radio render_as_tabs=Render sections as tabs horizontal=Horizontal vertical=Vertical +add_custom_text=Add custom text +header=Header +subheader=Sub-header render_horizontally=Render vertically compulsory_fields_complete_only=Complete allowed only if compulsory fields are filled auto_save_data_entry_forms=Auto-save data entry forms diff --git a/webpack.config.js b/webpack.config.js index 46f51ac8b..9b216dcd7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -55,7 +55,7 @@ const webpackConfig = { { test: /\.jsx?$/, include: [ - path.resolve(__dirname, 'src/'), + path.resolve(__dirname, 'src/'), path.resolve(__dirname, 'node_modules/dompurify') ], loader: 'babel-loader',