What is your context name?
@@ -102,10 +114,10 @@ export const ContextForm: React.FC = ({
label="Context name"
value={contextName}
disabled={mode === 'Edit'}
- onChange={e => setContextName(trim(e.target.value))}
+ onChange={e => setContextName(e.target.value.trim())}
error={Boolean(errors.name)}
errorText={errors.name}
- onFocus={() => clearErrors()}
+ onFocus={() => clearErrors('name')}
onBlur={validateContext}
autoFocus
/>
@@ -119,25 +131,15 @@ export const ContextForm: React.FC = ({
multiline
maxRows={4}
value={contextDesc}
+ size="small"
onChange={e => setContextDesc(e.target.value)}
/>
Which values do you want to allow?
- {legalValues.map((value, index) => {
- return (
- removeLegalValue(index)}
- title="Remove value"
- />
- );
- })}
= ({
helperText={errors.tag}
variant="outlined"
size="small"
- onChange={e => setValue(trim(e.target.value))}
- onKeyPress={e => handleKeyDown(e)}
- onBlur={e => setFocused(false)}
- onFocus={e => setFocused(true)}
+ onChange={e => setValue(e.target.value)}
+ onKeyPress={e => onKeyDown(e)}
+ onBlur={() => setValueFocused(false)}
+ onFocus={() => setValueFocused(true)}
+ inputProps={{ maxLength: 100 }}
+ />
+ setValueDesc(e.target.value)}
+ onKeyPress={e => onKeyDown(e)}
+ onBlur={() => setValueFocused(false)}
+ onFocus={() => setValueFocused(true)}
+ inputProps={{ maxLength: 100 }}
/>
}
onClick={addLegalValue}
- variant="contained"
+ variant="outlined"
color="primary"
+ disabled={!value.trim() || isDuplicateValue}
>
Add
+
+ {legalValues.map(legalValue => {
+ return (
+ removeLegalValue(legalValue)}
+ />
+ );
+ })}
+
Custom stickiness
By enabling stickiness on this context field you can use it
diff --git a/frontend/src/component/context/hooks/useContextForm.ts b/frontend/src/component/context/hooks/useContextForm.ts
index a146a07e59..e29c551f10 100644
--- a/frontend/src/component/context/hooks/useContextForm.ts
+++ b/frontend/src/component/context/hooks/useContextForm.ts
@@ -1,26 +1,27 @@
import { useEffect, useState } from 'react';
import useContextsApi from 'hooks/api/actions/useContextsApi/useContextsApi';
+import { ILegalValue } from 'interfaces/context';
export const useContextForm = (
- initialcontextName = '',
- initialcontextDesc = '',
- initialLegalValues = [] as string[],
+ initialContextName = '',
+ initialContextDesc = '',
+ initialLegalValues = [] as ILegalValue[],
initialStickiness = false
) => {
- const [contextName, setContextName] = useState(initialcontextName);
- const [contextDesc, setContextDesc] = useState(initialcontextDesc);
+ const [contextName, setContextName] = useState(initialContextName);
+ const [contextDesc, setContextDesc] = useState(initialContextDesc);
const [legalValues, setLegalValues] = useState(initialLegalValues);
const [stickiness, setStickiness] = useState(initialStickiness);
const [errors, setErrors] = useState({});
const { validateContextName } = useContextsApi();
useEffect(() => {
- setContextName(initialcontextName);
- }, [initialcontextName]);
+ setContextName(initialContextName);
+ }, [initialContextName]);
useEffect(() => {
- setContextDesc(initialcontextDesc);
- }, [initialcontextDesc]);
+ setContextDesc(initialContextDesc);
+ }, [initialContextDesc]);
useEffect(() => {
setLegalValues(initialLegalValues);
@@ -66,8 +67,12 @@ export const useContextForm = (
}
};
- const clearErrors = () => {
- setErrors({});
+ const clearErrors = (key?: string) => {
+ if (key) {
+ setErrors(prev => ({ ...prev, [key]: undefined }));
+ } else {
+ setErrors({});
+ }
};
return {
diff --git a/frontend/src/interfaces/context.ts b/frontend/src/interfaces/context.ts
index fdc8802a73..7b76312029 100644
--- a/frontend/src/interfaces/context.ts
+++ b/frontend/src/interfaces/context.ts
@@ -4,5 +4,10 @@ export interface IUnleashContextDefinition {
createdAt: string;
sortOrder: number;
stickiness: boolean;
- legalValues?: string[];
+ legalValues?: ILegalValue[];
+}
+
+export interface ILegalValue {
+ value: string;
+ description?: string;
}