Skip to content

Commit 7af752b

Browse files
committed
frontend/site settings: fix "Invalid:" when it is valid
1 parent 6711a43 commit 7af752b

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/packages/frontend/admin/site-settings/row-entry-inner.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@ import Password, {
1111
PasswordTextArea,
1212
} from "@cocalc/frontend/components/password";
1313
import { modelToName } from "@cocalc/frontend/frame-editors/llm/llm-selector";
14+
import { LOCALIZATIONS } from "@cocalc/frontend/i18n";
15+
import { LOCALE } from "@cocalc/util/consts/locale";
1416
import { USER_SELECTABLE_LANGUAGE_MODELS } from "@cocalc/util/db-schema/llm-utils";
1517
import {
1618
ConfigValid,
1719
to_list_of_llms,
1820
to_list_of_locale,
1921
} from "@cocalc/util/db-schema/site-defaults";
2022
import { RowEntryInnerProps } from "./row-entry";
21-
import { LOCALE } from "@cocalc/util/consts/locale";
22-
import { LOCALIZATIONS } from "../../i18n";
2323

24-
export function rowEntryStyle(value, valid?: ConfigValid): CSSProperties {
25-
if (
24+
export function testIsInvalid(value, valid?: ConfigValid): boolean {
25+
return (
2626
(Array.isArray(valid) && !valid.includes(value)) ||
2727
(typeof valid == "function" && !valid(value))
28-
) {
28+
);
29+
}
30+
31+
export function rowEntryStyle(value, valid?: ConfigValid): CSSProperties {
32+
if (testIsInvalid(value, valid)) {
2933
return { border: "2px solid red" };
3034
}
3135
return {};

src/packages/frontend/admin/site-settings/row-entry.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ConfigValid, RowType } from "@cocalc/util/db-schema/site-defaults";
1212
import { version } from "@cocalc/util/smc-version";
1313
import { ON_PREM_DEFAULT_QUOTAS, upgrades } from "@cocalc/util/upgrade-spec";
1414
import { JsonEditor } from "../json-editor";
15-
import { RowEntryInner } from "./row-entry-inner";
15+
import { RowEntryInner, testIsInvalid } from "./row-entry-inner";
1616
import { IsReadonly } from "./types";
1717

1818
const MAX_UPGRADES = upgrades.max_per_project;
@@ -94,6 +94,7 @@ export function RowEntry({
9494
</>
9595
);
9696
default:
97+
const is_valid = !testIsInvalid(value, valid);
9798
return (
9899
<FormGroup>
99100
<RowEntryInner
@@ -117,7 +118,7 @@ export function RowEntry({
117118
{displayed_val != null && (
118119
<span>
119120
{" "}
120-
{valid ? "Interpreted as" : "Invalid:"}{" "}
121+
{is_valid ? "Interpreted as" : "Invalid:"}{" "}
121122
<code>{displayed_val}</code>.{" "}
122123
</span>
123124
)}

src/packages/util/db-schema/site-defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import jsonic from "jsonic";
99
import { isEqual } from "lodash";
1010

11+
import { LOCALE } from "@cocalc/util/consts/locale";
1112
import { is_valid_email_address } from "@cocalc/util/misc";
1213
import {
1314
DEFAULT_MODEL,
@@ -16,7 +17,6 @@ import {
1617
getDefaultLLM,
1718
isValidModel,
1819
} from "./llm-utils";
19-
import { LOCALE } from "../consts/locale";
2020

2121
export type ConfigValid = Readonly<string[]> | ((val: string) => boolean);
2222

0 commit comments

Comments
 (0)