MCPcopy Create free account
hub / github.com/FeatureProbe/FeatureProbe / Variations

Function Variations

ui/src/components/Variations/index.tsx:21–163  ·  view source on GitHub ↗
(props: IProps)

Source from the content-addressed store, hash-verified

19}
20
21const Variations = (props: IProps) => {
22 const { disabled, returnType, prefix, variationContainer, hooksFormContainer, ruleContainer, defaultServeContainer } = props;
23 const [ isError, setIsError ] = useState<boolean>(false);
24 const { rules, saveRules } = ruleContainer.useContainer();
25 const { defaultServe, saveDefaultServe } = defaultServeContainer.useContainer();
26 const intl = useIntl();
27
28 const {
29 variations,
30 handleAdd,
31 handleInput,
32 handleDelete,
33 handleChangeVariation,
34 } = variationContainer.useContainer();
35
36 const {
37 unregister,
38 setError,
39 clearErrors,
40 } = hooksFormContainer.useContainer();
41
42 const { registerErrorName } = useFormErrorScrollIntoView();
43
44 const handleDeleteVariation = useCallback((index: number, variationId?: string) => {
45 unregister(`variation_${variationId}_name`);
46 unregister(`variation_${variationId}`);
47 unregister(`variation_${variationId}_normal`);
48 handleDelete(index);
49 }, [handleDelete, unregister]);
50
51 useEffect(() => {
52 if (variations?.length > 0) {
53 setIsError(false);
54 // const valueNotNullVariations = variations.filter((variation: IVariation) => {
55 // return variation.value !== '';
56 // });
57 // const len = valueNotNullVariations.length;
58
59 // const uniqValueLen = uniqBy(valueNotNullVariations, 'value').length;
60 // if (uniqValueLen !== len) {
61 // setIsError(true);
62 // setErrorType('value');
63 // return;
64 // }
65
66 const nameNotNullVariations = variations.filter((variation: IVariation) => {
67 return variation.name !== '';
68 });
69
70 const length = nameNotNullVariations.length;
71 if (length === 0) {
72 return;
73 }
74
75 const uniqNameLen = uniqBy(nameNotNullVariations, 'name').length;
76 if (uniqNameLen !== nameNotNullVariations.length) {
77 setIsError(true);
78 return;

Callers

nothing calls this directly

Calls 4

pushMethod · 0.65
handleDeleteFunction · 0.50
handleAddFunction · 0.50

Tested by

no test coverage detected