History

feat(environments): draw each environment as the machine it runs on (#9299)

Julius Marminge committed 2 months ago

Commit 0fbb9421 parent d89764132 files · +1222 −84Browse files

Showing the changes to apps/web/src/components/pullRequest/pullRequestProjectAssignment.logic.ts (1 of 32 files). Show all

Unified · Split

apps/web/src/components/pullRequest/pullRequestProjectAssignment.logic.ts+13−6
@@ -1,4 +1,4 @@
1import type { EnvironmentId, ProjectId } from "@t3tools/contracts";1import type { EnvironmentId, EnvironmentMachineKind, ProjectId } from "@t3tools/contracts";
2 2
3/** The little of a project this needs: who holds it, and which repository it is a copy of. */3/** The little of a project this needs: who holds it, and which repository it is a copy of. */
4export interface AssignableProject {4export interface AssignableProject {
@@ -69,6 +69,7 @@ export interface PickableEnvironment { · 64 unmodified lines
69 readonly projectId: ProjectId;69 readonly projectId: ProjectId;
70 readonly workspaceRoot: string;70 readonly workspaceRoot: string;
71 readonly label: string;71 readonly label: string;
72 readonly machine?: EnvironmentMachineKind;
72}73}
73 74
74/**75/**
@@ -85,17 +86,21 @@ export interface PickableEnvironment { · 10 unmodified lines
85export function resolvePickableEnvironments(86export function resolvePickableEnvironments(
86 current: { readonly environmentId: EnvironmentId; readonly projectId: ProjectId },87 current: { readonly environmentId: EnvironmentId; readonly projectId: ProjectId },
87 projects: ReadonlyArray<AssignableProject & { readonly workspaceRoot: string }>,88 projects: ReadonlyArray<AssignableProject & { readonly workspaceRoot: string }>,
88 environments: ReadonlyArray<{ readonly environmentId: EnvironmentId; readonly label: string }>,89 environments: ReadonlyArray<{
90 readonly environmentId: EnvironmentId;
91 readonly label: string;
92 readonly machine?: EnvironmentMachineKind;
93 }>,
89): ReadonlyArray<PickableEnvironment> {94): ReadonlyArray<PickableEnvironment> {
90 const own = projects.find(95 const own = projects.find(
91 (project) =>96 (project) =>
92 project.environmentId === current.environmentId && project.id === current.projectId,97 project.environmentId === current.environmentId && project.id === current.projectId,
93 );98 );
94 const key = own === undefined ? undefined : repositoryKey(own);99 const key = own === undefined ? undefined : repositoryKey(own);
95 const ownLabel = environments.find(100 const ownEnvironment = environments.find(
96 (environment) => environment.environmentId === current.environmentId,101 (environment) => environment.environmentId === current.environmentId,
97 )?.label;102 );
98 if (own === undefined || !key || ownLabel === undefined) return [];103 if (own === undefined || !key || ownEnvironment === undefined) return [];
99 const others = environments.flatMap((environment) => {104 const others = environments.flatMap((environment) => {
100 if (environment.environmentId === current.environmentId) return [];105 if (environment.environmentId === current.environmentId) return [];
101 // One entry per server, whichever copy comes first: a server holding two worktrees of the106 // One entry per server, whichever copy comes first: a server holding two worktrees of the
@@ -112,6 +117,7 @@ export function resolvePickableEnvironments( · 10 unmodified lines
112 projectId: copy.id,117 projectId: copy.id,
113 workspaceRoot: copy.workspaceRoot,118 workspaceRoot: copy.workspaceRoot,
114 label: environment.label,119 label: environment.label,
120 ...(environment.machine === undefined ? {} : { machine: environment.machine }),
115 },121 },
116 ];122 ];
117 });123 });
@@ -123,7 +129,8 @@ export function resolvePickableEnvironments( · 5 unmodified lines
123 environmentId: current.environmentId,129 environmentId: current.environmentId,
124 projectId: own.id,130 projectId: own.id,
125 workspaceRoot: own.workspaceRoot,131 workspaceRoot: own.workspaceRoot,
126 label: ownLabel,132 label: ownEnvironment.label,
133 ...(ownEnvironment.machine === undefined ? {} : { machine: ownEnvironment.machine }),
127 },134 },
128 ...others,135 ...others,
129 ];136 ];