From 3324a142021edcc4e8098d231289ffb8916907bb Mon Sep 17 00:00:00 2001 From: M Fahru Date: Thu, 28 Sep 2023 09:36:08 -0700 Subject: [PATCH] Merge pull request #15029 from overleaf/mf-remove-angular-settings-dependency-rename-project [web] Remove angular settings dependency when renaming a project in editor top bar GitOrigin-RevId: 45a8b71fc84135f5291217f613cc95aea7192c35 --- .../js/features/editor-left-menu/utils/api.ts | 1 + .../frontend/js/shared/context/editor-context.jsx | 15 ++++++++++----- .../frontend/js/shared/context/root-context.jsx | 5 ++--- .../web/frontend/stories/decorators/scope.tsx | 2 +- .../test/frontend/helpers/editor-providers.jsx | 2 +- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/services/web/frontend/js/features/editor-left-menu/utils/api.ts b/services/web/frontend/js/features/editor-left-menu/utils/api.ts index f888bc61f6..ea2aee696a 100644 --- a/services/web/frontend/js/features/editor-left-menu/utils/api.ts +++ b/services/web/frontend/js/features/editor-left-menu/utils/api.ts @@ -30,6 +30,7 @@ export type ProjectSettings = { imageName: string rootDocId: string spellCheckLanguage: string + name: string } type SaveUserSettings = Partial< diff --git a/services/web/frontend/js/shared/context/editor-context.jsx b/services/web/frontend/js/shared/context/editor-context.jsx index 17d7ed8ee7..8da1462540 100644 --- a/services/web/frontend/js/shared/context/editor-context.jsx +++ b/services/web/frontend/js/shared/context/editor-context.jsx @@ -14,6 +14,7 @@ import { useProjectContext } from './project-context' import { useDetachContext } from './detach-context' import getMeta from '../../utils/meta' import { useUserContext } from './user-context' +import { saveProjectSettings } from '@/features/editor-left-menu/utils/api' export const EditorContext = createContext() @@ -42,18 +43,23 @@ EditorContext.Provider.propTypes = { }), } -export function EditorProvider({ children, settings }) { +export function EditorProvider({ children }) { const ide = useIdeContext() const { id: userId } = useUserContext() const { role } = useDetachContext() - const { owner, features } = useProjectContext({ + const { + owner, + features, + _id: projectId, + } = useProjectContext({ owner: PropTypes.shape({ _id: PropTypes.string.isRequired, }), features: PropTypes.shape({ compileGroup: PropTypes.string, }), + _id: PropTypes.string.isRequired, }) const cobranding = useMemo(() => { @@ -106,7 +112,7 @@ export function EditorProvider({ children, settings }) { newName => { setProjectName(oldName => { if (oldName !== newName) { - settings.saveProjectSettings({ name: newName }).catch(response => { + saveProjectSettings(projectId, { name: newName }).catch(response => { setProjectName(oldName) const { data, status } = response if (status === 400) { @@ -122,7 +128,7 @@ export function EditorProvider({ children, settings }) { return newName }) }, - [settings, ide, setProjectName] + [ide, setProjectName, projectId] ) const { setTitle } = useBrowserWindow() @@ -192,7 +198,6 @@ export function EditorProvider({ children, settings }) { EditorProvider.propTypes = { children: PropTypes.any, - settings: PropTypes.object, } export function useEditorContext(propTypes) { diff --git a/services/web/frontend/js/shared/context/root-context.jsx b/services/web/frontend/js/shared/context/root-context.jsx index 7808d7f689..a99a17e479 100644 --- a/services/web/frontend/js/shared/context/root-context.jsx +++ b/services/web/frontend/js/shared/context/root-context.jsx @@ -14,7 +14,7 @@ import { SplitTestProvider } from './split-test-context' import { FileTreeDataProvider } from './file-tree-data-context' import { ProjectSettingsProvider } from '../../features/editor-left-menu/context/project-settings-context' -export function ContextRoot({ children, ide, settings }) { +export function ContextRoot({ children, ide }) { return ( @@ -22,7 +22,7 @@ export function ContextRoot({ children, ide, settings }) { - + @@ -45,7 +45,6 @@ export function ContextRoot({ children, ide, settings }) { ContextRoot.propTypes = { children: PropTypes.any, ide: PropTypes.object, - settings: PropTypes.object, } export const rootContext = createSharedContext(ContextRoot) diff --git a/services/web/frontend/stories/decorators/scope.tsx b/services/web/frontend/stories/decorators/scope.tsx index 7d97290a27..45e710fbc1 100644 --- a/services/web/frontend/stories/decorators/scope.tsx +++ b/services/web/frontend/stories/decorators/scope.tsx @@ -229,7 +229,7 @@ export const ScopeDecorator = ( }, []) return ( - + ) diff --git a/services/web/test/frontend/helpers/editor-providers.jsx b/services/web/test/frontend/helpers/editor-providers.jsx index bfcc2ea20a..86dd70b611 100644 --- a/services/web/test/frontend/helpers/editor-providers.jsx +++ b/services/web/test/frontend/helpers/editor-providers.jsx @@ -117,7 +117,7 @@ export function EditorProviders({ - +