2022-07-27 12:00:15 +02:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import { Box } from '@mui/material';
|
|
|
|
import { SectionSeparator } from 'component/feature/FeatureView/FeatureOverview/FeatureOverviewEnvironments/FeatureOverviewEnvironment/SectionSeparator/SectionSeparator';
|
|
|
|
import useFeatureStrategyApi from 'hooks/api/actions/useFeatureStrategyApi/useFeatureStrategyApi';
|
|
|
|
import useToast from 'hooks/useToast';
|
|
|
|
import { useFeature } from 'hooks/api/getters/useFeature/useFeature';
|
2022-03-09 14:59:24 +01:00
|
|
|
import { FeatureStrategyMenu } from '../FeatureStrategyMenu/FeatureStrategyMenu';
|
2022-07-27 12:00:15 +02:00
|
|
|
import { PresetCard } from './PresetCard/PresetCard';
|
|
|
|
import { useStyles } from './FeatureStrategyEmpty.styles';
|
|
|
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
2022-03-09 14:59:24 +01:00
|
|
|
|
|
|
|
interface IFeatureStrategyEmptyProps {
|
|
|
|
projectId: string;
|
|
|
|
featureId: string;
|
|
|
|
environmentId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const FeatureStrategyEmpty = ({
|
|
|
|
projectId,
|
|
|
|
featureId,
|
|
|
|
environmentId,
|
|
|
|
}: IFeatureStrategyEmptyProps) => {
|
2022-05-02 15:52:41 +02:00
|
|
|
const { classes: styles } = useStyles();
|
2022-07-27 12:00:15 +02:00
|
|
|
const { addStrategyToFeature } = useFeatureStrategyApi();
|
|
|
|
const { setToastData, setToastApiError } = useToast();
|
|
|
|
const { refetchFeature } = useFeature(projectId, featureId);
|
|
|
|
|
|
|
|
const onAfterAddStrategy = () => {
|
|
|
|
refetchFeature();
|
|
|
|
setToastData({
|
|
|
|
title: 'Strategy created',
|
|
|
|
text: 'Successfully created strategy',
|
|
|
|
type: 'success',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const onAddSimpleStrategy = async () => {
|
|
|
|
try {
|
|
|
|
await addStrategyToFeature(projectId, featureId, environmentId, {
|
|
|
|
name: 'default',
|
|
|
|
parameters: {},
|
|
|
|
constraints: [],
|
|
|
|
});
|
|
|
|
onAfterAddStrategy();
|
|
|
|
} catch (error) {
|
|
|
|
setToastApiError(formatUnknownError(error));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const onAddGradualRolloutStrategy = async () => {
|
|
|
|
try {
|
|
|
|
await addStrategyToFeature(projectId, featureId, environmentId, {
|
|
|
|
name: 'flexibleRollout',
|
|
|
|
parameters: {
|
|
|
|
rollout: '50',
|
|
|
|
stickiness: 'default',
|
|
|
|
},
|
|
|
|
constraints: [],
|
|
|
|
});
|
|
|
|
onAfterAddStrategy();
|
|
|
|
} catch (error) {
|
|
|
|
setToastApiError(formatUnknownError(error));
|
|
|
|
}
|
|
|
|
};
|
2022-03-09 14:59:24 +01:00
|
|
|
|
|
|
|
return (
|
2022-07-27 12:00:15 +02:00
|
|
|
<div className={styles.container}>
|
|
|
|
<div className={styles.title}>
|
|
|
|
You have not defined any strategies yet.
|
|
|
|
</div>
|
|
|
|
<p className={styles.description}>
|
2022-03-09 14:59:24 +01:00
|
|
|
Strategies added in this environment will only be executed if
|
2022-07-27 12:00:15 +02:00
|
|
|
the SDK is using an{' '}
|
|
|
|
<Link to="/admin/api">API key configured</Link> for this
|
|
|
|
environment.
|
2022-03-09 14:59:24 +01:00
|
|
|
</p>
|
|
|
|
<FeatureStrategyMenu
|
|
|
|
label="Add your first strategy"
|
|
|
|
projectId={projectId}
|
|
|
|
featureId={featureId}
|
|
|
|
environmentId={environmentId}
|
|
|
|
/>
|
2022-07-27 12:00:15 +02:00
|
|
|
<Box sx={{ width: '100%', mt: 3 }}>
|
|
|
|
<SectionSeparator>Or use a strategy template</SectionSeparator>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: 'grid',
|
|
|
|
width: '100%',
|
|
|
|
gap: 2,
|
|
|
|
gridTemplateColumns: '1fr 1fr',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<PresetCard
|
|
|
|
title="Standard strategy"
|
|
|
|
onClick={onAddSimpleStrategy}
|
|
|
|
>
|
|
|
|
The standard strategy is strictly on/off for your entire
|
|
|
|
userbase.
|
|
|
|
</PresetCard>
|
|
|
|
<PresetCard
|
|
|
|
title="Gradual rollout"
|
|
|
|
onClick={onAddGradualRolloutStrategy}
|
|
|
|
>
|
|
|
|
Roll out to a percentage of your userbase.
|
|
|
|
</PresetCard>
|
|
|
|
</Box>
|
|
|
|
</div>
|
2022-03-09 14:59:24 +01:00
|
|
|
);
|
|
|
|
};
|