1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

add strategy link to environment strategy dialog component

This commit is contained in:
Youssef 2021-12-06 22:13:04 +01:00
parent c2b1645083
commit 580c22805a
7 changed files with 116 additions and 42 deletions

View File

@ -0,0 +1,15 @@
import { makeStyles } from '@material-ui/core/styles';
export const useStyles = makeStyles(theme => ({
envName: {
display: 'inline-block',
width: '90px',
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap',
},
infoText: {
marginBottom: '10px',
fontSize: theme.fontSizes.bodySize,
},
}));

View File

@ -0,0 +1,46 @@
import React from 'react';
import { useHistory } from 'react-router-dom';
import Dialogue from '../Dialogue';
import { useStyles } from './EnvironmentStrategyDialog.styles';
interface IEnvironmentStrategyDialogProps {
open: boolean;
featureId: string;
projectId: string;
onClose: () => void;
environmentName?: string;
}
const EnvironmentStrategyDialog = ({
open,
environmentName,
featureId,
projectId,
onClose,
}: IEnvironmentStrategyDialogProps) => {
const styles = useStyles();
const history = useHistory();
const strategiesLink = `/projects/${projectId}/features2/${featureId}/strategies?environment=${environmentName}&addStrategy=true`;
return (
<Dialogue
open={open}
maxWidth="sm"
onClick={() => history.push(strategiesLink)}
onClose={() => onClose()}
title="You need to add a strategy to your toggle"
primaryButtonText="Take me directly to add strategy"
secondaryButtonText="Cancel"
>
<p className={styles.infoText}>
Before you can enable the toggle in the environment, you need to
add an execution strategy.
</p>
<p className={styles.infoText}>
You can add the execution strategy by selecting the toggle, open
the environment accordion and add the execution strategy.
</p>
</Dialogue>
);
};
export default EnvironmentStrategyDialog;

View File

@ -48,15 +48,4 @@ export const useStyles = makeStyles(theme => ({
textDecoration: 'none',
color: 'inherit',
},
envName: {
display: 'inline-block',
width: '90px',
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap',
},
infoText:{
marginBottom: '10px',
fontSize: theme.fontSizes.bodySize,
},
}));

View File

