mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
feat: check flag status snippet (#8097)
This commit is contained in:
parent
ec417bf15e
commit
62d03d35cd
@ -179,6 +179,7 @@ export const NewInUnleash = ({
|
|||||||
summary,
|
summary,
|
||||||
}) => (
|
}) => (
|
||||||
<NewInUnleashItem
|
<NewInUnleashItem
|
||||||
|
key={label}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
trackEvent('new-in-unleash-click', {
|
trackEvent('new-in-unleash-click', {
|
||||||
props: {
|
props: {
|
||||||
|
@ -23,6 +23,7 @@ interface IConnectSDKDialogProps {
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
project: string;
|
project: string;
|
||||||
environments: string[];
|
environments: string[];
|
||||||
|
feature: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConnectSdk = styled('main')(({ theme }) => ({
|
const ConnectSdk = styled('main')(({ theme }) => ({
|
||||||
@ -70,6 +71,7 @@ export const ConnectSdkDialog = ({
|
|||||||
onClose,
|
onClose,
|
||||||
environments,
|
environments,
|
||||||
project,
|
project,
|
||||||
|
feature,
|
||||||
}: IConnectSDKDialogProps) => {
|
}: IConnectSDKDialogProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isLargeScreen = useMediaQuery(theme.breakpoints.up('lg'));
|
const isLargeScreen = useMediaQuery(theme.breakpoints.up('lg'));
|
||||||
@ -115,7 +117,11 @@ export const ConnectSdkDialog = ({
|
|||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{isTestConnectionStage ? (
|
{isTestConnectionStage ? (
|
||||||
<TestSdkConnection sdk={sdk} apiKey={apiKey} />
|
<TestSdkConnection
|
||||||
|
sdk={sdk}
|
||||||
|
apiKey={apiKey}
|
||||||
|
feature={feature}
|
||||||
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{stage === 'generate-api-key' ? (
|
{stage === 'generate-api-key' ? (
|
||||||
|
@ -46,7 +46,7 @@ const SdkListSection = styled('div')(({ theme }) => ({
|
|||||||
|
|
||||||
const SdkTile = styled('div')(({ theme }) => ({
|
const SdkTile = styled('div')(({ theme }) => ({
|
||||||
fontSize: theme.typography.body2.fontSize,
|
fontSize: theme.typography.body2.fontSize,
|
||||||
backgroundColor: theme.palette.common.white,
|
backgroundColor: theme.palette.background.default,
|
||||||
borderRadius: theme.shape.borderRadius,
|
borderRadius: theme.shape.borderRadius,
|
||||||
padding: theme.spacing(2, 3),
|
padding: theme.spacing(2, 3),
|
||||||
width: '170px',
|
width: '170px',
|
||||||
|
@ -3,7 +3,11 @@ import { Box, IconButton, styled, Tooltip, Typography } from '@mui/material';
|
|||||||
import { SectionHeader } from './SharedComponents';
|
import { SectionHeader } from './SharedComponents';
|
||||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||||
import type { Sdk } from './sharedTypes';
|
import type { Sdk } from './sharedTypes';
|
||||||
import { codeSnippets, installCommands } from './sdkSnippets';
|
import {
|
||||||
|
checkFlagCodeSnippets,
|
||||||
|
initializeCodeSnippets,
|
||||||
|
installCommands,
|
||||||
|
} from './sdkSnippets';
|
||||||
import copy from 'copy-to-clipboard';
|
import copy from 'copy-to-clipboard';
|
||||||
import useToast from 'hooks/useToast';
|
import useToast from 'hooks/useToast';
|
||||||
import CopyIcon from '@mui/icons-material/FileCopy';
|
import CopyIcon from '@mui/icons-material/FileCopy';
|
||||||
@ -32,29 +36,7 @@ const CopyToClipboard = styled(Tooltip)(({ theme }) => ({
|
|||||||
right: theme.spacing(1),
|
right: theme.spacing(1),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
interface ITestSdkConnectionProps {
|
const CopyBlock: FC<{ title: string; code: string }> = ({ title, code }) => {
|
||||||
sdk: Sdk;
|
|
||||||
apiKey: string;
|
|
||||||
}
|
|
||||||
export const TestSdkConnection: FC<ITestSdkConnectionProps> = ({
|
|
||||||
sdk,
|
|
||||||
apiKey,
|
|
||||||
}) => {
|
|
||||||
const { uiConfig } = useUiConfig();
|
|
||||||
const { setToastData } = useToast();
|
|
||||||
|
|
||||||
const clientApiUrl = `${uiConfig.unleashUrl}/api/`;
|
|
||||||
const frontendApiUrl = `${uiConfig.unleashUrl}/api/frontend/`;
|
|
||||||
const apiUrl = sdk.type === 'client' ? clientApiUrl : frontendApiUrl;
|
|
||||||
const codeSnippet =
|
|
||||||
codeSnippets[sdk.name] || `No snippet found for the ${sdk.name} SDK`;
|
|
||||||
const installCommand =
|
|
||||||
installCommands[sdk.name] ||
|
|
||||||
`No install command found for the ${sdk.name} SDK`;
|
|
||||||
const filledCodeSnippet = codeSnippet
|
|
||||||
.replace('<YOUR_API_TOKEN>', apiKey)
|
|
||||||
.replace('<YOUR_API_URL>', apiUrl);
|
|
||||||
|
|
||||||
const onCopyToClipboard = (data: string) => () => {
|
const onCopyToClipboard = (data: string) => () => {
|
||||||
copy(data);
|
copy(data);
|
||||||
setToastData({
|
setToastData({
|
||||||
@ -62,6 +44,51 @@ export const TestSdkConnection: FC<ITestSdkConnectionProps> = ({
|
|||||||
title: 'Copied to clipboard',
|
title: 'Copied to clipboard',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const { setToastData } = useToast();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StyledCodeBlock>
|
||||||
|
{code}
|
||||||
|
<CopyToClipboard title={title} arrow>
|
||||||
|
<IconButton onClick={onCopyToClipboard(code)} size='small'>
|
||||||
|
<CopyIcon />
|
||||||
|
</IconButton>
|
||||||
|
</CopyToClipboard>
|
||||||
|
</StyledCodeBlock>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface ITestSdkConnectionProps {
|
||||||
|
sdk: Sdk;
|
||||||
|
apiKey: string;
|
||||||
|
feature: string;
|
||||||
|
}
|
||||||
|
export const TestSdkConnection: FC<ITestSdkConnectionProps> = ({
|
||||||
|
sdk,
|
||||||
|
apiKey,
|
||||||
|
feature,
|
||||||
|
}) => {
|
||||||
|
const { uiConfig } = useUiConfig();
|
||||||
|
|
||||||
|
const clientApiUrl = `${uiConfig.unleashUrl}/api/`;
|
||||||
|
const frontendApiUrl = `${uiConfig.unleashUrl}/api/frontend/`;
|
||||||
|
const apiUrl = sdk.type === 'client' ? clientApiUrl : frontendApiUrl;
|
||||||
|
const initializeCodeSnippet =
|
||||||
|
initializeCodeSnippets[sdk.name] ||
|
||||||
|
`No snippet found for the ${sdk.name} SDK`;
|
||||||
|
const installCommand =
|
||||||
|
installCommands[sdk.name] ||
|
||||||
|
`No install command found for the ${sdk.name} SDK`;
|
||||||
|
const filledInitializeCodeSnippet = initializeCodeSnippet
|
||||||
|
.replace('<YOUR_API_TOKEN>', apiKey)
|
||||||
|
.replace('<YOUR_API_URL>', apiUrl);
|
||||||
|
const checkFlagCodeSnippet =
|
||||||
|
checkFlagCodeSnippets[sdk.name] ||
|
||||||
|
`No snippet found for the ${sdk.name} SDK`;
|
||||||
|
const filledCheckFlagCodeSnippet = checkFlagCodeSnippet.replace(
|
||||||
|
'<YOUR_FLAG>',
|
||||||
|
feature,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SpacedContainer>
|
<SpacedContainer>
|
||||||
@ -69,29 +96,17 @@ export const TestSdkConnection: FC<ITestSdkConnectionProps> = ({
|
|||||||
<Box sx={{ mt: 4 }}>
|
<Box sx={{ mt: 4 }}>
|
||||||
<SectionHeader>Setup the SDK</SectionHeader>
|
<SectionHeader>Setup the SDK</SectionHeader>
|
||||||
<p>1. Install the SDK</p>
|
<p>1. Install the SDK</p>
|
||||||
<StyledCodeBlock>
|
<CopyBlock title='Copy command' code={installCommand} />
|
||||||
{installCommand}
|
|
||||||
<CopyToClipboard title='Copy command' arrow>
|
|
||||||
<IconButton
|
|
||||||
onClick={onCopyToClipboard(installCommand)}
|
|
||||||
size='small'
|
|
||||||
>
|
|
||||||
<CopyIcon />
|
|
||||||
</IconButton>
|
|
||||||
</CopyToClipboard>
|
|
||||||
</StyledCodeBlock>
|
|
||||||
<p>2. Initialize the SDK</p>
|
<p>2. Initialize the SDK</p>
|
||||||
<StyledCodeBlock>
|
<CopyBlock
|
||||||
{filledCodeSnippet}
|
title='Copy snippet'
|
||||||
<CopyToClipboard title='Copy snippet' arrow>
|
code={filledInitializeCodeSnippet}
|
||||||
<IconButton
|
/>
|
||||||
onClick={onCopyToClipboard(filledCodeSnippet)}
|
<p>3. Check feature status</p>
|
||||||
size='small'
|
<CopyBlock
|
||||||
>
|
title='Copy snippet'
|
||||||
<CopyIcon />
|
code={filledCheckFlagCodeSnippet}
|
||||||
</IconButton>
|
/>
|
||||||
</CopyToClipboard>
|
|
||||||
</StyledCodeBlock>
|
|
||||||
</Box>
|
</Box>
|
||||||
</SpacedContainer>
|
</SpacedContainer>
|
||||||
);
|
);
|
||||||
|
@ -20,12 +20,15 @@ dotnet add package Newtonsoft.Json`,
|
|||||||
Vue: 'npm install @unleash/proxy-client-vue',
|
Vue: 'npm install @unleash/proxy-client-vue',
|
||||||
Svelte: 'npm install @unleash/proxy-client-svelte',
|
Svelte: 'npm install @unleash/proxy-client-svelte',
|
||||||
Swift: 'https://github.com/Unleash/unleash-proxy-client-swift',
|
Swift: 'https://github.com/Unleash/unleash-proxy-client-swift',
|
||||||
Android:
|
Android: `implementation("io.getunleash:unleash-android:\${unleash.sdk.version}")
|
||||||
'implementation("io.getunleash:unleash-android:${unleash.sdk.version}")',
|
|
||||||
|
// enabled required permissions
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />`,
|
||||||
Flutter: 'flutter pub add unleash_proxy_client_flutter',
|
Flutter: 'flutter pub add unleash_proxy_client_flutter',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const codeSnippets: Record<SdkName, string> = {
|
export const initializeCodeSnippets: Record<SdkName, string> = {
|
||||||
Node: `import { initialize } from 'unleash-client';
|
Node: `import { initialize } from 'unleash-client';
|
||||||
|
|
||||||
const unleash = initialize({
|
const unleash = initialize({
|
||||||
@ -181,3 +184,25 @@ final unleash = UnleashClient(
|
|||||||
clientKey: '<YOUR_API_TOKEN>',
|
clientKey: '<YOUR_API_TOKEN>',
|
||||||
appName: 'unleash-onboarding-flutter');`,
|
appName: 'unleash-onboarding-flutter');`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: add idiomatic way of checking flag status that will populate metrics
|
||||||
|
export const checkFlagCodeSnippets: Record<SdkName, string> = {
|
||||||
|
Node: `setInterval(() => {
|
||||||
|
console.log('Is enabled', unleash.isEnabled('<YOUR_FLAG>'));
|
||||||
|
}, 1000);
|
||||||
|
`,
|
||||||
|
Golang: ``,
|
||||||
|
Ruby: ``,
|
||||||
|
PHP: ``,
|
||||||
|
Rust: ``,
|
||||||
|
DotNet: ``,
|
||||||
|
Java: ``,
|
||||||
|
Python: ``,
|
||||||
|
Javascript: ``,
|
||||||
|
React: ``,
|
||||||
|
Vue: ``,
|
||||||
|
Svelte: ``,
|
||||||
|
Swift: ``,
|
||||||
|
Android: ``,
|
||||||
|
Flutter: ``,
|
||||||
|
};
|
||||||
|
@ -502,14 +502,17 @@ export const ProjectFeatureToggles = ({
|
|||||||
|
|
||||||
{featureToggleModals}
|
{featureToggleModals}
|
||||||
|
|
||||||
<ConnectSdkDialog
|
{'feature' in project.onboardingStatus ? (
|
||||||
open={connectSdkOpen}
|
<ConnectSdkDialog
|
||||||
onClose={() => {
|
open={connectSdkOpen}
|
||||||
setConnectSdkOpen(false);
|
onClose={() => {
|
||||||
}}
|
setConnectSdkOpen(false);
|
||||||
project={projectId}
|
}}
|
||||||
environments={environments}
|
project={projectId}
|
||||||
/>
|
environments={environments}
|
||||||
|
feature={project.onboardingStatus.feature}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</PageContent>
|
</PageContent>
|
||||||
<BatchSelectionActionsBar count={selectedData.length}>
|
<BatchSelectionActionsBar count={selectedData.length}>
|
||||||
|
Loading…
Reference in New Issue
Block a user