Skip to content

Commit 4447ab4

Browse files
authored
Merge pull request #1263 from cmu-delphi/signal_dashboard_default_date_fix
Fixed default date for the particular indicator(signal) dashboard
2 parents 0626cd2 + 613ea13 commit 4447ab4

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/blocks/IndicatorWarning.svelte

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
function switchDate() {
2727
date.set(sensor.timeFrame.max);
2828
}
29+
function getUrlWithParams() {
30+
let params = window.location.search;
31+
let result = new URLSearchParams();
32+
result.append('date', formatAPITime(sensor.timeFrame.max));
33+
result.append('sensor', sensor.key);
34+
let regionParam = new URLSearchParams(params).get('region');
35+
if (regionParam) {
36+
result.append('region', regionParam);
37+
}
38+
return result.toString();
39+
}
2940
</script>
3041

3142
{#if !sensor.value.levels.includes(region.level)}
@@ -38,14 +49,7 @@
3849
<div data-uk-alert class="uk-alert-warning">
3950
The indicator "{sensor.name}" is not available for {formatDateYearDayOfWeekAbbr(date.value)}, yet. The latest
4051
known data is available on
41-
<!--
42-
window.location.search.split('&').slice(1).join('&') is used to keep the query parameters except the date parameter.
43-
So we are getting query params from url, splitting them by & and removing the first element which is date parameter.
44-
-->
45-
<a
46-
href="?date={formatAPITime(sensor.timeFrame.max)}&{window.location.search.split('&').slice(1).join('&')}"
47-
on:click={switchDate}>{formatDateYearDayOfWeekAbbr(sensor.timeFrame.max)}</a
48-
>.
52+
<a href="?{getUrlWithParams()}" on:click={switchDate}>{formatDateYearDayOfWeekAbbr(sensor.timeFrame.max)}</a>.
4953
</div>
5054
{/if}
5155
{/await}

0 commit comments

Comments
 (0)