Skip to content

feat(webui): Reset states when switching between freeform and guided.#1482

Merged
davemarco merged 12 commits into
y-scope:mainfrom
davemarco:switchsql
Oct 27, 2025
Merged

feat(webui): Reset states when switching between freeform and guided.#1482
davemarco merged 12 commits into
y-scope:mainfrom
davemarco:switchsql

Conversation

@davemarco

@davemarco davemarco commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

Description

Resets states and cancels queries when switching modes.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

I tested before, but I had to make a significant change due to the linter failing after merging main. I had to add another effect dependency that could brake things. I can no longer test since it lost my old package build, and can no longer build package on my machine due to package build changes. Can you confirm the that it still properly transitions between states?

If not we might have to remove searchUiState from the effect, and suppress the lint


Summary by CodeRabbit

  • Improvements
    • Switching between guided and freeform search modes now consistently clears previous results and resets related search state, with mode-switch logic centralized for more reliable transitions.
    • Result-metadata processing now skips when the search UI is in its default state, reducing unnecessary work and improving responsiveness.

@coderabbitai

coderabbitai Bot commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Centralizes Presto SQL interface switching into exported handler functions and updates button click handlers to call them; adds an early guard to the metadata update effect to skip processing when search UI state is DEFAULT.

Changes

Cohort / File(s) Change Summary
Freeform Button
components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlInterfaceButton/FreeformButton/index.tsx
Replaced direct Presto state mutation with a call to handleSwitchToFreeform() on click; removed local setSqlInterface usage and related imports; rendering and disabled logic unchanged.
Guided Button
components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlInterfaceButton/GuidedButton/index.tsx
Replaced local Presto state mutation with a call to handleSwitchToGuided() on click; removed PRESTO_SQL_INTERFACE and local setters; rendering and disabled logic unchanged.
Presto guided handlers
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-guided-search-requests.ts
Added exported handleSwitchToFreeform() which clears guided results, resets Presto/search fields to PRESTO_SEARCH_STATE_DEFAULT, updates error/cached query and query drawer state, and switches SQL interface to FREEFORM; updated imports/exports.
Presto search handlers
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts
Added exported handleSwitchToGuided() which sets SQL interface to GUIDED, clears results as needed, resets searchJobId and result counters to SEARCH_STATE_DEFAULT, and sets Search UI state to DEFAULT; added necessary imports/exports.
State effect hook
components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts
Added searchUiState to effect dependencies and early-return when searchUiState === DEFAULT, skipping resultsMetadata processing; otherwise existing metadata handling preserved.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GuidedBtn as GuidedButton
    participant FreeformBtn as FreeformButton
    participant Handlers as Presto Handlers
    participant Store as Search Store
    participant Effect as useUpdateStateWithMetadata

    User->>GuidedBtn: Click "Guided"
    GuidedBtn->>Handlers: handleSwitchToGuided()
    Handlers->>Store: clear results if needed
    Handlers->>Store: reset searchJobId & result counters to SEARCH_STATE_DEFAULT
    Handlers->>Store: set search UI state = DEFAULT
    Handlers->>Store: set PRESTO_SQL_INTERFACE = GUIDED

    activate Effect
    Effect->>Effect: is searchUiState == DEFAULT?
    Effect-->>Effect: early return (skip metadata)
    deactivate Effect

    User->>FreeformBtn: Click "Freeform"
    FreeformBtn->>Handlers: handleSwitchToFreeform()
    Handlers->>Store: clear guided results
    Handlers->>Store: reset Presto/search fields to PRESTO_SEARCH_STATE_DEFAULT
    Handlers->>Store: update error/cached query and query drawer state
    Handlers->>Store: set PRESTO_SQL_INTERFACE = FREEFORM
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Potential review focal points:

  • Correctness of state-reset values (SEARCH_STATE_DEFAULT, PRESTO_SEARCH_STATE_DEFAULT) and their usage sites.
  • Ensuring result-clearing functions (e.g., handlePrestoGuidedClearResults) are correctly invoked and handle async/side effects.
  • Dependency and early-return logic in useUpdateStateWithMetadata to avoid regressions in metadata processing.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat(webui): Reset states when switching between freeform and guided." accurately reflects the main objective of the changeset. The modifications across multiple files—adding handleSwitchToFreeform() and handleSwitchToGuided() functions, updating button click handlers to use these functions, and adding a guard condition in the effect to skip processing when in DEFAULT state—all work together to implement state reset functionality when transitioning between freeform and guided modes. The title is specific, clear, and concise without vague terminology or noise.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@davemarco davemarco requested a review from hoophalab October 23, 2025 19:09
