From 7147f2f6c3636d53f8ea741f8dcc2939dedc5d71 Mon Sep 17 00:00:00 2001 From: filip131311 <159789821+filip131311@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:41:13 +0200 Subject: [PATCH] Change WorkspaceSettings if they exist. (#65) Before: changing a location of the IDE would not work from our settings dropdown menu if a User had workspace specific configuration. After: If a User has workspace specific configuration this is the one we are changing. Co-authored-by: Filip Andrzej Kaminski --- .../vscode-extension/src/common/WorkspaceConfig.ts | 4 ++-- .../src/panels/WorkspaceConfigController.ts | 11 ++++++----- .../src/webview/components/SettingsDropdown.tsx | 8 ++++---- .../webview/providers/WorkspaceConfigProvider.tsx | 13 +++++-------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/vscode-extension/src/common/WorkspaceConfig.ts b/packages/vscode-extension/src/common/WorkspaceConfig.ts index dda829a31..a6075608b 100644 --- a/packages/vscode-extension/src/common/WorkspaceConfig.ts +++ b/packages/vscode-extension/src/common/WorkspaceConfig.ts @@ -15,8 +15,8 @@ export interface WorkspaceConfigEventListener { export interface WorkspaceConfig { getConfig(): Promise; - // updateUserLevel method can take any of the keys from WorkspaceConfigProps and appropriate value: - updateUserLevel( + // update method can take any of the keys from WorkspaceConfigProps and appropriate value: + update( key: K, value: WorkspaceConfigProps[K] ): Promise; diff --git a/packages/vscode-extension/src/panels/WorkspaceConfigController.ts b/packages/vscode-extension/src/panels/WorkspaceConfigController.ts index 16d45dc06..b21862c20 100644 --- a/packages/vscode-extension/src/panels/WorkspaceConfigController.ts +++ b/packages/vscode-extension/src/panels/WorkspaceConfigController.ts @@ -37,12 +37,13 @@ export class WorkspaceConfigController implements Disposable, WorkspaceConfig { return this.config; } - async updateUserLevel( - key: K, - value: WorkspaceConfigProps[K] - ) { + async update(key: K, value: WorkspaceConfigProps[K]) { const configuration = workspace.getConfiguration("ReactNativeIDE"); - await configuration.update(key as string, value, true); + if (configuration.inspect(key as string)?.workspaceValue) { + await configuration.update(key as string, value, false); + } else { + await configuration.update(key as string, value, true); + } } async addListener( diff --git a/packages/vscode-extension/src/webview/components/SettingsDropdown.tsx b/packages/vscode-extension/src/webview/components/SettingsDropdown.tsx index c0ce85734..3b6a25e7c 100644 --- a/packages/vscode-extension/src/webview/components/SettingsDropdown.tsx +++ b/packages/vscode-extension/src/webview/components/SettingsDropdown.tsx @@ -15,7 +15,7 @@ interface SettingsDropdownProps { } function SettingsDropdown({ project, children, disabled }: SettingsDropdownProps) { - const { panelLocation, updateUserLevel } = useWorkspaceConfig(); + const { panelLocation, update } = useWorkspaceConfig(); const { openModal } = useModal(); return ( @@ -55,14 +55,14 @@ function SettingsDropdown({ project, children, disabled }: SettingsDropdownProps alignOffset={-5}> updateUserLevel("panelLocation", "tab")}> + onSelect={() => update("panelLocation", "tab")}> Editor tab {panelLocation === "tab" && } updateUserLevel("panelLocation", "side-panel")}> + onSelect={() => update("panelLocation", "side-panel")}> Side panel {panelLocation === "side-panel" && ( @@ -72,7 +72,7 @@ function SettingsDropdown({ project, children, disabled }: SettingsDropdownProps { - updateUserLevel("panelLocation", "secondary-side-panel"); + update("panelLocation", "secondary-side-panel"); openModal( "Drag and drop to secondary side panel",
diff --git a/packages/vscode-extension/src/webview/providers/WorkspaceConfigProvider.tsx b/packages/vscode-extension/src/webview/providers/WorkspaceConfigProvider.tsx index aaa21ce47..a51574ad4 100644 --- a/packages/vscode-extension/src/webview/providers/WorkspaceConfigProvider.tsx +++ b/packages/vscode-extension/src/webview/providers/WorkspaceConfigProvider.tsx @@ -12,16 +12,13 @@ import { WorkspaceConfig, WorkspaceConfigProps } from "../../common/WorkspaceCon const workspaceConfig = makeProxy("WorkspaceConfig"); type WorkspaceConfigContextType = WorkspaceConfigProps & { - updateUserLevel: ( - key: K, - value: WorkspaceConfigProps[K] - ) => void; + update: (key: K, value: WorkspaceConfigProps[K]) => void; }; const WorkspaceConfigContext = createContext({ panelLocation: "tab", relativeAppLocation: "", - updateUserLevel: () => {}, + update: () => {}, }); export default function WorkspaceConfigProvider({ children }: PropsWithChildren) { @@ -39,7 +36,7 @@ export default function WorkspaceConfigProvider({ children }: PropsWithChildren) }; }, []); - const updateUserLevel = useCallback( + const update = useCallback( ( key: K, value: WorkspaceConfigProps[K], @@ -47,13 +44,13 @@ export default function WorkspaceConfigProvider({ children }: PropsWithChildren) ) => { const newState = { ...config, [key]: value }; setConfig(newState); - workspaceConfig.updateUserLevel(key, value); + workspaceConfig.update(key, value); }, [config, setConfig] ); return ( - + {children} );