Skip to content

Commit 6b5767b

Browse files
NicolappsConvex, Inc.
authored andcommitted
dashboard: Make whitespace warnings in EnvironmentVariables yellow (#41990)
Whitespace warnings are warning only but you can still submit the form, so let’s use `-warning` for consistency. GitOrigin-RevId: 1c224249e5be7fdc63d9247978fd9fd76cd83302
1 parent 0fa53ca commit 6b5767b

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

npm-packages/dashboard-common/src/features/settings/components/EnvironmentVariables.tsx

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -854,26 +854,26 @@ function EnvVarValueInput({
854854
const formState = useFormikContext();
855855
const error = (formState.errors as Record<string, string>)[formKey];
856856
const value = getIn(formState.values, formKey) as string;
857-
const touched = getIn(formState.touched, formKey);
857+
const touched = Boolean(getIn(formState.touched, formKey));
858858

859859
const hasAnyWhitespace = /\s/.test(value);
860860
const hasLeadingOrTrailingWhitespace =
861861
value.length > 0 && value !== value.trim();
862862
const hasReturnCharacter = value.includes("\n");
863863

864-
// Build whitespace error message
865-
let whitespaceError = "";
864+
// Build whitespace warning message
865+
let whitespaceWarning = "";
866866
if (hasLeadingOrTrailingWhitespace || hasReturnCharacter) {
867867
const hasLeading = value !== value.trimStart();
868868
const hasTrailing = value !== value.trimEnd();
869869
if (hasLeading && hasTrailing) {
870-
whitespaceError = "This value has leading and trailing whitespace.";
870+
whitespaceWarning = "This value has leading and trailing whitespace.";
871871
} else if (hasLeading) {
872-
whitespaceError = "This value has leading whitespace.";
872+
whitespaceWarning = "This value has leading whitespace.";
873873
} else if (hasTrailing) {
874-
whitespaceError = "This value has trailing whitespace.";
874+
whitespaceWarning = "This value has trailing whitespace.";
875875
} else {
876-
whitespaceError = "This value contains return characters.";
876+
whitespaceWarning = "This value contains return characters.";
877877
}
878878
}
879879

@@ -892,7 +892,7 @@ function EnvVarValueInput({
892892
const isTrailing = i >= value.length - trailingCount;
893893
const colorClass =
894894
isSpace && (isLeading || isTrailing)
895-
? "text-content-errorSecondary bg-background-error/60"
895+
? "text-content-warning bg-background-warning/60"
896896
: isSpace
897897
? "text-content-tertiary/50"
898898
: "text-transparent";
@@ -902,9 +902,18 @@ function EnvVarValueInput({
902902
}
903903
}
904904

905-
// Combine validation error with whitespace error
906-
const displayError = error || whitespaceError;
907-
const hasError = Boolean((touched || whitespaceError) && displayError);
905+
const { hint, hintStyle } =
906+
touched && error
907+
? {
908+
hint: error,
909+
hintStyle: "error" as const,
910+
}
911+
: whitespaceWarning
912+
? {
913+
hint: whitespaceWarning,
914+
hintStyle: "warning" as const,
915+
}
916+
: { hint: null, hintStyle: null };
908917

909918
const textareaRef = useRef<HTMLTextAreaElement>(null);
910919

@@ -931,9 +940,11 @@ function EnvVarValueInput({
931940
"font-mono text-sm break-all whitespace-break-spaces placeholder-content-tertiary",
932941
"focus:outline-hidden",
933942
"disabled:cursor-not-allowed disabled:bg-background-tertiary disabled:text-content-secondary",
934-
hasError
943+
hintStyle === "error"
935944
? "focus:border-content-error"
936-
: "text-content-primary focus:border-border-selected",
945+
: hintStyle === "warning"
946+
? "focus:border-content-warning"
947+
: "text-content-primary focus:border-border-selected",
937948
)}
938949
disabled={formState.isSubmitting}
939950
{...formState.getFieldProps(formKey)}
@@ -955,12 +966,17 @@ function EnvVarValueInput({
955966
</pre>
956967
)}
957968
</div>
958-
{hasError && displayError && (
969+
{hint && (
959970
<p
960-
className="mt-1 flex max-w-full animate-fadeInFromLoading gap-1 text-xs break-words text-content-errorSecondary"
971+
className={cn(
972+
"mt-1 flex max-w-full animate-fadeInFromLoading gap-1 text-xs break-words",
973+
hintStyle === "error"
974+
? "text-content-errorSecondary"
975+
: "text-content-warning",
976+
)}
961977
role="alert"
962978
>
963-
{displayError}
979+
{hint}
964980
</p>
965981
)}
966982
</>

0 commit comments

Comments
 (0)