mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	feat: navigate between all stages (#8080)
This commit is contained in:
		
							parent
							
								
									ba8d043f3c
								
							
						
					
					
						commit
						5c4d0bf99b
					
				@ -56,10 +56,7 @@ const NextStepSectionSpacedContainer = styled('div')(({ theme }) => ({
 | 
				
			|||||||
    padding: theme.spacing(3, 8, 3, 8),
 | 
					    padding: theme.spacing(3, 8, 3, 8),
 | 
				
			||||||
}));
 | 
					}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type OnboardingStage =
 | 
					type OnboardingStage = 'select-sdk' | 'generate-api-key' | 'test-connection';
 | 
				
			||||||
    | { name: 'select-sdk' }
 | 
					 | 
				
			||||||
    | { name: 'generate-api-key' }
 | 
					 | 
				
			||||||
    | { name: 'test-connection' };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const ConnectSdkDialog = ({
 | 
					export const ConnectSdkDialog = ({
 | 
				
			||||||
    open,
 | 
					    open,
 | 
				
			||||||
@ -71,7 +68,14 @@ export const ConnectSdkDialog = ({
 | 
				
			|||||||
    const isLargeScreen = useMediaQuery(theme.breakpoints.up('lg'));
 | 
					    const isLargeScreen = useMediaQuery(theme.breakpoints.up('lg'));
 | 
				
			||||||
    const [sdk, setSdk] = useState<Sdk | null>(null);
 | 
					    const [sdk, setSdk] = useState<Sdk | null>(null);
 | 
				
			||||||
    const [environment, setEnvironment] = useState<string | null>(null);
 | 
					    const [environment, setEnvironment] = useState<string | null>(null);
 | 
				
			||||||
    const [stage, setStage] = useState<OnboardingStage>({ name: 'select-sdk' });
 | 
					    const [apiKey, setApiKey] = useState<string | null>(null);
 | 
				
			||||||
 | 
					    const [stage, setStage] = useState<OnboardingStage>('select-sdk');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const isSelectSdkStage = stage === 'select-sdk';
 | 
				
			||||||
 | 
					    const isGenerateApiKeyStage =
 | 
				
			||||||
 | 
					        stage === 'generate-api-key' && sdk && environment;
 | 
				
			||||||
 | 
					    const isTestConnectionStage =
 | 
				
			||||||
 | 
					        stage === 'test-connection' && sdk && environment && apiKey;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    useEffect(() => {
 | 
					    useEffect(() => {
 | 
				
			||||||
        if (environments.length > 0) {
 | 
					        if (environments.length > 0) {
 | 
				
			||||||
@ -83,46 +87,80 @@ export const ConnectSdkDialog = ({
 | 
				
			|||||||
        <StyledDialog open={open} onClose={onClose}>
 | 
					        <StyledDialog open={open} onClose={onClose}>
 | 
				
			||||||
            <Box sx={{ display: 'flex' }}>
 | 
					            <Box sx={{ display: 'flex' }}>
 | 
				
			||||||
                <ConnectSdk>
 | 
					                <ConnectSdk>
 | 
				
			||||||
                    {stage.name === 'select-sdk' ? (
 | 
					                    {isSelectSdkStage ? (
 | 
				
			||||||
                        <SelectSdk
 | 
					                        <SelectSdk
 | 
				
			||||||
                            onSelect={(sdk) => {
 | 
					                            onSelect={(sdk) => {
 | 
				
			||||||
                                setSdk(sdk);
 | 
					                                setSdk(sdk);
 | 
				
			||||||
                                setStage({ name: 'generate-api-key' });
 | 
					                                setStage('generate-api-key');
 | 
				
			||||||
                            }}
 | 
					                            }}
 | 
				
			||||||
                        />
 | 
					                        />
 | 
				
			||||||
                    ) : null}
 | 
					                    ) : null}
 | 
				
			||||||
                    {stage.name === 'generate-api-key' && sdk && environment ? (
 | 
					                    {isGenerateApiKeyStage ? (
 | 
				
			||||||
                        <GenerateApiKey
 | 
					                        <GenerateApiKey
 | 
				
			||||||
                            environments={environments}
 | 
					                            environments={environments}
 | 
				
			||||||
                            environment={environment}
 | 
					                            environment={environment}
 | 
				
			||||||
                            project={project}
 | 
					                            project={project}
 | 
				
			||||||
                            sdkType={sdk.type}
 | 
					                            sdkType={sdk.type}
 | 
				
			||||||
                            onEnvSelect={setEnvironment}
 | 
					                            onEnvSelect={setEnvironment}
 | 
				
			||||||
 | 
					                            onApiKey={(apiKey) => {
 | 
				
			||||||
 | 
					                                setApiKey(apiKey);
 | 
				
			||||||
 | 
					                            }}
 | 
				
			||||||
                        />
 | 
					                        />
 | 
				
			||||||
                    ) : null}
 | 
					                    ) : null}
 | 
				
			||||||
 | 
					                    {isTestConnectionStage ? <div>Last stage</div> : null}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    {stage.name === 'generate-api-key' ? (
 | 
					                    {stage === 'generate-api-key' ? (
 | 
				
			||||||
                        <Navigation>
 | 
					                        <Navigation>
 | 
				
			||||||
                            <NextStepSectionSpacedContainer>
 | 
					                            <NextStepSectionSpacedContainer>
 | 
				
			||||||
                                <Button
 | 
					                                <Button
 | 
				
			||||||
                                    variant='text'
 | 
					                                    variant='text'
 | 
				
			||||||
                                    color='inherit'
 | 
					                                    color='inherit'
 | 
				
			||||||
                                    onClick={() => {
 | 
					                                    onClick={() => {
 | 
				
			||||||
                                        setStage({ name: 'select-sdk' });
 | 
					                                        setStage('select-sdk');
 | 
				
			||||||
                                    }}
 | 
					                                    }}
 | 
				
			||||||
                                >
 | 
					                                >
 | 
				
			||||||
                                    Back
 | 
					                                    Back
 | 
				
			||||||
                                </Button>
 | 
					                                </Button>
 | 
				
			||||||
                                <Button variant='contained'>Next</Button>
 | 
					                                <Button
 | 
				
			||||||
 | 
					                                    variant='contained'
 | 
				
			||||||
 | 
					                                    onClick={() => {
 | 
				
			||||||
 | 
					                                        setStage('test-connection');
 | 
				
			||||||
 | 
					                                    }}
 | 
				
			||||||
 | 
					                                >
 | 
				
			||||||
 | 
					                                    Next
 | 
				
			||||||
 | 
					                                </Button>
 | 
				
			||||||
 | 
					                            </NextStepSectionSpacedContainer>
 | 
				
			||||||
 | 
					                        </Navigation>
 | 
				
			||||||
 | 
					                    ) : null}
 | 
				
			||||||
 | 
					                    {isTestConnectionStage ? (
 | 
				
			||||||
 | 
					                        <Navigation>
 | 
				
			||||||
 | 
					                            <NextStepSectionSpacedContainer>
 | 
				
			||||||
 | 
					                                <Button
 | 
				
			||||||
 | 
					                                    variant='text'
 | 
				
			||||||
 | 
					                                    color='inherit'
 | 
				
			||||||
 | 
					                                    onClick={() => {
 | 
				
			||||||
 | 
					                                        setStage('generate-api-key');
 | 
				
			||||||
 | 
					                                    }}
 | 
				
			||||||
 | 
					                                >
 | 
				
			||||||
 | 
					                                    Back
 | 
				
			||||||
 | 
					                                </Button>
 | 
				
			||||||
 | 
					                                <Button
 | 
				
			||||||
 | 
					                                    variant='contained'
 | 
				
			||||||
 | 
					                                    onClick={() => {
 | 
				
			||||||
 | 
					                                        onClose();
 | 
				
			||||||
 | 
					                                    }}
 | 
				
			||||||
 | 
					                                >
 | 
				
			||||||
 | 
					                                    Finish
 | 
				
			||||||
 | 
					                                </Button>
 | 
				
			||||||
                            </NextStepSectionSpacedContainer>
 | 
					                            </NextStepSectionSpacedContainer>
 | 
				
			||||||
                        </Navigation>
 | 
					                        </Navigation>
 | 
				
			||||||
                    ) : null}
 | 
					                    ) : null}
 | 
				
			||||||
                </ConnectSdk>
 | 
					                </ConnectSdk>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                {isLargeScreen && stage.name === 'select-sdk' ? (
 | 
					                {isLargeScreen && isSelectSdkStage ? (
 | 
				
			||||||
                    <SelectSdkConcepts />
 | 
					                    <SelectSdkConcepts />
 | 
				
			||||||
                ) : null}
 | 
					                ) : null}
 | 
				
			||||||
                {isLargeScreen && stage.name === 'generate-api-key' ? (
 | 
					                {isLargeScreen && isGenerateApiKeyStage ? (
 | 
				
			||||||
                    <GenrateApiKeyConcepts />
 | 
					                    <GenrateApiKeyConcepts />
 | 
				
			||||||
                ) : null}
 | 
					                ) : null}
 | 
				
			||||||
            </Box>
 | 
					            </Box>
 | 
				
			||||||
 | 
				
			|||||||
@ -14,6 +14,7 @@ import {
 | 
				
			|||||||
import { SingleSelectConfigButton } from '../common/DialogFormTemplate/ConfigButtons/SingleSelectConfigButton';
 | 
					import { SingleSelectConfigButton } from '../common/DialogFormTemplate/ConfigButtons/SingleSelectConfigButton';
 | 
				
			||||||
import EnvironmentsIcon from '@mui/icons-material/CloudCircle';
 | 
					import EnvironmentsIcon from '@mui/icons-material/CloudCircle';
 | 
				
			||||||
import { ArcherContainer, ArcherElement } from 'react-archer';
 | 
					import { ArcherContainer, ArcherElement } from 'react-archer';
 | 
				
			||||||
 | 
					import { useEffect } from 'react';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const ChooseEnvironment = ({
 | 
					const ChooseEnvironment = ({
 | 
				
			||||||
    environments,
 | 
					    environments,
 | 
				
			||||||
@ -159,11 +160,11 @@ const TokenExplanation = ({
 | 
				
			|||||||
                            </SecretExplanationDescription>
 | 
					                            </SecretExplanationDescription>
 | 
				
			||||||
                        </ArcherElement>
 | 
					                        </ArcherElement>
 | 
				
			||||||
                        <ArcherElement
 | 
					                        <ArcherElement
 | 
				
			||||||
                            id='secreat-description'
 | 
					                            id='secret-description'
 | 
				
			||||||
                            relations={[
 | 
					                            relations={[
 | 
				
			||||||
                                {
 | 
					                                {
 | 
				
			||||||
                                    targetId: 'secret',
 | 
					                                    targetId: 'secret',
 | 
				
			||||||
                                    targetAnchor: 'bottom',
 | 
					                                    targetAnchor: 'right',
 | 
				
			||||||
                                    sourceAnchor: 'top',
 | 
					                                    sourceAnchor: 'top',
 | 
				
			||||||
                                },
 | 
					                                },
 | 
				
			||||||
                            ]}
 | 
					                            ]}
 | 
				
			||||||
@ -185,6 +186,7 @@ interface GenerateApiKeyProps {
 | 
				
			|||||||
    environment: string;
 | 
					    environment: string;
 | 
				
			||||||
    sdkType: 'client' | 'frontend';
 | 
					    sdkType: 'client' | 'frontend';
 | 
				
			||||||
    onEnvSelect: (env: string) => void;
 | 
					    onEnvSelect: (env: string) => void;
 | 
				
			||||||
 | 
					    onApiKey: (apiKey: string | null) => void;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const GenerateApiKey = ({
 | 
					export const GenerateApiKey = ({
 | 
				
			||||||
@ -193,12 +195,18 @@ export const GenerateApiKey = ({
 | 
				
			|||||||
    project,
 | 
					    project,
 | 
				
			||||||
    sdkType,
 | 
					    sdkType,
 | 
				
			||||||
    onEnvSelect,
 | 
					    onEnvSelect,
 | 
				
			||||||
 | 
					    onApiKey,
 | 
				
			||||||
}: GenerateApiKeyProps) => {
 | 
					}: GenerateApiKeyProps) => {
 | 
				
			||||||
    const { tokens, refetch: refreshTokens } = useProjectApiTokens(project);
 | 
					    const { tokens, refetch: refreshTokens } = useProjectApiTokens(project);
 | 
				
			||||||
    const { createToken, loading: creatingToken } = useProjectApiTokensApi();
 | 
					    const { createToken, loading: creatingToken } = useProjectApiTokensApi();
 | 
				
			||||||
    const currentEnvironmentToken = tokens.find(
 | 
					    const currentEnvironmentToken = tokens.find(
 | 
				
			||||||
        (token) => token.environment === environment && token.type === sdkType,
 | 
					        (token) => token.environment === environment && token.type === sdkType,
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    useEffect(() => {
 | 
				
			||||||
 | 
					        onApiKey(currentEnvironmentToken?.secret || null);
 | 
				
			||||||
 | 
					    }, [currentEnvironmentToken]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const parsedToken = parseToken(currentEnvironmentToken?.secret);
 | 
					    const parsedToken = parseToken(currentEnvironmentToken?.secret);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const { setToastApiError } = useToast();
 | 
					    const { setToastApiError } = useToast();
 | 
				
			||||||
 | 
				
			|||||||
@ -15,6 +15,7 @@ import ruby from 'assets/icons/sdks/Logo-ruby.svg';
 | 
				
			|||||||
import rust from 'assets/icons/sdks/Logo-rust.svg';
 | 
					import rust from 'assets/icons/sdks/Logo-rust.svg';
 | 
				
			||||||
import svelte from 'assets/icons/sdks/Logo-svelte.svg';
 | 
					import svelte from 'assets/icons/sdks/Logo-svelte.svg';
 | 
				
			||||||
import vue from 'assets/icons/sdks/Logo-vue.svg';
 | 
					import vue from 'assets/icons/sdks/Logo-vue.svg';
 | 
				
			||||||
 | 
					import { formatAssetPath } from 'utils/formatPath';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const SpacedContainer = styled('div')(({ theme }) => ({
 | 
					const SpacedContainer = styled('div')(({ theme }) => ({
 | 
				
			||||||
    padding: theme.spacing(5, 8, 8, 8),
 | 
					    padding: theme.spacing(5, 8, 8, 8),
 | 
				
			||||||
@ -108,7 +109,7 @@ export const SelectSdk: FC<ISelectSdkProps> = ({ onSelect }) => {
 | 
				
			|||||||
                <SdkListSection>
 | 
					                <SdkListSection>
 | 
				
			||||||
                    {serverSdks.map((sdk) => (
 | 
					                    {serverSdks.map((sdk) => (
 | 
				
			||||||
                        <SdkTile>
 | 
					                        <SdkTile>
 | 
				
			||||||
                            <StyledAvatar src={sdk.icon} />
 | 
					                            <StyledAvatar src={formatAssetPath(sdk.icon)} />
 | 
				
			||||||
                            <SdkTileContent>
 | 
					                            <SdkTileContent>
 | 
				
			||||||
                                <b>{sdk.name}</b>{' '}
 | 
					                                <b>{sdk.name}</b>{' '}
 | 
				
			||||||
                                <Link
 | 
					                                <Link
 | 
				
			||||||
@ -132,7 +133,7 @@ export const SelectSdk: FC<ISelectSdkProps> = ({ onSelect }) => {
 | 
				
			|||||||
                <SdkListSection>
 | 
					                <SdkListSection>
 | 
				
			||||||
                    {clientSdks.map((sdk) => (
 | 
					                    {clientSdks.map((sdk) => (
 | 
				
			||||||
                        <SdkTile>
 | 
					                        <SdkTile>
 | 
				
			||||||
                            <StyledAvatar src={sdk.icon} />
 | 
					                            <StyledAvatar src={formatAssetPath(sdk.icon)} />
 | 
				
			||||||
                            <SdkTileContent>
 | 
					                            <SdkTileContent>
 | 
				
			||||||
                                <b>{sdk.name}</b>{' '}
 | 
					                                <b>{sdk.name}</b>{' '}
 | 
				
			||||||
                                <Link
 | 
					                                <Link
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user