diff --git a/packages/pxweb2/src/app/context/TableDataProvider.tsx b/packages/pxweb2/src/app/context/TableDataProvider.tsx index d203ef473..dd6fb75b4 100644 --- a/packages/pxweb2/src/app/context/TableDataProvider.tsx +++ b/packages/pxweb2/src/app/context/TableDataProvider.tsx @@ -4,6 +4,7 @@ import React, { createContext, useEffect, useState, ReactNode } from 'react'; import useVariables from './useVariables'; import { Dataset, + OutputFormatType, TableService, VariableSelection, VariablesSelection, @@ -261,7 +262,7 @@ const TableDataProvider: React.FC = ({ children }) => { const res = await TableService.getTableDataByPost( tableId, i18n.language, - 'json-stat2', + OutputFormatType.JSON_STAT2, undefined, variablesSelection, ); @@ -312,6 +313,13 @@ const TableDataProvider: React.FC = ({ children }) => { return false; } + // Check if any variable has an empty or undefined valueCodes array + for (const selection of variablesSelection.selection) { + if (!selection.valueCodes || selection.valueCodes.length === 0) { + return false; + } + } + for (const selection of variablesSelection.selection) { // Check that the variable exists in accumulatedData const variable = accumulatedData.metadata.variables.find( diff --git a/packages/pxweb2/src/app/context/VariablesProvider.tsx b/packages/pxweb2/src/app/context/VariablesProvider.tsx index a7658150b..e42d2f71c 100644 --- a/packages/pxweb2/src/app/context/VariablesProvider.tsx +++ b/packages/pxweb2/src/app/context/VariablesProvider.tsx @@ -78,9 +78,16 @@ export const VariablesProvider: React.FC<{ children: React.ReactNode }> = ({ const addSelectedValues = (variableId: string, values: string[]) => { setVariables((prev) => { const newVariables = new Map(prev); - values.forEach((value) => { - newVariables.set(variableId + '-' + value, { id: variableId, value }); - }); + if (values.length === 0) { + newVariables.set(variableId + '-none-selected', { + id: variableId, + value: 'none-selected', + }); + } else { + values.forEach((value) => { + newVariables.set(variableId + '-' + value, { id: variableId, value }); + }); + } return newVariables; }); };