feat: publish and synchronize workspace drafts
This commit is contained in:
@@ -113,7 +113,7 @@ function Section({ title, children }: { title: string; children: React.ReactNode
|
||||
|
||||
const fieldClass = "h-9 w-full rounded-md border border-input bg-background px-2.5 text-sm shadow-xs outline-none focus-visible:ring-3 focus-visible:ring-ring/25 aria-invalid:border-destructive";
|
||||
|
||||
export function WorkspaceEditor({ draft, onSaveDraft, onPublish: _onPublish, idLocked = Boolean(draft?.baseBlob) }: WorkspaceEditorProps) {
|
||||
export function WorkspaceEditor({ draft, onSaveDraft, onPublish, idLocked = Boolean(draft?.baseBlob) }: WorkspaceEditorProps) {
|
||||
const [workspace, setWorkspace] = useState<CanonicalWorkspace>(draft?.workspace ?? emptyWorkspace());
|
||||
const [errors, setErrors] = useState<FieldErrors>({});
|
||||
const allowedModels = useMemo(() => workspace.llm_policy.allowed.join(", "), [workspace.llm_policy.allowed]);
|
||||
@@ -144,6 +144,17 @@ export function WorkspaceEditor({ draft, onSaveDraft, onPublish: _onPublish, idL
|
||||
});
|
||||
}
|
||||
|
||||
function publishDraft() {
|
||||
const nextErrors = validate(workspace);
|
||||
setErrors(nextErrors);
|
||||
if (Object.keys(nextErrors).length) return;
|
||||
const baseCommit = draft?.baseCommit ?? EMPTY_COMMIT;
|
||||
const request: PublishWorkspaceRequest = draft?.baseBlob
|
||||
? { action: "update", workspace, baseCommit, baseBlob: draft.baseBlob }
|
||||
: { action: "create", workspace, baseCommit };
|
||||
void onPublish(request);
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="grid gap-6" onSubmit={(event) => { event.preventDefault(); saveDraft(); }} noValidate>
|
||||
<Section title="General">
|
||||
@@ -228,8 +239,9 @@ export function WorkspaceEditor({ draft, onSaveDraft, onPublish: _onPublish, idL
|
||||
<p className="sm:col-span-2 text-sm text-muted-foreground">Hosts, users, secret-file paths, and credentials are installation bindings. They are intentionally not editable or stored in workspace drafts.</p>
|
||||
</Section>
|
||||
|
||||
<div className="flex justify-end border-t border-border/70 pt-4">
|
||||
<Button type="submit">Save draft</Button>
|
||||
<div className="flex justify-end gap-2 border-t border-border/70 pt-4">
|
||||
<Button type="submit" variant="outline">Save draft</Button>
|
||||
<Button type="button" onClick={publishDraft}>Publish draft</Button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user