From 5210005edb85b9a47d707aad76295430f74a3c4d Mon Sep 17 00:00:00 2001 From: msivasubramaniaan Date: Tue, 26 Nov 2024 16:00:30 +0530 Subject: [PATCH] added scenorio for chage butten text between setup and update. Also handled enable/disable of the button Signed-off-by: msivasubramaniaan --- src/panels/setupGranitePage.ts | 22 ++++++++++++++++++++++ webviews/src/App.tsx | 31 +++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/panels/setupGranitePage.ts b/src/panels/setupGranitePage.ts index 10a76b9..8ffe779 100644 --- a/src/panels/setupGranitePage.ts +++ b/src/panels/setupGranitePage.ts @@ -360,6 +360,17 @@ export class SetupGranitePage { tabModel, embeddingsModel ); + + //set recent used models + webview.postMessage({ + command: "recentModels", + data: { + recentChatModel: chatModel, + recentTabModel: tabModel, + recentEmbeddingModel: embeddingsModel + }, + }); + console.log("Granite AI-Assistant setup complete"); await Telemetry.send("paver.setup.success", { chatModelId: chatModel ?? 'none', @@ -371,6 +382,17 @@ export class SetupGranitePage { if (error instanceof CancellationError || error?.name === "Canceled") { return; } + + //set recent used models to null when error + webview.postMessage({ + command: "recentModels", + data: { + recentChatModel: null, + recentTabModel: null, + recentEmbeddingModel: null + }, + }); + // Generic error handling for all errors await Telemetry.send("paver.setup.error", { error: error?.message ?? 'unknown error', diff --git a/webviews/src/App.tsx b/webviews/src/App.tsx index a9586f2..32617aa 100644 --- a/webviews/src/App.tsx +++ b/webviews/src/App.tsx @@ -45,6 +45,12 @@ function App() { const [isKeepExistingConfigSelected, setIsKeepExistingConfigSelected] = useState(false); + const [buttonTitle, setButtonTitle] = useState(''); + + const [recentTabModel, setRecentTabModel] = useState(null); + const [recentChatModel, setRecentChatModel] = useState(null); + const [recentEmbeddingsModel, setRecentEmbeddingsModel] = useState(null); + const getModelStatus = useCallback((model: string | null): ModelStatus | null => { if (model === null) { return null; @@ -85,6 +91,11 @@ function App() { }); } + function handleSetupGraniteEnableDisable(): boolean { + return serverStatus === ServerStatus.started && chatModel === recentChatModel && + embeddingsModel === recentEmbeddingsModel; + } + const REFETCH_MODELS_INTERVAL_MS = 1500; let ollamaStatusChecker: NodeJS.Timeout | undefined; @@ -122,6 +133,12 @@ function App() { setEnabled(!disabled); break; } + case 'recentModels': { + setRecentChatModel(payload.data.recentChatModel); + setRecentTabModel(payload.data.recentTabModel); + setRecentEmbeddingsModel(payload.data.recentEmbeddingModel); + break; + } } }, []); @@ -155,6 +172,15 @@ function App() { }; }, [serverStatus, modelStatuses]); + useEffect(() => { + if (serverStatus === ServerStatus.started && ModelStatus.installed === getModelStatus(chatModel) && + ModelStatus.installed === getModelStatus(embeddingsModel)) { + setButtonTitle('Update Granite'); + } else { + setButtonTitle('Setup Granite'); + } + }), [buttonTitle]; + const getServerIconType = useCallback((status: ServerStatus): StatusValue => { switch (status) { case ServerStatus.installing: @@ -272,8 +298,9 @@ function App() { />
-