forked from Dimillian/CodexMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsEnvironmentsSection.tsx
More file actions
184 lines (178 loc) · 6.83 KB
/
Copy pathSettingsEnvironmentsSection.tsx
File metadata and controls
184 lines (178 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import type { Dispatch, SetStateAction } from "react";
import { SettingsSection } from "@/features/design-system/components/settings/SettingsPrimitives";
import type { WorkspaceInfo } from "@/types";
import { pushErrorToast } from "@services/toasts";
type SettingsEnvironmentsSectionProps = {
mainWorkspaces: WorkspaceInfo[];
environmentWorkspace: WorkspaceInfo | null;
environmentSaving: boolean;
environmentError: string | null;
environmentDraftScript: string;
environmentSavedScript: string | null;
environmentDirty: boolean;
worktreesFolderDraft: string;
worktreesFolderSaved: string | null;
worktreesFolderDirty: boolean;
onSetEnvironmentWorkspaceId: Dispatch<SetStateAction<string | null>>;
onSetEnvironmentDraftScript: Dispatch<SetStateAction<string>>;
onSetWorktreesFolderDraft: Dispatch<SetStateAction<string>>;
onSaveEnvironmentSetup: () => Promise<void>;
};
export function SettingsEnvironmentsSection({
mainWorkspaces,
environmentWorkspace,
environmentSaving,
environmentError,
environmentDraftScript,
environmentSavedScript,
environmentDirty,
worktreesFolderDraft,
worktreesFolderSaved: _worktreesFolderSaved,
worktreesFolderDirty,
onSetEnvironmentWorkspaceId,
onSetEnvironmentDraftScript,
onSetWorktreesFolderDraft,
onSaveEnvironmentSetup,
}: SettingsEnvironmentsSectionProps) {
const hasAnyChanges = environmentDirty || worktreesFolderDirty;
return (
<SettingsSection
title="Environments"
subtitle="Configure per-project setup scripts and worktree locations."
>
{mainWorkspaces.length === 0 ? (
<div className="settings-empty">No projects yet.</div>
) : (
<>
<div className="settings-field">
<label className="settings-field-label" htmlFor="settings-environment-project">
Project
</label>
<select
id="settings-environment-project"
className="settings-select"
value={environmentWorkspace?.id ?? ""}
onChange={(event) => onSetEnvironmentWorkspaceId(event.target.value)}
disabled={environmentSaving}
>
{mainWorkspaces.map((workspace) => (
<option key={workspace.id} value={workspace.id}>
{workspace.name}
</option>
))}
</select>
{environmentWorkspace ? (
<div className="settings-help">{environmentWorkspace.path}</div>
) : null}
</div>
<div className="settings-field">
<div className="settings-field-label">Setup script</div>
<div className="settings-help">
Runs once in a dedicated terminal after each new worktree is created.
</div>
{environmentError ? (
<div className="settings-agents-error">{environmentError}</div>
) : null}
<textarea
className="settings-agents-textarea"
value={environmentDraftScript}
onChange={(event) => onSetEnvironmentDraftScript(event.target.value)}
placeholder="pnpm install"
spellCheck={false}
disabled={environmentSaving}
/>
<div className="settings-field-actions">
<button
type="button"
className="ghost settings-button-compact"
onClick={() => {
const clipboard = typeof navigator === "undefined" ? null : navigator.clipboard;
if (!clipboard?.writeText) {
pushErrorToast({
title: "Copy failed",
message:
"Clipboard access is unavailable in this environment. Copy the script manually instead.",
});
return;
}
void clipboard.writeText(environmentDraftScript).catch(() => {
pushErrorToast({
title: "Copy failed",
message:
"Could not write to the clipboard. Copy the script manually instead.",
});
});
}}
disabled={environmentSaving || environmentDraftScript.length === 0}
>
Copy
</button>
<button
type="button"
className="ghost settings-button-compact"
onClick={() => onSetEnvironmentDraftScript(environmentSavedScript ?? "")}
disabled={environmentSaving || !environmentDirty}
>
Reset
</button>
<button
type="button"
className="primary settings-button-compact"
onClick={() => {
void onSaveEnvironmentSetup();
}}
disabled={environmentSaving || !hasAnyChanges}
>
{environmentSaving ? "Saving..." : "Save"}
</button>
</div>
</div>
<div className="settings-field">
<label className="settings-field-label" htmlFor="settings-worktrees-folder">
Worktrees folder
</label>
<div className="settings-help">
Custom location for worktrees. Leave empty to use the default location.
</div>
<div className="settings-field-row">
<input
id="settings-worktrees-folder"
type="text"
className="settings-input"
value={worktreesFolderDraft}
onChange={(event) => onSetWorktreesFolderDraft(event.target.value)}
placeholder="/path/to/worktrees"
disabled={environmentSaving}
/>
<button
type="button"
className="ghost settings-button-compact"
onClick={async () => {
try {
const { open } = await import("@tauri-apps/plugin-dialog");
const selected = await open({
directory: true,
multiple: false,
title: "Select worktrees folder",
});
if (selected && typeof selected === "string") {
onSetWorktreesFolderDraft(selected);
}
} catch (error) {
pushErrorToast({
title: "Failed to open folder picker",
message: error instanceof Error ? error.message : String(error),
});
}
}}
disabled={environmentSaving}
>
Browse
</button>
</div>
</div>
</>
)}
</SettingsSection>
);
}