ui: extract ChildCheckboxContainer component out of AdvancedMultiSelect

This commit is contained in:
Mike Salvatore 2021-01-28 08:51:30 -05:00
parent 155da384c2
commit 5942fad434
2 changed files with 45 additions and 20 deletions

View File

@ -1,12 +1,11 @@
import React from 'react'; import React from 'react';
import {Button, Card, Form} from 'react-bootstrap'; import {Button, Card} from 'react-bootstrap';
import {cloneDeep} from 'lodash'; import {cloneDeep} from 'lodash';
import {getComponentHeight} from './utils/HeightCalculator';
import {getDefaultPaneParams, InfoPane} from './InfoPane'; import {getDefaultPaneParams, InfoPane} from './InfoPane';
import {MasterCheckbox, MasterCheckboxState} from './MasterCheckbox'; import {MasterCheckbox, MasterCheckboxState} from './MasterCheckbox';
import ChildCheckbox from './ChildCheckbox'; import ChildCheckboxContainer from './ChildCheckbox';
import {getFullDefinitionByKey} from './JsonSchemaHelpers'; import {getFullDefinitionByKey} from './JsonSchemaHelpers';
function AdvancedMultiSelectHeader(props) { function AdvancedMultiSelectHeader(props) {
@ -123,7 +122,7 @@ class AdvancedMultiSelect extends React.Component {
})); }));
} }
isSafe(itemKey) { isSafe = (itemKey) => {
return getFullDefinitionByKey(this.infoPaneRefString, this.registry, itemKey).safe; return getFullDefinitionByKey(this.infoPaneRefString, this.registry, itemKey).safe;
} }
@ -144,21 +143,12 @@ class AdvancedMultiSelect extends React.Component {
disabled={disabled} onCheckboxClick={this.onMasterCheckboxClick} disabled={disabled} onCheckboxClick={this.onMasterCheckboxClick}
checkboxState={this.state.masterCheckboxState} checkboxState={this.state.masterCheckboxState}
hideReset={this.state.hideReset} onResetClick={this.onResetClick}/> hideReset={this.state.hideReset} onResetClick={this.onResetClick}/>
<Form.Group
style={{height: `${getComponentHeight(this.enumOptions.length)}px`}} <ChildCheckboxContainer id={id} multiple={multiple} required={required}
id={id} multiple={multiple} className='choice-block form-control' disabled={disabled || readonly} autoFocus={autofocus} isSafe={this.isSafe}
required={required} disabled={disabled || readonly} autoFocus={autofocus}> onPaneClick={this.setPaneInfo} onCheckboxClick={this.onChildCheckboxClick}
{ selectedValues={this.props.value} enumOptions={this.enumOptions}/>
this.enumOptions.map(({value, label}, i) => {
return (
<ChildCheckbox key={i} onPaneClick={this.setPaneInfo}
onClick={this.onChildCheckboxClick} value={value}
disabled={disabled} label={label} checkboxState={this.props.value.includes(value)}
safe={this.isSafe(value)}/>
);
}
)}
</Form.Group>
<InfoPane title={this.state.infoPaneParams.title} <InfoPane title={this.state.infoPaneParams.title}
body={this.state.infoPaneParams.content} body={this.state.infoPaneParams.content}
link={this.state.infoPaneParams.link}/> link={this.state.infoPaneParams.link}/>

View File

@ -5,6 +5,41 @@ import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import {faCheckSquare, faExclamationTriangle} from '@fortawesome/free-solid-svg-icons'; import {faCheckSquare, faExclamationTriangle} from '@fortawesome/free-solid-svg-icons';
import {faSquare} from '@fortawesome/free-regular-svg-icons'; import {faSquare} from '@fortawesome/free-regular-svg-icons';
import {getComponentHeight} from './utils/HeightCalculator';
function ChildCheckboxContainer(props) {
const {
enumOptions,
id,
multiple,
required,
disabled,
autofocus,
onPaneClick,
onCheckboxClick,
selectedValues,
isSafe
} = props;
return(
<Form.Group
style={{height: `${getComponentHeight(enumOptions.length)}px`}}
id={id} multiple={multiple} className='choice-block form-control'
required={required} disabled={disabled} autoFocus={autofocus}>
{
enumOptions.map(({value, label}, i) => {
return (
<ChildCheckbox key={i} onPaneClick={onPaneClick}
onClick={onCheckboxClick} value={value}
disabled={disabled} label={label} checkboxState={selectedValues.includes(value)}
safe={isSafe(value)}/>
);
}
)}
</Form.Group>
);
}
function ChildCheckbox(props) { function ChildCheckbox(props) {
const { const {
onPaneClick, onPaneClick,
@ -32,4 +67,4 @@ function ChildCheckbox(props) {
); );
} }
export default ChildCheckbox; export default ChildCheckboxContainer;