aglinxinyuan commented on code in PR #9382:
URL: https://github.com/apache/texera/pull/9382#discussion_r4520433997


##########
frontend/src/app/common/formly/preset-wrapper/preset-wrapper.component.ts:
##########
@@ -101,16 +98,13 @@ export class PresetWrapperComponent extends FieldWrapper 
implements OnInit, OnDe
       );
     }
     const presetKey = <PresetKey>this.field.templateOptions.presetKey;
-    this.searchTerm = this.formControl.value !== null ? this.formControl.value 
: "";
     this.presetType = presetKey.presetType;
     this.saveTarget = presetKey.saveTarget;
     this.applyTarget = presetKey.applyTarget;
     this.updateSearchResults();
-    this.basePreset = this.filterPresetFromForm();
+    this.filterPresetFromForm();

Review Comment:
   Done in 13cd60c036: the guard now also checks `this.field.parent?.fieldGroup 
=== undefined` and names `.parent.fieldGroup` in its message, the discarded 
`filterPresetFromForm()` call is gone, and the test expects that message 
(dropping the check fails only that test).
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
frontend/src/app/common/formly/preset-wrapper/preset-wrapper.component.html:
##########
@@ -25,7 +25,7 @@
   nzBackdrop="false"
   [nzOverlayClassName]="searchResults.length === 0 ? 'preset-dropdown 
no-results' : 'preset-dropdown'"
   (nzVisibleChange)="onDropdownVisibilityEvent($event)"
-  [nzVisible]="presetMenuVisible"
+  [nzVisible]="false"

Review Comment:
   Done in 13cd60c036: dropped the binding, since `nzVisible` already defaults 
to false and the click trigger alone drives the menu.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
frontend/src/app/common/formly/preset-wrapper/preset-wrapper.component.ts:
##########
@@ -254,36 +206,15 @@ export class PresetWrapperComponent extends FieldWrapper 
implements OnInit, OnDe
     return preset;
   }
 
-  /**
-   * handles user typing into form field
-   * updates earch results to account for filtering
-   */
-  private handleFieldValueChanges() {
-    // WIERD CODE EXPLANATION: debounceTime(0)?
-    // After a preset is applied (by clicking a dropdown entry), it changes a 
field value and
-    // activates this handler function.
-    // updating the searchResults (which also changes the HTML template due to 
binding) too quickly
-    // can sometimes interrupt the dropdown closing animation. (dropdown 
should close after clicking dropdown entry, but instead stays open)
-    // hence the debounceTime(0) to slow this function down.
-    this.formControl.valueChanges.pipe(debounceTime(0), 
takeUntil(this.teardownObservable)).subscribe({
-      next: (value: string | number | boolean) => {
-        this.searchTerm = (value ?? "").toString();
-        if (this.presetMenuVisible) {
-          this.updateSearchResults(false);
-        }
-      },
-    });
-  }
-
   /**
    * updates search results
    */
-  private updateSearchResults(showAllResults = true) {
+  private updateSearchResults() {
     this.presetService
       .getPresets(this.presetType, this.saveTarget)
       .pipe(first(), takeUntil(this.teardownObservable))
       .subscribe(presets => {
-        this.searchResults = this.getSearchResults(presets, this.searchTerm, 
showAllResults);
+        this.searchResults = presets.slice();

Review Comment:
   Done in 13cd60c036: `searchResults` is now `readonly Preset[]`, so 
`updateSearchResults()` and `handleSavePresets()` assign the emitted arrays 
directly.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
frontend/src/app/common/formly/preset-wrapper/preset-wrapper.component.spec.ts:
##########
@@ -214,32 +201,21 @@ describe("PresetWrapperComponent", () => {
       ).toBe("first, second");
     });
 
-    describe("getSearchResults", () => {
-      it("returns a copy of all presets when showAllResults is true", () => {
+    describe("preset list copies", () => {
+      it("copies the fetched presets when the dropdown opens", () => {
         const presets: Preset[] = [testPreset, otherPreset];
-        const results = component.getSearchResults(presets, "anything", true);
+        presetServiceStub.getPresets.mockReturnValue(of(presets));
+        component.onDropdownVisibilityEvent(true);
+        const results = component.searchResults;
         expect(results).toEqual(presets);
         expect(results).not.toBe(presets);
       });
 
-      it("returns all presets when showAllResults is true even if the search 
term doesn't match", () => {
-        expect(component.getSearchResults([testPreset], "no-match", 
true)).toEqual([testPreset]);
-      });
-
-      it("filters by case-insensitive prefix match on the entry title when 
showAllResults is false", () => {
-        const presets: Preset[] = [testPreset, otherPreset];
-        // testPreset title 'testPresetValue' starts with 'TEST'
-        expect(component.getSearchResults(presets, "TEST", 
false)).toEqual([testPreset]);
-        // otherPreset title 'otherPresetValue2' starts with 'other'
-        expect(component.getSearchResults(presets, "other", 
false)).toEqual([otherPreset]);
-      });
-
-      it("returns the full list when search term is empty and showAllResults 
is false", () => {
-        expect(component.getSearchResults([testPreset], "", 
false)).toEqual([testPreset]);
-      });
-
-      it("returns an empty list when the search term matches nothing", () => {
-        expect(component.getSearchResults([testPreset], "zzzz", 
false)).toEqual([]);
+      it("shows all fetched presets even when the field value does not match", 
() => {
+        formControl.setValue("no-match");
+        presetServiceStub.getPresets.mockReturnValue(of([testPreset]));
+        component.onDropdownVisibilityEvent(true);
+        expect(component.searchResults).toEqual([testPreset]);
       });
     });

Review Comment:
   Done in 13cd60c036: removed the "preset list copies" block, both "keeps the 
preset list" tests and the stub's `applyPresetStream`.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



-- 
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