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

Set COVIDcast export values based on URL parameters #1244

Merged
merged 7 commits into from
May 13, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/modes/exportdata/ExportData.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,33 @@
}
}

// Pre-fill the form from URL parameters.
// Supported parameters: source, sensor, start, end, geo_type, geo_id
Copy link
Contributor

Choose a reason for hiding this comment

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

change these to match new parameter names

const urlParams = new URLSearchParams(window.location.search);

// Overwrite default source & sensor if these are present in the URL
if (urlParams.has('source')) {
sourceValue = urlParams.get('source');

if (urlParams.has('sensor')) {
sensorValue = urlParams.get('sensor');
}
}

$: isWeekly = sensor ? sensor.isWeeklySignal : false;
$: formatDate = isWeekly ? (d) => formatWeek(d).replace('W', '') : formatDateISO;

let geoType = 'county';
let geoType = urlParams.has('geo_type') ? urlParams.get('geo_type') : 'county';

let startDate = new Date();
let endDate = new Date();

function initDate(date) {
const param = new DateParam(date);
endDate = param.sparkLineTimeFrame.max;
startDate = param.sparkLineTimeFrame.min;

// Populate date based on URL params or, if absent, the current date
startDate = urlParams.has('start') ? new Date(urlParams.get('start')) : param.sparkLineTimeFrame.min;
endDate = urlParams.has('end') ? new Date(urlParams.get('end')) : param.sparkLineTimeFrame.max;
}
$: initDate($currentDateObject);

Expand All @@ -59,12 +74,20 @@

let geoValuesMode = 'all';
let geoValues = [];
let geoURLSet = false;
$: geoItems = [...(infosByLevel[geoType] || []), ...(geoType === 'county' ? infosByLevel.state : [])];
$: {
if (geoItems != null) {
geoValues = [];
geoValuesMode = guessMode(geoItems.length);
}

// Populate region based on URL params... but let the user override this later
if (urlParams.has('geo_id') && !geoURLSet) {
let infos = infosByLevel[geoType].filter((d) => d.propertyId == urlParams.get('geo_id'));
addRegion(infos[0]);
geoURLSet = true;
}
}

function flatIds(geoValues) {
Expand Down
Loading