Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(torii-sql): sql playground for slot #2779

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Dec 6, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced URL construction for fetching schema and executing SQL queries in the SQL Playground, improving flexibility based on the current page's URL.
  • Bug Fixes

    • Maintained existing error handling for fetch failures, ensuring consistent logging behavior.

Copy link

coderabbitai bot commented Dec 6, 2024

Walkthrough

Ohayo, sensei! This pull request introduces changes to the sql-playground.html file, specifically modifying the URL construction for fetching schema and executing SQL queries. The previous hardcoded URL path has been updated to dynamically use window.location.href, ensuring requests are made relative to the current page's URL. This affects two fetch calls without altering error handling or the overall functionality of the SQL Playground.

Changes

File Path Change Summary
crates/torii/server/static/sql-playground.html Updated URL construction for fetching schema and executing SQL queries to use window.location.href instead of hardcoded path "/sql?". Error handling remains unchanged.

Possibly related PRs

  • feat(torii): sql playground #2714: The changes in this PR involve modifications to the sql-playground.html file, which are directly related to the URL construction for fetching schema and executing SQL queries, similar to the changes made in the main PR.

Suggested reviewers

  • glihm

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

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.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c5e7d6b and 40b665b.

📒 Files selected for processing (1)
  • crates/torii/server/static/sql-playground.html (2 hunks)
🔇 Additional comments (1)
crates/torii/server/static/sql-playground.html (1)

377-377: Verify the URL construction in different deployment scenarios.

The URL construction changes might behave differently based on:

  • Base path of the application
  • Proxy configurations
  • Different deployment environments

Also applies to: 511-511

✅ Verification successful

URL construction is safe and self-contained, sensei!

The URL construction in sql-playground.html is using window.location.href consistently and correctly. The implementation:

  • Uses relative URL construction that automatically inherits the current page's base path
  • Is used consistently in both fetch calls (lines 377 and 511)
  • Doesn't rely on any hard-coded paths that could break in different environments
  • Automatically adapts to whatever base path or proxy configuration is in place

The search results show no other SQL endpoint consumers that would need similar updates, and the URL construction pattern is deployment-environment agnostic.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any other fetch calls in the codebase that might need similar updates
rg -l 'fetch\(' | xargs rg '/sql\?'

# Look for any deployment configuration files that might affect the base path
fd -t f "nginx\.conf|\.htaccess|vercel\.json|netlify\.toml"

Length of output: 99


Script:

#!/bin/bash
# Let's check for any URL construction patterns in the SQL playground HTML file
rg -A 2 "window\.location" crates/torii/server/static/sql-playground.html

# Check for any base path or URL configurations in the codebase
rg -i "base.*url|base.*path" --type rust

# Look for any fetch calls or API endpoint configurations
rg "fetch\(|/sql" crates/torii/server/static/sql-playground.html

# Check for any deployment or server configuration files
fd -t f "config|settings|deploy" -e toml -e json

Length of output: 6431

@@ -508,7 +508,7 @@
const startTime = performance.now();
try {
const response = await fetch(
"/sql?" + new URLSearchParams({ query })
`${window.location.href}?` + new URLSearchParams({ query })
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Similar URL construction improvement needed here, sensei!

For consistency and robustness, apply the same URL construction pattern here.

Here's the suggested improvement:

- `${window.location.href}?` + new URLSearchParams({ query })
+ `${new URL('sql', window.location.href)}?${new URLSearchParams({ query })}`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`${window.location.href}?` + new URLSearchParams({ query })
`${new URL('sql', window.location.href)}?${new URLSearchParams({ query })}`

@@ -374,7 +374,7 @@
ORDER BY m.name, p.cid;
`;
const response = await fetch(
"/sql?" + new URLSearchParams({ query: schemaQuery })
`${window.location.href}?` + new URLSearchParams({ query: schemaQuery })
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ohayo sensei! Consider improving URL construction.

The URL construction could be made more robust by handling trailing slashes and using proper URL joining.

Here's a suggested improvement:

- `${window.location.href}?` + new URLSearchParams({ query: schemaQuery })
+ `${new URL('sql', window.location.href)}?${new URLSearchParams({ query: schemaQuery })}`

This ensures:

  • Proper URL path joining
  • Handles trailing slashes correctly
  • Maintains the intended endpoint path
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`${window.location.href}?` + new URLSearchParams({ query: schemaQuery })
`${new URL('sql', window.location.href)}?${new URLSearchParams({ query: schemaQuery })}`

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.01%. Comparing base (c5e7d6b) to head (40b665b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2779      +/-   ##
==========================================
- Coverage   56.01%   56.01%   -0.01%     
==========================================
  Files         434      434              
  Lines       55068    55068              
==========================================
- Hits        30849    30847       -2     
- Misses      24219    24221       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Larkooo Larkooo merged commit a023fc6 into dojoengine:main Dec 6, 2024
14 checks passed
Larkooo added a commit to Larkooo/dojo that referenced this pull request Dec 9, 2024
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.

2 participants