From aa480a266303c68a449ef2581a9f916ff1f9fc23 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 18 Jun 2024 12:01:37 +0200 Subject: [PATCH] Merge pull request #18898 from overleaf/jpa-no-window [web] migrate from window attributes to getMeta GitOrigin-RevId: 3dcf1ab6b01155e5e4abeb3e78d0fa9053e055bc --- services/web/.eslintrc.js | 3 - services/web/.storybook/preview.tsx | 88 +++++- .../app/src/infrastructure/ExpressLocals.js | 8 + .../web/app/views/project/editor/meta.pug | 3 - services/web/cypress/support/component.ts | 12 +- services/web/cypress/support/ct/window.ts | 26 +- .../js/features/cookie-banner/index.js | 9 +- .../components/actions-menu.tsx | 4 +- .../editor-left-menu/components/help-menu.tsx | 2 +- .../components/settings-menu.tsx | 4 +- .../settings/settings-editor-theme.tsx | 6 +- .../settings/settings-image-name.tsx | 14 +- .../settings/settings-overall-theme.tsx | 5 +- .../settings-spell-check-language.tsx | 3 +- .../editor-left-menu/components/sync-menu.tsx | 6 +- .../hooks/use-set-overall-theme.tsx | 3 +- .../components/toolbar-header.jsx | 3 +- .../file-tree-modal-create-file-body.jsx | 12 +- .../modes/file-tree-import-from-project.tsx | 3 +- .../modes/file-tree-upload-doc.tsx | 5 +- .../file-tree/contexts/file-tree-path.tsx | 2 +- .../features/file-tree/util/count-in-tree.js | 4 +- .../file-tree/util/is-acceptable-file.ts | 3 +- .../file-view/components/file-view.jsx | 3 +- .../components/group-managers.tsx | 4 +- .../components/group-members.tsx | 6 +- .../components/institution-managers.tsx | 4 +- .../components/managers-table.tsx | 2 +- .../components/members-table/member-row.tsx | 2 +- .../components/members-table/members-list.tsx | 2 +- .../components/publisher-managers.tsx | 4 +- .../context/group-members-context.tsx | 4 +- .../features/ide-react/components/loading.tsx | 6 +- .../ide-react/context/ide-react-context.tsx | 15 +- .../ide-react/context/permissions-context.tsx | 2 +- .../hooks/use-review-panel-state.ts | 3 +- .../ide-react/editor/document-container.ts | 3 +- .../features/ide-react/editor/share-js-doc.ts | 4 +- .../compile-time-warning-upgrade-prompt.tsx | 3 +- .../components/timeout-upgrade-prompt-new.tsx | 5 +- .../pdf-preview/util/pdf-js-versions.js | 2 +- .../plans/utils/group-plan-pricing.js | 2 +- .../components/add-affiliation.tsx | 6 +- .../current-plan-widget.tsx | 5 +- .../modals/projects-action-modal.tsx | 5 +- .../modals/rename-project-modal.tsx | 5 +- .../components/new-project-button.tsx | 8 +- .../modal-content-new-project-form.tsx | 6 +- .../upload-project-modal.tsx | 7 +- .../components/notifications/geo-banners.tsx | 6 +- .../groups-and-enterprise-banner.tsx | 25 +- .../affiliation/reconfirm-affiliation.tsx | 8 +- .../affiliation/reconfirmation-info.tsx | 11 +- .../notifications/groups/common.tsx | 13 +- .../notifications/groups/confirm-email.tsx | 16 +- .../group-invitation-cancel-subscription.tsx | 5 +- .../group-invitation-join.tsx | 5 +- .../group-invitation-successful.tsx | 5 +- .../use-group-invitation-notification.tsx | 2 +- .../notifications/groups/institution.tsx | 16 +- .../components/notifications/notification.tsx | 3 +- .../notifications/user-notifications.tsx | 16 +- .../project-list/components/survey-widget.tsx | 3 +- .../action-buttons/delete-project-button.tsx | 3 +- .../action-buttons/leave-project-button.tsx | 3 +- ...me-message-create-new-project-dropdown.tsx | 10 +- .../components/welcome-message.tsx | 5 +- .../context/project-list-context.tsx | 2 +- .../js/features/project-list/util/user.ts | 3 +- .../components/account-info-section.tsx | 11 +- .../settings/components/emails-section.tsx | 9 +- .../components/emails/actions/remove.tsx | 2 +- .../settings/components/emails/add-email.tsx | 2 +- .../emails/add-email/sso-linking-info.tsx | 3 +- .../components/emails/reconfirmation-info.tsx | 9 +- .../settings/components/emails/row.tsx | 3 +- .../settings/components/emails/sso-alert.tsx | 19 +- .../components/leave/modal-content.tsx | 5 +- .../components/leave/modal-form-error.tsx | 3 +- .../settings/components/leave/modal-form.tsx | 2 +- .../settings/components/linking-section.tsx | 46 +-- .../components/managed-account-alert.tsx | 7 +- .../settings/components/password-section.tsx | 14 +- .../js/features/settings/components/root.tsx | 5 +- .../settings/components/security-section.tsx | 7 +- .../features/settings/context/sso-context.tsx | 10 +- .../js/features/settings/utils/sso.ts | 9 +- .../components/link-sharing.jsx | 3 +- .../components/share-modal-body.tsx | 3 +- .../features/share-project-modal/utils/api.js | 3 +- .../figure-modal-source-picker.tsx | 3 +- .../figure-modal-other-project-source.tsx | 3 +- .../figure-modal-upload-source.tsx | 7 +- .../components/grammarly-advert.tsx | 3 +- .../toolbar/insert-figure-dropdown.tsx | 3 +- .../hooks/use-codemirror-scope.ts | 6 +- .../dashboard/group-settings-button.tsx | 6 +- .../group-subscription-membership.tsx | 4 +- .../dashboard/managed-group-subscriptions.tsx | 7 +- .../dashboard/managed-institution.tsx | 5 +- .../dashboard/managed-institutions.tsx | 10 - .../dashboard/managed-publisher.tsx | 2 +- .../dashboard/managed-publishers.tsx | 7 - ...rsonal-subscription-recurly-sync-email.tsx | 2 +- .../modals/change-to-group-modal.tsx | 5 +- .../modals/confirm-change-plan-modal.tsx | 3 +- .../dashboard/subscription-dashboard.tsx | 2 +- .../group-invite/accepted-invite.tsx | 6 +- .../components/group-invite/group-invite.tsx | 10 +- .../components/group-invite/join-group.tsx | 4 +- .../group-invite/managed-user-cannot-join.tsx | 2 +- .../group-invites/group-invites.tsx | 3 +- .../successful-subscription.tsx | 7 +- .../subscription-dashboard-context.tsx | 24 +- .../subscription/util/recurly-pricing.ts | 5 +- services/web/frontend/js/i18n.js | 5 +- .../frontend/js/ide/colors/ColorManager.js | 3 +- .../file-tree/util/fileOperationI18nNames.js | 14 - .../js/ide/history/util/displayNameForUser.js | 18 +- .../HumanReadableLogsHints.jsx | 5 +- .../js/infrastructure/error-reporter.js | 23 +- .../js/infrastructure/event-tracking.js | 3 +- .../frontend/js/infrastructure/fetch-json.ts | 3 +- .../web/frontend/js/main/is-valid-tex-file.js | 4 +- .../js/shared/components/recaptcha-2.tsx | 12 +- .../js/shared/components/system-messages.tsx | 9 +- .../shared/components/translation-message.tsx | 5 +- .../js/shared/context/editor-context.tsx | 29 +- .../shared/context/local-compile-context.tsx | 5 +- .../js/shared/context/project-context.tsx | 4 +- services/web/frontend/js/utils/meta.js | 50 ---- services/web/frontend/js/utils/meta.ts | 269 ++++++++++++++++++ .../web/frontend/js/vendor/libs/sharejs.js | 3 +- .../web/frontend/stories/decorators/scope.tsx | 94 +----- .../create-file/create-file-modal.stories.jsx | 25 +- .../project-list/add-affiliation.stories.tsx | 4 +- .../project-list/color-picker.stories.tsx | 2 - ...mpile-and-download-project-pdf.stories.tsx | 4 +- .../stories/project-list/helpers/emails.ts | 5 +- .../new-project-button.stories.tsx | 5 +- .../project-list/project-list.stories.tsx | 2 +- .../project-list/survey-widget.stories.tsx | 1 - .../project-list/system-messages.stories.tsx | 2 - .../stories/settings/account-info.stories.jsx | 3 +- .../stories/settings/helpers/account-info.js | 6 +- .../stories/settings/helpers/emails.js | 6 +- .../stories/settings/helpers/leave.js | 6 +- .../stories/settings/helpers/linking.js | 3 +- .../stories/settings/helpers/password.js | 6 +- .../stories/settings/linking.stories.jsx | 3 +- .../stories/settings/page.stories.jsx | 7 +- .../stories/settings/password.stories.jsx | 3 +- .../stories/settings/sso-alert.stories.tsx | 6 - .../stories/share-project-modal.stories.jsx | 14 +- .../source-editor/source-editor.stories.tsx | 2 +- services/web/test/frontend/bootstrap.js | 54 +--- .../editor-left-menu.spec.tsx | 5 +- .../detach-compile-button.spec.tsx | 6 +- .../pdf-preview/pdf-logs-entries.spec.tsx | 4 +- .../pdf-preview-detached-root.spec.tsx | 5 +- .../pdf-preview-hybrid-toolbar.spec.tsx | 8 +- .../token-access/token-access-page.spec.tsx | 6 +- .../chat/components/chat-pane.test.jsx | 2 - .../features/chat/components/message.test.jsx | 3 +- .../chat/context/chat-context.test.jsx | 2 - .../dictionary-modal-content.test.jsx | 7 +- .../components/actions-menu.test.jsx | 1 - .../components/help-contact-us.test.jsx | 2 - .../components/help-menu.test.jsx | 2 - .../settings/settings-editor-theme.test.tsx | 1 - .../settings/settings-image-name.test.tsx | 1 - .../settings/settings-overall-theme.test.tsx | 4 +- .../settings-spell-check-language.test.tsx | 1 - .../layout-dropdown-button.test.jsx | 2 - .../file-tree-modal-create-file.spec.tsx | 29 +- .../components/group-members.spec.tsx | 2 - .../components/managed-group-members.spec.tsx | 2 - .../members-table/member-row.spec.tsx | 9 - .../members-table/unlink-user-modal.test.tsx | 2 - .../components/current-plan-widget.test.tsx | 1 - .../components/new-project-button.test.tsx | 13 +- .../components/notifications.test.tsx | 35 +-- .../components/project-list-root.test.tsx | 7 +- .../sidebar/add-affiliation.test.tsx | 11 +- .../components/sidebar/tags-list.test.tsx | 1 - .../components/survey-widget.test.tsx | 1 - .../components/system-messages.test.tsx | 3 - .../delete-project-button.test.tsx | 6 +- .../leave-project-button.test.tsx | 2 +- .../table/project-list-table.test.tsx | 4 +- .../project-tools-rename.test.tsx | 1 - .../components/welcome-message.test.tsx | 24 +- .../components/account-info-section.test.tsx | 7 +- .../components/beta-program-section.test.tsx | 4 - .../components/emails/emails-row.test.tsx | 4 +- .../emails/emails-section-actions.test.tsx | 9 +- .../emails-section-add-new-email.test.tsx | 4 +- ...ails-section-institution-and-role.test.tsx | 5 +- .../components/emails/emails-section.test.tsx | 4 +- .../emails/reconfirmation-info.test.tsx | 18 +- .../components/emails/sso-alert.test.tsx | 4 - .../components/leave-section.test.tsx | 8 +- .../components/leave/modal-content.test.tsx | 5 +- .../components/leave/modal-form.test.tsx | 9 +- .../settings/components/leave/modal.test.tsx | 5 +- .../components/linking-section.test.tsx | 6 +- .../components/password-section.test.tsx | 7 +- .../settings/components/root.test.tsx | 9 +- .../components/security-section.test.tsx | 5 - .../settings/context/sso-context.test.tsx | 1 - .../components/share-project-modal.test.jsx | 2 - .../codemirror-editor-figure-modal.spec.tsx | 18 +- .../source-editor/helpers/mock-doc.ts | 2 +- .../components/dashboard/free-plan.test.tsx | 8 - .../group-subscription-memberships.test.tsx | 5 +- .../managed-group-subscriptions.test.tsx | 3 +- .../dashboard/managed-institutions.test.tsx | 12 +- .../dashboard/managed-publishers.test.tsx | 10 +- .../dashboard/states/expired.test.tsx | 8 - .../group-invite/accepted-invite.test.tsx | 4 - .../group-invite/group-invite.test.tsx | 5 - .../successful-subscription.test.tsx | 4 - .../render-with-subscription-dash-context.tsx | 2 - .../subscription/util/recurly-pricing.test.ts | 7 - .../frontend/helpers/editor-providers.jsx | 21 +- .../frontend/helpers/render-with-context.jsx | 2 - .../web/test/frontend/helpers/reset-meta.ts | 51 ++++ .../history/util/displayNameForUserTests.js | 15 +- .../test/frontend/reset-meta-before-each.js | 5 + .../shared/utils/group-plan-pricing.test.js | 6 +- .../web/types/group-management/validation.ts | 3 + .../types/project/dashboard/notification.ts | 9 + services/web/types/settings-page.ts | 18 ++ services/web/types/split-test.ts | 11 + .../data => types/subscription}/currency.ts | 0 .../dashboard/managed-institution.ts | 9 + .../types/subscription/dashboard/publisher.ts | 6 + .../subscription/dashboard/subscription.ts | 2 +- .../subscription/payment-context-value.tsx | 68 +++++ services/web/types/window.ts | 23 +- 240 files changed, 1089 insertions(+), 1126 deletions(-) delete mode 100644 services/web/frontend/js/ide/file-tree/util/fileOperationI18nNames.js delete mode 100644 services/web/frontend/js/utils/meta.js create mode 100644 services/web/frontend/js/utils/meta.ts create mode 100644 services/web/test/frontend/helpers/reset-meta.ts create mode 100644 services/web/test/frontend/reset-meta-before-each.js create mode 100644 services/web/types/group-management/validation.ts create mode 100644 services/web/types/settings-page.ts create mode 100644 services/web/types/split-test.ts rename services/web/{frontend/js/features/subscription/data => types/subscription}/currency.ts (100%) create mode 100644 services/web/types/subscription/dashboard/managed-institution.ts create mode 100644 services/web/types/subscription/dashboard/publisher.ts create mode 100644 services/web/types/subscription/payment-context-value.tsx diff --git a/services/web/.eslintrc.js b/services/web/.eslintrc.js index 9bc1656822..0aefd86d0c 100644 --- a/services/web/.eslintrc.js +++ b/services/web/.eslintrc.js @@ -195,9 +195,6 @@ module.exports = { $: true, angular: true, ga: true, - // Injected in layout.pug - user_id: true, - ExposedSettings: true, }, rules: { // TODO: remove once https://github.com/standard/eslint-config-standard-react/issues/68 (support eslint@8) is fixed. diff --git a/services/web/.storybook/preview.tsx b/services/web/.storybook/preview.tsx index 39d5913ba3..6975503524 100644 --- a/services/web/.storybook/preview.tsx +++ b/services/web/.storybook/preview.tsx @@ -9,11 +9,82 @@ import i18n from 'i18next' import { initReactI18next } from 'react-i18next' // @ts-ignore import en from '../../../services/web/locales/en.json' -import { ExposedSettings } from '../types/exposed-settings' -import { User } from '../types/user' -window.i18n = window.i18n || {} -window.i18n.currentLangCode = window.i18n.currentLangCode || 'en' +function resetMeta() { + window.metaAttributesCache = new Map() + window.metaAttributesCache.set('ol-i18n', { currentLangCode: 'en' }) + window.metaAttributesCache.set('ol-ExposedSettings', { + adminEmail: 'placeholder@example.com', + appName: 'Overleaf', + cookieDomain: '.overleaf.stories', + dropboxAppName: 'Overleaf-Stories', + emailConfirmationDisabled: false, + enableSubscriptions: true, + hasAffiliationsFeature: false, + hasLinkUrlFeature: true, + hasLinkedProjectFileFeature: true, + hasLinkedProjectOutputFileFeature: true, + hasSamlFeature: true, + ieeeBrandId: 15, + isOverleaf: true, + labsEnabled: true, + maxEntitiesPerProject: 10, + maxUploadSize: 5 * 1024 * 1024, + recaptchaDisabled: { + invite: true, + login: true, + passwordReset: true, + register: true, + addEmail: true, + }, + sentryAllowedOriginRegex: '', + siteUrl: 'http://localhost', + templateLinks: [], + textExtensions: [ + 'tex', + 'latex', + 'sty', + 'cls', + 'bst', + 'bib', + 'bibtex', + 'txt', + 'tikz', + 'mtx', + 'rtex', + 'md', + 'asy', + 'lbx', + 'bbx', + 'cbx', + 'm', + 'lco', + 'dtx', + 'ins', + 'ist', + 'def', + 'clo', + 'ldf', + 'rmd', + 'lua', + 'gv', + 'mf', + 'lhs', + 'mk', + 'xmpdata', + 'cfg', + 'rnw', + 'ltx', + 'inc', + ], + editableFilenames: ['latexmkrc', '.latexmkrc', 'makefile', 'gnumakefile'], + validRootDocExtensions: ['tex', 'Rtex', 'ltx', 'Rnw'], + fileIgnorePattern: + '**/{{__MACOSX,.git,.texpadtmp,.R}{,/**},.!(latexmkrc),*.{dvi,aux,log,toc,out,pdfsync,synctex,synctex(busy),fdb_latexmk,fls,nlo,ind,glo,gls,glg,bbl,blg,doc,docx,gz,swp}}', + projectUploadTimeout: 12000, + }) +} + i18n.use(initReactI18next).init({ lng: 'en', @@ -41,10 +112,6 @@ i18n.use(initReactI18next).init({ }, }) -// avoid some errors by creating these objects in advance -window.user = {} as User -window.ExposedSettings = {} as ExposedSettings - const preview: Preview = { parameters: { // Automatically mark prop-types like onClick, onToggle, etc as Storybook @@ -98,6 +165,8 @@ const preview: Preview = { ? bootstrap5Style : bootstrap3Style + resetMeta() + return ( <> {activeStyle && } @@ -109,3 +178,6 @@ const preview: Preview = { } export default preview + +// Populate meta for top-level access in modules on import +resetMeta() diff --git a/services/web/app/src/infrastructure/ExpressLocals.js b/services/web/app/src/infrastructure/ExpressLocals.js index cdfa08df84..c7dcb9eebb 100644 --- a/services/web/app/src/infrastructure/ExpressLocals.js +++ b/services/web/app/src/infrastructure/ExpressLocals.js @@ -18,6 +18,10 @@ const { const { addOptionalCleanupHandlerAfterDrainingConnections, } = require('./GracefulShutdown') +const { expressify } = require('@overleaf/promise-utils') +const { + loadAssignmentsInLocals, +} = require('../Features/SplitTests/SplitTestMiddleware') const IEEE_BRAND_ID = Settings.ieeeBrandId @@ -76,6 +80,10 @@ function getWebpackAssets(entrypoint, section) { } module.exports = function (webRouter, privateApiRouter, publicApiRouter) { + webRouter.use( + expressify(loadAssignmentsInLocals(['remove-window-attributes'])) + ) + if (process.env.NODE_ENV === 'development') { // In the dev-env, delay requests until we fetched the manifest once. webRouter.use(function (req, res, next) { diff --git a/services/web/app/views/project/editor/meta.pug b/services/web/app/views/project/editor/meta.pug index 3210d65537..5a5ecd8ff8 100644 --- a/services/web/app/views/project/editor/meta.pug +++ b/services/web/app/views/project/editor/meta.pug @@ -39,9 +39,6 @@ meta(name="ol-projectTags" data-type="json" content=projectTags) meta(name="ol-loadingText", data-type="string" content=translate("loading")) meta(name="ol-translationLoadErrorMessage", data-type="string" content=translate("could_not_load_translations")) -- var fileActionI18n = ['edited', 'renamed', 'created', 'deleted'].reduce((acc, i) => {acc[i] = translate('file_action_' + i); return acc}, {}) -meta(name="ol-fileActionI18n" data-type="json" content=fileActionI18n) - if (settings.overleaf != null) meta(name="ol-overallThemes" data-type="json" content=overallThemes) diff --git a/services/web/cypress/support/component.ts b/services/web/cypress/support/component.ts index 704458cb2b..0f246c392a 100644 --- a/services/web/cypress/support/component.ts +++ b/services/web/cypress/support/component.ts @@ -1,19 +1,11 @@ import 'cypress-plugin-tab' import '../../frontend/stylesheets/main-style.less' -import './ct/window' // needs to be before i18n +import { resetMeta } from './ct/window' // needs to be before i18n import '../../frontend/js/i18n' import './shared/commands' import './shared/exceptions' import './ct/commands' beforeEach(function () { - cy.window().then(win => { - win.metaAttributesCache = new Map() - }) -}) - -afterEach(function () { - cy.window().then(win => { - win.metaAttributesCache?.clear() - }) + resetMeta() }) diff --git a/services/web/cypress/support/ct/window.ts b/services/web/cypress/support/ct/window.ts index fcdcc79479..ae2a194bc1 100644 --- a/services/web/cypress/support/ct/window.ts +++ b/services/web/cypress/support/ct/window.ts @@ -1,10 +1,16 @@ -window.i18n = { currentLangCode: 'en' } -window.ExposedSettings = { - appName: 'Overleaf', - validRootDocExtensions: ['tex', 'Rtex', 'ltx', 'Rnw'], - fileIgnorePattern: - '**/{{__MACOSX,.git,.texpadtmp,.R}{,/**},.!(latexmkrc),*.{dvi,aux,log,toc,out,pdfsync,synctex,synctex(busy),fdb_latexmk,fls,nlo,ind,glo,gls,glg,bbl,blg,doc,docx,gz,swp}}', - hasLinkedProjectFileFeature: true, - hasLinkedProjectOutputFileFeature: true, - hasLinkUrlFeature: true, -} as typeof window.ExposedSettings +export function resetMeta() { + window.metaAttributesCache = new Map() + window.metaAttributesCache.set('ol-i18n', { currentLangCode: 'en' }) + window.metaAttributesCache.set('ol-ExposedSettings', { + appName: 'Overleaf', + validRootDocExtensions: ['tex', 'Rtex', 'ltx', 'Rnw'], + fileIgnorePattern: + '**/{{__MACOSX,.git,.texpadtmp,.R}{,/**},.!(latexmkrc),*.{dvi,aux,log,toc,out,pdfsync,synctex,synctex(busy),fdb_latexmk,fls,nlo,ind,glo,gls,glg,bbl,blg,doc,docx,gz,swp}}', + hasLinkedProjectFileFeature: true, + hasLinkedProjectOutputFileFeature: true, + hasLinkUrlFeature: true, + }) +} + +// Populate meta for top-level access in modules on import +resetMeta() diff --git a/services/web/frontend/js/features/cookie-banner/index.js b/services/web/frontend/js/features/cookie-banner/index.js index afd48f2787..a22046a08d 100644 --- a/services/web/frontend/js/features/cookie-banner/index.js +++ b/services/web/frontend/js/features/cookie-banner/index.js @@ -1,3 +1,5 @@ +import getMeta from '@/utils/meta' + function loadGA() { if (window.olLoadGA) { window.olLoadGA() @@ -6,7 +8,7 @@ function loadGA() { function setConsent(value) { document.querySelector('.cookie-banner').classList.add('hidden') - const cookieDomain = window.ExposedSettings.cookieDomain + const cookieDomain = getMeta('ol-ExposedSettings').cookieDomain const oneYearInSeconds = 60 * 60 * 24 * 365 const cookieAttributes = '; path=/' + @@ -23,7 +25,10 @@ function setConsent(value) { } } -if (window.ExposedSettings.gaToken || window.ExposedSettings.gaTokenV4) { +if ( + getMeta('ol-ExposedSettings').gaToken || + getMeta('ol-ExposedSettings').gaTokenV4 +) { document .querySelectorAll('[data-ol-cookie-banner-set-consent]') .forEach(el => { diff --git a/services/web/frontend/js/features/editor-left-menu/components/actions-menu.tsx b/services/web/frontend/js/features/editor-left-menu/components/actions-menu.tsx index b94a11f15b..65d53a557d 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/actions-menu.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/actions-menu.tsx @@ -12,9 +12,9 @@ const components = importOverleafModules('editorLeftMenuManageTemplate') as { export default function ActionsMenu() { const { t } = useTranslation() - const anonymous = getMeta('ol-anonymous') as boolean | undefined + const anonymous = getMeta('ol-anonymous') - if (anonymous === true || anonymous === undefined) { + if (anonymous) { return null } diff --git a/services/web/frontend/js/features/editor-left-menu/components/help-menu.tsx b/services/web/frontend/js/features/editor-left-menu/components/help-menu.tsx index d5c34e7abd..ceb64d1857 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/help-menu.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/help-menu.tsx @@ -6,7 +6,7 @@ import HelpShowHotkeys from './help-show-hotkeys' export default function HelpMenu() { const { t } = useTranslation() - const showSupport = getMeta('ol-showSupport') as boolean | undefined + const showSupport = getMeta('ol-showSupport') return ( <> diff --git a/services/web/frontend/js/features/editor-left-menu/components/settings-menu.tsx b/services/web/frontend/js/features/editor-left-menu/components/settings-menu.tsx index 5504419e2f..42c930cb40 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/settings-menu.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/settings-menu.tsx @@ -19,9 +19,9 @@ import SettingsSyntaxValidation from './settings/settings-syntax-validation' export default function SettingsMenu() { const { t } = useTranslation() - const anonymous = getMeta('ol-anonymous') as boolean | undefined + const anonymous = getMeta('ol-anonymous') - if (anonymous === true || anonymous === undefined) { + if (anonymous) { return null } diff --git a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-editor-theme.tsx b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-editor-theme.tsx index 8244b298b9..dfd9fddd9f 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-editor-theme.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-editor-theme.tsx @@ -7,10 +7,8 @@ import type { Option } from './settings-menu-select' export default function SettingsEditorTheme() { const { t } = useTranslation() - const editorThemes = getMeta('ol-editorThemes') as string[] | undefined - const legacyEditorThemes = getMeta('ol-legacyEditorThemes') as - | string[] - | undefined + const editorThemes = getMeta('ol-editorThemes') + const legacyEditorThemes = getMeta('ol-legacyEditorThemes') const { editorTheme, setEditorTheme } = useProjectSettingsContext() const options = useMemo(() => { diff --git a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-image-name.tsx b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-image-name.tsx index 78c62ab755..5986999a26 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-image-name.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-image-name.tsx @@ -4,26 +4,26 @@ import getMeta from '../../../../utils/meta' import SettingsMenuSelect from './settings-menu-select' import type { Option } from './settings-menu-select' import { useProjectSettingsContext } from '../../context/project-settings-context' -import type { AllowedImageName } from '../../../../../../types/project-settings' export default function SettingsImageName() { const { t } = useTranslation() const { imageName, setImageName } = useProjectSettingsContext() - const allowedImageNames = getMeta('ol-allowedImageNames') as - | AllowedImageName[] - | undefined + const allowedImageNames = useMemo( + () => getMeta('ol-allowedImageNames') || [], + [] + ) const options: Array