-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(region): Hide annotations if visibility is false #483
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,14 @@ export default class BaseAnnotator { | |
}; | ||
|
||
setVisibility = (visibility: boolean): void => { | ||
this.store.dispatch(store.setVisibilityAction(visibility)); | ||
if (!this.rootEl) { | ||
return; | ||
} | ||
if (visibility) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be handled by the parent at this point? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we're using redux to store the state, but not relying on it to hide and show the annotations, but rather rely on the value passed into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Jared thinks this logic should live in the higher level. Otherwise we'll have to replicate this logic for all future annotation types. |
||
this.rootEl.classList.remove('is-hidden'); | ||
} else { | ||
this.rootEl.classList.add('is-hidden'); | ||
} | ||
}; | ||
|
||
toggleAnnotationMode(mode: store.Mode): void { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,10 +130,10 @@ describe('BaseAnnotator', () => { | |
}); | ||
|
||
describe('setVisibility()', () => { | ||
test.each([true, false])('should dispatch setVisibilityAction with visibility %p', visibility => { | ||
test.each([true, false])('should hide/show annotations if visibility is %p', visibility => { | ||
annotator.rootEl = defaults.container; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably just call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If call |
||
annotator.setVisibility(visibility); | ||
expect(annotator.store.dispatch).toBeCalled(); | ||
expect(store.setVisibilityAction).toBeCalledWith(visibility); | ||
expect(annotator.rootEl.classList.contains('is-hidden')).toEqual(!visibility); | ||
}); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,4 @@ import { Mode } from '../types'; | |
|
||
export default { | ||
mode: Mode.NONE, | ||
visibility: true, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
import commonState from '../__mocks__/commonState'; | ||
import { getAnnotationMode, getVisibility } from '../selectors'; | ||
import { getAnnotationMode } from '../selectors'; | ||
|
||
describe('store/common/selectors', () => { | ||
describe('getAnnotationMode', () => { | ||
test('should return annotation mode', () => { | ||
expect(getAnnotationMode({ common: commonState })).toBe('none'); | ||
}); | ||
}); | ||
|
||
describe('getVisibility', () => { | ||
test('should return annotation visibility', () => { | ||
expect(getVisibility({ common: commonState })).toBe(true); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { createAction } from '@reduxjs/toolkit'; | ||
import { Mode } from './types'; | ||
|
||
export const setVisibilityAction = createAction<boolean>('SET_VISIBILITY'); | ||
export const toggleAnnotationModeAction = createAction<Mode>('TOGGLE_ANNOTATION_MODE'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isVisible