From dbc6a9cb5f60ba2a28f417e1d1df5b2ca0a0ec11 Mon Sep 17 00:00:00 2001 From: Markus Wagner Date: Tue, 26 Nov 2024 17:58:47 +0100 Subject: [PATCH 1/2] fix: Disable pro provider configuration for pro providers that support the new flow --- desktop/src/lib/modals/useLoginProModal.tsx | 68 ++++++++++++++++----- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/desktop/src/lib/modals/useLoginProModal.tsx b/desktop/src/lib/modals/useLoginProModal.tsx index 79fd273d5..ede569d3e 100644 --- a/desktop/src/lib/modals/useLoginProModal.tsx +++ b/desktop/src/lib/modals/useLoginProModal.tsx @@ -1,5 +1,5 @@ import { BottomActionBar, BottomActionBarError, Form, useStreamingTerminal } from "@/components" -import { useProInstanceManager, useProInstances, useProviders } from "@/contexts" +import { useProInstanceManager, useProInstances, useProvider, useProviders } from "@/contexts" import { canHealthCheck, exists, useFormErrors } from "@/lib" import { Routes } from "@/routes" import { @@ -23,14 +23,17 @@ import { ModalHeader, ModalOverlay, Tooltip, - VStack, useDisclosure, + VStack, } from "@chakra-ui/react" import { useCallback, useEffect, useMemo, useRef, useState } from "react" import { SubmitHandler, useForm } from "react-hook-form" import { useNavigate } from "react-router" import { ConfigureProviderOptionsForm, useSetupProvider } from "@/views/Providers" import { To } from "react-router-dom" +import { useQueryClient } from "@tanstack/react-query" +import { client } from "@/client" +import { QueryKeys } from "@/queryKeys" type TFormValues = { [FieldName.PRO_HOST]: string @@ -98,17 +101,6 @@ export function useLoginProModal() { const { proURLError } = useFormErrors(Object.values(FieldName), formState) - useEffect(() => { - if (login.status === "success") { - const providerID = login.provider?.config?.name - - if (!exists(providerID)) { - return - } - completeSetupProvider({ providerID, suggestedOptions }) - } - }, [completeSetupProvider, login.provider, login.status, suggestedOptions]) - const resetModal = useCallback( (checkDanglingProInstance: boolean = false) => { reset() @@ -167,6 +159,54 @@ export function useLoginProModal() { }, 0) }, [completeConfigureProvider, navigate, providers, proInstances, resetModal, state.providerID]) + const [provider] = useProvider(state.providerID) + + const supportsProFlow = useMemo(() => { + return canHealthCheck(provider?.config) + }, [provider]) + + const queryClient = useQueryClient() + + const saveAndSkipForm = useCallback(async () => { + if (!state.providerID) { + return + } + + ;( + await client.providers.configure(state.providerID, { + useAsDefaultProvider: true, + reuseMachine: false, + options: {}, + }) + ).unwrap() + + await queryClient.invalidateQueries(QueryKeys.PROVIDERS) + + completeFlow() + }, [queryClient, state.providerID, completeFlow]) + + useEffect(() => { + if (login.status === "success") { + const providerID = login.provider?.config?.name + + if (!exists(providerID)) { + return + } + completeSetupProvider({ providerID, suggestedOptions }) + + if (supportsProFlow) { + saveAndSkipForm() + } + } + }, [ + completeSetupProvider, + supportsProFlow, + saveAndSkipForm, + login.provider, + login.status, + suggestedOptions, + ]) + const modal = useMemo(() => { return ( )} - {state.currentStep === "configure-provider" && ( + {!supportsProFlow && state.currentStep === "configure-provider" && ( <> From 50ef048260a134186f464d5cfd983cf2f51d4556 Mon Sep 17 00:00:00 2001 From: Markus Wagner Date: Mon, 9 Dec 2024 12:39:02 +0100 Subject: [PATCH 2/2] fix: Prevent concurrent writes to config.yaml when skipping the provider configuration form --- desktop/src/lib/modals/useLoginProModal.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/desktop/src/lib/modals/useLoginProModal.tsx b/desktop/src/lib/modals/useLoginProModal.tsx index ede569d3e..76e679104 100644 --- a/desktop/src/lib/modals/useLoginProModal.tsx +++ b/desktop/src/lib/modals/useLoginProModal.tsx @@ -185,16 +185,20 @@ export function useLoginProModal() { completeFlow() }, [queryClient, state.providerID, completeFlow]) + const skippedConfigurationRef = useRef(false) + useEffect(() => { - if (login.status === "success") { + if (login.status === "success" && !skippedConfigurationRef.current) { const providerID = login.provider?.config?.name if (!exists(providerID)) { return } + completeSetupProvider({ providerID, suggestedOptions }) if (supportsProFlow) { + skippedConfigurationRef.current = true saveAndSkipForm() } }