Skip to content

Commit

Permalink
New: Emit metric when missing xrefs (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradJChan authored Jun 11, 2019
1 parent a2508e6 commit eca5b2c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ export const USER_DOCUMENT_THUMBNAIL_EVENTS = {
NAVIGATE: 'user_document_thumbnails_navigate',
OPEN: 'user_document_thumbnails_open'
};

export const MISSING_EXTERNAL_REFS = 'missing_x_refs';
13 changes: 7 additions & 6 deletions src/lib/metadataAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ const metadataAPI = {
return Promise.reject(new Error('id and template are required parameters'));
}

return metadataAPI.getMetadata(id, SCOPE_GLOBAL, template, options).then((response) => {
// The hasxrefs value is returned as a string 'false' or 'true' so we want
// to convert this to a boolean
const { [FIELD_HASXREFS]: hasXrefsValue } = response;
return { ...response, [FIELD_HASXREFS]: hasXrefsValue === 'true' };
});
return metadataAPI
.getMetadata(id, SCOPE_GLOBAL, template, options)
.then(({ [FIELD_HASXREFS]: hasXrefsValue, ...rest }) => {
// The hasxrefs value is returned as a string 'false' or 'true' so we want
// to convert this to a boolean
return { ...rest, [FIELD_HASXREFS]: hasXrefsValue === 'true' };
});
},

/**
Expand Down
8 changes: 7 additions & 1 deletion src/lib/viewers/doc/AutoCADViewer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import DocumentViewer from './DocumentViewer';
import metadataAPI from '../../metadataAPI';
import { METADATA } from '../../constants';
import { MISSING_EXTERNAL_REFS } from '../../events';

const { FIELD_HASXREFS, TEMPLATE_AUTOCAD } = METADATA;

Expand All @@ -19,11 +20,16 @@ class AutoCADViewer extends DocumentViewer {
* @return {void}
*/
checkForXrefs() {
const { id } = this.options.file;
const { extension, id } = this.options.file;

metadataAPI.getXrefsMetadata(id, TEMPLATE_AUTOCAD, this.options).then(({ [FIELD_HASXREFS]: hasxrefsValue }) => {
if (hasxrefsValue) {
this.options.ui.showNotification(__('has_x_refs'), null, true);

this.emitMetric({
name: MISSING_EXTERNAL_REFS,
data: extension
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/doc/DocLoader.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import AssetLoader from '../AssetLoader';
import { getRepresentation } from '../../file';
import AutoCADViewer from './AutoCADViewer';
import DocumentViewer from './DocumentViewer';
import PresentationViewer from './PresentationViewer';
import SinglePageViewer from './SinglePageViewer';
import RepStatus from '../../RepStatus';
import { ORIGINAL_REP_NAME, STATUS_SUCCESS } from '../../constants';
import { DOCUMENT_EXTENSIONS } from '../../extensions';
import AutoCADViewer from './AutoCADViewer';

// Order of the viewers matters. For example, a PDF file can be previewed by using the preferred optimized 'pdf' rep
// or the original as a fallback. Additionally, we include multiple entries for the presentation viewer so that it can be
Expand Down
8 changes: 7 additions & 1 deletion src/lib/viewers/doc/__tests__/AutoCADViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import DocumentViewer from '../DocumentViewer';
import AutoCADViewer from '../AutoCADViewer';
import metadataAPI from '../../../metadataAPI';
import { METADATA } from '../../../constants';
import { MISSING_EXTERNAL_REFS } from '../../../events';

const { FIELD_HASXREFS, TEMPLATE_AUTOCAD } = METADATA;
const EXTENSION = 'dwg';
const sandbox = sinon.sandbox.create();

let containerEl;
Expand All @@ -23,10 +25,12 @@ describe('lib/viewers/doc/AutoCADViewer', () => {

stubs.getXrefsMetadata = sandbox.stub(metadataAPI, 'getXrefsMetadata');
stubs.showNotification = sandbox.stub();
stubs.emitMetric = sandbox.stub(autocad, 'emitMetric');

autocad.options = {
file: {
id: '123'
id: '123',
extension: EXTENSION
},
ui: {
showNotification: stubs.showNotification
Expand Down Expand Up @@ -63,6 +67,7 @@ describe('lib/viewers/doc/AutoCADViewer', () => {

return xrefsPromise.then(() => {
expect(stubs.showNotification).to.have.been.called;
expect(stubs.emitMetric).to.have.been.calledWith({ name: MISSING_EXTERNAL_REFS, data: EXTENSION });
});
});

Expand All @@ -76,6 +81,7 @@ describe('lib/viewers/doc/AutoCADViewer', () => {

return xrefsPromise.then(() => {
expect(stubs.showNotification).not.to.have.been.called;
expect(stubs.emitMetric).not.to.have.been.called;
});
});
});
Expand Down

0 comments on commit eca5b2c

Please sign in to comment.