mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
feat: variant with number payload (#4654)
Adds `number` as possible payload type for variant. Adds a flag to enable the feature Updates all relevant models and schemas Adds the option to the UI Closes: # [1-1357](https://linear.app/unleash/issue/1-1357/support-number-in-variant-payload) --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
c6af38b12b
commit
1cd0edb11a
@ -19,6 +19,7 @@ import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashCon
|
||||
import { WeightType } from 'constants/variantTypes';
|
||||
import { IFeatureVariantEdit } from '../EnvironmentVariantsModal';
|
||||
import { Delete } from '@mui/icons-material';
|
||||
import { useUiFlag } from 'hooks/useUiFlag';
|
||||
|
||||
const StyledVariantForm = styled('div')(({ theme }) => ({
|
||||
position: 'relative',
|
||||
@ -195,6 +196,14 @@ export const VariantForm = ({
|
||||
|
||||
const [errors, setErrors] = useState<IVariantFormErrors>({});
|
||||
|
||||
const variantTypeNumber = useUiFlag('variantTypeNumber');
|
||||
|
||||
useEffect(() => {
|
||||
if (variantTypeNumber) {
|
||||
payloadOptions.push({ key: 'number', label: 'number' });
|
||||
}
|
||||
}, [variantTypeNumber]);
|
||||
|
||||
const clearError = (field: ErrorField) => {
|
||||
setErrors(errors => ({ ...errors, [field]: undefined }));
|
||||
};
|
||||
@ -283,6 +292,9 @@ export const VariantForm = ({
|
||||
if (payload.type === 'json') {
|
||||
JSON.parse(payload.value);
|
||||
}
|
||||
if (variantTypeNumber && payload.type === 'number') {
|
||||
Number(payload.value);
|
||||
}
|
||||
return true;
|
||||
} catch (e: unknown) {
|
||||
return false;
|
||||
@ -428,7 +440,12 @@ export const VariantForm = ({
|
||||
name="variant-payload-value"
|
||||
label="Value"
|
||||
multiline={payload.type !== 'string'}
|
||||
rows={payload.type === 'string' ? 1 : 4}
|
||||
rows={
|
||||
payload.type === 'string' ||
|
||||
payload.type === 'number'
|
||||
? 1
|
||||
: 4
|
||||
}
|
||||
value={payload.value}
|
||||
onChange={e => {
|
||||
clearError(ErrorField.PAYLOAD);
|
||||
|
@ -64,6 +64,7 @@ export type UiFlags = {
|
||||
multipleRoles?: boolean;
|
||||
featureNamingPattern?: boolean;
|
||||
doraMetrics?: boolean;
|
||||
variantTypeNumber?: boolean;
|
||||
[key: string]: boolean | Variant | undefined;
|
||||
};
|
||||
|
||||
|
@ -99,6 +99,7 @@ exports[`should create default config 1`] = `
|
||||
"responseTimeWithAppNameKillSwitch": false,
|
||||
"slackAppAddon": false,
|
||||
"strictSchemaValidation": false,
|
||||
"variantTypeNumber": false,
|
||||
},
|
||||
},
|
||||
"flagResolver": FlagResolver {
|
||||
@ -134,6 +135,7 @@ exports[`should create default config 1`] = `
|
||||
"responseTimeWithAppNameKillSwitch": false,
|
||||
"slackAppAddon": false,
|
||||
"strictSchemaValidation": false,
|
||||
"variantTypeNumber": false,
|
||||
},
|
||||
"externalResolver": {
|
||||
"getVariant": [Function],
|
||||
|
@ -10,7 +10,7 @@ interface Override {
|
||||
}
|
||||
|
||||
export interface Payload {
|
||||
type: 'string' | 'csv' | 'json';
|
||||
type: 'string' | 'csv' | 'json' | 'number';
|
||||
value: string;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ exports[`featureSchema variant override values must be an array 1`] = `
|
||||
"json",
|
||||
"csv",
|
||||
"string",
|
||||
"number",
|
||||
],
|
||||
},
|
||||
"schemaPath": "#/properties/payload/properties/type/enum",
|
||||
|
@ -40,9 +40,9 @@ export const createStrategyVariantSchema = {
|
||||
properties: {
|
||||
type: {
|
||||
description:
|
||||
'The type of the value. Commonly used types are string, json and csv.',
|
||||
'The type of the value. Commonly used types are string, number, json and csv.',
|
||||
type: 'string',
|
||||
enum: ['json', 'csv', 'string'],
|
||||
enum: ['json', 'csv', 'string', 'number'],
|
||||
},
|
||||
value: {
|
||||
description: 'The actual value of payload',
|
||||
|
@ -83,7 +83,7 @@ export const strategyEvaluationResults = {
|
||||
type: {
|
||||
description: 'The format of the payload.',
|
||||
type: 'string',
|
||||
enum: ['json', 'csv', 'string'],
|
||||
enum: ['json', 'csv', 'string', 'number'],
|
||||
},
|
||||
value: {
|
||||
type: 'string',
|
||||
|
@ -42,9 +42,9 @@ export const variantSchema = {
|
||||
properties: {
|
||||
type: {
|
||||
description:
|
||||
'The type of the value. Commonly used types are string, json and csv.',
|
||||
'The type of the value. Commonly used types are string, number, json and csv.',
|
||||
type: 'string',
|
||||
enum: ['json', 'csv', 'string'],
|
||||
enum: ['json', 'csv', 'string', 'number'],
|
||||
},
|
||||
value: {
|
||||
description: 'The actual value of payload',
|
||||
|
@ -27,7 +27,8 @@ export type IFlagKey =
|
||||
| 'integrationsRework'
|
||||
| 'multipleRoles'
|
||||
| 'featureNamingPattern'
|
||||
| 'doraMetrics';
|
||||
| 'doraMetrics'
|
||||
| 'variantTypeNumber';
|
||||
|
||||
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
|
||||
|
||||
@ -127,6 +128,10 @@ const flags: IFlags = {
|
||||
process.env.UNLEASH_EXPERIMENTAL_DORA_METRICS,
|
||||
false,
|
||||
),
|
||||
variantTypeNumber: parseEnvVarBoolean(
|
||||
process.env.UNLEASH_EXPERIMENTAL_VARIANT_TYPE_NUMBER,
|
||||
false,
|
||||
),
|
||||
};
|
||||
|
||||
export const defaultExperimentalOptions: IExperimentalOptions = {
|
||||
|
@ -123,7 +123,7 @@ export interface IVariant {
|
||||
weight: number;
|
||||
weightType: 'variable' | 'fix';
|
||||
payload?: {
|
||||
type: 'json' | 'csv' | 'string';
|
||||
type: 'json' | 'csv' | 'string' | 'number';
|
||||
value: string;
|
||||
};
|
||||
stickiness: string;
|
||||
|
@ -42,6 +42,7 @@ process.nextTick(async () => {
|
||||
integrationsRework: true,
|
||||
featureNamingPattern: true,
|
||||
doraMetrics: true,
|
||||
variantTypeNumber: true,
|
||||
},
|
||||
},
|
||||
authentication: {
|
||||
|
Loading…
Reference in New Issue
Block a user