# Universal Filters on WIZE See example filter on [https://insight.livestories.com/s/v2/sample-smart-story/350b9a01-5b90-4842-83d4-a123be0ac286/](https://insight.livestories.com/s/v2/sample-smart-story/350b9a01-5b90-4842-83d4-a123be0ac286/) **Discovery Notes:** - A universal filter allows to set a filter on a given dataset (not a chart). All charts based on that dataset should refresh based on the filter selection. > In Wize we can't introspect the dataset of a chart so the server will have to do a check. - Charts maybe configured to ignore universal filters, meaning that even if there is a universal filter defined on their dataset in a story, they should not update. > Same as above the server will have to perform that check because it has the details of the chart. - The values to display in a universal filter drop down may change based on the dataset content (which can change if user refresh, independently of republishing the story). So WIZE will need to dynamically pull the list. > There is an endpoint ready on Insight to do this. See below. - There may be multiple universal filters on a page, that control multiple pairs `(dataset_id, field_value)` so the URL system we implement must support that. > This means we need to create a sample story with that use case, and ask CS if they know of any example to validate. ## Implementing the Universal Filter Drop down. When a story contains a universal filter, the following JSON is received by WIZE to render: ``` { "id": "d8aba51d-bd3f-43bc-be23-9939fcc12cf8", "sortOrder": 0, "height": 20, "type": "filter", "cellId": "1fb96cdf-de8b-4bec-ada0-2a3f36cb4b4e", "instance": { "id": "abb268c2-6af4-4a65-887b-80877207f10d", "moduleId": "d8aba51d-bd3f-43bc-be23-9939fcc12cf8", "datasetId": "5b7c3871666890001364deac", "field": "Year" } } ``` The list of values to populate the drop can be fetched from: `https://insight.livestories.com/api/dataset/field_values?dataset_id=5b7c3871666890001364deac&field=Year ` Which returns: `{"values": [2013, 2014, 2015, 2016], "type": "generic"}` **Note**: the field value can contain unexpected characters, so it is important to URL encode it in the queryParam. In fact the example story above uses `"field": "�Region"` so it is a good test that the encoding is correct, or else no values are returned. ## Passing the values of the filter(s) to charts Since WIZE can't introspect the charts, it needs to pass all the information blindly to all legacy charts, and let the server check what is relevant for what chart. Also, we need to account for the multi-dataset/multi-filter case. So I propose we augment the URL structure of charts in iFrame as follows: `https://insight.livestories.com/chart/embed?dashId=5d5dac70fb9e940014c2a0bf&select=5b7c3871666890001364deac,Year,2013&select=<dataset_id>,<field>,<selected_value> ` - there should be 1 `select` entry per universal filter - the value should be `select=<dataset_id>,<field>,<selected_value>`