mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-15 17:50:48 +02:00
feat: add use template button to strategies selector on flag config pane (#9605)
This commit is contained in:
parent
dbc953b222
commit
9106fbf721
@ -20,6 +20,7 @@ import { useReleasePlans } from 'hooks/api/getters/useReleasePlans/useReleasePla
|
||||
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
|
||||
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||
import { useUiFlag } from 'hooks/useUiFlag';
|
||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||
|
||||
interface IFeatureStrategyMenuProps {
|
||||
label: string;
|
||||
@ -57,6 +58,7 @@ export const FeatureStrategyMenu = ({
|
||||
disableReason,
|
||||
}: IFeatureStrategyMenuProps) => {
|
||||
const [anchor, setAnchor] = useState<Element>();
|
||||
const [onlyReleasePlans, setOnlyReleasePlans] = useState<boolean>(false);
|
||||
const navigate = useNavigate();
|
||||
const { trackEvent } = usePlausibleTracker();
|
||||
const [selectedTemplate, setSelectedTemplate] =
|
||||
@ -71,8 +73,9 @@ export const FeatureStrategyMenu = ({
|
||||
usePendingChangeRequests(projectId);
|
||||
const { refetch } = useReleasePlans(projectId, featureId, environmentId);
|
||||
const { addReleasePlanToFeature } = useReleasePlansApi();
|
||||
const { isOss } = useUiConfig();
|
||||
const releasePlansEnabled = useUiFlag('releasePlans');
|
||||
|
||||
const displayReleasePlanButton = !isOss() && releasePlansEnabled;
|
||||
const crProtected =
|
||||
releasePlansEnabled && isChangeRequestConfigured(environmentId);
|
||||
|
||||
@ -90,6 +93,12 @@ export const FeatureStrategyMenu = ({
|
||||
};
|
||||
|
||||
const openMoreStrategies = (event: React.SyntheticEvent) => {
|
||||
setOnlyReleasePlans(false);
|
||||
setAnchor(event.currentTarget);
|
||||
};
|
||||
|
||||
const openReleasePlans = (event: React.SyntheticEvent) => {
|
||||
setOnlyReleasePlans(true);
|
||||
setAnchor(event.currentTarget);
|
||||
};
|
||||
|
||||
@ -151,6 +160,27 @@ export const FeatureStrategyMenu = ({
|
||||
|
||||
return (
|
||||
<StyledStrategyMenu onClick={(event) => event.stopPropagation()}>
|
||||
{displayReleasePlanButton ? (
|
||||
<>
|
||||
<PermissionButton
|
||||
data-testid='ADD_TEMPLATE_BUTTON'
|
||||
permission={CREATE_FEATURE_STRATEGY}
|
||||
projectId={projectId}
|
||||
environmentId={environmentId}
|
||||
onClick={openReleasePlans}
|
||||
aria-labelledby={popoverId}
|
||||
variant='outlined'
|
||||
sx={{ minWidth: matchWidth ? '282px' : 'auto' }}
|
||||
disabled={Boolean(disableReason)}
|
||||
tooltipProps={{
|
||||
title: disableReason ? disableReason : undefined,
|
||||
}}
|
||||
>
|
||||
Use template
|
||||
</PermissionButton>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
<PermissionButton
|
||||
data-testid='ADD_STRATEGY_BUTTON'
|
||||
permission={CREATE_FEATURE_STRATEGY}
|
||||
@ -198,6 +228,7 @@ export const FeatureStrategyMenu = ({
|
||||
projectId={projectId}
|
||||
featureId={featureId}
|
||||
environmentId={environmentId}
|
||||
onlyReleasePlans={onlyReleasePlans}
|
||||
onAddReleasePlan={(template) => {
|
||||
setSelectedTemplate(template);
|
||||
setAddReleasePlanOpen(true);
|
||||
|
@ -10,6 +10,7 @@ interface IFeatureStrategyMenuCardsProps {
|
||||
projectId: string;
|
||||
featureId: string;
|
||||
environmentId: string;
|
||||
onlyReleasePlans: boolean;
|
||||
onAddReleasePlan: (template: IReleasePlanTemplate) => void;
|
||||
}
|
||||
|
||||
@ -22,10 +23,12 @@ export const FeatureStrategyMenuCards = ({
|
||||
projectId,
|
||||
featureId,
|
||||
environmentId,
|
||||
onlyReleasePlans,
|
||||
onAddReleasePlan,
|
||||
}: IFeatureStrategyMenuCardsProps) => {
|
||||
const { strategies } = useStrategies();
|
||||
const { templates } = useReleasePlanTemplates();
|
||||
const allStrategies = !onlyReleasePlans;
|
||||
|
||||
const preDefinedStrategies = strategies.filter(
|
||||
(strategy) => !strategy.deprecated && !strategy.editable,
|
||||
@ -43,20 +46,22 @@ export const FeatureStrategyMenuCards = ({
|
||||
};
|
||||
return (
|
||||
<List dense>
|
||||
<>
|
||||
<StyledTypography color='textSecondary'>
|
||||
Default strategy for {environmentId} environment
|
||||
</StyledTypography>
|
||||
<ListItem key={defaultStrategy.name}>
|
||||
<FeatureStrategyMenuCard
|
||||
projectId={projectId}
|
||||
featureId={featureId}
|
||||
environmentId={environmentId}
|
||||
strategy={defaultStrategy}
|
||||
defaultStrategy={true}
|
||||
/>
|
||||
</ListItem>
|
||||
</>
|
||||
{allStrategies ? (
|
||||
<>
|
||||
<StyledTypography color='textSecondary'>
|
||||
Default strategy for {environmentId} environment
|
||||
</StyledTypography>
|
||||
<ListItem key={defaultStrategy.name}>
|
||||
<FeatureStrategyMenuCard
|
||||
projectId={projectId}
|
||||
featureId={featureId}
|
||||
environmentId={environmentId}
|
||||
strategy={defaultStrategy}
|
||||
defaultStrategy={true}
|
||||
/>
|
||||
</ListItem>
|
||||
</>
|
||||
) : null}
|
||||
<ConditionallyRender
|
||||
condition={templates.length > 0}
|
||||
show={
|
||||
@ -75,39 +80,43 @@ export const FeatureStrategyMenuCards = ({
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<StyledTypography color='textSecondary'>
|
||||
Predefined strategy types
|
||||
</StyledTypography>
|
||||
{preDefinedStrategies.map((strategy) => (
|
||||
<ListItem key={strategy.name}>
|
||||
<FeatureStrategyMenuCard
|
||||
projectId={projectId}
|
||||
featureId={featureId}
|
||||
environmentId={environmentId}
|
||||
strategy={strategy}
|
||||
{allStrategies ? (
|
||||
<>
|
||||
<StyledTypography color='textSecondary'>
|
||||
Predefined strategy types
|
||||
</StyledTypography>
|
||||
{preDefinedStrategies.map((strategy) => (
|
||||
<ListItem key={strategy.name}>
|
||||
<FeatureStrategyMenuCard
|
||||
projectId={projectId}
|
||||
featureId={featureId}
|
||||
environmentId={environmentId}
|
||||
strategy={strategy}
|
||||
/>
|
||||
</ListItem>
|
||||
))}
|
||||
<ConditionallyRender
|
||||
condition={customStrategies.length > 0}
|
||||
show={
|
||||
<>
|
||||
<StyledTypography color='textSecondary'>
|
||||
Custom strategies
|
||||
</StyledTypography>
|
||||
{customStrategies.map((strategy) => (
|
||||
<ListItem key={strategy.name}>
|
||||
<FeatureStrategyMenuCard
|
||||
projectId={projectId}
|
||||
featureId={featureId}
|
||||
environmentId={environmentId}
|
||||
strategy={strategy}
|
||||
/>
|
||||
</ListItem>
|
||||
))}
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</ListItem>
|
||||
))}
|
||||
<ConditionallyRender
|
||||
condition={customStrategies.length > 0}
|
||||
show={
|
||||
<>
|
||||
<StyledTypography color='textSecondary'>
|
||||
Custom strategies
|
||||
</StyledTypography>
|
||||
{customStrategies.map((strategy) => (
|
||||
<ListItem key={strategy.name}>
|
||||
<FeatureStrategyMenuCard
|
||||
projectId={projectId}
|
||||
featureId={featureId}
|
||||
environmentId={environmentId}
|
||||
strategy={strategy}
|
||||
/>
|
||||
</ListItem>
|
||||
))}
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</List>
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user