Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AddProjectScreen.logic.ts

42 lines1.4 KB

1import { canCreateProjectInEnvironment } from "@t3tools/client-runtime/operations/projects";
2import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
3import { type EnvironmentId, FilesystemBrowseError } from "@t3tools/contracts";
4import * as Schema from "effect/Schema";
5​
6const isFilesystemBrowseError = Schema.is(FilesystemBrowseError);
7​
8/** Clone destinations may name folders that do not exist yet; cloning creates them. */
9export function isMissingCloneParentBrowseFailure(input: {
10 readonly cloning: boolean;
11 readonly failure: unknown;
12}): boolean {
13 return (
14 input.cloning &&
15 isFilesystemBrowseError(input.failure) &&
16 input.failure.failure === "read_directory_failed" &&
17 input.failure.pathMissing === true
18 );
20​
21export function resolveAddProjectEnvironment<
22 T extends {
23 readonly environmentId: EnvironmentId;
24 readonly connectionState: EnvironmentConnectionPhase;
25 },
26>(environmentOptions: ReadonlyArray<T>, requestedEnvironmentId: EnvironmentId | null): T | null {
27 if (requestedEnvironmentId !== null) {
28 return (
29 environmentOptions.find(
30 (environment) =>
31 environment.environmentId === requestedEnvironmentId &&
32 canCreateProjectInEnvironment(environment.connectionState),
33 ) ?? null
34 );
35 }
36​
37 return (
38 environmentOptions.find((environment) =>
39 canCreateProjectInEnvironment(environment.connectionState),
40 ) ?? null
41 );