Skip to content

Commit 33a0281

Browse files
authored
Merge pull request #998 from cmu-delphi/sgratzl/fix_invalid_signal
feat: allow lazy evaluation of sensor param for generic pages
2 parents a5b65e5 + 68dde58 commit 33a0281

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

src/modes/dashboard/DashboardParameters.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import SensorDatePicker2 from '../../components/SensorDatePicker2.svelte';
44
import SensorSearch from '../../components/SensorSearch.svelte';
55
import { formatAPITime } from '../../data';
6-
import { nameInfos } from '../../data/regions';
76
import { metaDataManager } from '../../stores';
87
import { trackEvent } from '../../stores/ga';
8+
import { sortedNameInfos } from './utils';
99
1010
/**
1111
* @type {import("../../stores/params").SensorParam}
@@ -57,7 +57,7 @@
5757
<RegionSearch
5858
className="grid-5-9"
5959
modern
60-
items={nameInfos}
60+
items={sortedNameInfos}
6161
selectedItem={region.value}
6262
on:change={(e) => setRegion(e.detail && e.detail.level === 'nation' ? null : e.detail)}
6363
/>

src/modes/dashboard/config/RegionPicker.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
import RegionSearch from '../../../components/RegionSearch.svelte';
3-
import { countyInfo, getInfoByName, hhsInfo, hrrInfo, msaInfo, nationInfo, stateInfo } from '../../../data/regions';
3+
import { getInfoByName } from '../../../data/regions';
4+
import { sortedNameInfos } from '../utils';
45
56
/**
67
* @type {import("../../../stores/params").RegionParam}
@@ -15,7 +16,7 @@
1516
id: '',
1617
displayName: `Use Configured: ${region.displayName}`,
1718
};
18-
$: allItems = [defaultRegion, nationInfo, ...stateInfo, ...msaInfo, ...countyInfo, ...hrrInfo, ...hhsInfo];
19+
$: allItems = [defaultRegion, ...sortedNameInfos];
1920
</script>
2021

2122
<div>

src/modes/dashboard/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { countyInfo, hhsInfo, hrrInfo, msaInfo, nationInfo, stateInfo } from '../../data/regions';
2+
13
export function formToConfig(formData: FormData): Record<string, unknown> {
24
const config: Record<string, unknown> = {};
35

@@ -30,3 +32,5 @@ export function formToConfig(formData: FormData): Record<string, unknown> {
3032
});
3133
return config;
3234
}
35+
36+
export const sortedNameInfos = [nationInfo, ...stateInfo, ...msaInfo, ...countyInfo, ...hrrInfo, ...hhsInfo];

src/modes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface Mode {
88
component: () => Promise<any>;
99
anchor?: string;
1010
waitForReady?: boolean;
11+
isGeneric?: boolean;
1112
}
1213

1314
export default modes;

src/modes/modes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ export const modes = [
3333
{
3434
id: 'export',
3535
label: 'Export Data',
36+
isGeneric: true,
3637
component: () => import(/* webpackChunkName: 'm-export' */ './exportdata/ExportData.svelte').then((r) => r.default),
3738
},
3839
{
3940
id: 'indicator-status',
4041
label: 'Indicator Status Overview',
42+
isGeneric: true,
4143
component: () =>
4244
import(/* webpackChunkName: 'm-indicator-status' */ './indicator-status/IndicatorStatusOverview.svelte').then(
4345
(r) => r.default,
@@ -47,6 +49,7 @@ export const modes = [
4749
{
4850
id: 'indicator-source',
4951
label: 'Indicator Source',
52+
isGeneric: true,
5053
component: () =>
5154
import(/* webpackChunkName: 'm-indicator-source' */ './indicator-status/IndicatorSource.svelte').then(
5255
(r) => r.default,
@@ -56,6 +59,7 @@ export const modes = [
5659
{
5760
id: 'indicator-signal',
5861
label: 'Indicator Signal',
62+
isGeneric: true,
5963
component: () =>
6064
import(/* webpackChunkName: 'm-indicator-signal' */ './indicator-status/IndicatorSignal.svelte').then(
6165
(r) => r.default,
@@ -65,6 +69,7 @@ export const modes = [
6569
{
6670
id: 'dashboard',
6771
label: 'Dashboard Builder',
72+
isGeneric: true,
6873
component: () =>
6974
import(/* webpackChunkName: 'm-dashboard' */ './dashboard/Dashboard.svelte').then((r) => r.default),
7075
waitForReady: true,

src/stores/index.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,26 @@ function deriveFromPath(url: Location) {
5050
const mode = urlParams.get('mode') || modeFromPath();
5151

5252
const modeObj = modes.find((d) => d.id === mode) || DEFAULT_MODE;
53+
const isGenericPage = modeObj.isGeneric === true;
54+
// if a generic page, try to resolve but fall back to the given one, since it might be a not configured one
5355
const resolveSensor = resolveSensorWithAliases(
5456
sensor,
55-
modeObj === modeByID['survey-results'] ? DEFAULT_SURVEY_SENSOR : DEFAULT_SENSOR,
57+
isGenericPage
58+
? sensor || DEFAULT_SENSOR
59+
: modeObj === modeByID['survey-results']
60+
? DEFAULT_SURVEY_SENSOR
61+
: DEFAULT_SENSOR,
5662
);
5763
return {
5864
mode: modeObj,
5965
sensor: resolveSensor,
6066
sensor2: resolveSensorWithAliases(
6167
sensor2,
62-
DEFAULT_CORRELATION_SENSOR === sensor2 ? DEFAULT_SENSOR : DEFAULT_CORRELATION_SENSOR,
68+
isGenericPage
69+
? sensor2 || DEFAULT_CORRELATION_SENSOR
70+
: DEFAULT_CORRELATION_SENSOR === sensor2
71+
? DEFAULT_SENSOR
72+
: DEFAULT_CORRELATION_SENSOR,
6373
),
6474
lag: lag ? Number.parseInt(lag, 10) : 0,
6575
date: /\d{8}/.test(date) ? date : MAGIC_START_DATE,
@@ -77,10 +87,28 @@ const defaultValues = deriveFromPath(window.location);
7787
export const currentMode = writable(defaultValues.mode);
7888

7989
export const currentSensor = writable(defaultValues.sensor);
80-
export const currentSensorEntry = derived([currentSensor], ([$currentSensor]) => sensorMap.get($currentSensor));
90+
91+
function resolveSensor(sensor: string, defaultKey: string) {
92+
if (!sensor) {
93+
return null;
94+
}
95+
const r = sensorMap.get(sensor);
96+
if (r) {
97+
return r;
98+
}
99+
return sensorMap.get(defaultKey);
100+
}
101+
102+
export const currentSensorEntry = derived(
103+
[currentSensor],
104+
// lookup the value, if not found maybe a generic one, if it is set, then return the default, else return the empty one
105+
([$currentSensor]) => resolveSensor($currentSensor, DEFAULT_SENSOR),
106+
);
81107

82108
export const currentSensor2 = writable(defaultValues.sensor2);
83-
export const currentSensorEntry2 = derived([currentSensor2], ([$currentSensor]) => sensorMap.get($currentSensor));
109+
export const currentSensorEntry2 = derived([currentSensor2], ([$currentSensor]) =>
110+
resolveSensor($currentSensor, DEFAULT_CORRELATION_SENSOR),
111+
);
84112

85113
export const currentLag = writable(defaultValues.lag);
86114

0 commit comments

Comments
 (0)