Repository navigation
feat(web): add an org default home view #1673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a5e63c1
3f7d87e
6a26f0d
32a36d0
36629ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |
| ### Added | ||
| - Added privacy-scoped setup wizard funnel and Docker startup-failure telemetry with deployment identity handoff, Node.js 20.20.0 support, and cross-platform end-to-end test coverage. [#1653](https://github.com/sourcebot-dev/sourcebot/pull/1653) | ||
| - Added an admin-configurable Markdown message with access instructions and links on sign-in and sign-up pages. [#1668](https://github.com/sourcebot-dev/sourcebot/pull/1668) | ||
| - Added an owner-configurable deployment default home view that users can override personally. [#1673](https://github.com/sourcebot-dev/sourcebot/pull/1673) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The changelog entry was placed under the already-dated Prompt for AI agents |
||
|
|
||
| ### Fixed | ||
| - [EE] Fixed missing account-linking prompts during OAuth authorization and restored prompts when new optional providers are configured. [#1663](https://github.com/sourcebot-dev/sourcebot/pull/1663) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- CreateEnum | ||
| CREATE TYPE "HomeView" AS ENUM ('SEARCH', 'ASK'); | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "Org" ADD COLUMN "defaultHomeView" "HomeView"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,25 @@ | ||
| import { HOME_VIEW_COOKIE_NAME } from "@/lib/constants"; | ||
| import { resolveHomeView } from "@/features/homeView/homeView"; | ||
| import { authenticatedPage, type OptionalAuthOptions } from "@/middleware/authenticatedPage"; | ||
| import { cookies } from "next/headers"; | ||
| import { ChatLandingPage } from "./chat/chatLandingPage"; | ||
| import SearchPage from "./search/page"; | ||
|
|
||
| interface Props { | ||
| interface Props extends Record<string, unknown> { | ||
| searchParams: Promise<{ query?: string }>; | ||
| } | ||
|
|
||
| export default async function Home(props: Props) { | ||
| export default authenticatedPage<Props, OptionalAuthOptions>(async ({ org, user }, props) => { | ||
| const cookieStore = await cookies(); | ||
| const homeView = cookieStore.get(HOME_VIEW_COOKIE_NAME)?.value; | ||
| const homeView = resolveHomeView({ | ||
| personalPreference: cookieStore.get(HOME_VIEW_COOKIE_NAME)?.value, | ||
| orgDefault: org.defaultHomeView, | ||
| isAuthenticated: !!user, | ||
| }); | ||
|
|
||
| if (homeView === "ask") { | ||
| return <ChatLandingPage />; | ||
| } | ||
|
|
||
| return <SearchPage {...props} />; | ||
| } | ||
| }, { allowAnonymous: true }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| import { authenticatedPage } from "@/middleware/authenticatedPage"; | ||
| import { parseHomeView } from "@/features/homeView/homeView"; | ||
| import { GeneralPage } from "./generalPage"; | ||
|
|
||
| export default authenticatedPage(async ({ user }) => { | ||
| export default authenticatedPage(async ({ org, user }) => { | ||
| return ( | ||
| <GeneralPage | ||
| userName={user.name ?? undefined} | ||
| userEmail={user.email ?? undefined} | ||
| userImage={user.image ?? undefined} | ||
| orgDefaultHomeView={parseHomeView(org.defaultHomeView) ?? "search"} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: For a user with no personal sb.home-view cookie, the Default home view select in General settings shows the inherited org default as its selected value. Because useHomeView writes a cookie on any Select onValueChange, a user who merely interacts with the dropdown (or re-selects the displayed value) silently gets a personal cookie pinned to the current org default; if an admin later changes the org default, that user no longer follows it. Consider tracking in useHomeView whether a personal cookie existed at first load and skipping the write (or writing only on genuine change) while the selected value equals the org default, so re-affirming the inherited value does not freeze it as a personal preference. Prompt for AI agents |
||
| /> | ||
| ); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ vi.mock('@/middleware/withAuth', () => ({ | |
| }, | ||
| })); | ||
|
|
||
| const { setLoginMessage } = await import('./actions'); | ||
| const { setDefaultHomeView, setLoginMessage } = await import('./actions'); | ||
|
|
||
| beforeEach(() => { | ||
| vi.resetAllMocks(); | ||
|
|
@@ -91,3 +91,30 @@ describe('setLoginMessage', () => { | |
| expect(mocks.captureException).toHaveBeenCalledWith(error); | ||
| }); | ||
| }); | ||
|
|
||
| describe('setDefaultHomeView', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The new suite never sends 'search', so the Prompt for AI agents |
||
| test('stores the deployment default on the authenticated organization', async () => { | ||
| await expect(setDefaultHomeView('ask')).resolves.toEqual({ success: true }); | ||
| expect(mocks.update).toHaveBeenCalledWith({ | ||
| where: { id: 42 }, | ||
| data: { defaultHomeView: 'ASK' }, | ||
| }); | ||
| }); | ||
|
|
||
| test('rejects invalid values without writing', async () => { | ||
| await expect(setDefaultHomeView('invalid')).resolves.toMatchObject({ | ||
| statusCode: 400, | ||
| errorCode: ErrorCode.INVALID_REQUEST_BODY, | ||
| }); | ||
| expect(mocks.update).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('denies organization members through the owner role check', async () => { | ||
| mocks.role = 'MEMBER'; | ||
| await expect(setDefaultHomeView('ask')).resolves.toMatchObject({ | ||
| statusCode: 403, | ||
| errorCode: ErrorCode.INSUFFICIENT_PERMISSIONS, | ||
| }); | ||
| expect(mocks.update).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,17 +8,20 @@ import { requestBodySchemaValidationError, ServiceError } from "@/lib/serviceErr | |
| import { sew } from "@/middleware/sew"; | ||
| import { withAuth } from "@/middleware/withAuth"; | ||
| import { withMinimumOrgRole } from "@/middleware/withMinimumOrgRole"; | ||
| import { OrgRole } from "@sourcebot/db"; | ||
| import { HomeView as PrismaHomeView, OrgRole } from "@sourcebot/db"; | ||
| import { env } from "@sourcebot/shared"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
| import { z } from "zod"; | ||
| import { LOGIN_MESSAGE_MAX_LENGTH } from "@/features/auth/constants"; | ||
| import { HOME_VIEW_VALUES } from "@/features/homeView/homeView"; | ||
|
|
||
| const loginMessageSchema = z.string() | ||
| .max(LOGIN_MESSAGE_MAX_LENGTH, "Login message must be 5,000 characters or fewer.") | ||
| .nullable() | ||
| .transform(message => message?.trim() ? message : null); | ||
|
|
||
| const defaultHomeViewSchema = z.enum(HOME_VIEW_VALUES); | ||
|
|
||
| export const setLoginMessage = async (message: string | null): Promise<{ success: boolean } | ServiceError> => sew(async () => | ||
| withAuth(async ({ org, role, prisma }) => | ||
| withMinimumOrgRole(role, OrgRole.OWNER, async () => { | ||
|
|
@@ -37,6 +40,28 @@ export const setLoginMessage = async (message: string | null): Promise<{ success | |
| ) | ||
| ); | ||
|
|
||
| export const setDefaultHomeView = async (homeView: unknown): Promise<{ success: boolean } | ServiceError> => sew(async () => | ||
| withAuth(async ({ org, role, prisma }) => | ||
| withMinimumOrgRole(role, OrgRole.OWNER, async () => { | ||
| const parsed = defaultHomeViewSchema.safeParse(homeView); | ||
| if (!parsed.success) { | ||
| return requestBodySchemaValidationError(parsed.error); | ||
| } | ||
|
|
||
| await prisma.org.update({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Refresh the current route after updating Prompt for AI agents |
||
| where: { id: org.id }, | ||
| data: { | ||
| defaultHomeView: parsed.data === "ask" | ||
| ? PrismaHomeView.ASK | ||
| : PrismaHomeView.SEARCH, | ||
| }, | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,130p' 'packages/web/src/app/(app)/settings/security/actions.ts'
sed -n '1,130p' 'packages/web/src/app/(app)/settings/security/components/defaultHomeViewSettingsCard.tsx'
sed -n '1,100p' 'packages/web/src/app/(app)/@sidebar/components/defaultSidebar/index.tsx'
rg -n 'refresh\(|revalidatePath|setDefaultHomeView|DefaultSidebar' 'packages/web/src/app/(app)'Repository: sourcebot-dev/sourcebot Length of output: 16182 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- Next version and scripts ---'
rg -n '"next"|next/cache|revalidatePath|export default|Settings' package.json packages/web/package.json packages/web/src/app/'(app)'/layout.tsx packages/web/src/app/'(app)'/settings -g '*.tsx' -g '*.ts' -g 'package.json' 2>/dev/null | head -240
printf '%s\n' '--- app layouts and settings route structure ---'
find 'packages/web/src/app/(app)' -maxdepth 4 -type f \( -name 'layout.tsx' -o -name 'page.tsx' -o -name '*Page.tsx' \) -print | sort | head -160
printf '%s\n' '--- relevant layout/settings files ---'
for f in \
'packages/web/src/app/(app)/layout.tsx' \
'packages/web/src/app/(app)/settings/layout.tsx' \
'packages/web/src/app/(app)/settings/security/page.tsx' \
'packages/web/src/app/(app)/settings/security/securityPage.tsx' \
'packages/web/src/app/(app)/settings/security/actions.test.ts'; do
if [ -f "$f" ]; then
echo "--- $f"
sed -n '1,220p' "$f"
fi
done
printf '%s\n' '--- home-view definitions and consumers ---'
rg -n -C 4 'resolveHomeView|defaultHomeView|HOME_VIEW_COOKIE_NAME' packages/web/src -g '*.ts' -g '*.tsx' | head -280Repository: sourcebot-dev/sourcebot Length of output: 42305 🏁 Script executed: #!/bin/bash
set -e
for f in \
'packages/web/src/app/(app)/layout.tsx' \
'packages/web/src/app/(app)/settings/layout.tsx' \
'packages/web/src/app/(app)/settings/security/page.tsx' \
'packages/web/src/app/(app)/@sidebar/(routes)/(default)/page.tsx' \
'packages/web/src/app/(app)/@sidebar/(routes)/(default)/[...slug]/page.tsx'; do
echo "--- $f"
sed -n '1,220p' "$f"
done
printf '%s\n' '--- all refresh/revalidation in app layout and action wrappers ---'
rg -n -C 5 'refresh\(|revalidate(Path|Tag)|use server|withAuth|sew\(' \
'packages/web/src/app/(app)/layout.tsx' \
'packages/web/src/app/(app)/settings/security/actions.ts' \
'packages/web/src/middleware' \
-g '*.ts' -g '*.tsx'Repository: sourcebot-dev/sourcebot Length of output: 41906 🌐 Web query:
💡 Result: <source_evidence> Citations:
Refresh server component data after the update.
Call 🤖 Prompt for AI Agents |
||
|
|
||
| return { success: true }; | ||
| }) | ||
| ) | ||
| ); | ||
|
|
||
| export const setMemberApprovalRequired = async (required: boolean): Promise<{ success: boolean } | ServiceError> => sew(async () => | ||
| withAuth(async ({ org, role, prisma }) => | ||
| withMinimumOrgRole(role, OrgRole.OWNER, async () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| "use client"; | ||
|
|
||
| import { BasicSettingsCard } from "@/app/(app)/settings/components/settingsCard"; | ||
| import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; | ||
| import { useToast } from "@/components/hooks/use-toast"; | ||
| import { type HomeView } from "@/features/homeView/homeView"; | ||
| import { isServiceError } from "@/lib/utils"; | ||
| import { useState } from "react"; | ||
| import { setDefaultHomeView } from "../actions"; | ||
|
|
||
| const homeViewOptions = [ | ||
| { value: "search", label: "Code Search" }, | ||
| { value: "ask", label: "Ask" }, | ||
| ] as const; | ||
|
|
||
| interface DefaultHomeViewSettingsCardProps { | ||
| defaultHomeView: HomeView; | ||
| } | ||
|
|
||
| export function DefaultHomeViewSettingsCard({ defaultHomeView }: DefaultHomeViewSettingsCardProps) { | ||
| const [homeView, setHomeView] = useState(defaultHomeView); | ||
| const [isSaving, setIsSaving] = useState(false); | ||
| const { toast } = useToast(); | ||
|
|
||
| const handleChange = async (value: string) => { | ||
| if (value !== "search" && value !== "ask") { | ||
| return; | ||
| } | ||
|
|
||
| setIsSaving(true); | ||
| try { | ||
| const result = await setDefaultHomeView(value); | ||
| if (isServiceError(result)) { | ||
| toast({ | ||
| title: "Error", | ||
| description: result.message, | ||
| variant: "destructive", | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| setHomeView(value); | ||
| toast({ description: "Deployment default home view saved." }); | ||
| } catch { | ||
| toast({ | ||
| title: "Error", | ||
| description: "Failed to update the deployment default home view.", | ||
| variant: "destructive", | ||
| }); | ||
| } finally { | ||
| setIsSaving(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <BasicSettingsCard | ||
| name="Deployment default home view" | ||
| description="Choose the default page for users without a personal preference. Individual user preferences override this setting." | ||
| > | ||
| <Select value={homeView} onValueChange={handleChange} disabled={isSaving}> | ||
| <SelectTrigger className="w-36"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Screen-reader users cannot reliably identify what this combobox controls because the card title is not associated with the trigger. Add an accessible label to the trigger. Prompt for AI agents |
||
| <SelectValue /> | ||
| </SelectTrigger> | ||
| <SelectContent> | ||
| {homeViewOptions.map((option) => ( | ||
| <SelectItem key={option.value} value={option.value}> | ||
| {option.label} | ||
| </SelectItem> | ||
| ))} | ||
| </SelectContent> | ||
| </Select> | ||
| </BasicSettingsCard> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
| import { resolveHomeView } from "./homeView"; | ||
|
|
||
| describe("resolveHomeView", () => { | ||
| test("uses the org default when an authenticated user has no personal preference", () => { | ||
| expect(resolveHomeView({ orgDefault: "ASK" })).toBe("ask"); | ||
| }); | ||
|
|
||
| test("uses an explicit personal preference over the org default", () => { | ||
| expect(resolveHomeView({ personalPreference: "search", orgDefault: "ASK" })).toBe("search"); | ||
| }); | ||
|
|
||
| test("falls back to search when the org default is unset", () => { | ||
| expect(resolveHomeView({ orgDefault: undefined })).toBe("search"); | ||
| }); | ||
|
|
||
| test("uses the org default for anonymous users even with a stale personal cookie", () => { | ||
| expect(resolveHomeView({ | ||
| personalPreference: "search", | ||
| orgDefault: "ASK", | ||
| isAuthenticated: false, | ||
| })).toBe("ask"); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Move this entry to the
[Unreleased]section.Version 5.1.14 is dated September 17, 2026. This change belongs under
[Unreleased], at the bottom of itsAddedsection.As per coding guidelines, “Every PR must include a follow-up commit with an entry in CHANGELOG.md under [Unreleased].”
🤖 Prompt for AI Agents
Source: Coding guidelines