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

Shared filter configurator filter #1598

Merged
merged 8 commits into from
Jun 12, 2024
Merged

Conversation

ptbrowne
Copy link
Collaborator

The shared filter configurator would fetch all the components for all cubes at once,
when in fact they should be fetched independently for each chart config. This PR
fixes that. It takes care of deduping fetching of components for the same cube
filter values.

@ptbrowne ptbrowne requested a review from bprusinowski as a code owner June 11, 2024 14:42
Copy link

vercel bot commented Jun 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
visualization-tool ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 11:32am

Copy link
Collaborator

@bprusinowski bprusinowski left a comment

Choose a reason for hiding this comment

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

LGTM 👌

app/configurator/components/layout-configurator.tsx Outdated Show resolved Hide resolved
@ptbrowne
Copy link
Collaborator Author

The problem is felt on dashboard with multiple datasets without joins.

For example

state = {"layout":{"meta":{"title":{"de":"Entwicklung der Werbeeinnahmen seit 2000","en":"Development of advertising revenues since 2000","fr":"Evolution des recettes publicitaires depuis 2000","it":"Evoluzione dei ricavi pubblicitari dal 2000"},"description":{"de":"Quelle: Werbeaufwand Schweiz 2024 (Stiftung Werbestatistik Schweiz) | aktualisiert: 03.06.2024 | BAKOM-M-GM (MF)","en":"Source: Advertising expenditure in Switzerland (Stiftung Werbestatistik Schweiz) | updated: 03.06.2024 |  | BAKOM-M-GM (MF)","fr":"Source: Dépenses publicitaires en Suisse (Fondation Statistique Suisse en Publicité) | acutalisé: 03.06.2024 | BAKOM-M-GM (MF)","it":"Fonte: Spese pubblicitarie in Svizzera (Fondazione Statistica Svizzera della Pubblicità) | aggiornato: 03.06.2024 | BAKOM-M-GM (MF)"}},"type":"tab"},"version":"3.4.0","dataSource":{"url":"https://int.lindas.admin.ch/query","type":"sparql"},"chartConfigs":[{"key":"lv5k3NNI5QUe","meta":{"title":{"de":"Entwicklung der Netto-Werbeumsätze","en":"Development of net advertising revenues","fr":"Evolution du chiffre d'affaires publicitaire net","it":"Sviluppo della raccolta pubblicitaria netta"},"description":{"de":"Jährliche Netto-Werbeeinnahmen publizistischer Medien (2000-2023)","en":"Annual net advertising revenues of publishing media (2000-2023)","fr":"Recettes publicitaires annuelles nettes des médias journalistiques (2000-2023)","it":"Entrate pubblicitarie nette annuali dei media giornalistici (2000-2023)"}},"cubes":[{"iri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/6","filters":{"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptmediengattung":{"type":"multi","values":{"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_1":true,"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_2":true,"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_3":true,"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_5":true}},"http://schema.org/observationDate":{"to":"2023","from":"2000","type":"range"}},"publishIri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/6"}],"fields":{"x":{"sorting":{"sortingType":"byAuto","sortingOrder":"asc"},"componentIri":"http://schema.org/observationDate"},"y":{"componentIri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/advertisingRevenue"},"segment":{"type":"stacked","palette":"category10","sorting":{"sortingType":"byTotalSize","sortingOrder":"asc"},"colorMapping":{"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_1":"#1f77b4","https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_2":"#ff7f0e","https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_3":"#2ca02c","https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_5":"#d62728"},"componentIri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptmediengattung"}},"version":"3.3.0","chartType":"column","interactiveFiltersConfig":{"legend":{"active":true,"componentIri":""},"timeRange":{"active":true,"presets":{"to":"2023","from":"2000","type":"range"},"componentIri":"http://schema.org/observationDate"},"calculation":{"type":"identity","active":true},"dataFilters":{"active":false,"componentIris":[]}}},{"key":"g6hh9H0qx0hl","meta":{"title":{"de":"Presse: Nettowerbeeinnahmen nach Pressetyp","en":"Press: net advertising revenue by press type","fr":"Presse : Recettes publicitaires nettes par type de presse","it":"Stampa: Ricavi pubblicitari netti per tipo di stampa"},"description":{"de":"Jährliche Nettowerbeeinnahmen: Presse (2002-2023)","en":"Annual net advertising revenues: press (2002-2023)","fr":"Recettes publicitaires annuelles nettes : Presse (2002-2023)","it":"Ricavi pubblicitari netti annuali: Stampa (2002-2023)"}},"cubes":[{"iri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/1","filters":{"http://schema.org/observationDate":{"to":"2023","from":"2002","type":"range"},"https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/conceptpressetyp":{"type":"multi","values":{"https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/conceptPressetyp/pressetyp_1":true,"https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/conceptPressetyp/pressetyp_2":true,"https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/conceptPressetyp/pressetyp_3":true}}},"publishIri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/1"}],"fields":{"x":{"componentIri":"http://schema.org/observationDate"},"y":{"componentIri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/advertisingRevenue"},"segment":{"palette":"category10","sorting":{"sortingType":"byTotalSize","sortingOrder":"asc"},"colorMapping":{"https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/conceptPressetyp/pressetyp_1":"#1f77b4","https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/conceptPressetyp/pressetyp_2":"#ff7f0e","https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/conceptPressetyp/pressetyp_3":"#2ca02c"},"componentIri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_press_types/conceptpressetyp"}},"version":"3.3.0","chartType":"line","interactiveFiltersConfig":{"legend":{"active":true,"componentIri":""},"timeRange":{"active":true,"presets":{"to":"2023","from":"2002","type":"range"},"componentIri":"http://schema.org/observationDate"},"calculation":{"type":"identity","active":false},"dataFilters":{"active":false,"componentIris":[]}}},{"key":"qCTNsCUxnaFE","meta":{"title":{"de":"Radio: Nettowerbeeinnahmen total","en":"Radio: Total net advertising revenue","fr":"Radio : recettes publicitaires nettes totales","it":"Radio: ricavi pubblicitari netti totali"},"description":{"de":"Jährliche Nettowerbeeinnahmen: Radio – Private und SRG (2000-2023), inkl. Sponsoring und Digital Audio (2023)","en":"Annual net advertising revenues: radio – private and SRG (2000-2023), incl. sponsorship and digital audio (2023)","fr":"Recettes publicitaires annuelles nettes : Radio - privés et SSR (2000-2023), y compris sponsoring et audio numérique (2023)","it":"Ricavi pubblicitari netti annuali: Radio - privata e SSR (2000-2023), incluse sponsorizzazioni e audio digitale (2023)"}},"cubes":[{"iri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/6","filters":{"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptmediengattung":{"type":"multi","values":{"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_3":true}},"http://schema.org/observationDate":{"to":"2023","from":"2000","type":"range"}},"publishIri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/6"}],"fields":{"x":{"sorting":{"sortingType":"byAuto","sortingOrder":"asc"},"componentIri":"http://schema.org/observationDate"},"y":{"componentIri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/advertisingRevenue"},"segment":{"type":"stacked","palette":"category10","sorting":{"sortingType":"byTotalSize","sortingOrder":"asc"},"colorMapping":{"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_1":"#1f77b4","https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_2":"#ff7f0e","https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_3":"#2ca02c","https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptMediengattung/mediengattung_5":"#d62728"},"componentIri":"https://communication.ld.admin.ch/ofcom/advertising_revenue_per_media_genre/conceptmediengattung"}},"version":"3.3.0","chartType":"column","interactiveFiltersConfig":{"legend":{"active":false,"componentIri":""},"timeRange":{"active":true,"presets":{"to":"2023","from":"2000","type":"range"},"componentIri":"http://schema.org/observationDate"},"calculation":{"type":"identity","active":false},"dataFilters":{"active":false,"componentIris":[]}}},{"key":"LlDI1leaVAvE","meta":{"title":{"de":"Fernsehen: Nettowerbeeinnahmen nach Senderart","en":"Television: net advertising revenue by type of station","fr":"Télévision : Recettes publicitaires nettes par type de chaîne","it":"Televisione: Ricavi pubblicitari netti per tipo di canale"},"description":{"de":"Jährliche Nettowerbeeinnahmen: Fernsehen (2000-2023)","en":"Annual net advertising revenues: Television (2000-2023)","fr":"Recettes publicitaires annuelles nettes : Télévision (2000-2023)","it":"Ricavi pubblicitari netti annuali: Televisione (2000-2023)"}},"cubes":[{"iri":"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/5","filters":{"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptsendegruppe":{"type":"multi","values":{"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_1":true,"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_2":true,"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_3":true}},"http://schema.org/observationDate":{"to":"2023","from":"2000","type":"range"}},"publishIri":"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/5"}],"fields":{"x":{"componentIri":"http://schema.org/observationDate"},"y":{"componentIri":"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/advertisingRevenue"},"segment":{"palette":"category10","sorting":{"sortingType":"byTotalSize","sortingOrder":"asc"},"colorMapping":{"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_1":"#1f77b4","https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_2":"#ff7f0e","https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_3":"#2ca02c"},"componentIri":"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptsendegruppe"}},"version":"3.3.0","chartType":"line","interactiveFiltersConfig":{"legend":{"active":true,"componentIri":""},"timeRange":{"active":true,"presets":{"to":"2023","from":"2000","type":"range"},"componentIri":"http://schema.org/observationDate"},"calculation":{"type":"identity","active":false},"dataFilters":{"active":false,"componentIris":[]}}},{"key":"ZUyTfZ75FlYV","meta":{"title":{"de":"Fernsehen: Markanteile Nettowerbeeinnahmen nach Senderart","en":"Television: market shares of net advertising revenues by type of broadcaster","fr":"Télévision : Parts de marché des recettes publicitaires nettes par type de chaîne","it":"Televisione: Quota di mercato dei ricavi pubblicitari netti per tipo di canale"},"description":{"de":"Jährliche Nettowerbeeinnahmen: Marktanteile TV (2000-2023), SRG vs. ausländische Werbefenster","en":"Annual net advertising revenues: market shares TV (2000-2023), SRG vs. foreign advertising windows","fr":"Recettes publicitaires annuelles nettes : Parts de marché TV (2000-2023), SSR vs. fenêtres publicitaires étrangères","it":"Ricavi pubblicitari netti annuali: Quote di mercato TV (2000-2023), SRG vs. finestre pubblicitarie estere"}},"cubes":[{"iri":"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/5","filters":{"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptsendegruppe":{"type":"multi","values":{"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_1":true,"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_2":true,"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_3":true}},"http://schema.org/observationDate":{"to":"2023","from":"2000","type":"range"}},"publishIri":"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/5"}],"fields":{"x":{"sorting":{"sortingType":"byAuto","sortingOrder":"asc"},"componentIri":"http://schema.org/observationDate"},"y":{"componentIri":"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/advertisingRevenue"},"segment":{"type":"stacked","palette":"category10","sorting":{"sortingType":"byAuto","sortingOrder":"asc"},"colorMapping":{"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_1":"#1f77b4","https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_2":"#ff7f0e","https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptSendegruppe/sendegruppe_3":"#2ca02c"},"componentIri":"https://communication.ld.admin.ch/ofcom/tv_programs_advertising_revenue/conceptsendegruppe"}},"version":"3.3.0","chartType":"column","interactiveFiltersConfig":{"legend":{"active":true,"componentIri":""},"timeRange":{"active":true,"presets":{"to":"2023","from":"2000","type":"range"},"componentIri":"http://schema.org/observationDate"},"calculation":{"type":"percent","active":false},"dataFilters":{"active":false,"componentIris":[]}}},{"key":"5hGPa51ai9XH","meta":{"title":{"de":"Online-Display-Werbung: Nettowerbeeinnahmen nach Publikationsart","en":"Online display advertising: net advertising revenue by type of publication","fr":"Publicité display en ligne : recettes publicitaires nettes par type de publication","it":"Pubblicità display online: ricavi pubblicitari netti per tipo di pubblicazione"},"description":{"de":"Jährliche Nettowerbeeinnahmen: Online-Display (2014-2023), inkl. Publikationsart (2019-2023)","en":"Annual net advertising revenues: online display (2014-2023), incl. publication type (2019-2023)","fr":"Recettes publicitaires annuelles nettes : Display en ligne (2014-2023), y compris type de publication (2019-2023)","it":"Ricavi pubblicitari netti annuali: Display online (2014-2023), incl. tipo di pubblicazione (2019-2023)"}},"cubes":[{"iri":"https://communication.ld.admin.ch/ofcom/online-media_display_advertising_revenue/4","filters":{"http://schema.org/observationDate":{"to":"2023","from":"2014","type":"range"}},"publishIri":"https://communication.ld.admin.ch/ofcom/online-media_display_advertising_revenue/4"}],"fields":{"x":{"sorting":{"sortingType":"byAuto","sortingOrder":"asc"},"componentIri":"http://schema.org/observationDate"},"y":{"componentIri":"https://communication.ld.admin.ch/ofcom/online-media_display_advertising_revenue/revenue"},"segment":{"type":"stacked","palette":"category10","sorting":{"sortingType":"byTotalSize","sortingOrder":"asc"},"colorMapping":{"https://communication.ld.admin.ch/ofcom/online-media_display_advertising_revenue/conceptKategorie/kategorie_1":"#1f77b4","https://communication.ld.admin.ch/ofcom/online-media_display_advertising_revenue/conceptKategorie/kategorie_2":"#ff7f0e","https://communication.ld.admin.ch/ofcom/online-media_display_advertising_revenue/conceptKategorie/kategorie_3":"#2ca02c","https://communication.ld.admin.ch/ofcom/online-media_display_advertising_revenue/conceptKategorie/kategorie_4":"#d62728","https://communication.ld.admin.ch/ofcom/online-media_display_advertising_revenue/conceptKategorie/kategorie_5":"#9467bd","https://communication.ld.admin.ch/ofcom/online-media_display_advertising_revenue/conceptKategorie/kategorie_6":"#8c564b"},"componentIri":"https://communication.ld.admin.ch/ofcom/online-media_display_advertising_revenue/conceptkategorie"}},"version":"3.3.0","chartType":"column","activeField":"x","interactiveFiltersConfig":{"legend":{"active":false,"componentIri":""},"timeRange":{"active":true,"presets":{"to":"2023","from":"2014","type":"range"},"componentIri":"http://schema.org/observationDate"},"calculation":{"type":"identity","active":true},"dataFilters":{"active":false,"componentIris":[]}}},{"key":"sC2WOUWWB-X1","meta":{"title":{"de":"Online-Werbeeinnahmen: Schätzung restlicher Online-Markt","en":"Online advertising revenues: estimate of rest of online market","fr":"Recettes publicitaires en ligne : Estimation du reste du marché en ligne","it":"Ricavi pubblicitari online: Stima del mercato online rimanente"},"description":{"de":"Online-Werbeeinnahmen: Schätzungen restlicher Online-Markt (Mittelwerte), 2021-2023","en":"Online advertising revenues: estimates for the rest of the online market (mean values), 2021-2023","fr":"Recettes publicitaires en ligne : Estimations du reste du marché en ligne (valeurs moyennes), 2021-2023","it":"Ricavi pubblicitari online: Stime per il resto del mercato online (valori medi), 2021-2023"}},"cubes":[{"iri":"https://communication.ld.admin.ch/ofcom/estimation_advertising_revenue_online/1","filters":{"http://schema.org/name":{"type":"multi","values":{"Search":true,"YouTube":true,"Social Media":true}},"http://schema.org/observationDate":{"to":"2023","from":"2021","type":"range"}},"publishIri":"https://communication.ld.admin.ch/ofcom/estimation_advertising_revenue_online/1"}],"fields":{"x":{"sorting":{"sortingType":"byAuto","sortingOrder":"asc"},"componentIri":"http://schema.org/observationDate"},"y":{"componentIri":"https://communication.ld.admin.ch/ofcom/estimation_advertising_revenue_online/advertisingRevenue"},"segment":{"type":"stacked","palette":"category10","sorting":{"sortingType":"byTotalSize","sortingOrder":"asc"},"colorMapping":{"Search":"#1f77b4","YouTube":"#2ca02c","Social Media":"#ff7f0e"},"componentIri":"http://schema.org/name"}},"version":"3.3.0","chartType":"column","interactiveFiltersConfig":{"legend":{"active":true,"componentIri":""},"timeRange":{"active":true,"presets":{"to":"2023","from":"2021","type":"range"},"componentIri":"http://schema.org/observationDate"},"calculation":{"type":"identity","active":true},"dataFilters":{"active":false,"componentIris":[]}}}],"activeChartKey":"lv5k3NNI5QUe","dashboardFilters":{"filters":[]},"state":"CONFIGURING_CHART"}

Here, the way the fetched worked was to flatMap all the cubeFilter together. It does not work when the multiple datasets are not joined, since we expect that cubeFilters have at least one join if they differ. This is why we need to execute multiple times executeDataCubesComponentsQuery.

Or maybe it's fine like now, but maybe it would make sense not introduce another data fetching wrapper, but reuse what we have already (with benefits like keepPreviousData, etc), let me know 😅

The data fetcher is not new, but you're right that here it makes sense to use makeUseQuery (I moved the hook to hooks.ts as a last step, and missed this, thanks !)

Copy link
Collaborator

@bprusinowski bprusinowski left a comment

Choose a reason for hiding this comment

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

Thanks for explanation 🙇‍♂️

ptbrowne added 2 commits June 12, 2024 13:22
… error)

When the call to execute is done in useEffect, the stack trace is lost,
while when it is done in the body of the component, the stack trace is
preserved
@ptbrowne ptbrowne force-pushed the fix/shared-filter-configurator branch from 153dcea to d799ab3 Compare June 12, 2024 11:23
@ptbrowne ptbrowne merged commit 1fe3762 into main Jun 12, 2024
2 checks passed
@ptbrowne ptbrowne deleted the fix/shared-filter-configurator branch June 12, 2024 11:31
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