Przeglądaj źródła

Merge pull request #4044 from overleaf/as-file-views-text-extension

Pull text extension list from settings, instead of hard-coding it

GitOrigin-RevId: b5ba956b8f065b852a2f5efc1a775ccb70df3226
Jakob Ackermann 5 lat temu
rodzic
commit
3f1ae7bff2

+ 31 - 0
services/web/.storybook/preview.js

@@ -90,6 +90,37 @@ window.ExposedSettings = {
   maxEntitiesPerProject: 10,
   maxUploadSize: 5 * 1024 * 1024,
   enableSubscriptions: true,
+  textExtensions: [
+    'tex',
+    'latex',
+    'sty',
+    'cls',
+    'bst',
+    'bib',
+    'bibtex',
+    'txt',
+    'tikz',
+    'mtx',
+    'rtex',
+    'md',
+    'asy',
+    'latexmkrc',
+    'lbx',
+    'bbx',
+    'cbx',
+    'm',
+    'lco',
+    'dtx',
+    'ins',
+    'ist',
+    'def',
+    'clo',
+    'ldf',
+    'rmd',
+    'lua',
+    'gv',
+    'mf',
+  ],
 }
 
 window.user = {

+ 6 - 33
services/web/frontend/js/features/binary-file/components/binary-file.js

@@ -1,50 +1,23 @@
 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 Icon from '../../../shared/components/icon'
-import { useTranslation } from 'react-i18next'
 
 const imageExtensions = ['png', 'jpg', 'jpeg', 'gif']
 
-const textExtensions = [
-  'tex',
-  'latex',
-  'sty',
-  'cls',
-  'bst',
-  'bib',
-  'bibtex',
-  'txt',
-  'tikz',
-  'mtx',
-  'rtex',
-  'md',
-  'asy',
-  'latexmkrc',
-  'lbx',
-  'bbx',
-  'cbx',
-  'm',
-  'lco',
-  'dtx',
-  'ins',
-  'ist',
-  'def',
-  'clo',
-  'ldf',
-  'rmd',
-  'lua',
-  'gv',
-]
+const textExtensions = window.ExposedSettings.textExtensions
 
 export default function BinaryFile({ file, storeReferencesKeys }) {
-  const extension = file.name.split('.').pop().toLowerCase()
-
   const [contentLoading, setContentLoading] = useState(true)
   const [hasError, setHasError] = useState(false)
+
   const { t } = useTranslation()
+
+  const extension = file.name.split('.').pop().toLowerCase()
   const isUnpreviewableFile =
     !imageExtensions.includes(extension) && !textExtensions.includes(extension)
 

+ 2 - 1
services/web/frontend/js/features/binary-file/controllers/binary-file-controller.js

@@ -1,8 +1,9 @@
 import App from '../../../base'
 import { react2angular } from 'react2angular'
-import BinaryFile from '../components/binary-file'
 import _ from 'lodash'
 
+import BinaryFile from '../components/binary-file'
+
 export default App.controller(
   'ReactBinaryFileController',
   function ($scope, $rootScope) {

+ 31 - 0
services/web/test/frontend/bootstrap.js

@@ -23,6 +23,37 @@ window.ExposedSettings = {
   maxEntitiesPerProject: 10,
   maxUploadSize: 5 * 1024 * 1024,
   siteUrl: 'https://www.dev-overleaf.com',
+  textExtensions: [
+    'tex',
+    'latex',
+    'sty',
+    'cls',
+    'bst',
+    'bib',
+    'bibtex',
+    'txt',
+    'tikz',
+    'mtx',
+    'rtex',
+    'md',
+    'asy',
+    'latexmkrc',
+    'lbx',
+    'bbx',
+    'cbx',
+    'm',
+    'lco',
+    'dtx',
+    'ins',
+    'ist',
+    'def',
+    'clo',
+    'ldf',
+    'rmd',
+    'lua',
+    'gv',
+    'mf',
+  ],
 }
 
 window.i18n = { currentLangCode: 'en' }