Skip to content

Commit f1c1ff7

Browse files
committed
Fix empty datasets locking UI
1 parent 7056e57 commit f1c1ff7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/api/EpiData.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ function loadEpidata(
9191
}
9292
points.push(new EpiPoint(date, row[col] as number));
9393
}
94-
datasets.push(new DataSet(points, col, params));
94+
if (points.length > 0) {
95+
datasets.push(new DataSet(points, col, params));
96+
}
9597
}
9698
return new DataGroup(name, datasets);
9799
}
@@ -135,7 +137,19 @@ export function loadDataSet(
135137
url.searchParams.set('format', 'json');
136138
return fetchImpl<Record<string, unknown>[]>(url)
137139
.then((res) => {
138-
return loadEpidata(title, res, columns, { _endpoint: endpoint, ...params });
140+
const data = loadEpidata(title, res, columns, { _endpoint: endpoint, ...params });
141+
if (data.datasets.length == 0) {
142+
console.warn('empty datasets');
143+
return UIkit.modal
144+
.alert(
145+
`
146+
<div class="uk-alert uk-alert-error">
147+
<a href="${url.href}">API Link</a> returned no data.
148+
</div>`,
149+
)
150+
.then(() => null);
151+
}
152+
return data;
139153
})
140154
.catch((error) => {
141155
console.warn('failed fetching data', error);

0 commit comments

Comments
 (0)