Skip to content

Commit

Permalink
Move input selected state to parent component
Browse files Browse the repository at this point in the history
Move input selected state from controller to parent component (plugin)
to prevent multiple selections and highlighting of checkbox fields
from different controllers.

Signed-off-by: Christos Malliaridis <c.malliaridis@gmail.com>
  • Loading branch information
malliaridis committed Jun 14, 2020
1 parent 52a54de commit 371a741
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import InputCheckbox from '../InputCheckboxPlugin';

import { Header, Label, Separator, Wrapper } from './Components';

function Controller({ actions, inputNamePath, isOpen, name }) {
function Controller({ actions, inputNamePath, isOpen, name, inputSelected, setInputSelected }) {
const { selectAllActions } = useEditPageContext();
const [inputSelected, setInputSelected] = useState('');

const areAllActionsSelected = () => {
return Object.keys(actions).every(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Banner, Chevron, ControllerWrapper, Description, Icon, Name, Wrapper }

class Plugin extends React.Component {
// eslint-disable-line react/prefer-stateless-function
state = { collapse: false };
state = { collapse: false, inputSelected: '' };

static contextType = EditPageContext;

Expand Down Expand Up @@ -51,6 +51,10 @@ class Plugin extends React.Component {
}
};

setInputSelectedState = name => {
this.setState({ inputSelected: name });
};

render() {
const { appPlugins } = this.context;
const { plugin } = this.props;
Expand Down Expand Up @@ -101,6 +105,8 @@ class Plugin extends React.Component {
inputNamePath={`permissions.${this.props.name}`}
isOpen={this.state.collapse}
key={key}
inputSelected={this.state.inputSelected}
setInputSelected={this.setInputSelectedState}
name={key}
actions={controllerActions}
resetInputBackground={this.state.resetInputBackground}
Expand Down

0 comments on commit 371a741

Please sign in to comment.