π OpenHands: AI-Driven Development
feat(frontend): add contextual info messages on LLM settings page (org project) (#13601)
Hiep Le30b7af31b9cc
diff --git a/frontend/__tests__/routes/llm-settings.test.tsx b/frontend/__tests__/routes/llm-settings.test.tsxindex 6278c4d037..b83f121192 100644--- a/frontend/__tests__/routes/llm-settings.test.tsx+++ b/frontend/__tests__/routes/llm-settings.test.tsx@@ -73,6 +73,12 @@ vi.mock("#/hooks/query/use-config", () => ({useConfig: () => mockUseConfig(),}));+// Mock useOrgTypeAndAccess hook+const mockUseOrgTypeAndAccess = vi.fn();+vi.mock("#/hooks/use-org-type-and-access", () => ({+ useOrgTypeAndAccess: () => mockUseOrgTypeAndAccess(),+}));+const renderLlmSettingsScreen = (orgId: string | null = null,meData?: {@@ -163,6 +169,15 @@ beforeEach(() => {// Reset organization storeuseSelectedOrganizationStore.setState({ organizationId: "1" });++ // Default mock for useOrgTypeAndAccess - returns team org by default+ mockUseOrgTypeAndAccess.mockReturnValue({+ selectedOrg: createMockOrganization({ id: "1", name: "Test Org", is_personal: false }),+ isPersonalOrg: false,+ isTeamOrg: true,+ canViewOrgRoutes: true,+ organizationId: "1",+ });});describe("Content", () => {@@ -1786,6 +1801,122 @@ describe("Role-based permissions", () => {});});+describe("Contextual info messages", () => {+ it("should show admin info message for admin user in team organization", async () => {+ // Arrange: SaaS mode with team org and admin role+ mockUseConfig.mockReturnValue({+ data: { app_mode: "saas" },+ isLoading: false,+ });+ mockUseOrgTypeAndAccess.mockReturnValue({+ selectedOrg: createMockOrganization({ id: "1", name: "Test Org", is_personal: false }),+ isPersonalOrg: false,+ isTeamOrg: true,+ canViewOrgRoutes: true,+ organizationId: "1",+ });+ const adminData = {+ org_id: "1",+ user_id: "99",+ email: "[email protected]",+ role: "admin",+ status: "active",+ llm_api_key: "",+ max_iterations: 20,+ llm_model: "",+ llm_api_key_for_byor: null,+ llm_base_url: "",+ };++ // Act+ renderLlmSettingsScreen("1", adminData);+ await screen.findByTestId("llm-settings-screen");++ // Assert+ const infoMessage = screen.getByTestId("llm-settings-info-message");+ expect(infoMessage).toHaveTextContent("SETTINGS$LLM_ADMIN_INFO");+ });++ it("should show member info message for member user in team organization", async () => {+ // Arrange: SaaS mode with team org and member role+ mockUseConfig.mockReturnValue({+ data: { app_mode: "saas" },+ isLoading: false,+ });+ mockUseOrgTypeAndAccess.mockReturnValue({+ selectedOrg: createMockOrganization({ id: "1", name: "Test Org", is_personal: false }),+ isPersonalOrg: false,+ isTeamOrg: true,+ canViewOrgRoutes: true,+ organizationId: "1",+ });+ const memberData = {+ org_id: "1",+ user_id: "99",+ email: "[email protected]",+ role: "member",+ status: "active",+ llm_api_key: "",+ max_iterations: 20,+ llm_model: "",+ llm_api_key_for_byor: null,+ llm_base_url: "",+ };++ // Act+ renderLlmSettingsScreen("1", memberData);+ await screen.findByTestId("llm-settings-screen");++ // Assert+ const infoMessage = screen.getByTestId("llm-settings-info-message");+ expect(infoMessage).toHaveTextContent("SETTINGS$LLM_MEMBER_INFO");+ });++ it("should not show info message for personal workspace", async () => {+ // Arrange: SaaS mode with personal org+ mockUseConfig.mockReturnValue({+ data: { app_mode: "saas" },+ isLoading: false,+ });+ mockUseOrgTypeAndAccess.mockReturnValue({+ selectedOrg: createMockOrganization({ id: "1", name: "Personal Org", is_personal: true }),+ isPersonalOrg: true,+ isTeamOrg: false,+ canViewOrgRoutes: false,+ organizationId: "1",+ });++ // Act+ renderLlmSettingsScreen("1");+ await screen.findByTestId("llm-settings-screen");++ // Assert+ expect(screen.queryByTestId("llm-settings-info-message")).not.toBeInTheDocument();+ });++ it("should not show info message in OSS mode", async () => {+ // Arrange: OSS mode+ mockUseConfig.mockReturnValue({+ data: { app_mode: "oss" },+ isLoading: false,+ });+ mockUseOrgTypeAndAccess.mockReturnValue({+ selectedOrg: createMockOrganization({ id: "1", name: "Test Org", is_personal: false }),+ isPersonalOrg: false,+ isTeamOrg: true,+ canViewOrgRoutes: true,+ organizationId: "1",+ });++ // Act+ renderLlmSettingsScreen("1");+ await screen.findByTestId("llm-settings-screen");++ // Assert+ expect(screen.queryByTestId("llm-settings-info-message")).not.toBeInTheDocument();+ });+});+describe("clientLoader permission checks", () => {it("should export a clientLoader for route protection", async () => {// This test verifies the clientLoader is exported for consistency with other routesdiff --git a/frontend/src/routes/llm-settings.tsx b/frontend/src/routes/llm-settings.tsxindex d9489ec35a..4aba314773 100644--- a/frontend/src/routes/llm-settings.tsx+++ b/frontend/src/routes/llm-settings.tsx@@ -31,6 +31,7 @@ import { getProviderId } from "#/utils/map-provider";import { DEFAULT_OPENHANDS_MODEL } from "#/utils/verified-models";import { useMe } from "#/hooks/query/use-me";import { usePermission } from "#/hooks/organizations/use-permissions";+import { useOrgTypeAndAccess } from "#/hooks/use-org-type-and-access";interface OpenHandsApiKeyHelpProps {testId: string;@@ -80,6 +81,20 @@ function LlmSettingsScreen() {const isOssMode = config?.app_mode === "oss";const isReadOnly = isOssMode ? false : !hasPermission("edit_llm_settings");+ // Get organization type for contextual info messages+ const { isTeamOrg } = useOrgTypeAndAccess();+ const isAdminOrOwner = me?.role === "admin" || me?.role === "owner";++ const getLlmSettingsInfoMessage = (): I18nKey | null => {+ if (isOssMode) return null;+ if (!isTeamOrg) return null;+ return isAdminOrOwner+ ? I18nKey.SETTINGS$LLM_ADMIN_INFO+ : I18nKey.SETTINGS$LLM_MEMBER_INFO;+ };++ const infoMessageKey = getLlmSettingsInfoMessage();+const [view, setView] = React.useState<"basic" | "advanced">("basic");const [dirtyInputs, setDirtyInputs] = React.useState({@@ -504,6 +519,15 @@ function LlmSettingsScreen() {className="flex flex-col h-full justify-between"><div className="flex flex-col gap-6">+ {infoMessageKey && (+ <p+ data-testid="llm-settings-info-message"+ className="text-sm text-tertiary-alt"+ >+ {t(infoMessageKey)}+ </p>+ )}+<SettingsSwitchtestId="advanced-settings-switch"defaultIsToggled={view === "advanced"}