From f16f8594f5b2c6e866f306c33571112fd01955b5 Mon Sep 17 00:00:00 2001 From: Simon Hornby Date: Tue, 28 May 2024 12:33:53 +0200 Subject: [PATCH] chore: deprecate custom strategies (#7186) --- .../FeatureStrategyForm.tsx | 26 +++++++- .../StrategyExecution/StrategyExecution.tsx | 60 +++++++++++++------ .../FeatureDetails/helpers.ts | 16 +---- .../CreateStrategy/CreateStrategy.tsx | 22 ++++++- .../CustomStrategyInfo/CustomStrategyInfo.tsx | 11 ++-- .../StrategiesList/StrategiesList.tsx | 20 ++++++- frontend/src/utils/strategyNames.tsx | 11 ++++ src/lib/routes/admin-api/strategy.ts | 3 +- 8 files changed, 127 insertions(+), 42 deletions(-) diff --git a/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx b/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx index 181bc44622..6e3b3cda4d 100644 --- a/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx +++ b/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx @@ -10,6 +10,7 @@ import { Box, Divider, Typography, + Link, } from '@mui/material'; import type { IFeatureStrategy, @@ -42,7 +43,7 @@ import { useHasProjectEnvironmentAccess } from 'hooks/useHasAccess'; import { FeatureStrategyTitle } from './FeatureStrategyTitle/FeatureStrategyTitle'; import { FeatureStrategyEnabledDisabled } from './FeatureStrategyEnabledDisabled/FeatureStrategyEnabledDisabled'; import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; -import { formatStrategyName } from 'utils/strategyNames'; +import { BuiltInStrategies, formatStrategyName } from 'utils/strategyNames'; import { Badge } from 'component/common/Badge/Badge'; import EnvironmentIcon from 'component/common/EnvironmentIcon/EnvironmentIcon'; @@ -389,6 +390,29 @@ export const FeatureStrategyForm = ({ /> } /> + + + Custom strategies are deprecated. We recommend not + adding them to any flags going forward and using the + predefined strategies like Gradual rollout with{' '} + + constraints + {' '} + instead. + + } + /> ( + + Custom strategies are deprecated and may be removed in a future major + version. Consider rewriting this strategy as a predefined strategy with{' '} + + constraints. + + +); + const NoItems: VFC = () => ( This strategy does not have constraints or parameters. @@ -299,22 +314,31 @@ export const StrategyExecution: VFC = ({ ].filter(Boolean); return ( - 0} - show={ - - {listItems.map((item, index) => ( - - 0} - show={} - /> - {item} - - ))} - - } - elseShow={} - /> + <> + } + /> + + 0} + show={ + + {listItems.map((item, index) => ( + + 0} + show={} + /> + {item} + + ))} + + } + elseShow={} + /> + ); }; diff --git a/frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/FeatureDetails/helpers.ts b/frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/FeatureDetails/helpers.ts index 81230bf9b2..13d66f960e 100644 --- a/frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/FeatureDetails/helpers.ts +++ b/frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/FeatureDetails/helpers.ts @@ -1,15 +1,5 @@ import type { PlaygroundFeatureSchema } from 'openapi'; - -export const DEFAULT_STRATEGIES = [ - 'default', - 'applicationHostname', - 'flexibleRollout', - 'gradualRolloutRandom', - 'gradualRolloutSessionId', - 'gradualRolloutUserId', - 'remoteAddress', - 'userWithId', -]; +import { BuiltInStrategies } from 'utils/strategyNames'; export function checkForEmptyValues(object?: Object): boolean { if (object === undefined) { @@ -22,7 +12,7 @@ export function checkForEmptyValues(object?: Object): boolean { export const hasCustomStrategies = (feature: PlaygroundFeatureSchema) => { return feature.strategies?.data?.find( - (strategy) => !DEFAULT_STRATEGIES.includes(strategy.name), + (strategy) => !BuiltInStrategies.includes(strategy.name), ); }; @@ -30,7 +20,7 @@ export const hasOnlyCustomStrategies = (feature: PlaygroundFeatureSchema) => { return ( feature.strategies?.data?.length > 0 && !feature.strategies?.data?.find((strategy) => - DEFAULT_STRATEGIES.includes(strategy.name), + BuiltInStrategies.includes(strategy.name), ) ); }; diff --git a/frontend/src/component/strategies/CreateStrategy/CreateStrategy.tsx b/frontend/src/component/strategies/CreateStrategy/CreateStrategy.tsx index 1ad86acba3..c9248b78f6 100644 --- a/frontend/src/component/strategies/CreateStrategy/CreateStrategy.tsx +++ b/frontend/src/component/strategies/CreateStrategy/CreateStrategy.tsx @@ -1,4 +1,4 @@ -import { useNavigate } from 'react-router-dom'; +import { useNavigate, Link } from 'react-router-dom'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import useToast from 'hooks/useToast'; import FormTemplate from 'component/common/FormTemplate/FormTemplate'; @@ -11,6 +11,25 @@ import { formatUnknownError } from 'utils/formatUnknownError'; import { CreateButton } from 'component/common/CreateButton/CreateButton'; import { GO_BACK } from 'constants/navigate'; import { CustomStrategyInfo } from '../CustomStrategyInfo/CustomStrategyInfo'; +import { Alert } from '@mui/material'; + +const CreateStrategyDeprecationWarning = () => ( + ({ + marginBottom: theme.spacing(3), + })} + > + Custom strategies are deprecated and may be removed in a future major + release. We recommend using the predefined strategies like Gradual + rollout with{' '} + + {' '} + constraints + {' '} + instead of creating a custom strategy. + +); export const CreateStrategy = () => { const { setToastData, setToastApiError } = useToast(); @@ -77,6 +96,7 @@ export const CreateStrategy = () => { documentationLinkLabel='Custom strategies documentation' formatApiCode={formatApiCode} > + = ({ alert }) => { const content = ( <> - We recommend you to use the predefined strategies like Gradual - rollout with constraints instead of creating a custom strategy. - - - If you decide to create a custom strategy be aware of: + If you decide to create a custom strategy be aware of the + following:
  • They require writing custom code and deployments for @@ -32,8 +29,8 @@ export const CustomStrategyInfo: FC<{ alert?: boolean }> = ({ alert }) => { to evaluate differently
  • - Requires a lot of configuration in both Unleash admin UI - and the SDK. + Custom strategies require a lot of configuration in both + Unleash admin UI and the SDK.
diff --git a/frontend/src/component/strategies/StrategiesList/StrategiesList.tsx b/frontend/src/component/strategies/StrategiesList/StrategiesList.tsx index 8c18a522a9..0ee82dba8e 100644 --- a/frontend/src/component/strategies/StrategiesList/StrategiesList.tsx +++ b/frontend/src/component/strategies/StrategiesList/StrategiesList.tsx @@ -1,6 +1,6 @@ import { useState, useMemo, useCallback, type FC } from 'react'; import { useNavigate } from 'react-router-dom'; -import { Box, Link, Typography, styled } from '@mui/material'; +import { Alert, Box, Link, Typography, styled } from '@mui/material'; import Extension from '@mui/icons-material/Extension'; import { Table, @@ -110,6 +110,23 @@ const PredefinedStrategyTitle = () => (
); +const StrategyDeprecationWarning = () => ( + + Custom strategies are deprecated and may be removed in a future major + version. We recommend not using custom strategies going forward and + instead using the predefined strategies with{' '} + + constraints + + . If you have a need for custom strategies that you cannot support with + constraints, please reach out to us. + +); + export const StrategiesList = () => { const navigate = useNavigate(); const [dialogueMetaData, setDialogueMetaData] = useState( @@ -434,6 +451,7 @@ export const StrategiesList = () => { } > + { } }; +export const BuiltInStrategies = [ + 'default', + 'applicationHostname', + 'flexibleRollout', + 'gradualRolloutRandom', + 'gradualRolloutSessionId', + 'gradualRolloutUserId', + 'remoteAddress', + 'userWithId', +]; + export const GetFeatureStrategyIcon: FC<{ strategyName: string }> = ({ strategyName, }) => { diff --git a/src/lib/routes/admin-api/strategy.ts b/src/lib/routes/admin-api/strategy.ts index a68d3e1078..0e3f1d4d7c 100644 --- a/src/lib/routes/admin-api/strategy.ts +++ b/src/lib/routes/admin-api/strategy.ts @@ -122,11 +122,12 @@ class StrategyController extends Controller { permission: CREATE_STRATEGY, middleware: [ openApiService.validPath({ + deprecated: true, tags: ['Strategies'], operationId: 'createStrategy', summary: 'Create a strategy', description: - 'Creates a strategy type based on the supplied data.', + 'Creates a custom strategy type based on the supplied data. Custom strategies are deprecated and should not be used. Prefer using built in strategies with constraints instead.', requestBody: createRequestSchema('createStrategySchema'), responses: { 201: resourceCreatedResponseSchema('strategySchema'),