The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
[AI Controls] Show validation error for group limits above instance limit (#72205)
Anderson25015ba31807
diff --git a/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotCustomizationPage/MetabotIconField.tsx b/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotCustomizationPage/MetabotIconField.tsxindex e0634cfb5c5..5c47994ed7f 100644--- a/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotCustomizationPage/MetabotIconField.tsx+++ b/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotCustomizationPage/MetabotIconField.tsx@@ -151,7 +151,7 @@ export function MetabotIconField() {</Text><Group gap="lg"><Text fz="md" c="text-secondary">- {t`Show Metabot illustrations in chat sidebar and natural language query page`}+ {t`Show Metabot illustrations in chat sidebar and AI exploration page`}</Text><Switcharia-label={t`Show Metabot illustrations`}diff --git a/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/GroupLimitsTab/GroupLimitsTab.tsx b/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/GroupLimitsTab/GroupLimitsTab.tsxindex 697ea28699a..9eefab51753 100644--- a/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/GroupLimitsTab/GroupLimitsTab.tsx+++ b/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/GroupLimitsTab/GroupLimitsTab.tsx@@ -107,7 +107,13 @@ export function GroupLimitsTab(props: GroupLimitsTabProps) {const handleChange = (group: GroupInfo, inputValue: string) => {const maxUsage = sanitizeUsageLimitValue(inputValue);setLocalLimitsMap((prev) => ({ ...prev, [group.id]: maxUsage }));- debouncedSaveGroupLimit(group, maxUsage);++ const isOverInstanceLimit =+ Number(maxUsage || 0) > Number(instanceLimit || 0);++ if (!isOverInstanceLimit) {+ debouncedSaveGroupLimit(group, maxUsage);+ }};return (@@ -132,8 +138,16 @@ export function GroupLimitsTab(props: GroupLimitsTabProps) {</thead><tbody>{groups.map((group) => {+ const inputValue = String(localLimitsMap?.[group.id] ?? "");+ const maxUsage = sanitizeUsageLimitValue(inputValue);+ const isOverInstanceLimit =+ maxUsage != null &&+ instanceLimit != null &&+ maxUsage > instanceLimit;const showAllUsersOverrideTooltip =- isAllUsersGroupOverridingLimit(group) && !!allUsersGroup;+ isAllUsersGroupOverridingLimit(group) &&+ !!allUsersGroup &&+ !isOverInstanceLimit;return (<tr key={group.id} className={S.BodyRow}>@@ -142,7 +156,7 @@ export function GroupLimitsTab(props: GroupLimitsTabProps) {<div className={S.InputWrapper}><TextInputplaceholder={placeholder}- value={localLimitsMap?.[group.id] ?? ""}+ value={inputValue}onChange={(e) =>handleChange(group, e.target.value)}@@ -153,13 +167,20 @@ export function GroupLimitsTab(props: GroupLimitsTabProps) {limitType,group.name,)}+ error={+ isOverInstanceLimit+ ? t`Can't be higher than the instance limit`+ : undefined+ }+ rightSection={+ showAllUsersOverrideTooltip ? (+ <AllUsersHigherAccessTooltipIcon+ groupName={allUsersGroup.name}+ variant="group-limits"+ />+ ) : undefined+ }/>- {showAllUsersOverrideTooltip && (- <AllUsersHigherAccessTooltipIcon- groupName={allUsersGroup.name}- variant="group-limits"- />- )}</div></td></tr>diff --git a/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/GroupLimitsTab/GroupLimitsTab.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/GroupLimitsTab/GroupLimitsTab.unit.spec.tsxindex 493d0f0a255..f98ade8be93 100644--- a/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/GroupLimitsTab/GroupLimitsTab.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/GroupLimitsTab/GroupLimitsTab.unit.spec.tsx@@ -1,7 +1,7 @@import userEvent from "@testing-library/user-event";import { setupUpdateAIControlsGroupLimitEndpoint } from "__support__/server-mocks/metabot";-import { renderWithProviders, screen, within } from "__support__/ui";+import { renderWithProviders, screen, waitFor, within } from "__support__/ui";import type {GroupInfo,MetabotGroupLimit,@@ -165,6 +165,23 @@ describe("GroupLimitsTab", () => {expect(screen.getByText(/each week/)).toBeInTheDocument();});+ it("shows error when value exceeds the instance limit", async () => {+ setup({ instanceLimit: 100 });++ expect(screen.queryByRole("alert")).not.toBeInTheDocument();+ const adminsGroupInput = screen.getByLabelText(+ /Max tokens per user for Administrators/,+ );+ await userEvent.type(adminsGroupInput, "200");++ await waitFor(() => {+ const alert = screen.getByRole("alert");+ expect(alert).toHaveTextContent(+ /Can't be higher than the instance limit/,+ );+ });+ });+describe("'All Users' group override warning icons", () => {it("shows info icon next to a group's input when 'All Users' has a higher limit", () => {// All Users limit = 500 (unlimited from perspective of Marketing which has 100)diff --git a/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/TenantLimitsTab/TenantLimitsTab.tsx b/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/TenantLimitsTab/TenantLimitsTab.tsxindex e772aafc16d..2a6c825a73b 100644--- a/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/TenantLimitsTab/TenantLimitsTab.tsx+++ b/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/TenantLimitsTab/TenantLimitsTab.tsx@@ -79,7 +79,12 @@ export function TenantLimitsTab(props: SpecificTenantsTabProps) {...prev,[tenant.id]: maxUsage,}));- debouncedSaveTenantLimit(tenant, maxUsage);+ const isOverInstanceLimit =+ maxUsage != null && instanceLimit != null && maxUsage > instanceLimit;++ if (!isOverInstanceLimit) {+ debouncedSaveTenantLimit(tenant, maxUsage);+ }};const filteredTenants = useMemo(() => {@@ -134,28 +139,44 @@ export function TenantLimitsTab(props: SpecificTenantsTabProps) {</tr></thead><tbody>- {filteredTenants.map((tenant) => (- <tr key={tenant.id} className={S.BodyRow}>- <td className={S.BodyCell}>{tenant.name}</td>- <td className={S.BodyCell}>- <TextInput- placeholder={placeholder}- value={localLimitsMap?.[tenant.id] ?? ""}- onChange={(e) =>- handleChange(tenant, e.target.value)- }- classNames={{ input: S.LimitInput }}- type="number"- min={1}- aria-label={getInputLabel(- tenant.name,- limitType,- limitPeriod,- )}- />- </td>- </tr>- ))}+ {filteredTenants.map((tenant) => {+ const inputValue = String(+ localLimitsMap?.[tenant.id] ?? "",+ );+ const maxUsage = sanitizeUsageLimitValue(inputValue);+ const isOverInstanceLimit =+ maxUsage != null &&+ instanceLimit != null &&+ maxUsage > instanceLimit;++ return (+ <tr key={tenant.id} className={S.BodyRow}>+ <td className={S.BodyCell}>{tenant.name}</td>+ <td className={S.BodyCell}>+ <TextInput+ placeholder={placeholder}+ value={inputValue}+ onChange={(e) =>+ handleChange(tenant, e.target.value)+ }+ classNames={{ input: S.LimitInput }}+ error={+ isOverInstanceLimit+ ? t`Can't be higher than the instance limit`+ : undefined+ }+ type="number"+ min={1}+ aria-label={getInputLabel(+ tenant.name,+ limitType,+ limitPeriod,+ )}+ />+ </td>+ </tr>+ );+ })}</tbody></table></Box>diff --git a/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/TenantLimitsTab/TenantLimitsTab.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/TenantLimitsTab/TenantLimitsTab.unit.spec.tsxindex e5827c06fed..1ecf9d19a07 100644--- a/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/TenantLimitsTab/TenantLimitsTab.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/ai-controls/pages/MetabotUsageLimitsPage/GroupLimitsSettingsSection/TenantLimitsTab/TenantLimitsTab.unit.spec.tsx@@ -1,7 +1,7 @@import userEvent from "@testing-library/user-event";import { setupUpdateAIControlsTenantLimitEndpoint } from "__support__/server-mocks/metabot";-import { renderWithProviders, screen } from "__support__/ui";+import { renderWithProviders, screen, waitFor } from "__support__/ui";import type {MetabotLimitPeriod,MetabotLimitType,@@ -145,4 +145,21 @@ describe("TenantLimitsTab", () => {expect(acmeInput).toHaveValue(300);});++ it("shows error when value exceeds the instance limit", async () => {+ setup({ instanceLimit: 100 });++ expect(screen.queryByRole("alert")).not.toBeInTheDocument();+ const tenantInput = screen.getByLabelText(+ /Max total monthly tokens for Acme Corp/,+ );+ await userEvent.type(tenantInput, "200");++ await waitFor(() => {+ const alert = screen.getByRole("alert");+ expect(alert).toHaveTextContent(+ /Can't be higher than the instance limit/,+ );+ });+ });});