@ -17,7 +17,8 @@ import useProject from '../../../../hooks/api/getters/useProject/useProject';
import { UPDATE_FEATURE } from '../../../providers/AccessProvider/permissions';
import PermissionSwitch from '../../../common/PermissionSwitch/PermissionSwitch';
import { Link } from 'react-router-dom';
import Dialogue from '../../../common/Dialogue';
import { ENVIRONMENT_STRATEGY_ERROR } from '../../../../constants/apiErrors';
import EnvironmentStrategyDialog from '../../../common/EnvironmentStrategiesDialog/EnvironmentStrategyDialog';
interface IFeatureToggleListNewItemProps {
name: string;
@ -48,6 +49,11 @@ const FeatureToggleListNewItem = ({
const history = useHistory();
const ref = useRef(null);
const [showInfoBox, setShowInfoBox] = useState(false);
const [environmentName, setEnvironmentName] = useState('');
const closeInfoBox = () => {
setShowInfoBox(false);
};
const onClick = (e: SyntheticEvent) => {
if (!ref.current?.contains(e.target)) {
@ -66,12 +72,16 @@ const FeatureToggleListNewItem = ({
refetch();
})
.catch(e => {
setShowInfoBox(true);
setToastData({
show: true,
type: 'error',
text: e.message,
});
if (e.message === ENVIRONMENT_STRATEGY_ERROR) {
setEnvironmentName(env.name);
setShowInfoBox(true);
} else {
setToastData({
show: true,
type: 'error',
text: e.message,
});
}
});
};
@ -148,26 +158,13 @@ const FeatureToggleListNewItem = ({
})}
</TableRow>
{toast}
<Dialogue
<EnvironmentStrategyDialog
open={showInfoBox}
maxWidth="sm"
onClick={() => console.log('hi')}
onClose={() => setShowInfoBox(false)}
title="You need to add a strategy to your toggle"
primaryButtonText="Take me directly to add strategy"
secondaryButtonText="Cancel"
>
<p className={styles.infoText}>
Before you can enable the toggle in the environment, you
need to add an execution strategy.
</p>
<p className={styles.infoText}>
You can add the execution strategy by selecting the toggle,
open the environment accordion and add the execution
strategy.
</p>
</Dialogue>
onClose={closeInfoBox}
projectId={projectId}
featureId={name}
environmentName={environmentName}
/>
</>
);
};

View File

@ -1,4 +1,5 @@
import { useParams } from 'react-router';
import { ENVIRONMENT_STRATEGY_ERROR } from '../../../../../../constants/apiErrors';
import useFeatureApi from '../../../../../../hooks/api/actions/useFeatureApi/useFeatureApi';
import useFeature from '../../../../../../hooks/api/getters/useFeature/useFeature';
import { TSetToastData } from '../../../../../../hooks/useToast';
@ -13,6 +14,7 @@ interface IFeatureOverviewEnvSwitchProps {
setToastData: TSetToastData;
callback?: () => void;
text?: string;
showInfoBox?: () => void;
}
const FeatureOverviewEnvSwitch = ({
@ -20,6 +22,7 @@ const FeatureOverviewEnvSwitch = ({
setToastData,
callback,
text,
showInfoBox,
}: IFeatureOverviewEnvSwitchProps) => {
const { featureId, projectId } = useParams<IFeatureViewParams>();
const { toggleFeatureEnvironmentOn, toggleFeatureEnvironmentOff } =
@ -39,11 +42,15 @@ const FeatureOverviewEnvSwitch = ({
callback();
}
} catch (e: any) {
setToastData({
show: true,
type: 'error',
text: e.toString(),
});
if (e.message === ENVIRONMENT_STRATEGY_ERROR) {
showInfoBox(true);
} else {
setToastData({
show: true,
type: 'error',
text: e.message,
});
}
}
};

View File

@ -1,9 +1,11 @@
import { Tooltip } from '@material-ui/core';
import { useState } from 'react';
import { useParams } from 'react-router';
import useFeatureApi from '../../../../../hooks/api/actions/useFeatureApi/useFeatureApi';
import useFeature from '../../../../../hooks/api/getters/useFeature/useFeature';
import useToast from '../../../../../hooks/useToast';
import { IFeatureViewParams } from '../../../../../interfaces/params';
import EnvironmentStrategyDialog from '../../../../common/EnvironmentStrategiesDialog/EnvironmentStrategyDialog';
import FeatureOverviewEnvSwitch from './FeatureOverviewEnvSwitch/FeatureOverviewEnvSwitch';
import { useStyles } from './FeatureOverviewEnvSwitches.styles';
@ -13,6 +15,12 @@ const FeatureOverviewEnvSwitches = () => {
useFeatureApi();
const { feature } = useFeature(projectId, featureId);
const { toast, setToastData } = useToast();
const [showInfoBox, setShowInfoBox] = useState(false);
const [environmentName, setEnvironmentName] = useState('');
const closeInfoBox = () => {
setShowInfoBox(false);
};
const renderEnvironmentSwitches = () => {
return feature?.environments.map(env => {
@ -21,6 +29,10 @@ const FeatureOverviewEnvSwitches = () => {
key={env.name}
env={env}
setToastData={setToastData}
showInfoBox={() => {
setEnvironmentName(env.name);
setShowInfoBox(true);
}}
/>
);
});
@ -38,6 +50,13 @@ const FeatureOverviewEnvSwitches = () => {
</Tooltip>
{renderEnvironmentSwitches()}
{toast}
<EnvironmentStrategyDialog
open={showInfoBox}
onClose={closeInfoBox}
projectId={projectId}
featureId={featureId}
environmentName={environmentName}
/>
</div>
);
};

View File

@ -0,0 +1 @@
export const ENVIRONMENT_STRATEGY_ERROR = 'You can not enable the environment before it has strategies';