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

feat(viewer): Add support for disabling .boxdicom file type #1436

Merged
merged 5 commits into from
Nov 17, 2021
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
15 changes: 15 additions & 0 deletions src/lib/viewers/iframe/IFrameLoader.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import getProp from 'lodash/get';
import AssetLoader from '../AssetLoader';
import IFrameViewer from './IFrameViewer';
import { ORIGINAL_REP_NAME } from '../../constants';
Expand All @@ -22,6 +23,20 @@ class IFrameLoader extends AssetLoader {
super();
this.viewers = VIEWERS;
}

/**
* @inheritdoc
*/
determineViewer(file, disabledViewers = [], viewerOptions = {}) {
const isDicomFile = file.extension === 'boxdicom';
const disableDicom = getProp(viewerOptions, 'IFrame.disableDicom');
// The IFrame viewer is disabled when the file is a Boxdicom file and the disableDicom viewer option is enabled
if (disableDicom && isDicomFile) {
disabledViewers.push('IFrame');
}

return super.determineViewer(file, disabledViewers);
jstoffan marked this conversation as resolved.
Show resolved Hide resolved
}
}

export default new IFrameLoader();
37 changes: 32 additions & 5 deletions src/lib/viewers/iframe/__tests__/IFrameLoader-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
/* eslint-disable no-unused-expressions */
import IFrameLoader from '../IFrameLoader';
import IFrameViewer from '../IFrameViewer';

const sandbox = sinon.createSandbox();

describe('lib/viewers/iframe/IFrameLoader', () => {
afterEach(() => {
sandbox.verifyAndRestore();
const iframe = new IFrameViewer({
file: {
id: '123',
extension: 'boxnote',
representations: {
entries: [
{
representation: 'ORIGINAL',
},
],
},
},
});

test('should have the correct viewer', () => {
Expand All @@ -18,4 +25,24 @@ describe('lib/viewers/iframe/IFrameLoader', () => {
EXT: ['boxnote', 'boxdicom'],
});
});

test.each`
disableDicom | fileType | viewerInstance
${true} | ${'boxdicom'} | ${undefined}
${true} | ${'boxnote'} | ${IFrameLoader.viewers[0]}
${false} | ${'boxdicom'} | ${IFrameLoader.viewers[0]}
`(
'should return correct result depending on the disableDicom viewer option and file type',
({ disableDicom, fileType, viewerInstance }) => {
iframe.options.file.extension = fileType;

const viewerOptions = {
IFrame: {
disableDicom,
},
};
const viewer = IFrameLoader.determineViewer(iframe.options.file, [], viewerOptions);
expect(viewer).toEqual(viewerInstance);
},
);
});