From 6175df9f955398488700fbc1d3839044749e0dcf Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Thu, 16 Feb 2023 13:23:53 +0000 Subject: [PATCH] Show preview for PDF image (#11793) GitOrigin-RevId: 5c7dde42cdfcf9952e47487358f7e2b52658cc59 --- .../frontend/js/ide/file-tree/FileTreeManager.js | 14 ++++++++++---- services/web/frontend/stories/decorators/scope.tsx | 2 +- .../web/test/frontend/helpers/editor-providers.js | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/services/web/frontend/js/ide/file-tree/FileTreeManager.js b/services/web/frontend/js/ide/file-tree/FileTreeManager.js index 0ee55474f2..b669f64079 100644 --- a/services/web/frontend/js/ide/file-tree/FileTreeManager.js +++ b/services/web/frontend/js/ide/file-tree/FileTreeManager.js @@ -292,19 +292,25 @@ export default FileTreeManager = class FileTreeManager { return this._findEntityByPathInFolder(this.$scope.rootFolder, path) } - getPreviewUrlByPath(path) { - for (const extension of [ + getPreviewByPath(path) { + for (const suffix of [ '', '.png', '.jpg', '.jpeg', + '.pdf', '.PNG', '.JPG', '.JPEG', + '.PDF', ]) { - const entity = this.findEntityByPath(path + extension) + const entity = this.findEntityByPath(path + suffix) + if (entity) { - return `/project/${this.$scope.project._id}/file/${entity.id}` + return { + url: `/project/${this.$scope.project._id}/file/${entity.id}`, + extension: entity.name.split('.').pop(), + } } } return null diff --git a/services/web/frontend/stories/decorators/scope.tsx b/services/web/frontend/stories/decorators/scope.tsx index 78c5c2c128..bcfad7369d 100644 --- a/services/web/frontend/stories/decorators/scope.tsx +++ b/services/web/frontend/stories/decorators/scope.tsx @@ -98,7 +98,7 @@ const initialize = () => { findEntityByPath: () => null, getEntityPath: () => null, getRootDocDirname: () => undefined, - getPreviewUrlByPath: () => undefined, + getPreviewByPath: () => null, }, editorManager: { getCurrentDocId: () => 'foo', diff --git a/services/web/test/frontend/helpers/editor-providers.js b/services/web/test/frontend/helpers/editor-providers.js index 7164f5df13..f221da50a7 100644 --- a/services/web/test/frontend/helpers/editor-providers.js +++ b/services/web/test/frontend/helpers/editor-providers.js @@ -52,7 +52,7 @@ export function EditorProviders({ findEntityByPath: () => null, getEntityPath: () => '', getRootDocDirname: () => '', - getPreviewUrlByPath: path => path, + getPreviewByPath: path => ({ url: path, extension: 'png' }), }, editorManager = { getCurrentDocId: () => 'foo',