Skip to content

Add variables without selected values to selection payload for data requests #592

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

Merged
merged 4 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion packages/pxweb2/src/app/context/TableDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { createContext, useEffect, useState, ReactNode } from 'react';
import useVariables from './useVariables';
import {
Dataset,
OutputFormatType,
TableService,
VariableSelection,
VariablesSelection,
Expand Down Expand Up @@ -261,7 +262,7 @@ const TableDataProvider: React.FC<TableDataProviderProps> = ({ children }) => {
const res = await TableService.getTableDataByPost(
tableId,
i18n.language,
'json-stat2',
OutputFormatType.JSON_STAT2,
undefined,
variablesSelection,
);
Expand Down Expand Up @@ -312,6 +313,13 @@ const TableDataProvider: React.FC<TableDataProviderProps> = ({ 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(
Expand Down
13 changes: 10 additions & 3 deletions packages/pxweb2/src/app/context/VariablesProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
};
Expand Down