From 35785790bb2dc5cb5e7127da7a94cb304ba66ac5 Mon Sep 17 00:00:00 2001
From: Jessie Keck <jessie.keck@gmail.com>
Date: Tue, 19 Mar 2019 15:39:30 -0700
Subject: [PATCH] Add reducers/actions for toggling All vs. Selected
 annotations

---
 __tests__/src/actions/annotation.test.js |  9 +++++++++
 __tests__/src/reducers/windows.test.js   | 12 ++++++++++++
 src/state/actions/action-types.js        |  2 +-
 src/state/actions/annotation.js          | 12 ++++++++++++
 src/state/actions/window.js              |  1 +
 src/state/reducers/windows.js            |  8 ++++++++
 6 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/__tests__/src/actions/annotation.test.js b/__tests__/src/actions/annotation.test.js
index 3609486fa..5428ce053 100644
--- a/__tests__/src/actions/annotation.test.js
+++ b/__tests__/src/actions/annotation.test.js
@@ -133,4 +133,13 @@ describe('annotation actions', () => {
     };
     expect(actions.deselectAnnotation(windowId, canvasId, annotationId)).toEqual(expectedAction);
   });
+
+  it('handles the toggleAnnotationDisplay action', () => {
+    const windowId = 'wId1';
+    const expectedAction = {
+      type: ActionTypes.TOGGLE_ANNOTATION_DISPLAY,
+      windowId,
+    };
+    expect(actions.toggleAnnotationDisplay(windowId)).toEqual(expectedAction);
+  });
 });
diff --git a/__tests__/src/reducers/windows.test.js b/__tests__/src/reducers/windows.test.js
index 800af2f76..a623cd699 100644
--- a/__tests__/src/reducers/windows.test.js
+++ b/__tests__/src/reducers/windows.test.js
@@ -345,5 +345,17 @@ describe('windows reducer', () => {
         expect(windowsReducer(beforeState, action)).toEqual(expectedState);
       });
     });
+
+    it('handles TOGGLE_ANNOTATION_DISPLAY by toggling the given window\'s displayAllAnnotation value', () => {
+      const beforeState = { abc123: { displayAllAnnotations: false } };
+      const action = {
+        type: ActionTypes.TOGGLE_ANNOTATION_DISPLAY, windowId: 'abc123',
+      };
+      const expectedState = {
+        abc123: { displayAllAnnotations: true },
+      };
+
+      expect(windowsReducer(beforeState, action)).toEqual(expectedState);
+    });
   });
 });
diff --git a/src/state/actions/action-types.js b/src/state/actions/action-types.js
index 64d801cdd..ca23ce29d 100644
--- a/src/state/actions/action-types.js
+++ b/src/state/actions/action-types.js
@@ -9,7 +9,7 @@ const ActionTypes = {
   RECEIVE_ANNOTATION_FAILURE: 'RECEIVE_ANNOTATION_FAILURE',
   DESELECT_ANNOTATION: 'DESELECT_ANNOTATION',
   SELECT_ANNOTATION: 'SELECT_ANNOTATION',
-
+  TOGGLE_ANNOTATION_DISPLAY: 'TOGGLE_ANNOTATION_DISPLAY',
 
   FOCUS_WINDOW: 'FOCUS_WINDOW',
   SET_WORKSPACE_FULLSCREEN: 'SET_WORKSPACE_FULLSCREEN',
diff --git a/src/state/actions/annotation.js b/src/state/actions/annotation.js
index 3fd9c6a18..bd1821279 100644
--- a/src/state/actions/annotation.js
+++ b/src/state/actions/annotation.js
@@ -93,3 +93,15 @@ export function deselectAnnotation(windowId, canvasId, annotationId) {
     type: ActionTypes.DESELECT_ANNOTATION, windowId, canvasId, annotationId,
   };
 }
+
+/**
+ * toggleAnnotationDisplay - action creator
+ *
+ * @param  {String} windowId
+ * @memberof ActionCreators
+ */
+export function toggleAnnotationDisplay(windowId) {
+  return {
+    type: ActionTypes.TOGGLE_ANNOTATION_DISPLAY, windowId,
+  };
+}
diff --git a/src/state/actions/window.js b/src/state/actions/window.js
index b80dbf839..07fe00a28 100644
--- a/src/state/actions/window.js
+++ b/src/state/actions/window.js
@@ -58,6 +58,7 @@ export function addWindow(options) {
       companionWindowIds: [cwDefault, cwThumbs],
       sideBarPanel: 'info',
       rotation: null,
+      displayAllAnnotations: false,
       selectedAnnotations: {},
       view: 'single',
       maximized: false,
diff --git a/src/state/reducers/windows.js b/src/state/reducers/windows.js
index 8804af7ed..771fef401 100644
--- a/src/state/reducers/windows.js
+++ b/src/state/reducers/windows.js
@@ -143,6 +143,14 @@ export const windowsReducer = (state = {}, action) => {
         },
       };
     }
+    case ActionTypes.TOGGLE_ANNOTATION_DISPLAY:
+      return {
+        ...state,
+        [action.windowId]: {
+          ...state[action.windowId],
+          displayAllAnnotations: !state[action.windowId].displayAllAnnotations,
+        },
+      };
     default:
       return state;
   }
-- 
GitLab