From 4b4527094f378de70218d30551fa26f1094ad72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Lappetel=C3=A4inen?= <38039015+pnupu@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:06:31 +0200 Subject: [PATCH 1/6] feat(settings): one list shows every project's pull request feed rule Settings > Source control gets Repository feed rules on web, desktop and mobile: one row per repository (projects without one get their own row), with the projects and environments it covers and a rule picker. A pick writes every writable copy, like the Pull Requests row menu. Rows say when copies differ, when the rule is the default, and which copies this client cannot change. A reset clears the overrides back to the default. The grouping lives in client-runtime's pullRequestFeedRuleRows so web and mobile share it, and it reads rules from PULL_REQUEST_FEED_RULES so new rules appear without changes here. Co-Authored-By: Claude Opus 5.5 --- ...SettingsServerControlsRouteScreen.test.tsx | 3 + .../SettingsServerControlsRouteScreen.tsx | 15 +- .../PullRequestFeedRulesSection.tsx | 160 ++++++++++++++++++ .../pullRequest/usePullRequestFeed.ts | 49 ++++++ .../settings/ProjectDefaultsSettings.tsx | 4 + .../settings/PullRequestFeedRulesSetting.tsx | 72 ++++++++ .../src/components/settings/settingsSearch.ts | 7 + docs/user/source-control.md | 3 +- .../src/pullRequestFeed.test.ts | 82 +++++++++ .../client-runtime/src/pullRequestFeed.ts | 120 ++++++++++++- 10 files changed, 512 insertions(+), 3 deletions(-) create mode 100644 apps/mobile/src/features/settings/components/PullRequestFeedRulesSection.tsx create mode 100644 apps/web/src/components/settings/PullRequestFeedRulesSetting.tsx diff --git a/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.test.tsx b/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.test.tsx index 3dedcc600721f..eee0e2b619bfc 100644 --- a/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.test.tsx +++ b/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.test.tsx @@ -127,6 +127,9 @@ vi.mock("./components/SettingsSwitchRow", () => ({ ), })); vi.mock("./components/SettingsRow", () => ({ SettingsRow: () => null })); +vi.mock("./components/PullRequestFeedRulesSection", () => ({ + PullRequestFeedRulesSection: () => null, +})); vi.mock("./components/BranchNamingSettings", () => ({ BranchNamingSettings: (props: { onChange: (patch: ServerSettingsPatch) => void }) => { mocks.branchNaming.onChange = props.onChange; diff --git a/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx index 4a3d6f8995784..980c20d8a5b0d 100644 --- a/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx @@ -30,6 +30,7 @@ import { SettingsSection } from "./components/SettingsSection"; import { SettingsSwitchRow } from "./components/SettingsSwitchRow"; import { SourceControlSignInSection } from "./components/SourceControlSignInSection"; import { SettingsProjectOverridesSection } from "./components/SettingsProjectOverridesSection"; +import { PullRequestFeedRulesSection } from "./components/PullRequestFeedRulesSection"; import { useSettingsEnvironmentFilter } from "./settings-environment-filter"; import { useSettingsWriter } from "./useSettingsWriter"; import { @@ -181,7 +182,8 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) { const environmentMenu = useSettingsEnvironmentMenu(); const insets = useSafeAreaInsets(); const navigation = useNavigation(); - const { selectedTargets, projectGroups, selectedProjectKey } = useSettingsEnvironmentFilter(); + const { selectedTargets, selectedIds, projectGroups, selectedProjectKey } = + useSettingsEnvironmentFilter(); const selectedProject = projectGroups.find((group) => group.key === selectedProjectKey); const writableEnvironments = useEnvironmentsWithScope(selectedTargets, AuthSettingsWriteScope); const projectSelected = selectedProjectKey !== null; @@ -483,6 +485,17 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) { ))} ) : null} + {!projectSelected && + targets.every( + (target) => + target.environment.serverConfig.environment.capabilities.pullRequestFeed === + true, + ) ? ( + + ) : null} {projectSelected || feed.hiddenUrls.length === 0 ? null : ( | null; + readonly targets: readonly SettingsTarget[]; +}) { + const { environments } = useEnvironments(); + const projects = useProjects(); + const writeSettings = useSettingsWriter(); + const [pending, setPending] = useState(false); + const rows = pullRequestFeedRuleRows( + projects.filter( + (project) => props.selectedIds === null || props.selectedIds.has(project.environmentId), + ), + (environmentId) => { + const environment = environments.find( + (candidate) => candidate.environmentId === environmentId, + ); + const config = environment?.serverConfig; + if (!environment || !config) return undefined; + return { + label: environment.label, + settings: config.settings, + access: + environment.connection.phase !== "connected" + ? "disconnected" + : config.environment.capabilities.pullRequestFeed !== true + ? "outdated" + : readEnvironmentScope(environmentId, AuthSettingsWriteScope) + ? "writable" + : "read-only", + }; + }, + ); + if (rows.length === 0) return null; + + type Row = (typeof rows)[number]; + const pick = (row: Row, action: string) => { + const reset = action === DEFAULT_ACTION; + const rule = PULL_REQUEST_FEED_RULES.find((option) => option.value === action)?.value; + if (pending || (!reset && rule === undefined)) return; + const members = row.copies.flatMap((copy) => + copy.access === "writable" && (!reset || copy.overridden) ? [copy.project] : [], + ); + const targets = resolveMobileSettingsTargets(props.targets, members); + const writes = reset + ? planMobileScopedSettingsClear(targets, ["pullRequestFeed"]) + : planMobileScopedSettingsPatch(targets, true, { pullRequestFeed: rule! }); + if (writes.length === 0) return; + setPending(true); + void writeSettings(targets, writes).finally(() => setPending(false)); + }; + + return ( + + {rows.map((row, index) => ( + 0} + disabled={pending || row.copies.every((copy) => copy.access !== "writable")} + onPick={(action) => pick(row, action)} + /> + ))} + + ); +} + +function RuleRow(props: { + readonly row: PullRequestFeedRuleRow; + readonly separated: boolean; + readonly disabled: boolean; + readonly onPick: (action: string) => void; +}) { + const { row } = props; + const value = + PULL_REQUEST_FEED_RULES.find((option) => option.value === row.rule)?.label ?? "Differs"; + const content = ( + + + + {row.name} + + + {value} + + {props.disabled ? null : ( + + )} + + + {row.covers} + + {row.status ? ( + + {row.status} + + ) : null} + + ); + if (props.disabled) return content; + return ( + ({ + id: option.value, + title: option.label, + state: row.rule === option.value ? ("on" as const) : ("off" as const), + })), + ...(row.canReset ? [{ id: DEFAULT_ACTION, title: "Use the default rule" }] : []), + ]} + onPressAction={({ nativeEvent }) => props.onPick(nativeEvent.event)} + > + {content} + + ); +} diff --git a/apps/web/src/components/pullRequest/usePullRequestFeed.ts b/apps/web/src/components/pullRequest/usePullRequestFeed.ts index 68f047e13acd7..7dc351aed216b 100644 --- a/apps/web/src/components/pullRequest/usePullRequestFeed.ts +++ b/apps/web/src/components/pullRequest/usePullRequestFeed.ts @@ -5,6 +5,8 @@ import { isPullRequestHidden, PULL_REQUEST_FEED_RULES, pullRequestFeedRule, + pullRequestFeedRuleRows, + type PullRequestFeedRuleRow, pullRequestProjectHidesRepository, pullRequestRepositoryHidden, pullRequestRepositoryRules, @@ -30,6 +32,7 @@ import { pendingScopedWritesAtom, planEnvironmentSettingsPatch, planProjectOverridePatch, + planProjectOverridesClear, } from "../settings/scopedSettings"; import { useRunScopedPlan } from "../settings/useScopedSettings"; import { runPullRequestLinkAction } from "./pullRequestLinkContextMenu"; @@ -141,6 +144,49 @@ export function usePullRequestFeed() { ); }; + /** One row per repository in these environments, for the Settings overview. */ + const ruleRows = (environmentIds: ReadonlyArray) => + pullRequestFeedRuleRows( + projects.filter((project) => environmentIds.includes(project.environmentId)), + (environmentId) => { + const environment = environments.find( + (candidate) => candidate.environmentId === environmentId, + ); + const config = environment?.serverConfig; + if (!environment || !config) return undefined; + return { + label: environment.label, + settings: config.settings, + access: !connected.has(environmentId) + ? "disconnected" + : config.environment.capabilities.pullRequestFeed !== true + ? "outdated" + : readEnvironmentScope(environmentId, AuthSettingsWriteScope) + ? "writable" + : "read-only", + }; + }, + ); + type RuleRow = PullRequestFeedRuleRow; + const writableCopies = (row: RuleRow) => row.copies.filter((copy) => copy.access === "writable"); + const setRowRule = (row: RuleRow, rule: PullRequestFeedRule) => + setProjectRule( + writableCopies(row).map((copy) => copy.project), + rule, + ); + const resetRowRule = (row: RuleRow) => + runPlan(environments, (current) => + planProjectOverridesClear( + current, + writableCopies(row).flatMap((copy) => + copy.overridden + ? [{ environmentId: copy.project.environmentId, projectId: copy.project.id }] + : [], + ), + ["pullRequestFeed"], + ), + ); + const openRowMenu = async ( entry: EnvironmentPullRequestEntry, openLabel: string, @@ -217,5 +263,8 @@ export function usePullRequestFeed() { canUnhide, unhideBlockedBy, showRowMenu, + ruleRows, + setRowRule, + resetRowRule, }; } diff --git a/apps/web/src/components/settings/ProjectDefaultsSettings.tsx b/apps/web/src/components/settings/ProjectDefaultsSettings.tsx index 48022143d92d9..163b6aa8354a1 100644 --- a/apps/web/src/components/settings/ProjectDefaultsSettings.tsx +++ b/apps/web/src/components/settings/ProjectDefaultsSettings.tsx @@ -28,6 +28,7 @@ import { toastManager } from "../ui/toast"; import { Switch } from "../ui/switch"; import { resolveDefaultModelSettingsPresentation } from "./ProjectDefaultsSettings.logic"; import type { ProjectSettingsCategory } from "./ProjectSettingsPanel"; +import { PullRequestFeedRulesSetting } from "./PullRequestFeedRulesSetting"; import { searchableSetting } from "./settingsSearch"; import { useSettingsScope } from "./SettingsScopeContext"; import { @@ -572,6 +573,9 @@ export function ProjectDefaultsSettings({ category }: { category: ProjectSetting } /> ) : null} + {pullRequestFeedSupported && (scope.kind === "all" || scope.kind === "environment") ? ( + + ) : null} )} diff --git a/apps/web/src/components/settings/PullRequestFeedRulesSetting.tsx b/apps/web/src/components/settings/PullRequestFeedRulesSetting.tsx new file mode 100644 index 0000000000000..6489c879c333f --- /dev/null +++ b/apps/web/src/components/settings/PullRequestFeedRulesSetting.tsx @@ -0,0 +1,72 @@ +import type { EnvironmentId } from "@t3tools/contracts"; +import { PULL_REQUEST_FEED_RULES } from "@t3tools/client-runtime/pull-request-feed"; + +import { usePullRequestFeed } from "../pullRequest/usePullRequestFeed"; +import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select"; +import { searchableSetting } from "./settingsSearch"; +import { SettingResetButton, SettingsRow } from "./settingsLayout"; + +/** Every repository's rule in one place; each write covers all writable copies of it. */ +export function PullRequestFeedRulesSetting(props: { + readonly environmentIds: ReadonlyArray; +}) { + const feed = usePullRequestFeed(); + const rows = feed.ruleRows(props.environmentIds); + return ( + + {rows.length === 0 ? null : ( +
    + {rows.map((row) => ( +
  • +
    +

    {row.name}

    +

    {row.covers}

    + {row.status ?

    {row.status}

    : null} +
    +
    + {row.canReset ? ( + feed.resetRowRule(row)} + /> + ) : null} + +
    +
  • + ))} +
