Copilot commented on code in PR #7314:
URL: https://github.com/apache/texera/pull/7314#discussion_r3716862595


##########
frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.html:
##########
@@ -0,0 +1,130 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<form
+  class="import-modal-form"
+  [formGroup]="importForm"
+  nz-form>
+  <div class="import-modal-diagram">
+    <img
+      ngSrc="assets/notebook_migration_tool/tool_popup_diagram.png"
+      alt="Notebook to Workflow"
+      width="1646"
+      height="479" />
+  </div>
+
+  <nz-alert
+    class="import-modal-warning"
+    nzType="warning"
+    nzShowIcon
+    nzMessage="Generating overwrites your current workflow; the previous 
version is kept in version history."></nz-alert>
+
+  <nz-form-item>
+    <p 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 will generate a corresponding Texera workflow. 
The conversion time depends on the
+      notebook’s complexity and can take 1–5 minutes. Once the process is 
complete, the workflow workspace will reload
+      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 the uploaded notebook for 
reference.</li>
+    </ol>
+    <p class="import-modal-text">
+      Feel free to navigate away from this tab while you wait for the workflow 
to generate. Please do not close the
+      window.
+    </p>
+  </nz-form-item>
+
+  <nz-form-item>
+    <nz-form-label [nzNoColon]="true">
+      <span class="import-modal-label"> Upload Python Jupyter Notebook </span>
+    </nz-form-label>
+    <nz-form-control>
+      <div class="import-modal-upload-row">
+        <nz-upload
+          [nzBeforeUpload]="beforeUpload"
+          [nzShowUploadList]="false">
+          <button nz-button>
+            <i
+              nz-icon
+              nzType="upload"></i>
+          </button>
+        </nz-upload>

Review Comment:
   The upload icon button is inside a <form> and does not specify 
type="button". In HTML the default is type="submit", which can trigger an 
unexpected form submit/navigation when clicking the upload button. Also, the 
icon-only button has no accessible label (no title/aria-label).



##########
frontend/src/app/workspace/component/notebook-import-modal/notebook-import-modal.component.ts:
##########
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { Component, inject } from "@angular/core";
+import { FormBuilder, 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";
+import { AsyncPipe, NgIf, NgFor, NgOptimizedImage } from "@angular/common";
+import { NzFormModule } from "ng-zorro-antd/form";
+import { NzSelectModule } from "ng-zorro-antd/select";
+import { NzAlertModule } from "ng-zorro-antd/alert";
+import { NzButtonComponent } from "ng-zorro-antd/button";
+import { NzIconDirective } from "ng-zorro-antd/icon";
+import { NotebookMigrationService } from 
"../../service/notebook-migration/notebook-migration.service";
+
+// Passed in via nzData. The modal delegates "may I proceed?" to the opener so 
the
+// opener can keep the overwrite-confirm and generation logic (and the 
workflow state it
+// needs) without the modal knowing about them. Resolve true to close the 
modal (the
+// import has started), false to keep it open with the user's selection intact.
+export interface NotebookImportModalData {
+  requestImport: (file: NzUploadFile, model: string) => Promise<boolean>;
+}
+
+/**
+ * The "AI Generate Workflow from Python Notebook" modal body. It owns the 
upload form and
+ * the three model-dropdown states (loading / has models / none). On Submit it 
delegates the
+ * decision to proceed to its opener via the requestImport callback (passed in 
through
+ * nzData); the opener runs the overwrite-confirm and generation pipeline and 
the modal
+ * closes itself only when that resolves true. Mirrors the 
component-as-nzContent pattern
+ * used by the other modals opened from the menu (ResultExportationComponent, 
...).
+ */
+@Component({
+  selector: "texera-notebook-import-modal",
+  templateUrl: "./notebook-import-modal.component.html",
+  styleUrls: ["./notebook-import-modal.component.scss"],
+  imports: [
+    NgIf,
+    NgFor,
+    AsyncPipe,
+    NgOptimizedImage,
+    ReactiveFormsModule,
+    NzFormModule,
+    NzSelectModule,
+    NzAlertModule,
+    NzUploadComponent,
+    NzButtonComponent,
+    NzIconDirective,
+  ],
+})
+export class NotebookImportModalComponent {
+  private readonly fb = inject(FormBuilder);
+  private readonly modalRef = inject(NzModalRef);
+  private readonly notebookMigrationService = inject(NotebookMigrationService);
+  private readonly data: NotebookImportModalData = inject(NZ_MODAL_DATA);
+
+  public readonly importForm: FormGroup = this.fb.group({
+    file: [null, Validators.required],
+    model: ["", Validators.required],
+  });
+
+  // Drives the three model-dropdown states: pending (loading), a non-empty 
list (selectable),
+  // and an empty list (no models available, e.g. the fetch failed or the 
feature is off).
+  public readonly models$: Observable<{ name: string }[]> = 
this.notebookMigrationService.getAvailableModels();
+
+  public beforeUpload = (file: NzUploadFile) => {
+    this.importForm.patchValue({ file });
+    this.importForm.get("file")?.markAsDirty();
+    this.importForm.get("file")?.updateValueAndValidity();
+    return false; // prevent auto upload
+  };
+
+  public onCancel(): void {
+    this.modalRef.close();
+  }
+
+  public async onSubmit(): Promise<void> {
+    if (!this.importForm.valid) return;
+    const file: NzUploadFile = this.importForm.get("file")?.value;
+    const model: string = this.importForm.get("model")?.value;
+    // Ask the opener whether to proceed; close only if it does, so cancelling 
the
+    // overwrite-confirm leaves this modal open with the selection preserved.
+    if (await this.data.requestImport(file, model)) {
+      this.modalRef.close();
+    }
+  }

Review Comment:
   onSubmit can be triggered multiple times while the opener callback is still 
pending (e.g., double-click Submit), which can start multiple concurrent 
imports/conversions. Add a simple in-flight guard so only one requestImport 
runs at a time (and optionally block Cancel while submitting).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to