-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to make a data set sections collapsible
- Loading branch information
Flaminia Cavallo
authored and
Flaminia Cavallo
committed
Jul 9, 2024
1 parent
7114ca8
commit 4b292fe
Showing
3 changed files
with
104 additions
and
87 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
src/config/field-overrides/data-set/RenderAsTabs.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React from "react"; | ||
import log from "loglevel"; | ||
import Checkbox from "../../../forms/form-fields/check-box"; | ||
import {RadioButton, RadioButtonGroup} from "material-ui/RadioButton"; | ||
|
||
class RenderAsTabs extends React.Component { | ||
constructor(props, context) { | ||
super(props); | ||
this.state = { | ||
displayOptions: this.parseDisplayOptions(), | ||
}; | ||
this.translate = context.d2.i18n.getTranslation.bind( | ||
context.d2.i18n | ||
); | ||
} | ||
|
||
|
||
parseDisplayOptions = () => { | ||
try { | ||
return this.props | ||
&& this.props.model['displayOptions'] | ||
&& JSON.parse(this.props.model['displayOptions']) | ||
} catch (e) { | ||
log.error(e); | ||
return undefined | ||
} | ||
} | ||
|
||
updateDisplayOptions = (newDisplayOptions) => { | ||
this.setState({displayOptions: newDisplayOptions}); | ||
this.props.model.displayOptions = JSON.stringify(newDisplayOptions) | ||
} | ||
|
||
onCollapsibleSectionsChanged = (event) => { | ||
const newDisplayOptions = { | ||
...this.state.displayOptions, | ||
collapsibleSections: event.target.value | ||
} | ||
this.updateDisplayOptions(newDisplayOptions) | ||
} | ||
|
||
onTabDirectionChanged = (event) => { | ||
const newDisplayOptions = { | ||
...this.state.displayOptions, | ||
tabsDirection: event.target.value | ||
} | ||
this.updateDisplayOptions(newDisplayOptions) | ||
} | ||
|
||
onRenderAsTabsChanged = (event) => { | ||
const renderAsTabs = event.target.value | ||
this.props.onChange({ target: { value: renderAsTabs } }); | ||
const newDisplayOptions = { | ||
...this.state.displayOptions, | ||
tabsDirection: renderAsTabs ? 'horizontal' : undefined | ||
} | ||
this.updateDisplayOptions(newDisplayOptions) | ||
} | ||
|
||
render() { | ||
const state = this.state; | ||
const props = this.props; | ||
return <div> | ||
<Checkbox | ||
labelText={this.translate('render_as_tabs')} | ||
value={props.value} | ||
onChange={this.onRenderAsTabsChanged} | ||
/> | ||
{props.value && | ||
<RadioButtonGroup | ||
onChange={this.onTabDirectionChanged} | ||
name="tabsDirection" | ||
defaultSelected={ | ||
(state.displayOptions && state.displayOptions.tabsDirection) || 'horizontal' } | ||
> | ||
<RadioButton | ||
key='horizontal' | ||
value='horizontal' | ||
label={this.translate('horizontal')} | ||
style={{margin: '10px'}} | ||
/> | ||
<RadioButton | ||
key='vertical' | ||
value='vertical' | ||
label={this.translate('vertical')} | ||
style={{margin: '10px'}} | ||
/> | ||
</RadioButtonGroup>} | ||
<Checkbox | ||
labelText={this.translate('make_sections_collapsible')} | ||
value={ (state.displayOptions && state.displayOptions.collapsibleSections) || false } | ||
onChange={this.onCollapsibleSectionsChanged} | ||
/> | ||
</div> | ||
|
||
} | ||
} | ||
|
||
export default RenderAsTabs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters