Skip to content
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

fix: do not call renderFullIImage for IIIF image #2487

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/portal/src/components/media/MediaImageViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div
id="media-image-viewer"
class="h-100 w-100"
v-on="fullImageRendered ? {} : { keydown: handleKeyboardToggleKeydown }"
>
<MediaImageViewerKeyboardToggle
id="media-image-viewer-keyboard-toggle"
@renderFullImage="renderFullImage"
/>
<slot />
</div>
Expand Down Expand Up @@ -145,6 +145,12 @@
},

methods: {
handleKeyboardToggleKeydown(event) {
if (['ArrowUp', 'ArrowRight', 'ArrowDown', 'ArrowLeft', '-', '+'].includes(event.key)) {
this.fullImageRendered || this.renderFullImage();
}
},

initOlAnnotationLayer() {
const layerCount = this.olMap.getLayers().getLength();
if (layerCount === 0) {
Expand Down Expand Up @@ -302,8 +308,6 @@
const url = this.$apis.record.mediaProxyUrl(this.url, this.itemId, { disposition: 'inline' });
const mapOptions = await this.initOlImageLayerStatic(url, this.width, this.height);
this.initMapWithFullImage(mapOptions);

this.fullImageRendered = true;
},

// IIIF Image API
Expand Down Expand Up @@ -348,7 +352,6 @@
if (this.source === 'IIIF') {
const mapOptions = this.initOlImageLayerIIIF();
this.initMapWithFullImage(mapOptions);
this.fullImageRendered = true;
} else if (this.annotation) {
this.renderFullImage();
} else {
Expand All @@ -358,6 +361,7 @@

initMapWithFullImage(mapOptions) {
this.initOlMap(mapOptions);
this.fullImageRendered = true;
this.highlightAnnotation();
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@
},
showToast() {
this.$bvToast.show('media-image-viewer-toast');
this.$refs.keyboardtoggle.addEventListener('keydown', this.renderFullMediaOnKeyboardInteraction);
},
renderFullMediaOnKeyboardInteraction(event) {
if (['ArrowUp', 'ArrowRight', 'ArrowDown', 'ArrowLeft', '-', '+'].includes(event.key)) {
this.$emit('renderFullImage');
this.$refs.keyboardtoggle.removeEventListener('keydown', this.renderFullMediaOnKeyboardInteraction);
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ describe('components/media/MediaImageViewer', () => {
expect(wrapper.vm.initOlImageLayerStatic.calledWith(thumbnail, 400, 1600)).toBe(true);
});

describe('and keydown on a key that triggers a zoom or pan', () => {
it('renders the full image', async() => {
const wrapper = factory({ propsData: { url, thumbnail, width, height } });
expect(wrapper.vm.fullImageRendered).toBe(false);
const viewerWrapper = wrapper.find('#media-image-viewer');

viewerWrapper.element.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp' }));
await wrapper.vm.$nextTick();

expect(wrapper.vm.fullImageRendered).toBe(true);
});
});

describe('when there is no thumbnail', () => {
it('renders the full image', async() => {
const wrapper = factory({ propsData: { url, width, height } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ describe('components/media/MediaImageViewerKeyboardToggle', () => {

expect(showToast.calledWith('media-image-viewer-toast')).toBe(true);
});
describe('and keydown on a key that triggers a zoom or pan', () => {
it('emits to render full image media', () => {
const wrapper = factory();

const keyboardToggleButton = wrapper.find('[data-qa="media image viewer keyboard toggle button"]');

keyboardToggleButton.element.dispatchEvent(new Event('focus'));
wrapper.vm.$refs.keyboardtoggle.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp' }));

expect(wrapper.emitted('renderFullImage').length).toBe(1);
});
});
});
});

Expand All @@ -64,4 +52,3 @@ describe('components/media/MediaImageViewerKeyboardToggle', () => {
});
});
});

Loading