mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +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 { WeightType } from 'constants/variantTypes';
|
||||||
import { IFeatureVariantEdit } from '../EnvironmentVariantsModal';
|
import { IFeatureVariantEdit } from '../EnvironmentVariantsModal';
|
||||||
import { Delete } from '@mui/icons-material';
|
import { Delete } from '@mui/icons-material';
|
||||||
|
import { useUiFlag } from 'hooks/useUiFlag';
|
||||||
|
|
||||||
const StyledVariantForm = styled('div')(({ theme }) => ({
|
const StyledVariantForm = styled('div')(({ theme }) => ({
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
@ -195,6 +196,14 @@ export const VariantForm = ({
|
|||||||
|
|
||||||
const [errors, setErrors] = useState<IVariantFormErrors>({});
|
const [errors, setErrors] = useState<IVariantFormErrors>({});
|
||||||
|
|
||||||
|
const variantTypeNumber = useUiFlag('variantTypeNumber');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (variantTypeNumber) {
|
||||||
|
payloadOptions.push({ key: 'number', label: 'number' });
|
||||||
|
}
|
||||||
|
}, [variantTypeNumber]);
|
||||||
|
|
||||||
const clearError = (field: ErrorField) => {
|
const clearError = (field: ErrorField) => {
|
||||||
setErrors(errors => ({ ...errors, [field]: undefined }));
|
setErrors(errors => ({ ...errors, [field]: undefined }));
|
||||||
};
|
};
|
||||||
@ -283,6 +292,9 @@ export const VariantForm = ({
|
|||||||
if (payload.type === 'json') {
|
if (payload.type === 'json') {
|
||||||
JSON.parse(payload.value);
|
JSON.parse(payload.value);
|
||||||
}
|
}
|
||||||
|
if (variantTypeNumber && payload.type === 'number') {
|
||||||
|
Number(payload.value);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
return false;
|
return false;
|
||||||
@ -428,7 +440,12 @@ export const VariantForm = ({
|
|||||||
name="variant-payload-value"
|
name="variant-payload-value"
|
||||||
label="Value"
|
label="Value"
|
||||||
multiline={payload.type !== 'string'}
|
multiline={payload.type !== 'string'}
|
||||||
rows={payload.type === 'string' ? 1 : 4}
|
rows={
|
||||||
|
payload.type === 'string' ||
|
||||||
|
payload.type === 'number'
|
||||||
|
? 1
|
||||||
|
: 4
|
||||||
|
}
|
||||||
value={payload.value}
|
value={payload.value}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
clearError(ErrorField.PAYLOAD);
|
clearError(ErrorField.PAYLOAD);
|
||||||
|
@ -64,6 +64,7 @@ export type UiFlags = {
|
|||||||
multipleRoles?: boolean;
|
multipleRoles?: boolean;
|
||||||
featureNamingPattern?: boolean;
|
featureNamingPattern?: boolean;
|
||||||
doraMetrics?: boolean;
|
doraMetrics?: boolean;
|
||||||
|
variantTypeNumber?: boolean;
|
||||||
[key: string]: boolean | Variant | undefined;
|
[key: string]: boolean | Variant | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -99,6 +99,7 @@ exports[`should create default config 1`] = `
|
|||||||
"responseTimeWithAppNameKillSwitch": false,
|
"responseTimeWithAppNameKillSwitch": false,
|
||||||
"slackAppAddon": false,
|
"slackAppAddon": false,
|
||||||
"strictSchemaValidation": false,
|
"strictSchemaValidation": false,
|
||||||
|
"variantTypeNumber": false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"flagResolver": FlagResolver {
|
"flagResolver": FlagResolver {
|
||||||
@ -134,6 +135,7 @@ exports[`should create default config 1`] = `
|
|||||||
"responseTimeWithAppNameKillSwitch": false,
|
"responseTimeWithAppNameKillSwitch": false,
|
||||||
"slackAppAddon": false,
|
"slackAppAddon": false,
|
||||||
"strictSchemaValidation": false,
|
"strictSchemaValidation": false,
|
||||||
|
"variantTypeNumber": false,
|
||||||
},
|
},
|
||||||
"externalResolver": {
|
"externalResolver": {
|
||||||
"getVariant": [Function],
|
"getVariant": [Function],
|
||||||
|
@ -10,7 +10,7 @@ interface Override {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Payload {
|
export interface Payload {
|
||||||
type: 'string' | 'csv' | 'json';
|
type: 'string' | 'csv' | 'json' | 'number';
|
||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ exports[`featureSchema variant override values must be an array 1`] = `
|
|||||||
"json",
|
"json",
|
||||||
"csv",
|
"csv",
|
||||||
"string",
|
"string",
|
||||||
|
"number",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"schemaPath": "#/properties/payload/properties/type/enum",
|
"schemaPath": "#/properties/payload/properties/type/enum",
|
||||||
|
@ -40,9 +40,9 @@ export const createStrategyVariantSchema = {
|
|||||||
properties: {
|
properties: {
|
||||||
type: {
|
type: {
|
||||||
description:
|
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',
|
type: 'string',
|
||||||
enum: ['json', 'csv', 'string'],
|
enum: ['json', 'csv', 'string', 'number'],
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
description: 'The actual value of payload',
|
description: 'The actual value of payload',
|
||||||
|
@ -83,7 +83,7 @@ export const strategyEvaluationResults = {
|
|||||||
type: {
|
type: {
|
||||||
description: 'The format of the payload.',
|
description: 'The format of the payload.',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: ['json', 'csv', 'string'],
|
enum: ['json', 'csv', 'string', 'number'],
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -42,9 +42,9 @@ export const variantSchema = {
|
|||||||
properties: {
|
properties: {
|
||||||
type: {
|
type: {
|
||||||
description:
|
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',
|
type: 'string',
|
||||||
enum: ['json', 'csv', 'string'],
|
enum: ['json', 'csv', 'string', 'number'],
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
description: 'The actual value of payload',
|
description: 'The actual value of payload',
|
||||||
|
@ -27,7 +27,8 @@ export type IFlagKey =
|
|||||||
| 'integrationsRework'
|
| 'integrationsRework'
|
||||||
| 'multipleRoles'
|
| 'multipleRoles'
|
||||||
| 'featureNamingPattern'
|
| 'featureNamingPattern'
|
||||||
| 'doraMetrics';
|
| 'doraMetrics'
|
||||||
|
| 'variantTypeNumber';
|
||||||
|
|
||||||
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
|
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
|
||||||
|
|
||||||
@ -127,6 +128,10 @@ const flags: IFlags = {
|
|||||||
process.env.UNLEASH_EXPERIMENTAL_DORA_METRICS,
|
process.env.UNLEASH_EXPERIMENTAL_DORA_METRICS,
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
|
variantTypeNumber: parseEnvVarBoolean(
|
||||||
|
process.env.UNLEASH_EXPERIMENTAL_VARIANT_TYPE_NUMBER,
|
||||||
|
false,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const defaultExperimentalOptions: IExperimentalOptions = {
|
export const defaultExperimentalOptions: IExperimentalOptions = {
|
||||||
|
@ -123,7 +123,7 @@ export interface IVariant {
|
|||||||
weight: number;
|
weight: number;
|
||||||
weightType: 'variable' | 'fix';
|
weightType: 'variable' | 'fix';
|
||||||
payload?: {
|
payload?: {
|
||||||
type: 'json' | 'csv' | 'string';
|
type: 'json' | 'csv' | 'string' | 'number';
|
||||||
value: string;
|
value: string;
|
||||||
};
|
};
|
||||||
stickiness: string;
|
stickiness: string;
|
||||||
|
@ -42,6 +42,7 @@ process.nextTick(async () => {
|
|||||||
integrationsRework: true,
|
integrationsRework: true,
|
||||||
featureNamingPattern: true,
|
featureNamingPattern: true,
|
||||||
doraMetrics: true,
|
doraMetrics: true,
|
||||||
|
variantTypeNumber: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
authentication: {
|
authentication: {
|
||||||
|
Loading…
Reference in New Issue
Block a user