Skip to content

Commit e78884b

Browse files
committed
If initialViewerConfig is set, override the preserveViewport: false default
1 parent c148577 commit e78884b

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"import/no-anonymous-default-export": "off",
7878
"import/no-extraneous-dependencies": "off",
7979
"max-len": ["error", {
80-
"code": 120,
80+
"code": 130,
8181
"ignoreComments": true,
8282
"ignoreStrings": true,
8383
"ignoreTemplateLiterals": true,

__tests__/src/sagas/windows.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,29 @@ describe('window-level sagas', () => {
148148
.run();
149149
});
150150

151+
it('overrides default preserveViewport: false when initialViewerConfig is set', () => {
152+
const action = {
153+
window: {
154+
canvasId: '1',
155+
id: 'x',
156+
initialViewerConfig: {
157+
x: 934,
158+
y: 782,
159+
zoom: 0.0007,
160+
},
161+
manifestId: 'manifest.json',
162+
},
163+
};
164+
165+
return expectSaga(setWindowStartingCanvas, action)
166+
.provide([
167+
[select(getManifests), { 'manifest.json': {} }],
168+
[call(setCanvas, 'x', '1', null, { preserveViewport: true }), { type: 'setCanvasThunk' }],
169+
])
170+
.put({ type: 'setCanvasThunk' })
171+
.run();
172+
});
173+
151174
it('calculates the starting canvas and calls setCanvas', () => {
152175
const action = {
153176
window: {

src/state/actions/canvas.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ export function setCanvas(windowId, canvasId, newGroup = undefined, options = {}
2525
}
2626

2727
dispatch({
28-
...options,
2928
canvasId,
30-
preserveViewport,
29+
preserveViewport: options?.preserveViewport ?? preserveViewport,
3130
type: ActionTypes.SET_CANVAS,
3231
visibleCanvases,
3332
windowId,

src/state/sagas/windows.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ export function* setWindowStartingCanvas(action) {
9595
const windowId = action.id || action.window.id;
9696

9797
if (canvasId) {
98-
const thunk = yield call(setCanvas, windowId, canvasId, null, { preserveViewport: !!action.payload });
98+
// Preserve viewport when initialViewerConfig exists, event if the preserveViewport OSD setting is set to false
99+
const preserveViewport = !!action.payload || !!(action.window?.initialViewerConfig);
100+
// When canvasId is explicitly provided, always pass preserveViewport flag
101+
const thunk = yield call(setCanvas, windowId, canvasId, null, { preserveViewport });
99102
yield put(thunk);
100103
} else {
101104
const getMiradorManifest = yield select(getMiradorManifestWrapper);
@@ -107,7 +110,11 @@ export function* setWindowStartingCanvas(action) {
107110
|| miradorManifest.canvasAt(canvasIndex || 0)
108111
|| miradorManifest.canvasAt(0);
109112
if (startCanvas) {
110-
const thunk = yield call(setCanvas, windowId, startCanvas.id);
113+
const preserveViewport = !!action.payload || !!(action.window?.initialViewerConfig);
114+
// When canvas is calculated, only pass preserveViewport when true
115+
const thunk = preserveViewport
116+
? yield call(setCanvas, windowId, startCanvas.id, null, { preserveViewport })
117+
: yield call(setCanvas, windowId, startCanvas.id);
111118
yield put(thunk);
112119
}
113120
}

0 commit comments

Comments
 (0)