Skip to content

Commit

Permalink
fix: add translations and remove render as tabs from the state
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaminia Cavallo authored and Flaminia Cavallo committed Jul 4, 2024
1 parent d04efc6 commit 7114ca8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/config/field-overrides/dataSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import DataInputPeriods from './data-set/DataInputPeriods.component';
import PeriodTypeDropDown from '../../forms/form-fields/period-type-drop-down';
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";

class RenderAsTabsSettings extends React.Component {
constructor(props) {
constructor(props, context) {
super(props);
this.state = {
renderAsTabs: props.value,
displayOptions: this.parseDisplayOptions()
};
this.translate = context.d2.i18n.getTranslation.bind(
context.d2.i18n
);
}

parseDisplayOptions = () => {
Expand All @@ -32,10 +35,7 @@ class RenderAsTabsSettings extends React.Component {
...this.state.displayOptions,
tabsDirection
}
this.setState((prevState, _) => ({
...prevState,
displayOptions: newDisplayOptions
}));
this.setState({displayOptions: newDisplayOptions});
this.props.model.displayOptions = JSON.stringify(newDisplayOptions)
}

Expand All @@ -44,31 +44,28 @@ class RenderAsTabsSettings extends React.Component {
this.updateTabsDirection(tabsDirection)
}

onDisplayAsTabsChanged = (event) => {
onRenderAsTabsChanged = (event) => {
const renderAsTabs = event.target.value
const tabsDirection =
renderAsTabs
? 'horizontal'
: undefined

this.setState((prevState) => ({
...prevState,
renderAsTabs
}));
this.props.onChange({ target: { value: renderAsTabs } });
this.updateTabsDirection(tabsDirection)
}


render() {
const state = this.state;
const props = this.props;
return <div>
<Checkbox
labelText="Render as tabs"
value={state.renderAsTabs}
onChange={this.onDisplayAsTabsChanged}
labelText={this.translate('render_as_tabs')}
value={props.value}
onChange={this.onRenderAsTabsChanged}
/>
{state.renderAsTabs &&
{props.value &&
<RadioButtonGroup
onChange={this.onDisplayOptionsChanged}
name="tabsDirection"
Expand All @@ -78,13 +75,13 @@ class RenderAsTabsSettings extends React.Component {
<RadioButton
key='horizontal'
value='horizontal'
label='Horizontal'
label={this.translate('horizontal')}
style={{margin: '10px'}}
/>
<RadioButton
key='vertical'
value='vertical'
label='Vertical'
label={this.translate('vertical')}
style={{margin: '10px'}}
/>
</RadioButtonGroup>}
Expand Down Expand Up @@ -114,7 +111,7 @@ export default new Map([
component: DataInputPeriods,
}],
['renderAsTabs', {
component: RenderAsTabsSettings,
component: addD2Context(RenderAsTabsSettings),
}]
]);

2 changes: 2 additions & 0 deletions src/i18n/i18n_module_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ no_value_requires_comment=Missing value requires comment on complete
skip_offline=Skip offline
render_options_as_radio=Render options as radio
render_as_tabs=Render sections as tabs
horizontal=Horizontal
vertical=Vertical
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
Expand Down

0 comments on commit 7114ca8

Please sign in to comment.