Skip to content

Commit 2aa4e15

Browse files
authored
Merge pull request #14 from PDFTron/priority
[update] resolves #13
2 parents 2bcf1d5 + f85c211 commit 2aa4e15

14 files changed

+107
-47
lines changed

src/apis/enableAnnotations.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import core from 'core';
22
import getAnnotationRelatedElements from 'helpers/getAnnotationRelatedElements';
3+
import { PRIORITY_ONE } from 'constants/actionPriority';
34
import actions from 'actions';
45

56
export default store => (enable = true) => {
@@ -10,10 +11,10 @@ export default store => (enable = true) => {
1011
];
1112

1213
if (enable) {
13-
store.dispatch(actions.enableElements(elements));
14+
store.dispatch(actions.enableElements(elements, PRIORITY_ONE));
1415
core.showAnnotations(core.getAnnotationsList());
1516
} else {
16-
store.dispatch(actions.disableElements(elements));
17+
store.dispatch(actions.disableElements(elements, PRIORITY_ONE));
1718
core.hideAnnotations(core.getAnnotationsList());
1819
}
1920
};

src/apis/enableDownload.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { PRIORITY_ONE } from 'constants/actionPriority';
12
import actions from 'actions';
23

34
export default store => (enable = true) => {
45
if (enable) {
5-
store.dispatch(actions.enableElement('downloadButton'));
6+
store.dispatch(actions.enableElement('downloadButton', PRIORITY_ONE));
67
} else {
7-
store.dispatch(actions.disableElement('downloadButton'));
8+
store.dispatch(actions.disableElement('downloadButton', PRIORITY_ONE));
89
}
910
};

src/apis/enableFilePicker.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { PRIORITY_ONE } from 'constants/actionPriority';
12
import actions from 'actions';
23

34
export default store => (enable = true) => {
45
if (enable) {
5-
store.dispatch(actions.enableElements(['filePickerHandler', 'filePickerButton']));
6+
store.dispatch(actions.enableElements(['filePickerHandler', 'filePickerButton'], PRIORITY_ONE));
67
} else {
7-
store.dispatch(actions.disableElements(['filePickerHandler', 'filePickerButton']));
8+
store.dispatch(actions.disableElements(['filePickerHandler', 'filePickerButton'], PRIORITY_ONE));
89
}
910
};

src/apis/enableNotesPanel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { PRIORITY_TWO } from 'constants/actionPriority';
12
import actions from 'actions';
23

34
export default store => (enable = true) => {
45
if (enable) {
5-
store.dispatch(actions.enableElements(['annotationCommentButton', 'notesPanelButton', 'notesPanel']));
6+
store.dispatch(actions.enableElements(['annotationCommentButton', 'notesPanelButton', 'notesPanel'], PRIORITY_TWO));
67
store.dispatch(actions.setActiveLeftPanel('notesPanel'));
78
} else {
8-
store.dispatch(actions.disableElements(['annotationCommentButton', 'notesPanelButton', 'notesPanel']));
9+
store.dispatch(actions.disableElements(['annotationCommentButton', 'notesPanelButton', 'notesPanel'], PRIORITY_TWO));
910
store.dispatch(actions.setActiveLeftPanel('thumbnailsPanel'));
1011
}
1112
};

src/apis/enablePrint.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PRIORITY_ONE } from 'constants/actionPriority';
12
import actions from 'actions';
23

34
export default store => (enable = true) => {
@@ -7,8 +8,8 @@ export default store => (enable = true) => {
78
];
89

910
if (enable) {
10-
store.dispatch(actions.enableElements(elements));
11+
store.dispatch(actions.enableElements(elements, PRIORITY_ONE));
1112
} else {
12-
store.dispatch(actions.disableElements(elements));
13+
store.dispatch(actions.disableElements(elements, PRIORITY_ONE));
1314
}
1415
};

src/apis/enableTextSelection.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import core from 'core';
2+
import { PRIORITY_ONE } from 'constants/actionPriority';
23
import actions from 'actions';
34

