Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
Comments on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Di Milia committed Aug 21, 2015
1 parent 749603f commit 006d608
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ui/jstests/test-learning-resource.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ define(['QUnit', 'jquery', 'react', 'lodash', 'learning_resources',
assert.equal($termsOptions[1].selected, false);
assert.equal($(termsSelect).val(), "required");

// remove selection for this vocabulary to not interfer to the rest of the test
// remove selection for this vocabulary to not interfere to the rest of the test
$(termsSelect).val("").trigger('change');
component.forceUpdate(function() {
// Switch to difficulty
$vocabSelect.val("difficulty").trigger('change');
component.forceUpdate(function() {
// re-fetch the selects to get the prerequisite one
// re-fetch the selects to get the difficulty one
$allSelects = $node.find("#vocabularies select");
// update the term select
termsSelect = $allSelects[1];
Expand Down
22 changes: 16 additions & 6 deletions ui/static/ui/js/learning_resources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ define('learning_resources', [
// extract the list of terms not in the vocabulary existing terms
var termsSlugs = _.pluck(this.props.selectedVocabulary.terms, 'slug');
var termsToCreate = _.filter(selectedValues, function (slug) {
return _.indexOf(termsSlugs, slug) === -1;
return !_.includes(termsSlugs, slug);
});
// if there are no new terms to create, set the state
if (!termsToCreate.length) {
Expand Down Expand Up @@ -165,21 +165,22 @@ define('learning_resources', [
});
})
.done(function(newTerm) {
// replace che current label in the selected
// values with the newly created slug
//append the new term to the list of newly created terms
// replace che current label in the selected values with the newly created slug
selectedValues.splice(
_.indexOf(selectedValues, termLabel),
1,
newTerm.slug
);
// add the term to the current selected vocabulary
thiz.props.selectedVocabulary.terms.push(newTerm);
// finally set the current selected valuse
// change the state
thiz.props.appendTermSelectedVocabulary(newTerm);
// finally set the current selected values
thiz.props.setValues(
thiz.props.selectedVocabulary.slug, selectedValues
);
});
});

}
} else {
this.props.setValues(
Expand Down Expand Up @@ -222,6 +223,14 @@ define('learning_resources', [
});
},

appendTermSelectedVocabulary: function (termObj) {
var selectedVocabulary = this.state.selectedVocabulary;
selectedVocabulary.terms.push(termObj);
this.setState({
selectedVocabulary: selectedVocabulary
});
},

reportMessage: function (messageObj) {
this.setState({
message: messageObj
Expand All @@ -248,6 +257,7 @@ define('learning_resources', [
vocabs={vocabulariesAndTerms}
selectedVocabulary={this.state.selectedVocabulary}
setValues={this.setSelectedTerms}
appendTermSelectedVocabulary={this.appendTermSelectedVocabulary}
repoSlug={this.props.repoSlug}
reportMessage={this.reportMessage}
/>;
Expand Down

0 comments on commit 006d608

Please sign in to comment.