From 9202f5cb41a918f7b0b88e0a59ecf9c3c4568eed Mon Sep 17 00:00:00 2001 From: kwasniew Date: Wed, 4 Sep 2024 12:56:21 +0200 Subject: [PATCH 1/9] feat: navigate between all stages --- .../component/onboarding/ConnectSdkDialog.tsx | 60 +++++++++++++++---- .../component/onboarding/GenerateApiKey.tsx | 12 +++- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/frontend/src/component/onboarding/ConnectSdkDialog.tsx b/frontend/src/component/onboarding/ConnectSdkDialog.tsx index 8fc02e13d7fb..fb5f6fc7fd61 100644 --- a/frontend/src/component/onboarding/ConnectSdkDialog.tsx +++ b/frontend/src/component/onboarding/ConnectSdkDialog.tsx @@ -56,10 +56,7 @@ const NextStepSectionSpacedContainer = styled('div')(({ theme }) => ({ padding: theme.spacing(3, 8, 3, 8), })); -type OnboardingStage = - | { name: 'select-sdk' } - | { name: 'generate-api-key' } - | { name: 'test-connection' }; +type OnboardingStage = 'select-sdk' | 'generate-api-key' | 'test-connection'; export const ConnectSdkDialog = ({ open, @@ -71,7 +68,8 @@ export const ConnectSdkDialog = ({ const isLargeScreen = useMediaQuery(theme.breakpoints.up('lg')); const [sdk, setSdk] = useState(null); const [environment, setEnvironment] = useState(null); - const [stage, setStage] = useState({ name: 'select-sdk' }); + const [apiKey, setApiKey] = useState(null); + const [stage, setStage] = useState('select-sdk'); useEffect(() => { if (environments.length > 0) { @@ -83,46 +81,82 @@ export const ConnectSdkDialog = ({ - {stage.name === 'select-sdk' ? ( + {stage === 'select-sdk' ? ( { setSdk(sdk); - setStage({ name: 'generate-api-key' }); + setStage('generate-api-key'); }} /> ) : null} - {stage.name === 'generate-api-key' && sdk && environment ? ( + {stage === 'generate-api-key' && sdk && environment ? ( { + setApiKey(apiKey); + }} /> ) : null} + {stage === 'test-connection' && sdk && environment ? ( +
Last stage
+ ) : null} - {stage.name === 'generate-api-key' ? ( + {stage === 'generate-api-key' ? ( - + + + + ) : null} + {stage === 'test-connection' ? ( + + + + ) : null}
- {isLargeScreen && stage.name === 'select-sdk' ? ( + {isLargeScreen && stage === 'select-sdk' ? ( ) : null} - {isLargeScreen && stage.name === 'generate-api-key' ? ( + {isLargeScreen && stage === 'generate-api-key' ? ( ) : null}
diff --git a/frontend/src/component/onboarding/GenerateApiKey.tsx b/frontend/src/component/onboarding/GenerateApiKey.tsx index 0517e9a4415d..f11c87fdb2d6 100644 --- a/frontend/src/component/onboarding/GenerateApiKey.tsx +++ b/frontend/src/component/onboarding/GenerateApiKey.tsx @@ -14,6 +14,7 @@ import { import { SingleSelectConfigButton } from '../common/DialogFormTemplate/ConfigButtons/SingleSelectConfigButton'; import EnvironmentsIcon from '@mui/icons-material/CloudCircle'; import { ArcherContainer, ArcherElement } from 'react-archer'; +import { useEffect } from 'react'; const ChooseEnvironment = ({ environments, @@ -159,11 +160,11 @@ const TokenExplanation = ({ void; + onApiKey: (apiKey: string | null) => void; } export const GenerateApiKey = ({ @@ -193,12 +195,18 @@ export const GenerateApiKey = ({ project, sdkType, onEnvSelect, + onApiKey, }: GenerateApiKeyProps) => { const { tokens, refetch: refreshTokens } = useProjectApiTokens(project); const { createToken, loading: creatingToken } = useProjectApiTokensApi(); const currentEnvironmentToken = tokens.find( (token) => token.environment === environment && token.type === sdkType, ); + + useEffect(() => { + onApiKey(currentEnvironmentToken?.secret || null); + }, [currentEnvironmentToken]); + const parsedToken = parseToken(currentEnvironmentToken?.secret); const { setToastApiError } = useToast(); From 5296a623edd31c0a34bd889e386705f3ced86a38 Mon Sep 17 00:00:00 2001 From: kwasniew Date: Wed, 4 Sep 2024 12:58:39 +0200 Subject: [PATCH 2/9] feat: navigate between all stages --- frontend/src/component/onboarding/ConnectSdkDialog.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/component/onboarding/ConnectSdkDialog.tsx b/frontend/src/component/onboarding/ConnectSdkDialog.tsx index fb5f6fc7fd61..ea3f4da03878 100644 --- a/frontend/src/component/onboarding/ConnectSdkDialog.tsx +++ b/frontend/src/component/onboarding/ConnectSdkDialog.tsx @@ -101,7 +101,10 @@ export const ConnectSdkDialog = ({ }} /> ) : null} - {stage === 'test-connection' && sdk && environment ? ( + {stage === 'test-connection' && + sdk && + environment && + apiKey ? (
Last stage
) : null} From 24c88118feba0d68499b49f25ef2cca34ab1a4a5 Mon Sep 17 00:00:00 2001 From: kwasniew Date: Wed, 4 Sep 2024 13:05:26 +0200 Subject: [PATCH 3/9] feat: navigate between all stages --- .../component/onboarding/ConnectSdkDialog.tsx | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/frontend/src/component/onboarding/ConnectSdkDialog.tsx b/frontend/src/component/onboarding/ConnectSdkDialog.tsx index ea3f4da03878..d22822edbf65 100644 --- a/frontend/src/component/onboarding/ConnectSdkDialog.tsx +++ b/frontend/src/component/onboarding/ConnectSdkDialog.tsx @@ -71,6 +71,12 @@ export const ConnectSdkDialog = ({ const [apiKey, setApiKey] = useState(null); const [stage, setStage] = useState('select-sdk'); + const isSelectSdkStage = stage === 'select-sdk'; + const isGenerateApiKeyStage = + stage === 'generate-api-key' && sdk && environment; + const isTestConnectionStage = + stage === 'test-connection' && sdk && environment && apiKey; + useEffect(() => { if (environments.length > 0) { setEnvironment(environments[0]); @@ -81,7 +87,7 @@ export const ConnectSdkDialog = ({ - {stage === 'select-sdk' ? ( + {isSelectSdkStage ? ( { setSdk(sdk); @@ -89,7 +95,7 @@ export const ConnectSdkDialog = ({ }} /> ) : null} - {stage === 'generate-api-key' && sdk && environment ? ( + {isGenerateApiKeyStage ? ( ) : null} - {stage === 'test-connection' && - sdk && - environment && - apiKey ? ( -
Last stage
- ) : null} + {isTestConnectionStage ?
Last stage
: null} {stage === 'generate-api-key' ? ( @@ -131,7 +132,7 @@ export const ConnectSdkDialog = ({ ) : null} - {stage === 'test-connection' ? ( + {isTestConnectionStage ? (