+ )} +
+ ); +} diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts index af9fcc06971e3..f5f9a2d179daa 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -1173,6 +1173,13 @@ export const SETTINGS_SEARCH_ITEMS = [ scope: "project-defaults", searchTerms: ["pull requests list feed authored waiting on me review requested hide exclude"], }, + { + id: "pull-request-feed-rules", + title: "Repository feed rules", + to: "/settings/source-control", + scope: "environment-defaults", + searchTerms: ["pull requests list feed per project repository override overview hide"], + }, { id: "source-control", title: "Source control", diff --git a/docs/user/source-control.md b/docs/user/source-control.md index c0f4159b43f3b..d1dadc53205ad 100644 --- a/docs/user/source-control.md +++ b/docs/user/source-control.md @@ -253,7 +253,8 @@ project selector there. On web and desktop you can also right-click a pull reque rule for its project. When the same repository is a project on several connected environments, the list shows a pull request if any of their rules allows it, and **Hidden** on any of them hides the repository. Picking one project in the list's project filter shows all its pull -requests. +requests. **Repository feed rules** in Settings → Source control lists every repository's rule in +one place, and a rule you pick there applies to every copy of that repository. To hide one pull request, right-click it on web and desktop, or touch and hold it on mobile, and choose **Hide from feed**. Hidden pull requests leave every list. Press **Show N hidden** in the diff --git a/packages/client-runtime/src/pullRequestFeed.test.ts b/packages/client-runtime/src/pullRequestFeed.test.ts index d34f6e45ff1d7..08193107da32a 100644 --- a/packages/client-runtime/src/pullRequestFeed.test.ts +++ b/packages/client-runtime/src/pullRequestFeed.test.ts @@ -13,7 +13,9 @@ import { pullRequestFeedGroup, pullRequestFeedRule, pullRequestFeedShows, + pullRequestFeedRuleRows, type PullRequestFeedGroup, + type PullRequestFeedRuleAccess, } from "./pullRequestFeed.ts"; const projectA = ProjectId.make("project-a"); @@ -212,3 +214,83 @@ describe("pull request feed rules", () => { expect(isPullRequestHidden(hiddenPullRequestUrls(settings), "https://h/A/1")).toBe(true); }); }); + +describe("pull request feed rule rows", () => { + const settings = ( + pullRequestFeed: PullRequestFeedRule, + overrides: Record = {}, + ) => ({ + ...DEFAULT_SERVER_SETTINGS, + pullRequestFeed, + projectSettingsOverrides: Object.fromEntries( + Object.entries(overrides).map(([id, rule]) => [id, { pullRequestFeed: rule }]), + ), + }); + const project = (environmentId: string, id: string, canonicalKey?: string) => ({ + environmentId, + id: ProjectId.make(id), + title: id, + repositoryIdentity: canonicalKey === undefined ? null : { canonicalKey }, + }); + const rows = ( + projects: ReadonlyArray>, + environments: Record< + string, + { settings: ReturnType; access?: PullRequestFeedRuleAccess } + >, + ) => + pullRequestFeedRuleRows(projects, (environmentId) => { + const environment = environments[environmentId]; + return environment === undefined + ? undefined + : { label: environmentId, access: "writable", ...environment }; + }); + + it("groups a repository's copies into one row and gives an unidentified project its own", () => { + const result = rows( + [ + project("laptop", "web", "github.com/x/Web"), + project("server", "web-copy", "github.com/x/web"), + project("laptop", "notes"), + project("offline", "lost", "github.com/x/web"), + ], + { laptop: { settings: settings("all") }, server: { settings: settings("all") } }, + ); + expect(result.map((row) => [row.name, row.covers])).toEqual([ + ["github.com/x/Web", "web, web-copy · laptop, server"], + ["notes", "notes · laptop"], + ]); + }); + + it("shows an inherited rule as the default and offers no reset", () => { + const [row] = rows([project("laptop", "web", "k"), project("server", "web", "k")], { + laptop: { settings: settings("authored") }, + server: { settings: settings("authored") }, + }); + expect(row).toMatchObject({ rule: "authored", status: "Default rule.", canReset: false }); + }); + + it("names each rule's environments when copies differ", () => { + const [row] = rows([project("laptop", "web", "k"), project("server", "web", "k")], { + laptop: { settings: settings("all") }, + server: { settings: settings("all", { web: "hidden" }) }, + }); + expect(row).toMatchObject({ + rule: null, + status: "Differs: All pull requests on laptop; Hidden on server.", + canReset: true, + }); + }); + + it("says which copies this client cannot change and resets only writable ones", () => { + const [row] = rows([project("laptop", "web", "k"), project("server", "web", "k")], { + laptop: { settings: settings("all"), access: "disconnected" }, + server: { settings: settings("all", { web: "all" }), access: "read-only" }, + }); + expect(row).toMatchObject({ + rule: "all", + status: "Connect laptop to change it. This connection cannot change settings on server.", + canReset: false, + }); + }); +}); diff --git a/packages/client-runtime/src/pullRequestFeed.ts b/packages/client-runtime/src/pullRequestFeed.ts index c6cc05ab9d4c3..d8bb0624a8d8c 100644 --- a/packages/client-runtime/src/pullRequestFeed.ts +++ b/packages/client-runtime/src/pullRequestFeed.ts @@ -145,7 +145,10 @@ export function pullRequestRepositoryHidden( type RepositoryProject = { readonly id: ProjectId; readonly environmentId: string; - readonly repositoryIdentity?: { readonly canonicalKey?: string | undefined } | null | undefined; + readonly repositoryIdentity?: + | { readonly canonicalKey?: string | undefined; readonly displayName?: string | undefined } + | null + | undefined; }; /** @@ -230,3 +233,118 @@ export function filterPullRequestFeed< }); return { groups: changed ? next : groups, hiddenCount, ruledOutCount }; } + +/** Why this client cannot change a copy's rule, or `writable`. */ +export type PullRequestFeedRuleAccess = "writable" | "disconnected" | "outdated" | "read-only"; + +export interface PullRequestFeedRuleCopy { + readonly project: Project; + readonly environmentLabel: string; + readonly rule: PullRequestFeedRule; + /** False when the project inherits its environment's default rule. */ + readonly overridden: boolean; + readonly access: PullRequestFeedRuleAccess; +} + +export interface PullRequestFeedRuleRow { + readonly key: string; + readonly name: string; + /** The project titles and environments the row covers. */ + readonly covers: string; + readonly copies: ReadonlyArray>; + /** The copies' one rule, or null when they differ. */ + readonly rule: PullRequestFeedRule | null; + /** Inheritance, disagreement, and the copies this client cannot change, in short sentences. */ + readonly status: string; + readonly canReset: boolean; +} + +const ruleLabel = (rule: PullRequestFeedRule) => + PULL_REQUEST_FEED_RULES.find((option) => option.value === rule)?.label ?? rule; + +const ACCESS_NOTES: Record< + Exclude, + (on: string) => string +> = { + disconnected: (on) => `Connect ${on} to change it.`, + outdated: (on) => `Update ${on} to change it.`, + "read-only": (on) => `This connection cannot change settings on ${on}.`, +}; + +const unique = (values: ReadonlyArray) => [...new Set(values)]; + +/** + * One row per repository, keyed like `pullRequestRepositoryRules`, so a write covers every copy + * the feed reads. A project without a repository identity gets its own row. Environments without + * settings are left out: their rule is unknown. + */ +export function pullRequestFeedRuleRows< + Project extends RepositoryProject & { readonly title: string }, +>( + projects: ReadonlyArray, + environmentOf: (environmentId: Project["environmentId"]) => + | { + readonly label: string; + readonly settings: PullRequestFeedSettings; + readonly access: PullRequestFeedRuleAccess; + } + | undefined, +): ReadonlyArray> { + const groups = new Map[] }>(); + for (const project of projects) { + const environment = environmentOf(project.environmentId); + if (environment === undefined) continue; + const identity = project.repositoryIdentity; + const repositoryKey = identity?.canonicalKey?.toLowerCase(); + const key = repositoryKey ?? `project ${project.environmentId} ${project.id}`; + const copy: PullRequestFeedRuleCopy = { + project, + environmentLabel: environment.label, + rule: pullRequestFeedRule(environment.settings, project.id), + overridden: + environment.settings.projectSettingsOverrides[project.id]?.pullRequestFeed !== undefined, + access: environment.access, + }; + const group = groups.get(key); + if (group) group.copies.push(copy); + else + groups.set(key, { + name: identity?.displayName ?? identity?.canonicalKey ?? project.title, + copies: [copy], + }); + } + const rows = [...groups].map(([key, { name, copies }]) => { + const rules = unique(copies.map((copy) => copy.rule)) as PullRequestFeedRule[]; + const rule = rules.length === 1 ? rules[0]! : null; + const notes: string[] = []; + if (rule === null) { + const parts = rules.map((candidate) => { + const on = unique( + copies.filter((copy) => copy.rule === candidate).map((copy) => copy.environmentLabel), + ); + return `${ruleLabel(candidate)} on ${on.join(", ")}`; + }); + notes.push(`Differs: ${parts.join("; ")}.`); + } else if (copies.every((copy) => !copy.overridden)) { + notes.push("Default rule."); + } + for (const access of ["disconnected", "outdated", "read-only"] as const) { + const on = unique( + copies.filter((copy) => copy.access === access).map((copy) => copy.environmentLabel), + ); + if (on.length > 0) notes.push(ACCESS_NOTES[access](on.join(", "))); + } + return { + key, + name, + covers: `${unique(copies.map((copy) => copy.project.title)).join(", ")} · ${unique( + copies.map((copy) => copy.environmentLabel), + ).join(", ")}`, + copies, + rule, + status: notes.join(" "), + canReset: copies.some((copy) => copy.overridden && copy.access === "writable"), + }; + }); + return rows.sort((left, right) => left.name.localeCompare(right.name)); +} From 8c1bffcc0e44d0a99973d9d0552bc711716b6adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Lappetel=C3=A4inen?= <38039015+pnupu@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:10:17 +0200 Subject: [PATCH 2/6] fix(settings): feed rule overview skips no-op picks and shows outdated servers A mobile pick of the rule a row already shows no longer pins overrides, and rows stay locked until the server pushes the saved settings. One outdated server no longer hides the whole overview: its copies say to update it. Copy says a pick covers only the copies this connection can change. Co-Authored-By: Claude Opus 5.5 --- .../SettingsServerControlsRouteScreen.tsx | 9 ++------ .../PullRequestFeedRulesSection.tsx | 21 ++++++++++++------- .../settings/ProjectDefaultsSettings.tsx | 2 +- .../settings/PullRequestFeedRulesSetting.tsx | 2 +- docs/user/source-control.md | 3 ++- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx index 980c20d8a5b0d..ad88dde8fb429 100644 --- a/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx @@ -485,17 +485,12 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) { ))} ) : null} - {!projectSelected && - targets.every( - (target) => - target.environment.serverConfig.environment.capabilities.pullRequestFeed === - true, - ) ? ( + {projectSelected ? null : ( - ) : null} + )} {projectSelected || feed.hiddenUrls.length === 0 ? null : ( | null; readonly targets: readonly SettingsTarget[]; }) { - const { environments } = useEnvironments(); + const { environments, presentationById } = useEnvironments(); const projects = useProjects(); const writeSettings = useSettingsWriter(); - const [pending, setPending] = useState(false); + const writable = useEnvironmentsWithScope(props.targets, AuthSettingsWriteScope); + // Until the server pushes the saved settings, the rows still show the old rule. + const [sentOver, setSentOver] = useState(null); + const pending = sentOver !== null && sentOver === presentationById; const rows = pullRequestFeedRuleRows( projects.filter( (project) => props.selectedIds === null || props.selectedIds.has(project.environmentId), @@ -51,7 +54,7 @@ export function PullRequestFeedRulesSection(props: { ? "disconnected" : config.environment.capabilities.pullRequestFeed !== true ? "outdated" - : readEnvironmentScope(environmentId, AuthSettingsWriteScope) + : writable.has(environmentId) ? "writable" : "read-only", }; @@ -63,7 +66,7 @@ export function PullRequestFeedRulesSection(props: { const pick = (row: Row, action: string) => { const reset = action === DEFAULT_ACTION; const rule = PULL_REQUEST_FEED_RULES.find((option) => option.value === action)?.value; - if (pending || (!reset && rule === undefined)) return; + if (pending || (!reset && (rule === undefined || rule === row.rule))) return; const members = row.copies.flatMap((copy) => copy.access === "writable" && (!reset || copy.overridden) ? [copy.project] : [], ); @@ -72,14 +75,16 @@ export function PullRequestFeedRulesSection(props: { ? planMobileScopedSettingsClear(targets, ["pullRequestFeed"]) : planMobileScopedSettingsPatch(targets, true, { pullRequestFeed: rule! }); if (writes.length === 0) return; - setPending(true); - void writeSettings(targets, writes).finally(() => setPending(false)); + setSentOver(presentationById); + void writeSettings(targets, writes).then((failed) => { + if (failed.length > 0) setSentOver(null); + }); }; return ( {rows.map((row, index) => ( ) : null} - {pullRequestFeedSupported && (scope.kind === "all" || scope.kind === "environment") ? ( + {scope.kind === "all" || scope.kind === "environment" ? ( ) : null} diff --git a/apps/web/src/components/settings/PullRequestFeedRulesSetting.tsx b/apps/web/src/components/settings/PullRequestFeedRulesSetting.tsx index 6489c879c333f..436fda6ddfbcc 100644 --- a/apps/web/src/components/settings/PullRequestFeedRulesSetting.tsx +++ b/apps/web/src/components/settings/PullRequestFeedRulesSetting.tsx @@ -18,7 +18,7 @@ export function PullRequestFeedRulesSetting(props: { description={ rows.length === 0 ? "No projects yet." - : "Each repository's rule. A rule set here applies to every copy of the repository." + : "Each repository's rule. A rule set here applies to every copy of the repository that this connection can change." } > {rows.length === 0 ? null : ( diff --git a/docs/user/source-control.md b/docs/user/source-control.md index d1dadc53205ad..6068fc201581a 100644 --- a/docs/user/source-control.md +++ b/docs/user/source-control.md @@ -254,7 +254,8 @@ rule for its project. When the same repository is a project on several connected the list shows a pull request if any of their rules allows it, and **Hidden** on any of them hides the repository. Picking one project in the list's project filter shows all its pull requests. **Repository feed rules** in Settings → Source control lists every repository's rule in -one place, and a rule you pick there applies to every copy of that repository. +one place, and a rule you pick there applies to every copy of that repository that you can change +from this device. To hide one pull request, right-click it on web and desktop, or touch and hold it on mobile, and choose **Hide from feed**. Hidden pull requests leave every list. Press **Show N hidden** in the From 96b9972f72b148ced7b6a4794f3571ff2bba773e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Lappetel=C3=A4inen?= <38039015+pnupu@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:40:53 +0200 Subject: [PATCH 3/6] fix(settings): feed rule overview respects policy locks, grants and offline servers - Mobile picks lock the list per sent override until that server's settings answer it, so a reset across two servers waits for both, and a no-op or an offline server no longer leaves rows locked. - Web subscribes to write grants, so a grant that loads late unlocks its copies in the overview and the row menu. - A policy-locked feed rule reads "Managed by on " and is skipped by overview writes and by the web row menu. - The overview stays visible from cached rules when the selected environment, or on mobile every environment, is offline. Co-Authored-By: Claude Opus 5.5 --- .../SettingsServerControlsRouteScreen.tsx | 16 +++-- .../PullRequestFeedRulesSection.tsx | 62 +++++++++++----- .../features/settings/sentFeedRules.test.ts | 43 +++++++++++ .../src/features/settings/sentFeedRules.ts | 36 ++++++++++ .../pullRequest/usePullRequestFeed.ts | 31 ++++---- apps/web/src/routes/_chat.settings.tsx | 9 ++- .../src/pullRequestFeed.test.ts | 36 +++++++--- .../client-runtime/src/pullRequestFeed.ts | 72 +++++++++++++++---- 8 files changed, 247 insertions(+), 58 deletions(-) create mode 100644 apps/mobile/src/features/settings/sentFeedRules.test.ts create mode 100644 apps/mobile/src/features/settings/sentFeedRules.ts diff --git a/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx index ad88dde8fb429..283bebc6d0434 100644 --- a/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx @@ -297,11 +297,17 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) { contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }} > {!hasConnectedSelection || reference === null ? ( - - {projectSelected - ? "Select a project with a checkout on a connected environment." - : "Use the filter above to select a connected environment."} - + <> + + {projectSelected + ? "Select a project with a checkout on a connected environment." + : "Use the filter above to select a connected environment."} + + {/* Cached rules stay readable; each row says what needs a connection. */} + {props.page === "source-control" && !projectSelected ? ( + + ) : null} + ) : ( <> diff --git a/apps/mobile/src/features/settings/components/PullRequestFeedRulesSection.tsx b/apps/mobile/src/features/settings/components/PullRequestFeedRulesSection.tsx index 23cbfca47013d..d96fc3b13bd81 100644 --- a/apps/mobile/src/features/settings/components/PullRequestFeedRulesSection.tsx +++ b/apps/mobile/src/features/settings/components/PullRequestFeedRulesSection.tsx @@ -1,10 +1,11 @@ +import { RegistryContext, useAtomValue } from "@effect/atom-react"; import { PULL_REQUEST_FEED_RULES, pullRequestFeedRuleRows, type PullRequestFeedRuleRow, } from "@t3tools/client-runtime/pull-request-feed"; import { AuthSettingsWriteScope, type EnvironmentId } from "@t3tools/contracts"; -import { useState } from "react"; +import { use, useState } from "react"; import { Pressable, View } from "react-native"; import { SymbolView } from "../../../components/ui/AppSymbol"; @@ -12,6 +13,7 @@ import { AppText as Text } from "../../../components/ui/AppText"; import { Menu } from "../../../components/ui/Menu"; import { useProjects } from "../../../state/entities"; import { useEnvironments } from "../../../state/environments"; +import { environmentServerConfigsAtom } from "../../../state/server"; import { useEnvironmentsWithScope } from "../../../state/session"; import { planMobileScopedSettingsClear, @@ -19,23 +21,38 @@ import { resolveMobileSettingsTargets, } from "../settings-scoped-server"; import type { SettingsTarget } from "../settings-environment-filter"; +import { openSentFeedRules, type SentFeedRule } from "../sentFeedRules"; import { useSettingsWriter } from "../useSettingsWriter"; import { SettingsSection } from "./SettingsSection"; const DEFAULT_ACTION = "default"; -/** Every repository's feed rule; a pick applies to every writable copy of the repository. */ +/** + * Every repository's feed rule; a pick applies to every writable copy of the repository. It reads + * cached settings, so it stays useful while environments are offline. + */ export function PullRequestFeedRulesSection(props: { readonly selectedIds: ReadonlySet | null; readonly targets: readonly SettingsTarget[]; }) { - const { environments, presentationById } = useEnvironments(); + const { environments } = useEnvironments(); + const configs = useAtomValue(environmentServerConfigsAtom); + const registry = use(RegistryContext); const projects = useProjects(); const writeSettings = useSettingsWriter(); const writable = useEnvironmentsWithScope(props.targets, AuthSettingsWriteScope); - // Until the server pushes the saved settings, the rows still show the old rule. - const [sentOver, setSentOver] = useState(null); - const pending = sentOver !== null && sentOver === presentationById; + // Each override this device sent locks the list until its server's settings answer it. + const [sent, setSent] = useState>>([]); + // A disconnected server will not push its answer, so its sends stop locking the list. + const pending = + openSentFeedRules(sent, (id) => + environments.some( + (environment) => + environment.environmentId === id && environment.connection.phase === "connected", + ) + ? configs.get(id)?.settings + : undefined, + ).length > 0; const rows = pullRequestFeedRuleRows( projects.filter( (project) => props.selectedIds === null || props.selectedIds.has(project.environmentId), @@ -44,19 +61,15 @@ export function PullRequestFeedRulesSection(props: { const environment = environments.find( (candidate) => candidate.environmentId === environmentId, ); - const config = environment?.serverConfig; + const config = configs.get(environmentId); if (!environment || !config) return undefined; return { label: environment.label, settings: config.settings, - access: - environment.connection.phase !== "connected" - ? "disconnected" - : config.environment.capabilities.pullRequestFeed !== true - ? "outdated" - : writable.has(environmentId) - ? "writable" - : "read-only", + connected: environment.connection.phase === "connected", + capable: config.environment.capabilities.pullRequestFeed === true, + writeGranted: writable.has(environmentId), + managedPolicy: config.managedPolicy, }; }, ); @@ -75,9 +88,24 @@ export function PullRequestFeedRulesSection(props: { ? planMobileScopedSettingsClear(targets, ["pullRequestFeed"]) : planMobileScopedSettingsPatch(targets, true, { pullRequestFeed: rule! }); if (writes.length === 0) return; - setSentOver(presentationById); + const sending = targets.flatMap((target) => + target.projectId === null + ? [] + : [{ environmentId: target.environment.environmentId, projectId: target.projectId, rule }], + ); + setSent(sending); void writeSettings(targets, writes).then((failed) => { - if (failed.length > 0) setSentOver(null); + // Read now: a push that arrived before this reply already answers its target. + const latest = registry.get(environmentServerConfigsAtom); + setSent((current) => + current !== sending + ? current + : sending.flatMap((write) => + failed.includes(write.environmentId) + ? [] + : [{ ...write, repliedOver: latest.get(write.environmentId)?.settings }], + ), + ); }); }; diff --git a/apps/mobile/src/features/settings/sentFeedRules.test.ts b/apps/mobile/src/features/settings/sentFeedRules.test.ts new file mode 100644 index 0000000000000..9fb0e4cd07167 --- /dev/null +++ b/apps/mobile/src/features/settings/sentFeedRules.test.ts @@ -0,0 +1,43 @@ +import { ProjectId } from "@t3tools/contracts"; +import { describe, expect, it } from "vite-plus/test"; + +import { openSentFeedRules } from "./sentFeedRules"; + +describe("feed rules sent from the overview", () => { + const web = ProjectId.make("web"); + const inherits = { projectSettingsOverrides: {} }; + const hidden = { projectSettingsOverrides: { [web]: { pullRequestFeed: "hidden" as const } } }; + + it("keeps a reset across two servers open until the second one shows it", () => { + const sent = [ + { environmentId: "laptop", projectId: web, rule: undefined }, + { environmentId: "server", projectId: web, rule: undefined }, + ]; + const settings: Record