Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: BUGFIX: Show if selectbox options mismatch with current value #3526

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class MultiSelectBox_ListPreviewSortable extends PureComponent {
).isRequired,
values: PropTypes.arrayOf(PropTypes.string),
onValuesChange: PropTypes.func.isRequired,
displayLoadingIndicator: PropTypes.bool,
ListPreviewElement: PropTypes.any.isRequired,

// API with MultiSelectBox
Expand Down Expand Up @@ -59,15 +60,23 @@ export default class MultiSelectBox_ListPreviewSortable extends PureComponent {
render() {
const {
options,
optionValueAccessor
optionValueAccessor,
displayLoadingIndicator
} = this.props;

if (displayLoadingIndicator) {
return '';
}

const {draggableValues} = this.state;

// Sorted options by draggable value ordering
const draggableOptions = draggableValues.map(value =>
options.find(option => optionValueAccessor(option) === value)
).filter(Boolean);
options.find(option => optionValueAccessor(option) === value) || {
label: `Invalid: "${value}"`,
icon: 'exclamation-triangle'
}
);

return draggableOptions.map(this.renderOption);
}
Expand Down
18 changes: 12 additions & 6 deletions packages/react-ui-components/src/SelectBox/selectBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {$get} from 'plow-js';
import SelectBox_Option_SingleLine from '../SelectBox_Option_SingleLine';
import mergeClassNames from 'classnames';
import isEqual from 'lodash.isequal';
import {isNil} from '@neos-project/utils-helpers';

// TODO: document component usage && check code in detail
export default class SelectBox extends PureComponent {
Expand Down Expand Up @@ -262,10 +261,13 @@ export default class SelectBox extends PureComponent {
// Compare selected value less strictly: allow loose comparision and deep equality of objects
const selectedOption = options.find(option => optionValueAccessor(option) == value || isEqual(optionValueAccessor(option), value)); // eslint-disable-line eqeqeq

// check for null or undefined
/* eslint-disable no-eq-null, eqeqeq */
const valueIsEmpty = value == null || value === '';

if (
displaySearchBox && (
isNil(value) ||
value === '' ||
valueIsEmpty ||
this.state.isExpanded ||
plainInputMode
)
Expand All @@ -281,13 +283,17 @@ export default class SelectBox extends PureComponent {
);
}

const showResetButton = Boolean(allowEmpty && !displayLoadingIndicator && value);
const mismatchOfValueInOptions = !valueIsEmpty && !selectedOption;
const showResetButton = (allowEmpty && !valueIsEmpty) || mismatchOfValueInOptions;

return (
<SelectBox_Header
{...this.props}
option={selectedOption}
showResetButton={showResetButton}
option={mismatchOfValueInOptions ? {
label: `Invalid: "${value}"`,
icon: 'exclamation-triangle'
} : selectedOption}
showResetButton={!displayLoadingIndicator && showResetButton}
onReset={this.handleDeleteClick}
onClick={onHeaderClick}
/>
Expand Down