diff --git a/services/web/app/src/Features/Project/ProjectController.js b/services/web/app/src/Features/Project/ProjectController.js index 9f71ca9858..a52097aba9 100644 --- a/services/web/app/src/Features/Project/ProjectController.js +++ b/services/web/app/src/Features/Project/ProjectController.js @@ -887,7 +887,7 @@ const ProjectController = { 'new_navigation_ui', user.alphaProgram ), - showNewBinaryFileUI: shouldDisplayFeature('new_binary_file'), + showNewFileViewUI: shouldDisplayFeature('new_file_view'), showSymbolPalette: shouldDisplayFeature( 'symbol_palette', user.alphaProgram diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index ba8c673f1a..64a019b94f 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -105,8 +105,8 @@ block content .ui-layout-center include ./editor/editor - if showNewBinaryFileUI - include ./editor/binary-file-react + if showNewFileViewUI + include ./editor/file-view else include ./editor/binary-file include ./editor/history diff --git a/services/web/app/views/project/editor/binary-file-react.pug b/services/web/app/views/project/editor/file-view.pug similarity index 67% rename from services/web/app/views/project/editor/binary-file-react.pug rename to services/web/app/views/project/editor/file-view.pug index d1ed6f9b3d..d16be07b50 100644 --- a/services/web/app/views/project/editor/binary-file-react.pug +++ b/services/web/app/views/project/editor/file-view.pug @@ -1,9 +1,9 @@ div( - ng-controller="ReactBinaryFileController" + ng-controller="FileViewController" ng-show="ui.view == 'file'" ng-if="openFile" ) - binary-file( + file-view( file='file' store-references-keys='storeReferencesKeys' ) diff --git a/services/web/frontend/js/features/binary-file/components/binary-file-header.js b/services/web/frontend/js/features/file-view/components/file-view-header.js similarity index 98% rename from services/web/frontend/js/features/binary-file/components/binary-file-header.js rename to services/web/frontend/js/features/file-view/components/file-view-header.js index 93dd30789d..e47687687a 100644 --- a/services/web/frontend/js/features/binary-file/components/binary-file-header.js +++ b/services/web/frontend/js/features/file-view/components/file-view-header.js @@ -31,7 +31,7 @@ function shortenedUrl(url) { return url } -export default function BinaryFileHeader({ file, storeReferencesKeys }) { +export default function FileViewHeader({ file, storeReferencesKeys }) { const { projectId } = useEditorContext({ projectId: PropTypes.string.isRequired, }) @@ -107,7 +107,7 @@ export default function BinaryFileHeader({ file, storeReferencesKeys }) { }, [file, projectId, isMounted, storeReferencesKeys]) return ( -
+
{file.linkedFileData && fileInfo} {file.linkedFileData && tprLinkedFileInfo.map(({ import: { LinkedFileInfo }, path }) => ( @@ -149,7 +149,7 @@ export default function BinaryFileHeader({ file, storeReferencesKeys }) { ) } -BinaryFileHeader.propTypes = { +FileViewHeader.propTypes = { file: PropTypes.shape({ id: PropTypes.string, name: PropTypes.string, diff --git a/services/web/frontend/js/features/binary-file/components/binary-file-image.js b/services/web/frontend/js/features/file-view/components/file-view-image.js similarity index 83% rename from services/web/frontend/js/features/binary-file/components/binary-file-image.js rename to services/web/frontend/js/features/file-view/components/file-view-image.js index 2a0ed4e6c5..f2ba66f96e 100644 --- a/services/web/frontend/js/features/binary-file/components/binary-file-image.js +++ b/services/web/frontend/js/features/file-view/components/file-view-image.js @@ -2,7 +2,7 @@ import React from 'react' import PropTypes from 'prop-types' import { useEditorContext } from '../../../shared/context/editor-context' -export default function BinaryFileImage({ fileName, fileId, onLoad, onError }) { +export default function FileViewImage({ fileName, fileId, onLoad, onError }) { const { projectId } = useEditorContext({ projectId: PropTypes.string.isRequired, }) @@ -18,7 +18,7 @@ export default function BinaryFileImage({ fileName, fileId, onLoad, onError }) { ) } -BinaryFileImage.propTypes = { +FileViewImage.propTypes = { fileName: PropTypes.string.isRequired, fileId: PropTypes.string.isRequired, onLoad: PropTypes.func.isRequired, diff --git a/services/web/frontend/js/features/binary-file/components/binary-file-text.js b/services/web/frontend/js/features/file-view/components/file-view-text.js similarity index 95% rename from services/web/frontend/js/features/binary-file/components/binary-file-text.js rename to services/web/frontend/js/features/file-view/components/file-view-text.js index 99f3d2d5a0..4d26ebacaf 100644 --- a/services/web/frontend/js/features/binary-file/components/binary-file-text.js +++ b/services/web/frontend/js/features/file-view/components/file-view-text.js @@ -4,7 +4,7 @@ import { useEditorContext } from '../../../shared/context/editor-context' const MAX_FILE_SIZE = 2 * 1024 * 1024 -export default function BinaryFileText({ file, onLoad, onError }) { +export default function FileViewText({ file, onLoad, onError }) { const { projectId } = useEditorContext({ projectId: PropTypes.string.isRequired, }) @@ -65,7 +65,7 @@ export default function BinaryFileText({ file, onLoad, onError }) { ) } -BinaryFileText.propTypes = { +FileViewText.propTypes = { file: PropTypes.shape({ id: PropTypes.string }).isRequired, onLoad: PropTypes.func.isRequired, onError: PropTypes.func.isRequired, diff --git a/services/web/frontend/js/features/binary-file/components/binary-file.js b/services/web/frontend/js/features/file-view/components/file-view.js similarity index 73% rename from services/web/frontend/js/features/binary-file/components/binary-file.js rename to services/web/frontend/js/features/file-view/components/file-view.js index 33422c9c21..04c84326f4 100644 --- a/services/web/frontend/js/features/binary-file/components/binary-file.js +++ b/services/web/frontend/js/features/file-view/components/file-view.js @@ -2,16 +2,16 @@ import React, { useState } from 'react' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' -import BinaryFileHeader from './binary-file-header' -import BinaryFileImage from './binary-file-image' -import BinaryFileText from './binary-file-text' +import FileViewHeader from './file-view-header' +import FileViewImage from './file-view-image' +import FileViewText from './file-view-text' import Icon from '../../../shared/components/icon' const imageExtensions = ['png', 'jpg', 'jpeg', 'gif'] const textExtensions = window.ExposedSettings.textExtensions -export default function BinaryFile({ file, storeReferencesKeys }) { +export default function FileView({ file, storeReferencesKeys }) { const [contentLoading, setContentLoading] = useState(true) const [hasError, setHasError] = useState(false) @@ -36,9 +36,9 @@ export default function BinaryFile({ file, storeReferencesKeys }) { const content = ( <> - + {imageExtensions.includes(extension) && ( - )} {textExtensions.includes(extension) && ( - +
{!hasError && content} - {!isUnpreviewableFile && contentLoading && } + {!isUnpreviewableFile && contentLoading && } {(isUnpreviewableFile || hasError) && (

{t('no_preview_available')}

)} @@ -66,10 +66,10 @@ export default function BinaryFile({ file, storeReferencesKeys }) { ) } -function BinaryFileLoadingIndicator() { +function FileViewLoadingIndicator() { const { t } = useTranslation() return ( -
+
  {t('loading')}… @@ -78,7 +78,7 @@ function BinaryFileLoadingIndicator() { ) } -BinaryFile.propTypes = { +FileView.propTypes = { file: PropTypes.shape({ id: PropTypes.string, name: PropTypes.string, diff --git a/services/web/frontend/js/features/binary-file/controllers/binary-file-controller.js b/services/web/frontend/js/features/file-view/controllers/file-view-controller.js similarity index 72% rename from services/web/frontend/js/features/binary-file/controllers/binary-file-controller.js rename to services/web/frontend/js/features/file-view/controllers/file-view-controller.js index d3906d0467..63223a7dbd 100644 --- a/services/web/frontend/js/features/binary-file/controllers/binary-file-controller.js +++ b/services/web/frontend/js/features/file-view/controllers/file-view-controller.js @@ -3,10 +3,10 @@ import { react2angular } from 'react2angular' import _ from 'lodash' import { rootContext } from '../../../shared/context/root-context' -import BinaryFile from '../components/binary-file' +import FileView from '../components/file-view' export default App.controller( - 'ReactBinaryFileController', + 'FileViewController', function ($scope, $rootScope) { $scope.file = $scope.openFile @@ -18,6 +18,6 @@ export default App.controller( ) App.component( - 'binaryFile', - react2angular(rootContext.use(BinaryFile), ['storeReferencesKeys', 'file']) + 'fileView', + react2angular(rootContext.use(FileView), ['storeReferencesKeys', 'file']) ) diff --git a/services/web/frontend/js/ide.js b/services/web/frontend/js/ide.js index 0da7f26f3c..6f4ec1ad22 100644 --- a/services/web/frontend/js/ide.js +++ b/services/web/frontend/js/ide.js @@ -35,9 +35,9 @@ import SafariScrollPatcher from './ide/SafariScrollPatcher' import { loadServiceWorker } from './ide/pdfng/directives/serviceWorkerManager' import './ide/cobranding/CobrandingDataService' import './ide/settings/index' -import './ide/binary-files/index' import './ide/chat/index' import './ide/clone/index' +import './ide/file-view/index' import './ide/hotkeys/index' import './ide/wordcount/index' import './ide/directives/layout' diff --git a/services/web/frontend/js/ide/binary-files/index.js b/services/web/frontend/js/ide/binary-files/index.js deleted file mode 100644 index ff01c5e7db..0000000000 --- a/services/web/frontend/js/ide/binary-files/index.js +++ /dev/null @@ -1 +0,0 @@ -import '../../features/binary-file/controllers/binary-file-controller' diff --git a/services/web/frontend/js/ide/file-view/index.js b/services/web/frontend/js/ide/file-view/index.js new file mode 100644 index 0000000000..b9502cf8eb --- /dev/null +++ b/services/web/frontend/js/ide/file-view/index.js @@ -0,0 +1 @@ +import '../../features/file-view/controllers/file-view-controller' diff --git a/services/web/frontend/stories/binary-file.stories.js b/services/web/frontend/stories/file-view.stories.js similarity index 88% rename from services/web/frontend/stories/binary-file.stories.js rename to services/web/frontend/stories/file-view.stories.js index 99d1ba78ec..c26df536cb 100644 --- a/services/web/frontend/stories/binary-file.stories.js +++ b/services/web/frontend/stories/file-view.stories.js @@ -1,7 +1,7 @@ import React from 'react' import { ContextRoot } from '../js/shared/context/root-context' -import BinaryFile from '../js/features/binary-file/components/binary-file' +import FileView from '../js/features/file-view/components/file-view' import useFetchMock from './hooks/use-fetch-mock' const setupFetchMock = fetchMock => { @@ -26,7 +26,7 @@ const fileData = { } export const FileFromUrl = args => { - return + return } FileFromUrl.args = { file: { @@ -39,7 +39,7 @@ FileFromUrl.args = { } export const FileFromProjectWithLinkableProjectId = args => { - return + return } FileFromProjectWithLinkableProjectId.args = { file: { @@ -53,7 +53,7 @@ FileFromProjectWithLinkableProjectId.args = { } export const FileFromProjectWithoutLinkableProjectId = args => { - return + return } FileFromProjectWithoutLinkableProjectId.args = { file: { @@ -67,7 +67,7 @@ FileFromProjectWithoutLinkableProjectId.args = { } export const FileFromProjectOutputWithLinkableProject = args => { - return + return } FileFromProjectOutputWithLinkableProject.args = { file: { @@ -81,7 +81,7 @@ FileFromProjectOutputWithLinkableProject.args = { } export const FileFromProjectOutputWithoutLinkableProjectId = args => { - return + return } FileFromProjectOutputWithoutLinkableProjectId.args = { file: { @@ -95,7 +95,7 @@ FileFromProjectOutputWithoutLinkableProjectId.args = { } export const ImageFile = args => { - return + return } ImageFile.args = { file: { @@ -111,7 +111,7 @@ ImageFile.args = { } export const ThirdPartyReferenceFile = args => { - return + return } ThirdPartyReferenceFile.args = { @@ -125,7 +125,7 @@ ThirdPartyReferenceFile.args = { } export const ThirdPartyReferenceFileWithError = args => { - return + return } ThirdPartyReferenceFileWithError.args = { file: { @@ -139,7 +139,7 @@ ThirdPartyReferenceFileWithError.args = { } export const TextFile = args => { - return + return } TextFile.args = { file: { @@ -154,7 +154,7 @@ TextFile.args = { } export const UploadedFile = args => { - return + return } UploadedFile.args = { file: { @@ -165,8 +165,8 @@ UploadedFile.args = { } export default { - title: 'BinaryFile', - component: BinaryFile, + title: 'FileView', + component: FileView, args: { storeReferencesKeys: () => {}, }, diff --git a/services/web/frontend/stylesheets/app/editor.less b/services/web/frontend/stylesheets/app/editor.less index d6d13b98b5..574673ea85 100644 --- a/services/web/frontend/stylesheets/app/editor.less +++ b/services/web/frontend/stylesheets/app/editor.less @@ -5,7 +5,7 @@ @import './editor/pdf.less'; @import './editor/share.less'; @import './editor/chat.less'; -@import './editor/binary-file.less'; +@import './editor/file-view.less'; @import './editor/search.less'; @import './editor/publish-template.less'; @import './editor/online-users.less'; @@ -191,7 +191,7 @@ background-color: #fafafa; } -.loading-panel-binary-files { +.loading-panel-file-view { background-color: @gray-lightest; } diff --git a/services/web/frontend/stylesheets/app/editor/binary-file.less b/services/web/frontend/stylesheets/app/editor/file-view.less similarity index 98% rename from services/web/frontend/stylesheets/app/editor/binary-file.less rename to services/web/frontend/stylesheets/app/editor/file-view.less index 4f57591021..d0d454c3be 100644 --- a/services/web/frontend/stylesheets/app/editor/binary-file.less +++ b/services/web/frontend/stylesheets/app/editor/file-view.less @@ -1,3 +1,4 @@ +.file-view, .binary-file { padding: @line-height-computed / 2; background-color: @gray-lightest; diff --git a/services/web/test/frontend/features/binary-file/components/binary-file-header.test.js b/services/web/test/frontend/features/file-view/components/file-view-header.test.js similarity index 89% rename from services/web/test/frontend/features/binary-file/components/binary-file-header.test.js rename to services/web/test/frontend/features/file-view/components/file-view-header.test.js index 9c89743001..fbe703f7a3 100644 --- a/services/web/test/frontend/features/binary-file/components/binary-file-header.test.js +++ b/services/web/test/frontend/features/file-view/components/file-view-header.test.js @@ -9,9 +9,9 @@ import fetchMock from 'fetch-mock' import sinon from 'sinon' import { renderWithEditorContext } from '../../../helpers/render-with-context' -import BinaryFileHeader from '../../../../../frontend/js/features/binary-file/components/binary-file-header.js' +import FileViewHeader from '../../../../../frontend/js/features/file-view/components/file-view-header.js' -describe('', function () { +describe('', function () { const urlFile = { name: 'example.tex', linkedFileData: { @@ -57,7 +57,7 @@ describe('', function () { describe('header text', function () { it('Renders the correct text for a file with the url provider', function () { renderWithEditorContext( - {}} /> + {}} /> ) screen.getByText('Imported from', { exact: false }) screen.getByText('at 3:24 am Wed, 17th Feb 21', { @@ -67,7 +67,7 @@ describe('', function () { it('Renders the correct text for a file with the project_file provider', function () { renderWithEditorContext( - {}} /> + {}} /> ) screen.getByText('Imported from', { exact: false }) screen.getByText('Another project', { exact: false }) @@ -78,7 +78,7 @@ describe('', function () { it('Renders the correct text for a file with the project_output_file provider', function () { renderWithEditorContext( - {}} /> @@ -101,7 +101,7 @@ describe('', function () { ) renderWithEditorContext( - {}} /> + {}} /> ) fireEvent.click(screen.getByRole('button', { name: 'Refresh' })) @@ -132,7 +132,7 @@ describe('', function () { const storeReferencesKeys = sinon.stub() renderWithEditorContext( - @@ -152,7 +152,7 @@ describe('', function () { describe('The download button', function () { it('exists', function () { renderWithEditorContext( - {}} /> + {}} /> ) screen.getByText('Download', { exact: false }) diff --git a/services/web/test/frontend/features/binary-file/components/binary-file-image.test.js b/services/web/test/frontend/features/file-view/components/file-view-image.test.js similarity index 76% rename from services/web/test/frontend/features/binary-file/components/binary-file-image.test.js rename to services/web/test/frontend/features/file-view/components/file-view-image.test.js index e08f14e16a..93b5dcb472 100644 --- a/services/web/test/frontend/features/binary-file/components/binary-file-image.test.js +++ b/services/web/test/frontend/features/file-view/components/file-view-image.test.js @@ -2,9 +2,9 @@ import React from 'react' import { screen } from '@testing-library/react' import { renderWithEditorContext } from '../../../helpers/render-with-context' -import BinaryFileImage from '../../../../../frontend/js/features/binary-file/components/binary-file-image.js' +import FileViewImage from '../../../../../frontend/js/features/file-view/components/file-view-image.js' -describe('', function () { +describe('', function () { const file = { id: '60097ca20454610027c442a8', name: 'file.jpg', @@ -16,7 +16,7 @@ describe('', function () { it('renders an image', function () { renderWithEditorContext( - {}} diff --git a/services/web/test/frontend/features/binary-file/components/binary-file-text.test.js b/services/web/test/frontend/features/file-view/components/file-view-text.test.js similarity index 80% rename from services/web/test/frontend/features/binary-file/components/binary-file-text.test.js rename to services/web/test/frontend/features/file-view/components/file-view-text.test.js index 11857a67b8..409132b302 100644 --- a/services/web/test/frontend/features/binary-file/components/binary-file-text.test.js +++ b/services/web/test/frontend/features/file-view/components/file-view-text.test.js @@ -3,9 +3,9 @@ import { screen } from '@testing-library/react' import fetchMock from 'fetch-mock' import { renderWithEditorContext } from '../../../helpers/render-with-context' -import BinaryFileText from '../../../../../frontend/js/features/binary-file/components/binary-file-text.js' +import FileViewText from '../../../../../frontend/js/features/file-view/components/file-view-text.js' -describe('', function () { +describe('', function () { const file = { name: 'example.tex', linkedFileData: { @@ -32,7 +32,7 @@ describe('', function () { ) renderWithEditorContext( - {}} onLoad={() => {}} /> + {}} onLoad={() => {}} /> ) await screen.findByText('Text file content', { exact: false }) diff --git a/services/web/test/frontend/features/binary-file/components/binary-file.test.js b/services/web/test/frontend/features/file-view/components/file-view.test.js similarity index 81% rename from services/web/test/frontend/features/binary-file/components/binary-file.test.js rename to services/web/test/frontend/features/file-view/components/file-view.test.js index 3df2834e80..876caa0caa 100644 --- a/services/web/test/frontend/features/binary-file/components/binary-file.test.js +++ b/services/web/test/frontend/features/file-view/components/file-view.test.js @@ -7,9 +7,9 @@ import { import fetchMock from 'fetch-mock' import { renderWithEditorContext } from '../../../helpers/render-with-context' -import BinaryFile from '../../../../../frontend/js/features/binary-file/components/binary-file.js' +import FileView from '../../../../../frontend/js/features/file-view/components/file-view.js' -describe('', function () { +describe('', function () { const textFile = { name: 'example.tex', linkedFileData: { @@ -37,7 +37,7 @@ describe('', function () { describe('for a text file', function () { it('shows a loading indicator while the file is loading', async function () { renderWithEditorContext( - {}} /> + {}} /> ) await waitForElementToBeRemoved(() => @@ -47,7 +47,7 @@ describe('', function () { it('shows messaging if the text view could not be loaded', async function () { renderWithEditorContext( - {}} /> + {}} /> ) await screen.findByText('Sorry, no preview is available', { @@ -59,7 +59,7 @@ describe('', function () { describe('for an image file', function () { it('shows a loading indicator while the file is loading', async function () { renderWithEditorContext( - {}} /> + {}} /> ) screen.getByText('Loading', { exact: false }) @@ -67,7 +67,7 @@ describe('', function () { it('shows messaging if the image could not be loaded', function () { renderWithEditorContext( - {}} /> + {}} /> ) // Fake the image request failing as the request is handled by the browser