This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-8963-ad085e964c5f9e2062b7efe147054d928c146621 in repository https://gitbox.apache.org/repos/asf/texera.git
commit 22cc29dd7574c2d4e5473d8deb6f0085203794fb Author: Ryan Zhang <[email protected]> AuthorDate: Fri Nov 13 00:20:19 2026 +0000 feat(notebook-migration): add r files to the import modal (#8963) ### What changes were proposed in this PR? This PR lets users convert R files, using the R script conversion from #8911. It is the second UI PR for R support (#8009), after R notebooks in #8912. R folders follow in #9386. **Import modal.** An "R File" tab after Python Folder, laid out like the Python File tab: its own diagram, a description, and an upload row that accepts `.R` and `.r`. It is one more entry in the `IMPORT_TABS` list from #8912, which is all the language and tab logic it needs. **Disabled, not hidden.** As with the R Notebook option in #8912, the tab is always shown. When `rNotebookMigrationEnabled` is off it is greyed out, cannot be selected, and its title shows the tooltip "R is not enabled on this deployment." **Dispatch.** A small per language table now holds each language's script extension and messages. For R, the dashboard accepts `.ipynb` or `.R` / `.r`, and anything else gets "Please upload an R Jupyter Notebook (.ipynb) or an R (.R) file." R files go through the R script conversion, and a file that cannot be read gets R wording. Python's messages are unchanged. **Assets.** A new R file diagram, at the same size and border as the others. `frontend/LICENSE-binary` adds it to the Material Symbols entry. #### Demo video (waiting time cut out) https://github.com/user-attachments/assets/fc1dc88a-452b-41ca-a972-22e4e9617e53 #### R File disabled on a deployment without R <img width="308" height="88" alt="image" src="https://github.com/user-attachments/assets/261f86ac-77a0-4a7f-99ff-6a15da1310f5" /> ### Any related issues, documentation, discussions? Closes #9385 Part of #8009 Parent-issue #4301 The plan is in https://github.com/apache/texera/discussions/8866. Language mismatches between the upload and the selected tab are tracked in #8929. ### How was this PR tested? * `notebook-import-modal.component.spec.ts`, four new tests: the tab is disabled with its tooltip while the R flag is off and a click does not select it; while the flag is on it shows its diagram, accepts `.R,.r` and reports the R language; and submit passes `"r"`. The tab count assertion now expects four tabs, and the tooltip lookup finds each tooltip by the element it is attached to, since the modal now has two. * `user-workflow.component.spec.ts`, three new tests: `.R` and `.r` convert as R scripts, and an unreadable R file gets R wording. The R test from #8912 now rejects a `.py`, since `.R` is accepted here, and the Python script assertion now expects `"python"`. The full frontend suite passes. Checked by hand against a local stack. With the R flag off, the R File tab is disabled, ignores clicks and shows its tooltip. With it on, the tab shows its diagram, description and `.R,.r` upload row, a staged file clears on changing tabs, and no tab scrolls. An R file 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 | 1 + .../user-workflow/user-workflow.component.spec.ts | 49 +++++++++++++++-- .../user/user-workflow/user-workflow.component.ts | 42 ++++++++++----- .../notebook-import-modal.component.html | 48 +++++++++++++++++ .../notebook-import-modal.component.spec.ts | 60 +++++++++++++++++++-- .../notebook-import-modal.component.ts | 3 +- .../notebook_migration_tool/r_file_diagram.png | Bin 0 -> 85535 bytes 7 files changed, 183 insertions(+), 20 deletions(-) diff --git a/frontend/LICENSE-binary b/frontend/LICENSE-binary index ff4f6e7d68..514ea3bbf5 100644 --- a/frontend/LICENSE-binary +++ b/frontend/LICENSE-binary @@ -230,6 +230,7 @@ Third-party assets: 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 + frontend/src/assets/notebook_migration_tool/r_file_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 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 9d8f0c55a9..3f487612bb 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 @@ -473,20 +473,61 @@ describe("SavedWorkflowSectionComponent", () => { expect(migration.sendToAIGenerateWorkflow).not.toHaveBeenCalled(); }); - it("rejects anything but a notebook for R", async () => { + it("rejects a Python file 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"); + const proceed = await getRequestImport()({ name: "analysis.py" } as NzUploadFile, "gpt-4", "r"); expect(proceed).toBe(false); - expect(errorSpy).toHaveBeenCalledWith("Please upload an R Jupyter Notebook (.ipynb)."); + expect(errorSpy).toHaveBeenCalledWith("Please upload an R Jupyter Notebook (.ipynb) or an R (.R) file."); expect(migration.parseAndTagNotebook).not.toHaveBeenCalled(); expect(scriptSpy).not.toHaveBeenCalled(); }); }); + describe("R file input", () => { + function mockRScriptGenerationSuccess() { + const migration = TestBed.inject(NotebookMigrationService); + vi.spyOn(migration, "parseScriptFile").mockResolvedValue("x <- 1\n"); + const convertSpy = vi.spyOn(migration, "sendScriptToAIGenerateWorkflow").mockResolvedValue({ + workflowContent: { operators: [] }, + mappingContent: { operator_to_cell: {}, cell_to_operator: {} }, + notebook: { cells: [] }, + } as any); + vi.spyOn(migration, "storeNotebookAndMapping").mockReturnValue(of({ success: true }) as any); + (TestBed.inject(WorkflowPersistService) as any).createWorkflow = vi + .fn() + .mockReturnValue(of({ workflow: { wid: 8 } })); + vi.spyOn(TestBed.inject(Router), "navigate").mockResolvedValue(true); + return { migration, convertSpy }; + } + + ["analysis.R", "analysis.r"].forEach(name => { + it(`converts ${name} as an R script`, async () => { + const { convertSpy } = mockRScriptGenerationSuccess(); + + const proceed = await getRequestImport()({ name } as NzUploadFile, "gpt-4", "r"); + + expect(convertSpy).toHaveBeenCalledWith("x <- 1\n", "gpt-4", "r"); + expect(proceed).toBe(true); + }); + }); + + it("reports an unreadable R file with R wording", async () => { + const { migration, convertSpy } = mockRScriptGenerationSuccess(); + vi.mocked(migration.parseScriptFile).mockRejectedValue(new Error("empty")); + 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("Failed to read the R file. Please upload a valid, non-empty .R file."); + expect(convertSpy).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", () => { @@ -513,7 +554,7 @@ describe("SavedWorkflowSectionComponent", () => { const proceed = await getRequestImport()(pyFile, "gpt-4"); - expect(convertSpy).toHaveBeenCalledWith("x = 1\n", "gpt-4"); + expect(convertSpy).toHaveBeenCalledWith("x = 1\n", "gpt-4", "python"); expect(persist.createWorkflow.mock.calls[0][1]).toBe("analysis_GENERATED_BY_LLM"); // The stored notebook is the derived one; nothing else could have supplied it. expect(storeSpy).toHaveBeenCalledWith(42, expect.anything(), derivedNotebook); 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 485f183639..7374932c4b 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 @@ -76,6 +76,20 @@ import { FiltersInstructionsComponent } from "../filters-instructions/filters-in import { NzSelectComponent } from "ng-zorro-antd/select"; import { FormsModule } from "@angular/forms"; +// The single-file input each language accepts besides .ipynb. +const SCRIPT_INPUTS: Record<MigrationLanguage, { name: string; extension: string; uploadHint: string }> = { + python: { + name: "Python", + extension: "py", + uploadHint: "Please upload a Jupyter Notebook (.ipynb) or a Python (.py) file.", + }, + r: { + name: "R", + extension: "R", + uploadHint: "Please upload an R Jupyter Notebook (.ipynb) or an R (.R) file.", + }, +}; + /** * Saved-workflow-section component contains information and functionality * of the saved workflows section: the list of workflows the user owns or has access to @@ -327,20 +341,17 @@ export class UserWorkflowComponent implements AfterViewInit, OnDestroy { return this.saveAndOpenGenerated(this.deriveFolderName(selection), generated); } + const scriptInput = SCRIPT_INPUTS[language]; 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."); + if (fileExtension !== "ipynb" && fileExtension !== scriptInput.extension.toLowerCase()) { + this.notificationService.error(scriptInput.uploadHint); return false; } const generated = fileExtension === "ipynb" ? await this.generateFromNotebook(selection, model, language) - : await this.generateFromScript(selection, model); + : await this.generateFromScript(selection, model, language); if (!generated) { return false; } @@ -381,19 +392,26 @@ export class UserWorkflowComponent implements AfterViewInit, OnDestroy { } } - /** Read and convert a .py. The notebook comes back derived, since the upload had no cells. */ - private async generateFromScript(file: NzUploadFile, model: string): Promise<GeneratedWorkflowContent | null> { + /** Read and convert a script. The notebook comes back derived, since the upload had no cells. */ + private async generateFromScript( + file: NzUploadFile, + model: string, + language: MigrationLanguage + ): Promise<GeneratedWorkflowContent | null> { + const { name, extension } = SCRIPT_INPUTS[language]; let scriptSource: string; try { scriptSource = await this.notebookMigrationService.parseScriptFile(file as unknown as File); } catch (error) { - this.notificationService.error("Failed to read the Python file. Please upload a valid, non-empty .py file."); - console.error("Python file read failed:", error); + this.notificationService.error( + `Failed to read the ${name} file. Please upload a valid, non-empty .${extension} file.` + ); + console.error(`${name} file read failed:`, error); return null; } try { - return await this.notebookMigrationService.sendScriptToAIGenerateWorkflow(scriptSource, model); + return await this.notebookMigrationService.sendScriptToAIGenerateWorkflow(scriptSource, model, language); } catch (error) { this.reportGenerationFailure(error, "script"); return null; 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 b19db81deb..2304d7d2aa 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 @@ -229,6 +229,54 @@ "></ng-container> </ng-template> </nz-tab> + + <nz-tab + [nzTitle]="rFileTitle" + [nzDisabled]="!rMigrationEnabled"> + <ng-template #rFileTitle> + <span + nz-tooltip + [nzTooltipTitle]="rMigrationEnabled ? null : rDisabledTooltip" + [nzTooltipOverlayStyle]="{ 'max-width': 'none' }"> + R File + </span> + </ng-template> + <ng-template nz-tab> + <div class="import-modal-diagram"> + <img + ngSrc="assets/notebook_migration_tool/r_file_diagram.png" + alt="R File to Workflow" + width="1350" + height="344" /> + </div> + + <nz-form-item> + <p class="import-modal-text"> + This tool converts an R file 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. A script has + no notebook cells, so the LLM also divides it into sections and records which section became which + operator. The conversion time depends on the script's complexity and can take 1-5 minutes. Once generation + finishes, you are taken to the new workflow, which opens with: + </p> + <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 + the workflow). + </li> + <li>A floating Jupyter window containing your script, divided into cells, for reference.</li> + </ol> + <p class="import-modal-text"> + Generation runs here after you submit. Please keep this window open while you wait. + </p> + </nz-form-item> + + <ng-container + *ngTemplateOutlet=" + uploadRow; + context: { accept: '.R,.r', label: 'Upload R File', action: 'Upload R file' } + "></ng-container> + </ng-template> + </nz-tab> </nz-tabs> <nz-form-item> 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 531cdb63db..76702d33f6 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 @@ -406,7 +406,7 @@ describe("NotebookImportModalComponent", () => { it("selects the Python tab from a click on its header, not just a direct call", async () => { await createWith(of([{ name: "gpt-4" }])); const headers = (fixture.nativeElement as HTMLElement).querySelectorAll(".ant-tabs-tab"); - expect(headers.length).toBe(3); + expect(headers.length).toBe(4); (headers[1] as HTMLElement).click(); // nz-tabs emits nzSelectedIndexChange from a microtask inside ngAfterContentChecked, @@ -627,6 +627,14 @@ describe("NotebookImportModalComponent", () => { }); }); + function tooltipOn(text: string) { + const host = fixture.debugElement + .queryAll(By.directive(NzTooltipDirective)) + .find(element => element.nativeElement.textContent.trim() === text); + if (!host) throw new Error(`No tooltip host with text "${text}"`); + return host.injector.get(NzTooltipDirective).title; + } + describe("notebook language switch", () => { const root = () => fixture.nativeElement as HTMLElement; const pane = () => root().querySelector(".ant-tabs-tabpane-active") as HTMLElement; @@ -634,8 +642,7 @@ describe("NotebookImportModalComponent", () => { 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; + const rTooltip = () => tooltipOn("R Notebook"); it("defaults to Python and keeps the Python diagram", async () => { await createWith(of([{ name: "gpt-4" }]), true); @@ -704,4 +711,51 @@ describe("NotebookImportModalComponent", () => { expect(requestImport).toHaveBeenCalledWith(file, "gpt-4", "r"); }); }); + + describe("R File tab", () => { + const root = () => fixture.nativeElement as HTMLElement; + const pane = () => root().querySelector(".ant-tabs-tabpane-active") as HTMLElement; + const rFileTab = () => root().querySelectorAll(".ant-tabs-tab")[3] as HTMLElement; + + it("is shown but disabled with an explanation while the R flag is off", async () => { + await createWith(of([{ name: "gpt-4" }])); + + expect(root().querySelectorAll(".ant-tabs-tab").length).toBe(4); + expect(rFileTab().classList).toContain("ant-tabs-tab-disabled"); + expect(tooltipOn("R File")).toBe(R_DISABLED_TOOLTIP); + }); + + it("cannot be selected while the R flag is off", async () => { + await createWith(of([{ name: "gpt-4" }])); + + (rFileTab().querySelector(".ant-tabs-tab-btn") as HTMLElement).click(); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.selectedTabIndex).toBe(0); + }); + + it("takes R files with the R language while the R flag is on", async () => { + await createWith(of([{ name: "gpt-4" }]), true); + component.onTabChange(3); + fixture.detectChanges(); + + expect(rFileTab().classList).not.toContain("ant-tabs-tab-disabled"); + expect(tooltipOn("R File")).toBeNull(); + expect(pane().querySelector("img[alt='R File to Workflow']")).not.toBeNull(); + expect(pane().querySelector("input[type='file']")?.getAttribute("accept")).toBe(".R,.r"); + expect(component.language).toBe("r"); + }); + + it("submits R files with the R language", async () => { + await createWith(of([{ name: "gpt-4" }]), true); + component.onTabChange(3); + const file = { name: "analysis.R" } 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 c4fb4a92e0..25c0d13f18 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 @@ -61,6 +61,7 @@ const IMPORT_TABS: readonly ImportTab[] = [ { kind: "notebook" }, { kind: "file", language: "python" }, { kind: "folder", language: "python" }, + { kind: "file", language: "r" }, ]; // How long after the last rejected file a drop is treated as over: long enough that a slow @@ -76,7 +77,7 @@ function describeFolderSelection(files: readonly NzUploadFile[]): string { /** * The "AI Generate Workflow from Source Code" modal body: a tab per accepted input kind - * (Jupyter notebook in Python or R, Python script, Python folder), each with its own diagram, description and + * (Jupyter notebook in Python or R, Python script, Python folder, R script), 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 diff --git a/frontend/src/assets/notebook_migration_tool/r_file_diagram.png b/frontend/src/assets/notebook_migration_tool/r_file_diagram.png new file mode 100644 index 0000000000..3b61ee30a8 Binary files /dev/null and b/frontend/src/assets/notebook_migration_tool/r_file_diagram.png differ
