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

feat: add documentation for component queries #2881

Merged
merged 10 commits into from
Dec 11, 2024

Conversation

ItsMeBrianD
Copy link
Member

Description

Checklist

  • For UI or styling changes, I have added a screenshot or gif showing before & after
  • I have added a changeset
  • I have added to the docs where applicable
  • I have added to the VS Code extension where applicable

Copy link
Member

@archiewood archiewood left a comment

Choose a reason for hiding this comment

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

It's really good to have docs for this, a big step on.

I think we can simplify these to make the docs more accessible.

  • Where possible, I think only showing or recommending one approach is preferable to multiple
  • A new custom component author is unlikely to know how to choose between at this early stage. (I didn't when reading)
  • Are there two types (and therefore sections in the page)
    • "Static/One-time" queries: these execute once on page load
    • Dynamic queries: these update whenever any query inputs change

A final thing I would consider (but not required) is publishing an example custom component in a standalone repo that implements a component query as a reference?


2. We then use the `QueryLoad` component to handle the query execution and loading states. The `let:loaded` syntax gives us access to our query results once they're ready.

<Alert status="info">
Copy link
Member

Choose a reason for hiding this comment

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

shall we just delete this completely, and document as though this is mandatory

feels like unneccessary info

// Build a static query
const query = buildQuery(
'SELECT * FROM information_schema.tables',
'table-list-query' // Optional unique identifier
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'table-list-query' // Optional unique identifier
'table-list-query' // unique identifier for the query

we can just say this is mandatory? no benefit to not using


## Working with Loading States

The `QueryLoad` component automatically handles loading states for your queries. You have three main approaches for managing how loading states appear:
Copy link
Member

Choose a reason for hiding this comment

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

not super clear why you would pick between these at the moment.

The recommended option is also the most complex because you have to specify the dimensions of the slot.

Why is the "Default" state not the recommended option


## Working with Query Results

There are several ways to access your query results within the `QueryLoad` component. Here are the different patterns and when to use them:
Copy link
Member

Choose a reason for hiding this comment

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

Can we just recommend the named variable approach here and remove the other options

It's not that verbose, and the other options seems less flexible

- Use descriptive names for your query results that reflect the data they contain
- Avoid naming conflicts by not reusing variable names
- Consider using custom loading states for better user experience
- Include query IDs when debugging or working with multiple queries
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Include query IDs when debugging or working with multiple queries
- Include unique query IDs

- Building interactive data exploration interfaces
- Optimizing query performance

Remember that dynamic queries are more powerful but also more complex. Start with simple implementations and gradually add more features as you become comfortable with the system.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Remember that dynamic queries are more powerful but also more complex. Start with simple implementations and gradually add more features as you become comfortable with the system.
Dynamic queries are more powerful but also more complex. Start with simple implementations and gradually add more features as you become comfortable with the system.


## Error Handling

When working with queries in your components, it's essential to handle errors gracefully to provide a good user experience. The `QueryLoad` component provides built-in error handling capabilities through its error slot.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
When working with queries in your components, it's essential to handle errors gracefully to provide a good user experience. The `QueryLoad` component provides built-in error handling capabilities through its error slot.
When working with queries in your components, handle errors gracefully to provide a good user experience. The `QueryLoad` component provides built-in error handling capabilities through its error slot:


When working with queries in your components, it's essential to handle errors gracefully to provide a good user experience. The `QueryLoad` component provides built-in error handling capabilities through its error slot.

Here's how you can implement basic error handling:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Here's how you can implement basic error handling:


</Alert>

When working with dynamic queries, you might want to handle errors differently depending on the state of your component:
Copy link
Member

Choose a reason for hiding this comment

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

Everything below this section feels pretty in the weeds

sites/docs/pages/components/custom-components/index.md Outdated Show resolved Hide resolved
Copy link
Member

@archiewood archiewood left a comment

Choose a reason for hiding this comment

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

inline

@ItsMeBrianD ItsMeBrianD merged commit 7b1fa31 into next Dec 11, 2024
30 of 31 checks passed
@ItsMeBrianD ItsMeBrianD deleted the docs/using-queries-in-custom-components branch December 11, 2024 22:15
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