Skip to content

Commit

Permalink
fix(multi-dim): handle missing indicators gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Jul 29, 2024
1 parent 0faa6fd commit 8b77661
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions adminSiteServer/mockSiteRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ getPlainRouteNonIdempotentWithRWTransaction(
"/grapher/:slug",
async (req, res, trx) => {
const chartRow = await getChartConfigBySlug(trx, req.params.slug).catch(
noop
console.error
)
if (chartRow) {
// XXX add dev-prod parity for this
Expand All @@ -231,7 +231,7 @@ getPlainRouteNonIdempotentWithRWTransaction(
const page = await renderMultiDimDataPageBySlug(
trx,
req.params.slug
).catch(noop)
).catch(console.error)
if (page) {
res.send(page)
return
Expand Down
22 changes: 12 additions & 10 deletions baker/MultiDimBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ const resolveMultiDimDataPageCatalogPathsToIndicatorIds = async (
): Promise<MultiDimDataPageConfigPreProcessed> => {
const allCatalogPaths = rawConfig.views
.flatMap((view) =>
Object.values(view.indicators).flatMap((indicatorOrIndicators) =>
Array.isArray(indicatorOrIndicators)
? indicatorOrIndicators
: [indicatorOrIndicators]
Object.values(view.indicators ?? {}).flatMap(
(indicatorOrIndicators) =>
Array.isArray(indicatorOrIndicators)
? indicatorOrIndicators
: [indicatorOrIndicators]
)
)
.filter((indicator) => typeof indicator === "string")
Expand Down Expand Up @@ -95,12 +96,13 @@ const resolveMultiDimDataPageCatalogPathsToIndicatorIds = async (
}

for (const view of rawConfig.views) {
view.indicators = Object.fromEntries(
Object.entries(view.indicators).map(([key, value]) => [
key,
resolveField(value),
])
) as any
if (view.indicators)
view.indicators = Object.fromEntries(
Object.entries(view.indicators).map(([key, value]) => [
key,
resolveField(value),
])
) as any
}

return rawConfig as MultiDimDataPageConfigPreProcessed
Expand Down
8 changes: 4 additions & 4 deletions public/multi-dim/energy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@ views:
source: all
metric: total
indicators:
y: 900831
y: grapher/energy/2024-05-08/primary_energy_consumption/primary_energy_consumption#primary_energy_consumption__twh
- dimensions:
source: all
metric: per_capita
indicators:
y: 900839
y: grapher/energy/2024-05-08/primary_energy_consumption/primary_energy_consumption#primary_energy_consumption_per_capita__kwh
- dimensions:
source: all
metric: share_total
- dimensions:
source: all
metric: proportional_change
indicators:
y: 900830
y: grapher/energy/2024-05-08/primary_energy_consumption/primary_energy_consumption#annual_change_in_primary_energy_consumption__pct
- dimensions:
source: all
metric: absolute_change
indicators:
y: 900832
y: grapher/energy/2024-05-08/primary_energy_consumption/primary_energy_consumption#annual_change_in_primary_energy_consumption__twh

- dimensions:
source: fossil
Expand Down
2 changes: 1 addition & 1 deletion site/multiDim/MultiDimDataPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const MultiDimDataPageContent = ({

useEffect(() => {
setDatapageDataFromVar(null)
const yIndicatorOrIndicators = currentView?.indicators["y"]
const yIndicatorOrIndicators = currentView?.indicators?.["y"]
const variableId = Array.isArray(yIndicatorOrIndicators)
? yIndicatorOrIndicators[0]
: yIndicatorOrIndicators
Expand Down

0 comments on commit 8b77661

Please sign in to comment.