1
0
mirror of https://github.com/Unleash/unleash.git synced 2026-02-04 20:10:52 +01:00
unleash.unleash/frontend/src/component/feature/FeatureStrategy/FeatureStrategyMenu/FeatureStrategyMenuButton.tsx
Kamala be130979ee
feat: Suggest release templates for production environments (#11279)
Adds a "Choose a release template" suggestion for production
environments without strategies (enterprise only).
When clicked, opens the "Add Strategy" dialog with the release templates
filter preselected.
Non-production environments continue to show the default strategy
suggestion.

## Notes 

This unfortunately turned out to be a big PR 🥲 as it includes some
refactoring to be able to reuse components.
- The "Add strategy" button has been broken out of
`FeatureStrategyMenu`, so the latter can be reused (since we want to
show the same dialog when clicking the button "Choose a release
template");
- The new `EnvironmentTemplateSuggestion` shares styles with
`EnvironmentStrategySuggestion` (which can be found in
`EnvironmentHeader.styles.tsx`);
- `FeatureStrategyMenu` now has a `defaultFilter` prop, so the dialog
can be opened with a preselected filter.

<img width="900" height="349" alt="Screenshot 2026-02-03 at 17 19 32
(2)"
src="https://github.com/user-attachments/assets/27f11e24-163f-4f4d-8134-a5d08ff540ac"
/>
<img width="1379001" height="557" alt="Screenshot 2026-02-03 at 17 20
14"
src="https://github.com/user-attachments/assets/0efe77f5-af3e-498a-b305-fd5c1ed98906"
/>
2026-02-04 11:34:42 +01:00

56 lines
1.6 KiB
TypeScript

import PermissionButton, {
type IPermissionButtonProps,
} from 'component/common/PermissionButton/PermissionButton';
import { CREATE_FEATURE_STRATEGY } from 'component/providers/AccessProvider/permissions';
import { styled } from '@mui/material';
interface IFeatureStrategyMenuButtonProps {
label: string;
projectId: string;
environmentId: string;
dialogId?: string;
onClick: any;
variant?: IPermissionButtonProps['variant'];
matchWidth?: boolean;
disableReason?: string;
}
const StyledStrategyMenu = styled('div')(({ theme }) => ({
display: 'flex',
flexFlow: 'row',
justifyContent: 'flex-end',
gap: theme.spacing(1),
}));
export const FeatureStrategyMenuButton = ({
label,
projectId,
environmentId,
dialogId,
onClick,
variant,
matchWidth,
disableReason,
}: IFeatureStrategyMenuButtonProps) => {
return (
<StyledStrategyMenu onClick={(event) => event.stopPropagation()}>
<PermissionButton
data-testid='ADD_STRATEGY_BUTTON'
permission={CREATE_FEATURE_STRATEGY}
projectId={projectId}
environmentId={environmentId}
onClick={onClick}
aria-labelledby={dialogId}
variant={variant}
sx={{ minWidth: matchWidth ? '282px' : 'auto' }}
disabled={Boolean(disableReason)}
tooltipProps={{
title: disableReason ? disableReason : undefined,
}}
>
{label}
</PermissionButton>
</StyledStrategyMenu>
);
};