diff --git a/webview-ui/package-lock.json b/webview-ui/package-lock.json index fdf6e6d116..b614ba387e 100644 --- a/webview-ui/package-lock.json +++ b/webview-ui/package-lock.json @@ -27,7 +27,6 @@ "debounce": "^2.1.1", "fast-deep-equal": "^3.1.3", "fzf": "^0.5.2", - "lodash": "^4.17.21", "lucide-react": "^0.475.0", "mermaid": "^11.4.1", "react": "^18.3.1", @@ -55,7 +54,6 @@ "@testing-library/react": "^16.2.0", "@testing-library/user-event": "^14.6.1", "@types/jest": "^27.5.2", - "@types/lodash": "^4.17.16", "@types/node": "^18.0.0", "@types/react": "^18.3.18", "@types/react-dom": "^18.3.5", @@ -6932,13 +6930,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/lodash": { - "version": "4.17.16", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.16.tgz", - "integrity": "sha512-HX7Em5NYQAXKW+1T+FiuG27NGwzJfCX3s1GjOa7ujxZa52kjJLOr4FUxT+giF6Tgxv1e+/czV/iTtBw27WTU9g==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/mdast": { "version": "3.0.15", "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-3.0.15.tgz", @@ -15321,6 +15312,7 @@ "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true, "license": "MIT" }, "node_modules/lodash-es": { diff --git a/webview-ui/package.json b/webview-ui/package.json index 0209d41129..12786d1060 100644 --- a/webview-ui/package.json +++ b/webview-ui/package.json @@ -34,7 +34,6 @@ "debounce": "^2.1.1", "fast-deep-equal": "^3.1.3", "fzf": "^0.5.2", - "lodash": "^4.17.21", "lucide-react": "^0.475.0", "mermaid": "^11.4.1", "react": "^18.3.1", @@ -62,7 +61,6 @@ "@testing-library/react": "^16.2.0", "@testing-library/user-event": "^14.6.1", "@types/jest": "^27.5.2", - "@types/lodash": "^4.17.16", "@types/node": "^18.0.0", "@types/react": "^18.3.18", "@types/react-dom": "^18.3.5", diff --git a/webview-ui/src/context/ExtensionStateContext.tsx b/webview-ui/src/context/ExtensionStateContext.tsx index fda47ed80f..abf921dc2b 100644 --- a/webview-ui/src/context/ExtensionStateContext.tsx +++ b/webview-ui/src/context/ExtensionStateContext.tsx @@ -1,7 +1,5 @@ import React, { createContext, useCallback, useContext, useEffect, useState } from "react" import { useEvent } from "react-use" -import { merge } from "lodash" - import { ApiConfigMeta, ExtensionMessage, ExtensionState } from "../../../src/shared/ExtensionMessage" import { ApiConfiguration } from "../../../src/shared/api" import { vscode } from "../utils/vscode" @@ -71,6 +69,32 @@ export interface ExtensionStateContextType extends ExtensionState { export const ExtensionStateContext = createContext(undefined) +export const mergeExtensionState = (prevState: ExtensionState, newState: ExtensionState) => { + const { + apiConfiguration: prevApiConfiguration, + customModePrompts: prevCustomModePrompts, + customSupportPrompts: prevCustomSupportPrompts, + experiments: prevExperiments, + ...prevRest + } = prevState + + const { + apiConfiguration: newApiConfiguration, + customModePrompts: newCustomModePrompts, + customSupportPrompts: newCustomSupportPrompts, + experiments: newExperiments, + ...newRest + } = newState + + const apiConfiguration = { ...prevApiConfiguration, ...newApiConfiguration } + const customModePrompts = { ...prevCustomModePrompts, ...newCustomModePrompts } + const customSupportPrompts = { ...prevCustomSupportPrompts, ...newCustomSupportPrompts } + const experiments = { ...prevExperiments, ...newExperiments } + const rest = { ...prevRest, ...newRest } + + return { ...rest, apiConfiguration, customModePrompts, customSupportPrompts, experiments } +} + export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [state, setState] = useState({ version: "", @@ -253,6 +277,3 @@ export const useExtensionState = () => { } return context } - -export const mergeExtensionState = (prevState: ExtensionState, newState: ExtensionState): ExtensionState => - merge({}, prevState, newState)