45
export default store => (enable = true) => {
56
if (enable) {
6-
store.dispatch(actions.enableElement('textPopup'));
7+
store.dispatch(actions.enableElement('textPopup', PRIORITY_ONE));
78
} else {
89
core.clearSelection();
910
core.setToolMode('AnnotationEdit');
1011
store.dispatch(actions.closeElement('textPopup'));
11-
store.dispatch(actions.disableElement('textPopup'));
12+
store.dispatch(actions.disableElement('textPopup', PRIORITY_ONE));
1213
}
1314

1415
window.Tools.Tool.ENABLE_TEXT_SELECTION = enable;

src/apis/getActions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import core from 'core';
2+
import { PRIORITY_THREE } from 'constants/actionPriority';
23
import * as exposedActions from 'actions/exposedActions';
34
import actions from 'actions';
45
import selectors from 'selectors';
56

67
export default store => ({
78
...mapExposedActions(store),
9+
disableElement: dataElement => store.dispatch(actions.disableElement(dataElement, PRIORITY_THREE)),
10+
disableElements: dataElements => store.dispatch(actions.disableElements(dataElements, PRIORITY_THREE)),
11+
enableElement: dataElement => store.dispatch(actions.enableElement(dataElement, PRIORITY_THREE)),
12+
enableElements: dataElements => store.dispatch(actions.enableElements(dataElements, PRIORITY_THREE)),
813
focusNote: id => {
914
const state = store.getState();
1015
const annotation = core.getAnnotationById(id);

src/constants/actionPriority.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const PRIORITY_THREE = 3;
2+
export const PRIORITY_TWO = 2;
3+
export const PRIORITY_ONE = 1;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import selectors from 'selectors';
2+
3+
export default (state, dataElements, priority) => {
4+
return dataElements.reduce((filteredDataElements, dataElement) => {
5+
const currentPriority = selectors.getDisabledElementPriority(state, dataElement);
6+
7+
if (!currentPriority || priority >= currentPriority) {
8+
return [ ...filteredDataElements, dataElement];
9+
}
10+
11+
return filteredDataElements;
12+
}, []);
13+
};

src/helpers/setDefaultDisabledElements.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import core from 'core';
22
import getHashParams from 'helpers/getHashParams';
33
import getAnnotationRelatedElements from 'helpers/getAnnotationRelatedElements';
4+
import { PRIORITY_THREE, PRIORITY_ONE } from 'constants/actionPriority';
45
import actions from 'actions';
56

67
export default store => {
@@ -18,7 +19,7 @@ export default store => {
1819
const disableElementsPassedByConstructor = (state, dispatch) => {
1920
if (state.advanced.defaultDisabledElements) {
2021
const elements = state.advanced.defaultDisabledElements.split(',');
21-
dispatch(actions.disableElements(elements));
22+
dispatch(actions.disableElements(elements, PRIORITY_THREE));
2223
}
2324
};
2425

@@ -29,7 +30,7 @@ const disableElementsIfReadOnly = (state, dispatch) => {
2930
...getAnnotationRelatedElements(state)
3031
];
3132

32-
dispatch(actions.disableElements(elements));
33+
dispatch(actions.disableElements(elements, PRIORITY_ONE));
3334
core.setToolMode('AnnotationEdit');
3435
}
3536
};
@@ -43,7 +44,7 @@ const disableElementsIfAnnotationDisabled = (state, dispatch) => {
4344
...getAnnotationRelatedElements(state),
4445
];
4546

46-
dispatch(actions.disableElements(elements));
47+
dispatch(actions.disableElements(elements, PRIORITY_ONE));
4748
}
4849
};
4950

@@ -56,7 +57,7 @@ const disableElementsIfFilePickerDisabled = dispatch => {
5657
'filePickerButton',
5758
];
5859

59-
dispatch(actions.disableElements(elements));
60+
dispatch(actions.disableElements(elements, PRIORITY_ONE));
6061
}
6162
};
6263

@@ -70,14 +71,14 @@ const disableElementsIfHideAnnotationPanel = dispatch => {
7071
'annotationCommentButton'
7172
];
7273

73-
dispatch(actions.disableElements(elements));
74+
dispatch(actions.disableElements(elements, PRIORITY_ONE));
7475
}
7576
};
7677

7778
const disableElementsIfToolBarDisabled = dispatch => {
7879
const toolBarDisabled = !getHashParams('toolbar', true);
7980

8081
if (toolBarDisabled) {
81-
dispatch(actions.disableElement('header'));
82+
dispatch(actions.disableElement('header', PRIORITY_ONE));
8283
}
8384
};

0 commit comments

Comments
 (0)