Skip to content

Edit query parameters on Ecto Stats page - #492

Open
mhanberg wants to merge 7 commits into
phoenixframework:mainfrom
mhanberg:parameters
Open

Edit query parameters on Ecto Stats page#492
mhanberg wants to merge 7 commits into
phoenixframework:mainfrom
mhanberg:parameters

Conversation

@mhanberg

@mhanberg mhanberg commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

The _extras modules used to power this form supply queries that
sometimes offer parameters to customize the query. This adds a form to
the Ecto Stats page that lets you change the values of parameters.

For some databases like Cockroach DB, to get table statistics, you have
to supply a table name, which made this sort of interaction necessary to
make that query useful.

This page is powered by a new "parameters" key in the info return value
from the c:info callback on the _extras module. This is a new key to
allow backwards compatibility with _extras modules that have not
implemented this.

I noticed that the exists modules all use string interpolation instead
of bind parameters, so the Ecto Stats page uses the new "parameters" key
as a sentinenl to know if the parameter form should be shown. I'll
update the other modules to use bind parameters and add the "parameters"
key to the c:info callback.

Screenshots of the form are attached to the pull request.

Please let me know what you think, thank you!

The `_extras` modules used to power this form supply queries that
sometimes offer parameters to customize the query. This adds a form to
the Ecto Stats page that lets you change the values of parameters.

For some databases like Cockroach DB, to get table statistics, you have
to supply a table name, which made this sort of interaction necessary to
make that query useful.

This page is powered by a new "parameters" key in the info return value
from the `c:info` callback on the `_extras` module. This is a new key to
allow backwards compatibility with `_extras` modules that have not
implemented this.

I noticed that the exists modules all use string interpolation instead
of bind parameters, so the Ecto Stats page uses the new "parameters" key
as a sentinenl to know if the parameter form should be shown. I'll
update the other modules to use bind parameters and add the "parameters"
key to the `c:info` callback.

Screenshots of the form are attached to the pull request.

Please let me know what you think, thank you!
@mhanberg

mhanberg commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Shows an error mesage when the query fails instead of just crashing
CleanShot 2026-08-03 at 10 30 48@2x

After filling in form
CleanShot 2026-08-03 at 10 31 39@2x

Shows number input
CleanShot 2026-08-03 at 10 33 40@2x

Shows boolean input
CleanShot 2026-08-03 at 10 34 06@2x

@mhanberg
mhanberg marked this pull request as draft August 3, 2026 14:35
@mhanberg

mhanberg commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Apologies, forgot I had some broken tests before I left for a long weekend last week. Converting to draft until I have those fixed up.

@mhanberg

mhanberg commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

I also removed OTP 24 from the test suite because that Elixir version was not compiling postgrex, and in #490 you mentioned not supporting OTP 24 any longer.

@mhanberg
mhanberg marked this pull request as ready for review August 3, 2026 15:07
Comment thread guides/ecto_stats.md Outdated
{:noreply, push_patch(socket, to: to)}
end

def handle_event("toggle_parameter_form", _params, socket) do

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.

Can be done with JS events rather than server side?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanted it to get persisted in the URL, which (to my knowledge) needs to go through the server. Please correct me if there is a better way to do this.

But if that is not desired, I can just remove the persistence.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, I put it in a details tag just to make it less obtrusive, but I can just get rid of that entirely too if that's desired (basically always show it)

|> Map.put_new(:row_attrs, [])
|> Map.put_new(:hint, nil)
|> Map.put_new(:dom_id, nil)
|> Map.put_new(:toolbar, [])

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.

Does this really belong in the table component? Should we render it on the page instead of making it part of tables?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanted the parameter form to go between the table title and the table itself, which required modifying the table component, or faking it by giving the table a nil title and then manually rendering a title on the page.

I'm open to an alternative if this new slot isn't desired.

Comment thread lib/phoenix/live_dashboard/components/table_component.ex
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