Skip to content

Commit

Permalink
Check presence of error inside input debounced instead of running the…
Browse files Browse the repository at this point in the history
… check at parent level
  • Loading branch information
AlinaGoaga committed Dec 27, 2023
1 parent 5b17f76 commit 9cff624
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const SecretProperty = ({
placeholder="Secret Property"
value={obj.key}
handleFormData={val => handleSecretChange(obj.id, true, val)}
error={formError === 'dataSecretKey' && !obj.key}
formError={formError}
/>
<InputDebounced
name="dataSecretValue"
Expand Down
14 changes: 5 additions & 9 deletions ui/src/components/Secrets/ExternalSecrets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ const CreateExternalSecret = () => {
label="EXTERNAL SECRET NAME"
value={formData.secretName}
handleFormData={val => handleFormData(val, 'secretName')}
error={formError === 'secretName' && !formData.secretName}
formError={formError}
/>
<InputDebounced
required
name="dataSecretKey"
label="TARGET K8s SECRET NAME"
value={formData.dataSecretKey}
handleFormData={val => handleFormData(val, 'dataSecretKey')}
error={formError === 'dataSecretKey' && !formData.dataSecretKey}
formError={formError}
/>
<Flex column>
<ListClusters
Expand Down Expand Up @@ -187,9 +187,7 @@ const CreateExternalSecret = () => {
return;
}}
disabled={true}
error={
formError === 'secretStoreType' && !formData.secretStoreType
}
formError={formError}
/>
<InputDebounced
required
Expand All @@ -201,9 +199,7 @@ const CreateExternalSecret = () => {
!!formData.secretNamespace &&
formData.defaultSecretNamespace === formData.secretNamespace
}
error={
formError === 'secretNamespace' && !formData.secretNamespace
}
formError={formError}
/>
</Flex>
)}
Expand All @@ -213,7 +209,7 @@ const CreateExternalSecret = () => {
label="SECRET PATH"
value={formData.secretPath}
handleFormData={val => handleFormData(val, 'secretPath')}
error={formError === 'secretPath' && !formData.secretPath}
formError={formError}
/>
<SecretProperty
formData={formData}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/Secrets/SOPS/SecretData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const data = ({
placeholder="Secret key"
value={obj.key}
handleFormData={val => handleSecretChange(obj.id, true, val)}
error={formError === 'dataSecretKey' && !obj.key}
formError={formError}
/>
<InputDebounced
required
Expand All @@ -67,7 +67,7 @@ const data = ({
placeholder="secret value"
value={obj.value}
handleFormData={val => handleSecretChange(obj.id, false, val)}
error={formError === 'dataSecretValue' && !obj.value}
formError={formError}
/>
{formData.data.length > 1 && (
<RemoveCircleOutlineIcon
Expand Down
6 changes: 2 additions & 4 deletions ui/src/components/Secrets/SOPS/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,15 @@ const CreateSOPS = () => {
label="SECRET NAME"
value={formData.secretName}
handleFormData={val => handleFormData(val, 'secretName')}
error={formError === 'secretName' && !formData.secretName}
formError={formError}
/>
<InputDebounced
required
name="secretNamespace"
label="SECRET NAMESPACE"
value={formData.secretNamespace}
handleFormData={val => handleFormData(val, 'secretNamespace')}
error={
formError === 'secretNamespace' && !formData.secretNamespace
}
formError={formError}
/>
</Flex>
<h2>Encryption</h2>
Expand Down
5 changes: 4 additions & 1 deletion ui/src/utils/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,17 @@ export const validateFormData = (

interface InputDebounceProps extends InputProps {
value?: string;
formError?: string;
handleFormData: (value: any) => void;
}

export const InputDebounced: FC<InputDebounceProps> = ({
value,
error,
formError,
handleFormData,
...rest
}) => {
const error = formError === rest.name && !value;
const [data, setData] = useState<string>(value || '');
const [inputError, setInputError] = useState<boolean>(error || false);

Expand Down Expand Up @@ -263,6 +265,7 @@ export const InputDebounced: FC<InputDebounceProps> = ({

return (
<Input
required={rest.required}
className="form-section"
{...rest}
value={data}
Expand Down

0 comments on commit 9cff624

Please sign in to comment.