This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git


The following commit(s) were added to refs/heads/main by this push:
     new 8420565e66 feat(notebook-migration): add r notebooks to the import 
modal (#8912)
8420565e66 is described below

commit 8420565e66fd226bb9158fd41aed894d41da70a1
Author: Ryan Zhang <[email protected]>
AuthorDate: Tue Nov 10 07:29:50 2026 +0000

    feat(notebook-migration): add r notebooks to the import modal (#8912)
    
    ### What changes were proposed in this PR?
    
    This PR lets users convert R Jupyter notebooks, using the R conversion
    from #8911. It is the first of the UI PRs for R support (#8009). R files
    follow in #8963 and R folders in a later PR, each as a new tab beside
    the Python ones.
    
    **Import modal.** The Jupyter Notebook tab gets a "Python Notebook | R
    Notebook" switch, centered above the diagram. It defaults to Python. The
    diagram, the description and the upload label follow it, and changing it
    clears the staged file. The switch is a `FormControl`, so it keeps its
    value when the tab re-renders. `requestImport` now receives a
    `language`.
    
    **Disabled, not hidden.** When `rNotebookMigrationEnabled` is off, the R
    Notebook option stays visible but disabled, with the tooltip "R is not
    enabled on this deployment." Users can see that R exists without being
    able to pick it on a deployment that cannot run it. The guard from #8911
    still refuses R in that case, before any model call.
    
    **Tab descriptors.** A small `IMPORT_TABS` list replaces the index
    checks that decided the folder tab and the language. The R file and
    folder tabs each add one entry.
    
    **Dispatch.** The dashboard passes the language to the notebook
    conversion. For R, only `.ipynb` is accepted in this PR. A notebook
    uploaded as R whose `kernelspec.language` is set and is not R is
    rejected before any model call: "This notebook uses a python kernel, not
    R. Switch the notebook type to Python Notebook." A notebook without a
    kernelspec is accepted. Other language mismatches are tracked in #8929.
    
    **Assets.** A new R notebook diagram, at the same size and border as the
    others. `frontend/LICENSE-binary` adds it to the Project Jupyter logo
    and Material Symbols entries.
    
    #### Demo video (wait time cut out)
    
    
    
https://github.com/user-attachments/assets/9769bdd8-5e2d-4994-8a5a-be216908b09f
    
    #### R disabled on a deployment without R
    
    <img width="420" height="159" alt="Screenshot 2026-10-12 at 1 51 42 PM"
    
src="https://github.com/user-attachments/assets/2c45ea97-9fe2-4b3c-a8ec-4fc2a8875d22";
    />
    
    ### Any related issues, documentation, discussions?
    
    Closes #9384
    Part of #8009
    Parent-issue #4301
    
    The plan is in https://github.com/apache/texera/discussions/8866. R
    notebooks open in the Jupyter panel without a kernel, since the Jupyter
    image has no R kernel. #8909 removed the "Kernel not found" dialog that
    otherwise appears and keeps the cells read only.
    
    ### How was this PR tested?
    
    * `notebook-import-modal.component.spec.ts`, seven new tests: Python is
    the default; the R option is disabled with its tooltip while the R flag
    is off and enabled without one while it is on; switching to R changes
    the diagram and label and drops the staged notebook; R stays selected
    across a re-render; the file and folder tabs keep their own language;
    and submit passes `"r"`. Existing assertions now expect `"python"`.
    * `user-workflow.component.spec.ts`, five new tests: a Python notebook
    converts as Python by default, an R notebook converts as R with or
    without a kernelspec, a Python kernel notebook is rejected as R, and a
    non notebook file is rejected as R.
    
    The full frontend suite passes.
    
    Checked by hand against a local stack. With the R flag on, the switch
    changes the diagram, description and label, clears a staged file, and
    survives leaving and returning to the tab. With it off, the R option is
    disabled and shows its tooltip. The tab fits the modal without scrolling
    in every state. An R notebook converted end to end with a live model.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (Claude Opus 5.5)
---
 frontend/LICENSE-binary                            |   2 +
 .../user-workflow/user-workflow.component.spec.ts  |  82 +++++++++++++++--
 .../user/user-workflow/user-workflow.component.ts  |  28 ++++--
 .../notebook-import-modal.component.html           |  46 +++++++++-
 .../notebook-import-modal.component.scss           |   5 ++
 .../notebook-import-modal.component.spec.ts        | 100 +++++++++++++++++++--
 .../notebook-import-modal.component.ts             |  59 ++++++++++--
 .../notebook_migration_tool/r_notebook_diagram.png | Bin 0 -> 100313 bytes
 8 files changed, 295 insertions(+), 27 deletions(-)

diff --git a/frontend/LICENSE-binary b/frontend/LICENSE-binary
index 9985b1af15..15b79c0e03 100644
--- a/frontend/LICENSE-binary
+++ b/frontend/LICENSE-binary
@@ -229,6 +229,7 @@ Third-party assets:
     frontend/src/assets/notebook_migration_tool/tool_popup_diagram.png
     frontend/src/assets/notebook_migration_tool/python_file_diagram.png
     frontend/src/assets/notebook_migration_tool/python_folder_diagram.png
+    frontend/src/assets/notebook_migration_tool/r_notebook_diagram.png
     https://github.com/google/material-design-icons
   - Google Material Symbols icons (area_chart, autorenew, batch_prediction, 
forest, join_inner, merge, table_chart, tune)
     frontend/src/assets/operator_images/FigureFactoryTable.png
@@ -495,6 +496,7 @@ Angular / npm packages:
 Third-party assets:
   - Project Jupyter logo
     frontend/src/assets/notebook_migration_tool/tool_popup_diagram.png
+    frontend/src/assets/notebook_migration_tool/r_notebook_diagram.png
     https://github.com/jupyter/design
 
 
--------------------------------------------------------------------------------
diff --git 
a/frontend/src/app/dashboard/component/user/user-workflow/user-workflow.component.spec.ts
 
b/frontend/src/app/dashboard/component/user/user-workflow/user-workflow.component.spec.ts
index 26373628c6..9d8f0c55a9 100644
--- 
a/frontend/src/app/dashboard/component/user/user-workflow/user-workflow.component.spec.ts
+++ 
b/frontend/src/app/dashboard/component/user/user-workflow/user-workflow.component.spec.ts
@@ -74,8 +74,12 @@ import { NotebookMigrationService } from 
"../../../../workspace/service/notebook
 import {
   LlmRequestTimeoutError,
   LlmResponseTruncatedError,
+  MigrationLanguage,
 } from "../../../../workspace/service/notebook-migration/migration-llm";
-import { NotebookImportModalComponent } from 
"../../../../workspace/component/notebook-import-modal/notebook-import-modal.component";
+import {
+  NotebookImportModalComponent,
+  NotebookImportModalData,
+} from 
"../../../../workspace/component/notebook-import-modal/notebook-import-modal.component";
 import { NzUploadFile } from "ng-zorro-antd/upload";
 import type { Mocked } from "vitest";
 describe("SavedWorkflowSectionComponent", () => {
@@ -322,16 +326,17 @@ describe("SavedWorkflowSectionComponent", () => {
 
     // Opens the modal and returns the requestImport callback the component 
handed to it; calling
     // it runs the full generation (true => generation succeeded and 
navigated, false => stay open).
-    function getRequestImport(): (selection: NzUploadFile | NzUploadFile[], 
model: string) => Promise<boolean> {
+    function getRequestImport(): (
+      selection: NzUploadFile | NzUploadFile[],
+      model: string,
+      language?: MigrationLanguage
+    ) => Promise<boolean> {
       const modalService = TestBed.inject(NzModalService);
       const createSpy = vi.spyOn(modalService, "create").mockReturnValue({} as 
unknown as NzModalRef);
       component.openAiGenerateModal();
       const config = createSpy.mock.calls[0][0] as ModalOptions;
-      return (
-        config.nzData as {
-          requestImport: (selection: NzUploadFile | NzUploadFile[], model: 
string) => Promise<boolean>;
-        }
-      ).requestImport;
+      const requestImport = (config.nzData as 
NotebookImportModalData).requestImport;
+      return (selection, model, language = "python") => 
requestImport(selection, model, language);
     }
 
     // Wires the NotebookMigrationService + persistence mocks for a successful 
generation.
@@ -419,6 +424,69 @@ describe("SavedWorkflowSectionComponent", () => {
       expect(scriptSpy).not.toHaveBeenCalled();
     });
 
+    describe("R notebook input", () => {
+      const rNotebook = { cells: [], metadata: { kernelspec: { language: "R" } 
} };
+
+      function mockRGenerationSuccess(notebook: unknown = rNotebook) {
+        const { storeSpy } = mockGenerationSuccess(7);
+        const migration = TestBed.inject(NotebookMigrationService);
+        vi.mocked(migration.parseAndTagNotebook).mockResolvedValue(notebook as 
any);
+        vi.spyOn(TestBed.inject(Router), "navigate").mockResolvedValue(true);
+        return { migration, storeSpy };
+      }
+
+      it("converts a Python notebook as Python by default", async () => {
+        const { migration } = mockRGenerationSuccess({ cells: [] });
+
+        await getRequestImport()(ipynbFile, "gpt-4");
+
+        expect(migration.sendToAIGenerateWorkflow).toHaveBeenCalledWith({ 
cells: [] }, "gpt-4", "python");
+      });
+
+      it("converts an R notebook as R", async () => {
+        const { migration } = mockRGenerationSuccess();
+
+        const proceed = await getRequestImport()(ipynbFile, "gpt-4", "r");
+
+        
expect(migration.sendToAIGenerateWorkflow).toHaveBeenCalledWith(rNotebook, 
"gpt-4", "r");
+        expect(proceed).toBe(true);
+      });
+
+      it("converts a notebook with no kernelspec as R", async () => {
+        const { migration } = mockRGenerationSuccess({ cells: [] });
+
+        await getRequestImport()(ipynbFile, "gpt-4", "r");
+
+        expect(migration.sendToAIGenerateWorkflow).toHaveBeenCalledWith({ 
cells: [] }, "gpt-4", "r");
+      });
+
+      it("rejects a notebook whose kernel is not R", async () => {
+        const { migration } = mockRGenerationSuccess({ cells: [], metadata: { 
kernelspec: { language: "python" } } });
+        const errorSpy = vi.spyOn(TestBed.inject(NotificationService), 
"error").mockImplementation(() => {});
+
+        const proceed = await getRequestImport()(ipynbFile, "gpt-4", "r");
+
+        expect(proceed).toBe(false);
+        expect(errorSpy).toHaveBeenCalledWith(
+          "This notebook uses a python kernel, not R. Switch the notebook type 
to Python Notebook."
+        );
+        expect(migration.sendToAIGenerateWorkflow).not.toHaveBeenCalled();
+      });
+
+      it("rejects anything but a notebook for R", async () => {
+        const { migration } = mockRGenerationSuccess();
+        const scriptSpy = vi.spyOn(migration, "parseScriptFile");
+        const errorSpy = vi.spyOn(TestBed.inject(NotificationService), 
"error").mockImplementation(() => {});
+
+        const proceed = await getRequestImport()({ name: "analysis.R" } as 
NzUploadFile, "gpt-4", "r");
+
+        expect(proceed).toBe(false);
+        expect(errorSpy).toHaveBeenCalledWith("Please upload an R Jupyter 
Notebook (.ipynb).");
+        expect(migration.parseAndTagNotebook).not.toHaveBeenCalled();
+        expect(scriptSpy).not.toHaveBeenCalled();
+      });
+    });
+
     // A .py takes the other branch: read as text, converted by the script 
method, and the
     // notebook it stores is the one the LLM derived rather than an uploaded 
file.
     describe("Python file input", () => {
diff --git 
a/frontend/src/app/dashboard/component/user/user-workflow/user-workflow.component.ts
 
b/frontend/src/app/dashboard/component/user/user-workflow/user-workflow.component.ts
index 06f498a80f..485f183639 100644
--- 
a/frontend/src/app/dashboard/component/user/user-workflow/user-workflow.component.ts
+++ 
b/frontend/src/app/dashboard/component/user/user-workflow/user-workflow.component.ts
@@ -49,6 +49,7 @@ import {
 import {
   LlmRequestTimeoutError,
   LlmResponseTruncatedError,
+  MigrationLanguage,
   Notebook,
 } from "../../../../workspace/service/notebook-migration/migration-llm";
 import {
@@ -300,7 +301,7 @@ export class UserWorkflowComponent implements 
AfterViewInit, OnDestroy {
       nzCentered: true,
       nzBodyStyle: { paddingTop: "4px" },
       nzData: {
-        requestImport: (selection, model) => 
this.generateWorkflowFromSelection(selection, model),
+        requestImport: (selection, model, language) => 
this.generateWorkflowFromSelection(selection, model, language),
       },
     });
   }
@@ -314,7 +315,8 @@ export class UserWorkflowComponent implements 
AfterViewInit, OnDestroy {
    */
   private async generateWorkflowFromSelection(
     selection: NzUploadFile | NzUploadFile[],
-    model: string
+    model: string,
+    language: MigrationLanguage
   ): Promise<boolean> {
     if (Array.isArray(selection)) {
       const generated = await this.generateFromFolder(selection, model);
@@ -326,6 +328,10 @@ export class UserWorkflowComponent implements 
AfterViewInit, OnDestroy {
     }
 
     const fileExtension = selection.name.split(".").pop()?.toLowerCase();
+    if (language === "r" && fileExtension !== "ipynb") {
+      this.notificationService.error("Please upload an R Jupyter Notebook 
(.ipynb).");
+      return false;
+    }
     if (fileExtension !== "ipynb" && fileExtension !== "py") {
       this.notificationService.error("Please upload a Jupyter Notebook 
(.ipynb) or a Python (.py) file.");
       return false;
@@ -333,7 +339,7 @@ export class UserWorkflowComponent implements 
AfterViewInit, OnDestroy {
 
     const generated =
       fileExtension === "ipynb"
-        ? await this.generateFromNotebook(selection, model)
+        ? await this.generateFromNotebook(selection, model, language)
         : await this.generateFromScript(selection, model);
     if (!generated) {
       return false;
@@ -343,7 +349,11 @@ export class UserWorkflowComponent implements 
AfterViewInit, OnDestroy {
   }
 
   /** Read and convert an .ipynb. Null after reporting a read or generation 
failure. */
-  private async generateFromNotebook(file: NzUploadFile, model: string): 
Promise<GeneratedWorkflowContent | null> {
+  private async generateFromNotebook(
+    file: NzUploadFile,
+    model: string,
+    language: MigrationLanguage
+  ): Promise<GeneratedWorkflowContent | null> {
     let notebook: Notebook;
     try {
       notebook = await this.notebookMigrationService.parseAndTagNotebook(file 
as unknown as File);
@@ -353,8 +363,16 @@ export class UserWorkflowComponent implements 
AfterViewInit, OnDestroy {
       return null;
     }
 
+    const kernelLanguage = notebook.metadata?.["kernelspec"]?.language;
+    if (language === "r" && kernelLanguage && 
String(kernelLanguage).toLowerCase() !== "r") {
+      this.notificationService.error(
+        `This notebook uses a ${kernelLanguage} kernel, not R. Switch the 
notebook type to Python Notebook.`
+      );
+      return null;
+    }
+
     try {
-      const generated = await 
this.notebookMigrationService.sendToAIGenerateWorkflow(notebook, model);
+      const generated = await 
this.notebookMigrationService.sendToAIGenerateWorkflow(notebook, model, 
language);
       // The uploaded notebook is what gets stored, so it rides along with the 
generated pair.
       return { ...generated, notebook };
     } catch (error) {
diff --git 
a/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.html
 
b/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.html
index 553b7f6235..b19db81deb 100644
--- 
a/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.html
+++ 
b/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.html
@@ -71,21 +71,60 @@
       (nzSelectedIndexChange)="onTabChange($event)">
       <nz-tab nzTitle="Jupyter Notebook">
         <ng-template nz-tab>
+          <div class="import-modal-language">
+            <nz-segmented
+              [formControl]="notebookLanguage"
+              (nzValueChange)="clearSelection()">
+              <label
+                nz-segmented-item
+                nzValue="python">
+                Python Notebook
+              </label>
+              <label
+                nz-segmented-item
+                nzValue="r"
+                [nzDisabled]="!rMigrationEnabled"
+                nz-tooltip
+                [nzTooltipTitle]="rMigrationEnabled ? null : rDisabledTooltip"
+                [nzTooltipOverlayStyle]="{ 'max-width': 'none' }">
+                R Notebook
+              </label>
+            </nz-segmented>
+          </div>
+
           <div class="import-modal-diagram">
             <img
+              *ngIf="notebookLanguage.value === 'python'; else 
rNotebookDiagram"
               ngSrc="assets/notebook_migration_tool/tool_popup_diagram.png"
               alt="Notebook to Workflow"
               width="1350"
               height="344" />
+            <ng-template #rNotebookDiagram>
+              <img
+                ngSrc="assets/notebook_migration_tool/r_notebook_diagram.png"
+                alt="R Notebook to Workflow"
+                width="1350"
+                height="344" />
+            </ng-template>
           </div>
 
           <nz-form-item>
-            <p class="import-modal-text">
+            <p
+              *ngIf="notebookLanguage.value === 'python'; else rNotebookText"
+              class="import-modal-text">
               This tool converts a Python Jupyter Notebook into a Texera 
workflow using LLM capabilities. After you
               submit a notebook, the LLM service generates a corresponding 
Texera workflow. The conversion time depends
               on the notebook's complexity and can take 1-5 minutes. Once 
generation finishes, you are taken to the new
               workflow, which opens with:
             </p>
+            <ng-template #rNotebookText>
+              <p class="import-modal-text">
+                This tool converts an R Jupyter Notebook into a Texera 
workflow using LLM capabilities. Every generated
+                operator is an R UDF, so the computing unit that runs the 
workflow needs the texera-rudf package
+                installed. The conversion time depends on the notebook's 
complexity and can take 1-5 minutes. Once
+                generation finishes, you are taken to the new workflow, which 
opens with:
+              </p>
+            </ng-template>
             <ol class="import-modal-list">
               <li>
                 The generated workflow ready to use (Note: you will still need 
to upload the dataset and connect it to
@@ -101,7 +140,10 @@
           <ng-container
             *ngTemplateOutlet="
               uploadRow;
-              context: { accept: '.ipynb', label: 'Upload Python Jupyter 
Notebook', action: 'Upload notebook' }
+              context:
+                notebookLanguage.value === 'python'
+                  ? { accept: '.ipynb', label: 'Upload Python Jupyter 
Notebook', action: 'Upload notebook' }
+                  : { accept: '.ipynb', label: 'Upload R Jupyter Notebook', 
action: 'Upload R notebook' }
             "></ng-container>
         </ng-template>
       </nz-tab>
diff --git 
a/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.scss
 
b/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.scss
index 862f9a4f37..a74005b97a 100644
--- 
a/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.scss
+++ 
b/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.scss
@@ -37,6 +37,11 @@
     }
   }
 
+  &-language {
+    text-align: center;
+    margin-bottom: 8px;
+  }
+
   &-diagram {
     text-align: center;
     margin-bottom: 12px;
diff --git 
a/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.spec.ts
 
b/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.spec.ts
index 20d3012d59..531cdb63db 100644
--- 
a/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.spec.ts
+++ 
b/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.spec.ts
@@ -23,11 +23,18 @@ import { NoopAnimationsModule } from 
"@angular/platform-browser/animations";
 import { NZ_MODAL_DATA, NzModalRef } from "ng-zorro-antd/modal";
 import { of, Subject } from "rxjs";
 import { NzUploadFile } from "ng-zorro-antd/upload";
-
-import { DROP_REJECTION_LATCH_MS, NotebookImportModalComponent } from 
"./notebook-import-modal.component";
+import { NzTooltipDirective } from "ng-zorro-antd/tooltip";
+import { By } from "@angular/platform-browser";
+
+import {
+  DROP_REJECTION_LATCH_MS,
+  NotebookImportModalComponent,
+  R_DISABLED_TOOLTIP,
+} from "./notebook-import-modal.component";
 import { NotebookMigrationService } from 
"../../service/notebook-migration/notebook-migration.service";
 import { NotificationService } from 
"../../../common/service/notification/notification.service";
 import { commonTestProviders } from "../../../common/testing/test-utils";
+import { GuiConfigService } from "../../../common/service/gui-config.service";
 
 describe("NotebookImportModalComponent", () => {
   let fixture: ComponentFixture<NotebookImportModalComponent>;
@@ -38,7 +45,7 @@ describe("NotebookImportModalComponent", () => {
   let requestImport: ReturnType<typeof vi.fn>;
 
   // Configures the modal with the given models$ stream, then creates and 
renders it.
-  async function createWith(models$: unknown): Promise<void> {
+  async function createWith(models$: unknown, rNotebookMigrationEnabled = 
false): Promise<void> {
     await TestBed.configureTestingModule({
       imports: [NotebookImportModalComponent, HttpClientTestingModule, 
NoopAnimationsModule],
       providers: [
@@ -47,6 +54,7 @@ describe("NotebookImportModalComponent", () => {
         ...commonTestProviders,
       ],
     }).compileComponents();
+    TestBed.inject(GuiConfigService).env.rNotebookMigrationEnabled = 
rNotebookMigrationEnabled;
 
     notebookMigrationService = TestBed.inject(NotebookMigrationService);
     vi.spyOn(notebookMigrationService, 
"getAvailableModels").mockReturnValue(models$ as any);
@@ -149,7 +157,7 @@ describe("NotebookImportModalComponent", () => {
 
     await component.onSubmit();
 
-    expect(requestImport).toHaveBeenCalledWith(file, "gpt-4");
+    expect(requestImport).toHaveBeenCalledWith(file, "gpt-4", "python");
     expect(modalRef.close).toHaveBeenCalled();
   });
 
@@ -359,7 +367,7 @@ describe("NotebookImportModalComponent", () => {
 
     await component.onSubmit();
 
-    expect(requestImport).toHaveBeenCalledWith(file, "gpt-4");
+    expect(requestImport).toHaveBeenCalledWith(file, "gpt-4", "python");
     expect(modalRef.close).toHaveBeenCalledWith();
   });
 
@@ -391,7 +399,7 @@ describe("NotebookImportModalComponent", () => {
     ).click();
     await fixture.whenStable();
 
-    expect(requestImport).toHaveBeenCalledWith(file, "gpt-4");
+    expect(requestImport).toHaveBeenCalledWith(file, "gpt-4", "python");
     expect(modalRef.close).toHaveBeenCalledWith();
   });
 
@@ -513,7 +521,7 @@ describe("NotebookImportModalComponent", () => {
 
       await component.onSubmit();
 
-      expect(requestImport).toHaveBeenCalledWith(files, "gpt-4");
+      expect(requestImport).toHaveBeenCalledWith(files, "gpt-4", "python");
       expect(modalRef.close).toHaveBeenCalledWith();
     });
 
@@ -618,4 +626,82 @@ describe("NotebookImportModalComponent", () => {
       expect((fixture.nativeElement as 
HTMLElement).textContent).not.toContain("Selected folder");
     });
   });
+
+  describe("notebook language switch", () => {
+    const root = () => fixture.nativeElement as HTMLElement;
+    const pane = () => root().querySelector(".ant-tabs-tabpane-active") as 
HTMLElement;
+    const option = (text: string) =>
+      Array.from(pane().querySelectorAll("label[nz-segmented-item]")).find(
+        label => label.textContent?.trim() === text
+      ) as HTMLElement;
+    const rTooltip = () =>
+      
fixture.debugElement.queryAll(By.directive(NzTooltipDirective))[0].injector.get(NzTooltipDirective).title;
+
+    it("defaults to Python and keeps the Python diagram", async () => {
+      await createWith(of([{ name: "gpt-4" }]), true);
+
+      expect(component.notebookLanguage.value).toBe("python");
+      expect(component.language).toBe("python");
+      expect(pane().querySelector("img[alt='Notebook to 
Workflow']")).not.toBeNull();
+    });
+
+    it("disables R with an explanation while the R flag is off", async () => {
+      await createWith(of([{ name: "gpt-4" }]));
+
+      expect(option("R 
Notebook").classList).toContain("ant-segmented-item-disabled");
+      expect(rTooltip()).toBe(R_DISABLED_TOOLTIP);
+    });
+
+    it("enables R without a tooltip while the R flag is on", async () => {
+      await createWith(of([{ name: "gpt-4" }]), true);
+
+      expect(option("R 
Notebook").classList).not.toContain("ant-segmented-item-disabled");
+      expect(rTooltip()).toBeNull();
+    });
+
+    it("switches to R notebooks and drops the staged notebook", async () => {
+      await createWith(of([{ name: "gpt-4" }]), true);
+      component.importForm.patchValue({ file: { name: "analysis.ipynb" } });
+
+      option("R Notebook").click();
+      fixture.detectChanges();
+
+      expect(component.language).toBe("r");
+      expect(pane().querySelector("img[alt='R Notebook to 
Workflow']")).not.toBeNull();
+      expect(pane().textContent).toContain("Upload R Jupyter Notebook");
+      expect(component.importForm.get("file")?.value).toBeNull();
+    });
+
+    it("keeps R selected when the tab is re-rendered", async () => {
+      await createWith(of([{ name: "gpt-4" }]), true);
+      component.notebookLanguage.setValue("r");
+      component.onTabChange(1);
+      fixture.detectChanges();
+
+      component.onTabChange(0);
+      fixture.detectChanges();
+
+      expect(pane().querySelector("img[alt='R Notebook to 
Workflow']")).not.toBeNull();
+    });
+
+    it("uses each tab's own language outside the notebook tab", async () => {
+      await createWith(of([{ name: "gpt-4" }]), true);
+      component.notebookLanguage.setValue("r");
+
+      component.onTabChange(1);
+
+      expect(component.language).toBe("python");
+    });
+
+    it("submits R notebooks with the R language", async () => {
+      await createWith(of([{ name: "gpt-4" }]), true);
+      component.notebookLanguage.setValue("r");
+      const file = { name: "analysis.ipynb" } as NzUploadFile;
+      component.importForm.setValue({ file, model: "gpt-4" });
+
+      await component.onSubmit();
+
+      expect(requestImport).toHaveBeenCalledWith(file, "gpt-4", "r");
+    });
+  });
 });
diff --git 
a/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.ts
 
b/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.ts
index ef48e3983a..c4fb4a92e0 100644
--- 
a/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.ts
+++ 
b/frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.ts
@@ -18,7 +18,7 @@
  */
 
 import { Component, HostListener, inject, OnDestroy } from "@angular/core";
-import { FormBuilder, FormGroup, Validators, ReactiveFormsModule } from 
"@angular/forms";
+import { FormBuilder, FormControl, FormGroup, Validators, ReactiveFormsModule 
} from "@angular/forms";
 import { NZ_MODAL_DATA, NzModalRef } from "ng-zorro-antd/modal";
 import { NzUploadComponent, NzUploadFile } from "ng-zorro-antd/upload";
 import { Observable } from "rxjs";
@@ -29,17 +29,40 @@ import { NzSpinComponent } from "ng-zorro-antd/spin";
 import { NzButtonComponent } from "ng-zorro-antd/button";
 import { NzIconDirective } from "ng-zorro-antd/icon";
 import { NzTabsComponent, NzTabComponent, NzTabDirective } from 
"ng-zorro-antd/tabs";
+import { NzSegmentedComponent, NzSegmentedItemComponent } from 
"ng-zorro-antd/segmented";
+import { NzTooltipDirective } from "ng-zorro-antd/tooltip";
 import { NotebookMigrationService } from 
"../../service/notebook-migration/notebook-migration.service";
 import { folderRootName, pickedFilePath } from 
"../../service/notebook-migration/folder-assembly";
 import { NotificationService } from 
"../../../common/service/notification/notification.service";
+import { GuiConfigService } from "../../../common/service/gui-config.service";
+import { MigrationLanguage } from 
"../../service/notebook-migration/migration-llm";
 
 // Passed in via nzData. requestImport resolves true to close the modal, false 
to keep it open
 // with the user's selection intact (bad file or a retryable failure). A 
folder is handed over as
 // the whole picked list, which is also how the opener tells a folder from a 
single file.
 export interface NotebookImportModalData {
-  requestImport: (selection: NzUploadFile | NzUploadFile[], model: string) => 
Promise<boolean>;
+  requestImport: (
+    selection: NzUploadFile | NzUploadFile[],
+    model: string,
+    language: MigrationLanguage
+  ) => Promise<boolean>;
 }
 
+export const R_DISABLED_TOOLTIP = "R is not enabled on this deployment.";
+
+interface ImportTab {
+  kind: "notebook" | "file" | "folder";
+  // Absent on the notebook tab, whose language comes from its Python / R 
switch.
+  language?: MigrationLanguage;
+}
+
+// Same order as the tabs in the template.
+const IMPORT_TABS: readonly ImportTab[] = [
+  { kind: "notebook" },
+  { kind: "file", language: "python" },
+  { kind: "folder", language: "python" },
+];
+
 // How long after the last rejected file a drop is treated as over: long 
enough that a slow
 // directory walk stays one burst, short enough that a second drop is reported 
again.
 export const DROP_REJECTION_LATCH_MS = 2000;
@@ -53,7 +76,7 @@ function describeFolderSelection(files: readonly 
NzUploadFile[]): string {
 
 /**
  * The "AI Generate Workflow from Source Code" modal body: a tab per accepted 
input kind
- * (Jupyter notebook, Python script, Python folder), each with its own 
diagram, description and
+ * (Jupyter notebook in Python or R, Python script, Python folder), each with 
its own diagram, description and
  * upload control, over a shared model dropdown and footer.
  *
  * On Submit it hands the selection and model to requestImport and shows a 
loading state until
@@ -79,6 +102,9 @@ function describeFolderSelection(files: readonly 
NzUploadFile[]): string {
     NzTabsComponent,
     NzTabComponent,
     NzTabDirective,
+    NzSegmentedComponent,
+    NzSegmentedItemComponent,
+    NzTooltipDirective,
   ],
 })
 export class NotebookImportModalComponent implements OnDestroy {
@@ -87,6 +113,7 @@ export class NotebookImportModalComponent implements 
OnDestroy {
   private readonly notebookMigrationService = inject(NotebookMigrationService);
   private readonly notificationService = inject(NotificationService);
   private readonly data: NotebookImportModalData = inject(NZ_MODAL_DATA);
+  private readonly config = inject(GuiConfigService);
 
   public readonly importForm: FormGroup = this.fb.group({
     file: [null, Validators.required],
@@ -101,11 +128,27 @@ export class NotebookImportModalComponent implements 
OnDestroy {
   // Held as a field rather than an inline literal so the binding keeps a 
stable reference.
   public readonly tabAnimation = { inkBar: true, tabPane: false };
 
-  // Tab order: 0 = Jupyter notebook, 1 = Python file, 2 = Python folder.
   public selectedTabIndex = 0;
 
+  // A control rather than a field so the switch shows the right option when 
the tab re-renders.
+  public readonly notebookLanguage = new 
FormControl<MigrationLanguage>("python", { nonNullable: true });
+
+  public readonly rDisabledTooltip = R_DISABLED_TOOLTIP;
+
+  public get rMigrationEnabled(): boolean {
+    return this.config.env.rNotebookMigrationEnabled;
+  }
+
+  private get selectedTab(): ImportTab {
+    return IMPORT_TABS[this.selectedTabIndex];
+  }
+
   public get isFolderTab(): boolean {
-    return this.selectedTabIndex === 2;
+    return this.selectedTab.kind === "folder";
+  }
+
+  public get language(): MigrationLanguage {
+    return this.selectedTab.language ?? this.notebookLanguage.value;
   }
 
   /** What the upload row shows once something is picked, or null while 
nothing is. */
@@ -124,6 +167,10 @@ export class NotebookImportModalComponent implements 
OnDestroy {
    */
   public onTabChange(index: number): void {
     this.selectedTabIndex = index;
+    this.clearSelection();
+  }
+
+  public clearSelection(): void {
     const fileControl = this.importForm.get("file");
     fileControl?.reset(null);
     fileControl?.updateValueAndValidity();
@@ -215,7 +262,7 @@ export class NotebookImportModalComponent implements 
OnDestroy {
     this.modalRef.updateConfig({ nzClosable: false, nzMaskClosable: false, 
nzKeyboard: false });
     try {
       // Close only on success, so a failure leaves the modal open with the 
selection preserved.
-      if (await this.data.requestImport(selection, model)) {
+      if (await this.data.requestImport(selection, model, this.language)) {
         this.modalRef.close();
         return;
       }
diff --git a/frontend/src/assets/notebook_migration_tool/r_notebook_diagram.png 
b/frontend/src/assets/notebook_migration_tool/r_notebook_diagram.png
new file mode 100644
index 0000000000..67c80b7b29
Binary files /dev/null and 
b/frontend/src/assets/notebook_migration_tool/r_notebook_diagram.png differ

Reply via email to