Commit 854bcedd authored by Samantha Ming's avatar Samantha Ming

Add suggestion patch

- Use computed hasRichViewer instead as a data
- Update date to suit
parent 56ffe743
...@@ -23,18 +23,10 @@ export default { ...@@ -23,18 +23,10 @@ export default {
filePath: this.path, filePath: this.path,
}; };
}, },
result({ data }) { result() {
const [blob] = data?.project?.repository?.blobs?.nodes; this.switchViewer(
this.hasRichViewer && !window.location.hash ? RICH_BLOB_VIEWER : SIMPLE_BLOB_VIEWER,
if (!blob) { );
return;
}
const hasRichViewer = blob?.richViewer !== null;
this.hasRichViewer = hasRichViewer;
this.activeViewerType =
hasRichViewer && !window.location.hash ? RICH_BLOB_VIEWER : SIMPLE_BLOB_VIEWER;
}, },
error() { error() {
createFlash({ message: __('An error occurred while loading the file. Please try again.') }); createFlash({ message: __('An error occurred while loading the file. Please try again.') });
...@@ -58,7 +50,6 @@ export default { ...@@ -58,7 +50,6 @@ export default {
}, },
data() { data() {
return { return {
hasRichViewer: false,
activeViewerType: SIMPLE_BLOB_VIEWER, activeViewerType: SIMPLE_BLOB_VIEWER,
project: { project: {
repository: { repository: {
...@@ -85,7 +76,7 @@ export default { ...@@ -85,7 +76,7 @@ export default {
canModifyBlob: true, canModifyBlob: true,
forkPath: '', forkPath: '',
simpleViewer: {}, simpleViewer: {},
richViewer: {}, richViewer: null,
}, },
], ],
}, },
...@@ -106,6 +97,9 @@ export default { ...@@ -106,6 +97,9 @@ export default {
const { richViewer, simpleViewer } = this.blobInfo; const { richViewer, simpleViewer } = this.blobInfo;
return this.activeViewerType === RICH_BLOB_VIEWER ? richViewer : simpleViewer; return this.activeViewerType === RICH_BLOB_VIEWER ? richViewer : simpleViewer;
}, },
hasRichViewer() {
return Boolean(this.blobInfo.richViewer);
},
hasRenderError() { hasRenderError() {
return Boolean(this.viewer.renderError); return Boolean(this.viewer.renderError);
}, },
......
...@@ -108,7 +108,7 @@ describe('Blob content viewer component', () => { ...@@ -108,7 +108,7 @@ describe('Blob content viewer component', () => {
describe('rich viewer', () => { describe('rich viewer', () => {
beforeEach(() => { beforeEach(() => {
factory({ factory({
mockData: { blobInfo: richMockData, hasRichViewer: true, activeViewerType: 'rich' }, mockData: { blobInfo: richMockData, activeViewerType: 'rich' },
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment