From f27562eb12ca58b4a4ea3baa838f5402db74e500 Mon Sep 17 00:00:00 2001 From: M Fahru Date: Tue, 29 Nov 2022 11:00:10 -0700 Subject: [PATCH] Data handling for settings in editor left menu react migration (#10470) - Importing SettingsController from the angular code, which enables post requests for every select menu and socket handler for compiler, texlive version, and main document select option - New context for the data handling infrastructure between react and angular. The data is still located in the angular version, and I use the context only as a proxy to fetch/post new data. GitOrigin-RevId: 59009bceb128d82969a2318e90036aacf79f9887 --- .../views/project/editor/left-menu-react.pug | 3 +- .../settings/settings-auto-close-brackets.tsx | 9 +- .../settings/settings-auto-complete.tsx | 8 +- .../components/settings/settings-compiler.tsx | 7 +- .../components/settings/settings-document.tsx | 21 +-- .../settings/settings-editor-theme.tsx | 6 +- .../settings/settings-font-family.tsx | 7 +- .../settings/settings-font-size.tsx | 4 + .../settings/settings-image-name.tsx | 13 +- .../settings/settings-keybindings.tsx | 7 +- .../settings/settings-line-height.tsx | 7 +- .../settings/settings-menu-select.tsx | 54 ++++-- .../settings/settings-overall-theme.tsx | 21 ++- .../settings/settings-pdf-viewer.tsx | 7 +- .../settings-spell-check-language.tsx | 14 +- .../settings/settings-syntax-validation.tsx | 10 +- .../context/project-settings-context.tsx | 166 ++++++++++++++++++ .../web/frontend/js/main/is-valid-tex-file.js | 10 +- .../js/shared/context/root-context.js | 17 +- .../settings-auto-close-brackets.test.tsx | 23 +++ .../settings/settings-auto-complete.test.tsx | 23 +++ .../settings/settings-document.test.tsx | 47 +++++ .../settings/settings-editor-theme.test.tsx | 37 ++++ .../settings/settings-font-family.test.tsx | 23 +++ .../settings/settings-font-size.test.tsx | 24 +++ .../settings/settings-image-name.test.tsx | 39 ++++ .../settings/settings-keybindings.test.tsx | 26 +++ .../settings/settings-line-height.test.tsx | 26 +++ .../settings/settings-overall-theme.test.tsx | 41 +++++ .../settings/settings-pdf-viewer.test.tsx | 23 +++ .../settings-spell-check-language.test.tsx | 42 +++++ .../settings-syntax-validation.test.tsx | 23 +++ .../test/frontend/helpers/editor-providers.js | 15 +- services/web/types/project-settings.ts | 33 ++++ 34 files changed, 753 insertions(+), 83 deletions(-) create mode 100644 services/web/frontend/js/features/editor-left-menu/context/project-settings-context.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-auto-close-brackets.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-auto-complete.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-document.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-editor-theme.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-font-family.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-font-size.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-image-name.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-keybindings.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-line-height.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-overall-theme.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-pdf-viewer.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-spell-check-language.test.tsx create mode 100644 services/web/test/frontend/features/editor-left-menu/components/settings/settings-syntax-validation.test.tsx create mode 100644 services/web/types/project-settings.ts diff --git a/services/web/app/views/project/editor/left-menu-react.pug b/services/web/app/views/project/editor/left-menu-react.pug index d6376250a6..60ce3d48ea 100644 --- a/services/web/app/views/project/editor/left-menu-react.pug +++ b/services/web/app/views/project/editor/left-menu-react.pug @@ -1 +1,2 @@ -editor-left-menu() \ No newline at end of file +div(ng-controller="SettingsController") + editor-left-menu() \ No newline at end of file diff --git a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-auto-close-brackets.tsx b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-auto-close-brackets.tsx index 5bc2903fb5..ae245873bc 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-auto-close-brackets.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-auto-close-brackets.tsx @@ -1,18 +1,23 @@ import { useTranslation } from 'react-i18next' +import { useProjectSettingsContext } from '../../context/project-settings-context' import SettingsMenuSelect from './settings-menu-select' export default function SettingsAutoCloseBrackets() { const { t } = useTranslation() + const { autoPairDelimiters, setAutoPairDelimiters } = + useProjectSettingsContext() return ( + onChange={setCompiler} + value={compiler} options={[ { value: 'pdflatex', diff --git a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-document.tsx b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-document.tsx index 76227fc5bb..607745547f 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-document.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-document.tsx @@ -2,28 +2,17 @@ import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import isValidTeXFile from '../../../../main/is-valid-tex-file' import { useEditorContext } from '../../../../shared/context/editor-context' -import { useProjectContext } from '../../../../shared/context/project-context' import useScopeValue from '../../../../shared/hooks/use-scope-value' +import { useProjectSettingsContext } from '../../context/project-settings-context' import SettingsMenuSelect from './settings-menu-select' import type { Option } from './settings-menu-select' - -type Doc = { - doc: { - name: string - id: string - type: string - selected: boolean - } - path: string -} +import type { MainDocument } from '../../../../../../types/project-settings' export default function SettingsDocument() { const { t } = useTranslation() - const { permissionsLevel } = useEditorContext() - - const { rootDocId } = useProjectContext() - const [docs] = useScopeValue('docs') + const [docs] = useScopeValue('docs') + const { rootDocId, setRootDocId } = useProjectSettingsContext() const validDocsOptions = useMemo(() => { const filteredDocs = @@ -45,6 +34,8 @@ export default function SettingsDocument() { return ( { const editorThemeOptions: Array