Skip to content

Commit

Permalink
Merge pull request #473 from unchartedsoftware/bugfix/472
Browse files Browse the repository at this point in the history
RelationState and EnumEntryState should react visibly to invalid typed values
  • Loading branch information
Ghnuberath authored Apr 29, 2019
2 parents db3fd71 + bd9ee32 commit 3176644
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/components/builders/generic/value-builder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ export class ValueBuilder extends Builder {
break;
}
}
if (!set) {
if (!set && this.machineState.suggestions[0].highlighted) {
this.value = this.machineState.suggestions[0];
} else if (!set) {
this.value = null;
}
} else if (!this.machineState.allowUnknown) {
// set value to null, since we can't create values and no suggestions match what was typed
Expand Down
11 changes: 3 additions & 8 deletions src/components/search-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,10 @@ export class SearchBar extends Component {
@Bind
archive () {
try {
this.state.activeMachine.archive(this.state.activeMachine.boxedValue);
this.state.activeMachine.archive();
return true;
} catch (err) {
if (err instanceof ValueArchiveError) {
console.error(err.message); // eslint-disable-line no-console
return false;
} else {
throw err;
Expand All @@ -330,11 +329,10 @@ export class SearchBar extends Component {
@Bind
unarchive () {
try {
this.state.activeMachine.unarchive(this.state.activeMachine.boxedValue);
this.state.activeMachine.unarchive();
return true;
} catch (err) {
if (err instanceof ValueArchiveError) {
console.error(err.message); // eslint-disable-line no-console
return false;
} else {
throw err;
Expand All @@ -345,11 +343,10 @@ export class SearchBar extends Component {
@Bind
removeArchivedValue (idx) {
try {
this.state.activeMachine.removeArchivedValue(idx, this.state.activeMachine.boxedValue);
this.state.activeMachine.removeArchivedValue(idx);
return true;
} catch (err) {
if (err instanceof ValueArchiveError) {
console.error(err.message); // eslint-disable-line no-console
return false;
} else {
throw err;
Expand All @@ -364,7 +361,6 @@ export class SearchBar extends Component {
return true;
} catch (err) {
if (err instanceof ValueArchiveError) {
console.error(err.message); // eslint-disable-line no-console
return false;
} else {
throw err;
Expand All @@ -379,7 +375,6 @@ export class SearchBar extends Component {
return true;
} catch (err) {
if (err instanceof ValueArchiveError) {
console.error(err.message); // eslint-disable-line no-console
return false;
} else {
throw err;
Expand Down
11 changes: 5 additions & 6 deletions src/lib/states/generic/relation-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ export class RelationState extends ValueState {
if (config.name === undefined) config.name = 'Choose a relation';
config.fetchSuggestions = function (hint) {
return config.options().map(o => {
return o.key.toLowerCase().indexOf(hint.toLowerCase()) === 0
? new ValueStateValue(o.key, o.meta, {
displayKey: o.displayKey,
hidden: o.hidden,
highlighted: true
}) : o;
return new ValueStateValue(o.key, o.meta, {
displayKey: o.displayKey,
hidden: o.hidden,
highlighted: o.key.toLowerCase().indexOf(hint.toLowerCase()) === 0
});
});
};
super(config);
Expand Down

0 comments on commit 3176644

Please sign in to comment.