Download button, share button, and url shortener button stay not in sync with visualization while editing
The json export button, the csv export button, the share button, and the url-shorter button are not updated when the user changes metrics, groupby, or other properties of the visualization. Thus, the user downloads or shares the wrong data. They are updated when the site is reloaded by clicking on refresh.
Steps to recreate it:
- Open a slice, e.g. /caravel/explore/table/2/?slice_name=World's+Pop+Growth&row_limit=50000&metric=sum__SP_POP_TOTL&show_bubbles=y&entity=country_code&secondary_metric=sum__SP_POP_TOTL&viz_type=area&since=1960-01-01&json=false&until=now&datasource_id=1&metrics=sum__SP_POP_TOTL&datasource_name=birth_names&country_fieldtype=cca3&granularity=year&slice_id=11&datasource_type=table&compare_lag=10&limit=25&markup_type=markdown&compare_suffix=o10Y&where=&groupby=region .
- Change the metric from sum__SP_POP_TOTAL to Count( ) and hit 'Query'. The visualization updates and location in the browser bar changes accordingly. The new metric is used.
- Download the json/csv file. Expected: The data uses the new "Count( )" metric. Actual result: The data still uses the the old metric sum__SP_POP_TOTAL metric. All other values like json_endpoint, csv_endpoint, or metric in the json data still refer to the old metric. Inspecting the link in the csv/json download button reveals that the links use the old metric. Though, the SQL-Query from the query button is correct.
- Refresh the page.
- Download json/csv and get the expected data.
The same bug applies when chart parameters are changed.
Cause
The state of the page with all the parameters for metric, group by, etc. is saved in the global variable 'slice'. When the user changes params, they are updated in 'slice'. The buttons are React Components created with the property 'slice'. However, they do not listen to updates of 'slice' and keep the initial value.
thanks for this report @prokh , i'll look into.