GeezerVison is showing github.com — fix(web): an unreachable environment no longer hides pull requests fr… · pingdotgg/t3code@f77656e
File treeExpand file treeCollapse file tree Open diff view settings apps/web/src/components/pullRequest
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/pullRequestProjectAssignment.logic.test.ts +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,6 +50,20 @@ describe("one server per repository", () => { | 50 | 50 | expect(plain(assignment)).toEqual({ "env-2": ["a2"] }); | 51 | 51 | }); | 52 | 52 |
| | 53 | + it("lets a reachable server list a repository an unreachable one also holds", () => { | | 54 | + const assignment = assignProjectsToEnvironments( | | 55 | + [ | | 56 | + project("a1", "env-1", "github.com/acme/app"), | | 57 | + project("b1", "env-1", "github.com/acme/tools"), | | 58 | + project("a2", "env-2", "github.com/acme/app"), | | 59 | + ], | | 60 | + envs("env-1", "env-2"), | | 61 | + "env-1" as EnvironmentId, | | 62 | + new Set(envs("env-1")), | | 63 | + ); | | 64 | + expect(plain(assignment)).toEqual({ "env-1": ["b1"], "env-2": ["a2"] }); | | 65 | + }); | | 66 | + | 53 | 67 | it("keeps every copy of a project that has no identity to compare", () => { | 54 | 68 | const assignment = assignProjectsToEnvironments( | 55 | 69 | [project("p1", "env-1"), project("p2", "env-2")], | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/pullRequestProjectAssignment.logic.ts +9-10Lines changed: 9 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,24 +14,23 @@ export function assignProjectsToEnvironments( | 14 | 14 | projects: ReadonlyArray<AssignableProject>, | 15 | 15 | environmentIds: ReadonlyArray<EnvironmentId>, | 16 | 16 | preferredEnvironmentId?: EnvironmentId | null, | | 17 | + unreachableEnvironmentIds: ReadonlySet<EnvironmentId> = new Set(), | 17 | 18 | ): Map<EnvironmentId, ProjectId[]> { | 18 | | - const rank = new Map(environmentIds.map((id, index) => [id, index] as const)); | | 19 | + const priority = (id: EnvironmentId) => | | 20 | + (unreachableEnvironmentIds.has(id) ? 2 : 0) + (id === preferredEnvironmentId ? 0 : 1); | | 21 | + const rank = new Map( | | 22 | + environmentIds | | 23 | + .toSorted((left, right) => priority(left) - priority(right)) | | 24 | + .map((id, index) => [id, index] as const), | | 25 | + ); | 19 | 26 | const owner = new Map<string, EnvironmentId>(); | 20 | 27 | for (const project of projects) { | 21 | 28 | const key = repositoryKey(project); | 22 | 29 | if (!key) continue; | 23 | 30 | const environmentRank = rank.get(project.environmentId); | 24 | 31 | if (environmentRank === undefined) continue; | 25 | 32 | const current = owner.get(key); | 26 | | - if (current === undefined) { | 27 | | - owner.set(key, project.environmentId); | 28 | | - continue; | 29 | | - } | 30 | | - if (current === preferredEnvironmentId) continue; | 31 | | - if ( | 32 | | - project.environmentId === preferredEnvironmentId || | 33 | | - environmentRank < (rank.get(current) ?? Number.MAX_SAFE_INTEGER) | 34 | | - ) { | | 33 | + if (current === undefined || environmentRank < (rank.get(current) ?? Number.MAX_SAFE_INTEGER)) { | 35 | 34 | owner.set(key, project.environmentId); | 36 | 35 | } | 37 | 36 | } | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/usePullRequestListView.ts +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,7 @@ export interface PullRequestsSearch extends PullRequestListPreferences { | 51 | 51 | } | 52 | 52 |
| 53 | 53 | const SEARCH_DEBOUNCE_MS = 250; | | 54 | +const UNREACHABLE_PHASES = new Set(["offline", "reconnecting", "error", "unsupported"]); | 54 | 55 |
| 55 | 56 | /** Which servers and projects the page reads, from the URL and what this client knows. */ | 56 | 57 | export function usePullRequestScope(search: PullRequestsSearch) { | @@ -120,10 +121,16 @@ export function usePullRequestScope(search: PullRequestsSearch) { | 120 | 121 | }> => { | 121 | 122 | const plain = queryEnvironmentIds.map((environmentId) => ({ environmentId })); | 122 | 123 | if (!projectsKnown || scopedProjectId !== undefined) return plain; | | 124 | + const unreachable = new Set( | | 125 | + environments.flatMap((environment) => | | 126 | + UNREACHABLE_PHASES.has(environment.connection.phase) ? [environment.environmentId] : [], | | 127 | + ), | | 128 | + ); | 123 | 129 | const assignment = assignProjectsToEnvironments( | 124 | 130 | projects, | 125 | 131 | queryEnvironmentIds, | 126 | 132 | queryEnvironmentIds[0], | | 133 | + unreachable, | 127 | 134 | ); | 128 | 135 | const totals = new Map<EnvironmentId, number>(); | 129 | 136 | for (const project of projects) { | |
|