Skip to content

Commit

Permalink
Merge pull request #316 from unchartedsoftware/bugfix/313
Browse files Browse the repository at this point in the history
Need to refresh suggestions in OptionAssistant when a value is unboxed.
  • Loading branch information
Ghnuberath authored Apr 27, 2018
2 parents 7ad1041 + 9f2b15e commit 1620a39
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
24 changes: 22 additions & 2 deletions src/components/assistants/generic/option-assistant.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ export class OptionAssistant extends Assistant {
return options.filter(o => !o.hidden && !lookup.has(o.key)).slice(0, this.machineStateTemplate.suggestionLimit);
}

cleanupListeners () {
super.cleanupListeners();
if (this.machineState) {
this.machineState.removeListener('value unarchived', this.onValueUnarchived);
}
}

connectListeners () {
super.connectListeners();
if (this.machineState) {
this.machineState.on('value unarchived', this.onValueUnarchived);
}
}

@Bind
onValueUnarchived () {
if (this.machineStateTemplate) {
setTimeout(() => this.machineStateTemplate.refreshOptions('', this.boxedValue, this.boxedArchive));
}
}

@Bind
onOptionsChanged (newOptions) {
this.setState({
Expand All @@ -42,7 +63,7 @@ export class OptionAssistant extends Assistant {
const result = this.requestArchive();
if (result) {
this.machineState.unboxedValue = null;
this.machineStateTemplate.refreshOptions('', this.machine.boxedValue, this.boxedArchive);
this.machineStateTemplate.refreshOptions('', this.boxedValue, this.boxedArchive);
this.setState({
suggestions: this.getSuggestions()
});
Expand All @@ -60,7 +81,6 @@ export class OptionAssistant extends Assistant {
@Bind
onArchivedRemoved (idx) {
this.requestRemoveArchivedValue(idx);
this.machineStateTemplate.refreshOptions('', this.machine.boxedValue, this.boxedArchive);
this.setState({
suggestions: this.getSuggestions()
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/search-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class SearchBar extends Component {
if (value !== this.state.tokenValues) {
this.setState({
tokenValues: value.map(v => {
const m = new TokenStateMachine(this.state.machineTemplate)
const m = new TokenStateMachine(this.state.machineTemplate);
m.bindValues(v);
return m;
}) // box incoming values
Expand Down Expand Up @@ -374,7 +374,7 @@ export class SearchBar extends Component {
return true;
} catch (err) {
if (err instanceof ValueArchiveError) {
console.error(err.message);
console.error(err.message); // eslint-disable-line no-console
return false;
} else {
throw err;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ export class StateTemplate extends EventEmitter {
*
* This class is an `EventEmitter`, exposing the following events:
* - `on('value changed', (newVal, oldVal) => {})` when the internal value changes.
* - `on('value archived', () => {})` when a value is archived.
* - `on('value unarchived', () => {})` when a value is archived.
* - `on('preview value changed', (newVal, oldVal) => {})` when the internal preview value changes.
* - `on('unboxed value change attempted', (newUnboxedVal, oldUnboxedVal))` when a user attempts to change the unboxed value. If it cannot be boxed, it may not trigger `value changed`.
*
Expand Down Expand Up @@ -526,6 +528,7 @@ export class State extends EventEmitter {
this.value = this.defaultValue;
this.previewValue = null;
this.emit('value changed', this.value, oldVal, this.unboxedValue, oldUnboxedVal);
this.emit('value archived');
}

/**
Expand All @@ -536,6 +539,7 @@ export class State extends EventEmitter {
const oldUnboxedVal = this.unboxedValue;
this.value = this.archive.pop();
this.emit('value changed', this.value, oldVal, this.unboxedValue, oldUnboxedVal);
this.emit('value unarchived');
}

/**
Expand All @@ -546,5 +550,6 @@ export class State extends EventEmitter {
removeArchivedValue (idx) {
this.archive.splice(idx, 1);
this.emit('value changed', this.value, this.value, this.unboxedValue, this.unboxedValue);
this.emit('value unarchived');
}
}

0 comments on commit 1620a39

Please sign in to comment.