Unverified Commit bcd488c7 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #686 from hypothesis/default-to-notes-tab-when-only-notes-present

Default to notes tab when only notes present
parents 99d764ab 07301504
......@@ -14,6 +14,7 @@ var immutable = require('seamless-immutable');
var toSet = require('../util/array-util').toSet;
var uiConstants = require('../ui-constants');
var tabs = require('../tabs');
var util = require('./util');
......@@ -132,6 +133,17 @@ var update = {
};
},
ADD_ANNOTATIONS(state, action) {
var counts = tabs.counts(action.annotations);
// If there are no annotations at all, ADD_ANNOTATIONS will not be called.
var haveOnlyPageNotes = counts.notes === action.annotations.length;
// If this is the init phase and there are only page notes, select the page notes tab.
if (state.annotations.length === 0 && haveOnlyPageNotes){
return {selectedTab: uiConstants.TAB_NOTES};
}
return {};
},
SET_FILTER_QUERY: function (state, action) {
return {
filterQuery: action.query,
......
......@@ -10,6 +10,7 @@ var uiConstants = require('../ui-constants');
var defaultAnnotation = annotationFixtures.defaultAnnotation;
var newAnnotation = annotationFixtures.newAnnotation;
var oldPageNote = annotationFixtures.oldPageNote;
var fixtures = immutable({
pair: [
......@@ -79,6 +80,27 @@ describe('annotationUI', function () {
[sinon.match(annot)]);
});
it('does not change `selectedTab` state if annotations are already loaded', function () {
var annot = defaultAnnotation();
annotationUI.addAnnotations([annot]);
var page = oldPageNote();
annotationUI.addAnnotations([page]);
assert.equal(annotationUI.getState().selectedTab, uiConstants.TAB_ANNOTATIONS);
});
it('sets `selectedTab` to "note" if only page notes are present', function () {
var page = oldPageNote();
annotationUI.addAnnotations([page]);
assert.equal(annotationUI.getState().selectedTab, uiConstants.TAB_NOTES);
});
it('leaves `selectedTab` as "annotation" if annotations and/or page notes are present', function () {
var page = oldPageNote();
var annot = defaultAnnotation();
annotationUI.addAnnotations([annot, page]);
assert.equal(annotationUI.getState().selectedTab, uiConstants.TAB_ANNOTATIONS);
});
it('assigns a local tag to annotations', function () {
var annotA = Object.assign(defaultAnnotation(), {id: 'a1'});
var annotB = Object.assign(defaultAnnotation(), {id: 'a2'});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment