Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

2.4 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

import { Button } from "@/components/ui/button";
import {
  Dialog,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog";
import { Textarea } from "@/components/ui/textarea";
import { type ReactElement, useState } from "react";
import { FieldLabel } from "./shared/field-label";
import { RecipeDialogContent } from "./shared/recipe-dialog-content";

type ImportDialogProps = {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  onImport: (value: string) => string | null;
  container?: HTMLDivElement | null;
};

export function ImportDialog({
  open,
  onOpenChange,
  onImport,
  container,
}: ImportDialogProps): ReactElement {
  const [value, setValue] = useState("");
  const [error, setError] = useState<string | null>(null);
  const payloadId = "recipe-import-payload";
  const handleOpenChange = (nextOpen: boolean) => {
    if (!nextOpen) {
      setValue("");
      setError(null);
    }
    onOpenChange(nextOpen);
  };

  const handleImport = () => {
    const message = onImport(value);
    if (message) {
      setError(message);
      return;
    }
    handleOpenChange(false);
  };

  return (
    <Dialog open={open} onOpenChange={handleOpenChange}>
      <RecipeDialogContent
        container={container}
        viewportClassName="overflow-auto"
      >
        <DialogHeader>
          <DialogTitle>Import recipe</DialogTitle>
        </DialogHeader>
        <div className="grid gap-1.5">
          <FieldLabel
            label="Recipe JSON"
            htmlFor={payloadId}
            hint="Paste JSON exported from Recipe Studio."
          />
          <Textarea
            id={payloadId}
            className="corner-squircle nodrag min-h-[calc(220px*var(--ui-space-scale,1))] max-h-[calc(450px*var(--ui-space-scale,1))]"
            placeholder='{"recipe": { "columns": [] }}'
            value={value}
            onChange={(event) => setValue(event.target.value)}
          />
          {error && (
            <p className="text-xs text-rose-600" role="alert">
              {error}
            </p>
          )}
        </div>
        <DialogFooter>
          <Button type="button" variant="outline" onClick={handleImport}>
            Import recipe
          </Button>
        </DialogFooter>
      </RecipeDialogContent>
    </Dialog>
  );
}