mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: enable toggle with disabled strategies dialog (#5416)
https://linear.app/unleash/issue/UNL-283/improve-dialog-when-there-are-disabled-strategies-and-we-want-to Improves the "enable toggle when there are disabled strategies" dialog. Also implements passing in the missing `disabledStrategiesCount` property to the dialog. ![image](https://github.com/Unleash/unleash/assets/14320932/95d9110e-8c1c-47ce-8e1b-389607115a54)
This commit is contained in:
parent
2e96ace14e
commit
47e214d96f
@ -1,10 +1,15 @@
|
|||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
import { Typography } from '@mui/material';
|
import { Typography, styled } from '@mui/material';
|
||||||
import { Dialogue } from 'component/common/Dialogue/Dialogue';
|
import { Dialogue } from 'component/common/Dialogue/Dialogue';
|
||||||
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
|
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
|
||||||
import PermissionButton from 'component/common/PermissionButton/PermissionButton';
|
import PermissionButton from 'component/common/PermissionButton/PermissionButton';
|
||||||
import { UPDATE_FEATURE } from 'component/providers/AccessProvider/permissions';
|
import { UPDATE_FEATURE } from 'component/providers/AccessProvider/permissions';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { useFeature } from 'hooks/api/getters/useFeature/useFeature';
|
||||||
|
|
||||||
|
const StyledList = styled('ul')(({ theme }) => ({
|
||||||
|
margin: theme.spacing(1),
|
||||||
|
paddingLeft: theme.spacing(2),
|
||||||
|
}));
|
||||||
|
|
||||||
interface IEnableEnvironmentDialogProps {
|
interface IEnableEnvironmentDialogProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@ -12,8 +17,8 @@ interface IEnableEnvironmentDialogProps {
|
|||||||
onAddDefaultStrategy: () => void;
|
onAddDefaultStrategy: () => void;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
environment?: string;
|
environment?: string;
|
||||||
|
featureId: string;
|
||||||
showBanner?: boolean;
|
showBanner?: boolean;
|
||||||
disabledStrategiesCount?: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const EnableEnvironmentDialog: FC<IEnableEnvironmentDialogProps> = ({
|
export const EnableEnvironmentDialog: FC<IEnableEnvironmentDialogProps> = ({
|
||||||
@ -22,10 +27,22 @@ export const EnableEnvironmentDialog: FC<IEnableEnvironmentDialogProps> = ({
|
|||||||
onActivateDisabledStrategies,
|
onActivateDisabledStrategies,
|
||||||
onClose,
|
onClose,
|
||||||
environment,
|
environment,
|
||||||
disabledStrategiesCount,
|
featureId,
|
||||||
}) => {
|
}) => {
|
||||||
const projectId = useRequiredPathParam('projectId');
|
const projectId = useRequiredPathParam('projectId');
|
||||||
|
|
||||||
|
const { feature } = useFeature(projectId, featureId);
|
||||||
|
|
||||||
|
const disabledStrategiesCount = feature.environments
|
||||||
|
?.find(({ name }) => name === environment)
|
||||||
|
?.strategies?.filter(({ disabled }) => disabled).length;
|
||||||
|
|
||||||
|
const disabledStrategiesText = disabledStrategiesCount
|
||||||
|
? disabledStrategiesCount === 1
|
||||||
|
? '1 disabled strategy'
|
||||||
|
: `${disabledStrategiesCount} disabled strategies`
|
||||||
|
: 'disabled strategies';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialogue
|
<Dialogue
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
@ -34,6 +51,7 @@ export const EnableEnvironmentDialog: FC<IEnableEnvironmentDialogProps> = ({
|
|||||||
<>
|
<>
|
||||||
<PermissionButton
|
<PermissionButton
|
||||||
type='button'
|
type='button'
|
||||||
|
variant='outlined'
|
||||||
permission={UPDATE_FEATURE}
|
permission={UPDATE_FEATURE}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
environmentId={environment}
|
environmentId={environment}
|
||||||
@ -43,7 +61,7 @@ export const EnableEnvironmentDialog: FC<IEnableEnvironmentDialogProps> = ({
|
|||||||
</PermissionButton>
|
</PermissionButton>
|
||||||
<PermissionButton
|
<PermissionButton
|
||||||
type='button'
|
type='button'
|
||||||
variant={'text'}
|
variant='outlined'
|
||||||
permission={UPDATE_FEATURE}
|
permission={UPDATE_FEATURE}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
environmentId={environment}
|
environmentId={environment}
|
||||||
@ -54,33 +72,28 @@ export const EnableEnvironmentDialog: FC<IEnableEnvironmentDialogProps> = ({
|
|||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
title='Enable feature toggle'
|
title={`Enable feature toggle in ${environment}`}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<Typography
|
<Typography sx={{ mb: (theme) => theme.spacing(3) }}>
|
||||||
variant='body1'
|
A feature toggle cannot be enabled without an enabled strategy.
|
||||||
color='text.primary'
|
|
||||||
sx={{ mb: (theme) => theme.spacing(2) }}
|
|
||||||
>
|
|
||||||
<ConditionallyRender
|
|
||||||
condition={disabledStrategiesCount !== undefined}
|
|
||||||
show={
|
|
||||||
<>
|
|
||||||
The feature toggle has {disabledStrategiesCount}{' '}
|
|
||||||
disabled
|
|
||||||
{disabledStrategiesCount === 1
|
|
||||||
? ' strategy'
|
|
||||||
: ' strategies'}
|
|
||||||
.
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
elseShow={'The feature toggle has disabled strategies.'}
|
|
||||||
/>
|
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant='body1' color='text.primary'>
|
<Typography>
|
||||||
You can choose to enable all the disabled strategies or you can
|
To enable this feature toggle you can choose to:
|
||||||
add the default strategy to enable this feature toggle.
|
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<StyledList>
|
||||||
|
<li>
|
||||||
|
<Typography>
|
||||||
|
<strong>Add the default strategy</strong>
|
||||||
|
</Typography>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<Typography>
|
||||||
|
<strong>Enable all the disabled strategies</strong>{' '}
|
||||||
|
(this feature toggle has {disabledStrategiesText})
|
||||||
|
</Typography>
|
||||||
|
</li>
|
||||||
|
</StyledList>
|
||||||
</Dialogue>
|
</Dialogue>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -46,6 +46,7 @@ export const useFeatureToggleSwitch: UseFeatureToggleSwitchType = (
|
|||||||
useState<ComponentProps<typeof EnableEnvironmentDialog>>({
|
useState<ComponentProps<typeof EnableEnvironmentDialog>>({
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
environment: '',
|
environment: '',
|
||||||
|
featureId: '',
|
||||||
onClose: () => {},
|
onClose: () => {},
|
||||||
onActivateDisabledStrategies: () => {},
|
onActivateDisabledStrategies: () => {},
|
||||||
onAddDefaultStrategy: () => {},
|
onAddDefaultStrategy: () => {},
|
||||||
@ -107,6 +108,7 @@ export const useFeatureToggleSwitch: UseFeatureToggleSwitchType = (
|
|||||||
setEnableEnvironmentDialogState({
|
setEnableEnvironmentDialogState({
|
||||||
isOpen: true,
|
isOpen: true,
|
||||||
environment: config.environmentName,
|
environment: config.environmentName,
|
||||||
|
featureId: config.featureId,
|
||||||
onClose: () => {
|
onClose: () => {
|
||||||
setEnableEnvironmentDialogState((prev) => ({
|
setEnableEnvironmentDialogState((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
|
Loading…
Reference in New Issue
Block a user