Populate Data Explorer params with URL params

AI-generated summary

The discussion revolves around enhancing the Data Explorer feature in Discourse to allow URL parameters to pre-fill query parameters. Nacho_Caballero initially proposed this idea to facilitate sharing queries with pre-filled parameters. sam welcomed the suggestion, marking it as a potential improvement. loginerror added suggestions for a &run parameter to automatically execute the report and parameters carrying user context. lucasbasquerotto cautioned about security implications of the &run parameter with same-site cookie settings. Nam implemented the feature, allowing parameters to be added to the URL after pressing ‘run’. markvanlan confirmed the PR was merged and asked if it met the original request. Nacho_Caballero expressed interest in extending this functionality to reports. markvanlan and Nacho_Caballero discussed generating URLs with parameters for group reports. Lhc_fl referenced a PR that addresses the report parameter functionality. hugh announced the addition of the &run parameter, which automatically runs the report upon page load, as documented in the Data Explorer plugin page.

It would be great if I could share a Data Explorer query with a group and have the query params be pre-filled with the URL params.

For example, if I have this param -- string :username, I should be able to share it with group “my-group” with username “myName”.

Something like this:

https://mydomain.com/g/my-group/reports/100?username=myName

11 Likes

Sure … putting a pr-welcome on this, seems like a nice quality of life change!

4 Likes

Bumping the topic with one more suggestion:

  • having a &run parameter that will fire report upon page load, to save user a click
  • having set of parameters that would carry user context (this way you could auto-insert the username of the current user, for example)

We would like this feature because it would allow us to easily automate internal notifications for topics for each interested user :slight_smile:

4 Likes

It’s just important to note that if a run parameter is added, it should not be used if the same-site cookie is set to None (or Disabled and the browser defines None as the default).

If the same-site is none, you could enter some other site and they could make a http GET request, in the same way that CSRF is exploited, although this would not be a CSRF vulnerability per se, but they could execute some really expensive instructions in the data explorer.

The same-site cookie policy is relatively new, but the major browsers already support it for some time, Chrome defaults to Lax, and Discourse too (if I’m not wrong), so it should not be a problem in most cases.

I added the Data Explorer params to the URL. The Params are added when the user press ‘run’ button.
This is the example after press ‘run’:
Screen Shot 2021-07-28 at 1.19.56 PM


and here is the link for the PR:
https://github.com/discourse/discourse-data-explorer/pull/128

6 Likes

The PR linked above was merged. Does this accomplish what you were looking for? You have to run the query to have the query params added to the URL, so you can run it, copy the link, and share.

3 Likes

@Nam Thanks for your work on this!

This currently works for queries run in the Data explorer, but I wonder if it would be possible to make this work as a report. Something like:

mysite.com/g/my-group/reports/6&params=%7B"months_ago"%3A"3"%7D

2 Likes

We could add support for filling the inputs on the groups report run page, with params from the URL. That wouldn’t be difficult at alI. The question I have is, how do you get this URL? Is it generated for a given group somehow, or are you just manually generating the URL?

If you go to the group page, you’ll see a “Reports” tab with links to the queries that are available for that group, but the params would probably have to generated manually.

1 Like

Okay, I’ll add support for filling in the inputs in the groups report show page, with params from the URL.

5 Likes

I thinks we never got to this? I can certainly see it being useful.

This PR should be able to make up for it:

https://github.com/discourse/discourse-data-explorer/pull/298

Its effect is as shown in the above quote

4 Likes

We circled back to this request and have now added a run paramater that will automatically run the report when the page is loaded. It is documented in the Data Explorer plugin page here:

2 Likes