@davemarco davemarco marked this pull request as ready for review October 23, 2025 19:12
@davemarco davemarco requested a review from a team as a code owner October 23, 2025 19:12
hoophalab
hoophalab previously approved these changes Oct 24, 2025

@hoophalab hoophalab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. One minor comment, but I'm fine with the current approach. I approved.

Validation: In the old package, switching between freeform and guided modes correctly resets the search results, result count, errors, and job ID.


const handleClick = () => {
handleSwitchToGuided();
setSqlInterface(PRESTO_SQL_INTERFACE.GUIDED);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to move setSqlInterface into handleSwitchToGuided?

Suggested change
setSqlInterface(PRESTO_SQL_INTERFACE.GUIDED);


const handleClick = () => {
handleSwitchToFreeform();
setSqlInterface(PRESTO_SQL_INTERFACE.FREEFORM);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setSqlInterface(PRESTO_SQL_INTERFACE.FREEFORM);

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a648ee6 and e028f2e.

📒 Files selected for processing (4)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlInterfaceButton/FreeformButton/index.tsx (2 hunks)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlInterfaceButton/GuidedButton/index.tsx (2 hunks)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-guided-search-requests.ts (2 hunks)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit configuration file

  • Prefer false == <expression> rather than !<expression>.

Files:

  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlInterfaceButton/FreeformButton/index.tsx
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-guided-search-requests.ts
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlInterfaceButton/GuidedButton/index.tsx
🧬 Code graph analysis (1)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlInterfaceButton/GuidedButton/index.tsx (1)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (1)
  • handleSwitchToGuided (143-143)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: package-image
  • GitHub Check: lint-check (macos-15)
🔇 Additional comments (6)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlInterfaceButton/GuidedButton/index.tsx (2)

6-6: Good refactoring to centralized handler.

The import of handleSwitchToGuided properly delegates state management to a centralized location, improving maintainability.


19-21: LGTM - Clean delegation pattern.

The click handler correctly delegates to the centralized handleSwitchToGuided() function, addressing the past review comment about moving setSqlInterface into the handler.

components/webui/client/src/pages/SearchPage/SearchControls/Presto/SqlInterfaceButton/FreeformButton/index.tsx (1)

6-6: Excellent consistency with GuidedButton.

The refactoring mirrors the approach in GuidedButton, providing a consistent pattern for both interface switches and improving code maintainability.

Also applies to: 19-21

components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (1)

12-13: LGTM - Necessary imports.

The imports support the new handleSwitchToGuided function correctly.

components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-guided-search-requests.ts (2)

14-15: LGTM - Necessary imports.

The imports properly support the new handleSwitchToFreeform function.


216-255: Original review comment does not correspond to actual changes in this PR.

The git diff shows no modifications to presto-guided-search-requests.ts—the code snippet provided is the current HEAD state unchanged. The original review references "critical fixes above" and asks verification "after applying the critical fixes," but no such fixes exist in this file within the PR. The current code structure (DEFAULT state guard, state transition sequence, effect dependencies) appears logically sound, but the review comment's premise is unfounded.

Likely an incorrect or invalid review comment.

Comment on lines +115 to +138
const handleSwitchToGuided = () => {
const {
searchUiState,
updateSearchUiState,
updateSearchJobId,
updateNumSearchResultsTable,
updateNumSearchResultsMetadata,
} = useSearchStore.getState();
const {setSqlInterface} = usePrestoSearchState.getState();

if (searchUiState === SEARCH_UI_STATE.DEFAULT) {
return;
}

handlePrestoClearResults();

updateSearchJobId(SEARCH_STATE_DEFAULT.searchJobId);
updateNumSearchResultsTable(SEARCH_STATE_DEFAULT.numSearchResultsTable);
updateNumSearchResultsMetadata(SEARCH_STATE_DEFAULT.numSearchResultsMetadata);

updateSearchUiState(SEARCH_UI_STATE.DEFAULT);

setSqlInterface(PRESTO_SQL_INTERFACE.GUIDED);
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Early return prevents interface switch in DEFAULT state.

The early return on Line 125 prevents setSqlInterface(PRESTO_SQL_INTERFACE.GUIDED) (Line 137) from executing when searchUiState === DEFAULT. Since the Guided button is enabled in DEFAULT state, users expect clicking it to switch the interface. Currently, clicking the button when in DEFAULT state has no effect.

Additionally, handlePrestoClearResults() already guards against clearing in DEFAULT state (Line 24), making the early return redundant for its intended purpose.

Apply this diff to fix the logic:

 const handleSwitchToGuided = () => {
     const {
         searchUiState,
         updateSearchUiState,
         updateSearchJobId,
         updateNumSearchResultsTable,
         updateNumSearchResultsMetadata,
     } = useSearchStore.getState();
     const {setSqlInterface} = usePrestoSearchState.getState();
 
-    if (searchUiState === SEARCH_UI_STATE.DEFAULT) {
-        return;
-    }
-
-    handlePrestoClearResults();
-
-    updateSearchJobId(SEARCH_STATE_DEFAULT.searchJobId);
-    updateNumSearchResultsTable(SEARCH_STATE_DEFAULT.numSearchResultsTable);
-    updateNumSearchResultsMetadata(SEARCH_STATE_DEFAULT.numSearchResultsMetadata);
-
-    updateSearchUiState(SEARCH_UI_STATE.DEFAULT);
+    // Only clear and reset if there's an active search
+    if (searchUiState !== SEARCH_UI_STATE.DEFAULT) {
+        handlePrestoClearResults();
+        updateSearchJobId(SEARCH_STATE_DEFAULT.searchJobId);
+        updateNumSearchResultsTable(SEARCH_STATE_DEFAULT.numSearchResultsTable);
+        updateNumSearchResultsMetadata(SEARCH_STATE_DEFAULT.numSearchResultsMetadata);
+        updateSearchUiState(SEARCH_UI_STATE.DEFAULT);
+    }
 
     setSqlInterface(PRESTO_SQL_INTERFACE.GUIDED);
 };
🤖 Prompt for AI Agents
In
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts
around lines 115 to 138, the early return when searchUiState ===
SEARCH_UI_STATE.DEFAULT prevents setSqlInterface(PRESTO_SQL_INTERFACE.GUIDED)
from running, so clicking Guided in DEFAULT does nothing; remove or relocate
that early return so the function always executes the state-reset and calls
setSqlInterface(PRESTO_SQL_INTERFACE.GUIDED) for DEFAULT, relying on
handlePrestoClearResults() (which already guards against clearing in DEFAULT) to
avoid any unwanted clearing.

@hoophalab

Copy link
Copy Markdown
Contributor

these two coderabbit comments are probably valid?

@davemarco

Copy link
Copy Markdown
Contributor Author

@hoophalab see latest

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e028f2e and ab11900.

📒 Files selected for processing (2)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-guided-search-requests.ts (2 hunks)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit configuration file

  • Prefer false == <expression> rather than !<expression>.

Files:

  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-guided-search-requests.ts
🧬 Code graph analysis (2)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (2)
components/webui/client/src/pages/SearchPage/SearchState/typings.ts (1)
  • SEARCH_UI_STATE (31-31)
components/webui/client/src/pages/SearchPage/SearchState/index.tsx (1)
  • SEARCH_STATE_DEFAULT (163-163)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-guided-search-requests.ts (3)
components/webui/client/src/pages/SearchPage/SearchState/typings.ts (1)
  • SEARCH_UI_STATE (31-31)
components/webui/client/src/pages/SearchPage/SearchState/index.tsx (1)
  • SEARCH_STATE_DEFAULT (163-163)
components/webui/client/src/pages/SearchPage/SearchState/Presto/index.tsx (1)
  • PRESTO_SEARCH_STATE_DEFAULT (110-110)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: package-image
  • GitHub Check: lint-check (ubuntu-24.04)
🔇 Additional comments (2)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts (1)

112-138: The critical issue has been resolved.

The interface switch now executes before the early return, ensuring that clicking the Guided button in DEFAULT state correctly switches the interface. The logic is sound: the interface switch happens unconditionally, while result clearing and state resetting only occur when there's an active search to clean up.

components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-guided-search-requests.ts (1)

213-255: The critical issue has been resolved.

The interface switch now executes before the early return, correctly handling the switch to freeform mode even when in DEFAULT state. The conditional clearing and resetting logic is appropriate—it only performs cleanup when transitioning away from an active search.

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deferring to @hoophalab 's review

@davemarco davemarco merged commit 80fdb78 into y-scope:main Oct 27, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants