32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import type { RelayClientEnvironmentRecord } from "@t3tools/contracts/relay";
|
|
import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types";
|
|
|
|
export interface EnvironmentSectionsInput {
|
|
readonly connectedEnvironments: ReadonlyArray<ConnectedEnvironmentSummary>;
|
|
readonly cloudEnvironments: ReadonlyArray<RelayClientEnvironmentRecord> | null;
|
|
}
|
|
|
|
export interface EnvironmentSections {
|
|
readonly localEnvironments: ReadonlyArray<ConnectedEnvironmentSummary>;
|
|
readonly connectedCloudEnvironments: ReadonlyArray<ConnectedEnvironmentSummary>;
|
|
readonly availableCloudEnvironments: ReadonlyArray<RelayClientEnvironmentRecord>;
|
|
}
|
|
|
|
export function splitEnvironmentSections(input: EnvironmentSectionsInput): EnvironmentSections {
|
|
const savedEnvironmentIds = new Set(
|
|
input.connectedEnvironments.map((environment) => environment.environmentId),
|
|
);
|
|
|
|
return {
|
|
localEnvironments: input.connectedEnvironments.filter(
|
|
(environment) => !environment.isRelayManaged,
|
|
),
|
|
connectedCloudEnvironments: input.connectedEnvironments.filter(
|
|
(environment) => environment.isRelayManaged,
|
|
),
|
|
availableCloudEnvironments: (input.cloudEnvironments ?? []).filter(
|
|
(environment) => !savedEnvironmentIds.has(environment.environmentId),
|
|
),
|
|
};
|
|
}
|