Skip to content

Commit

Permalink
refactor(api): Refactor WidgetUtils.getSupportedVisualizations function
Browse files Browse the repository at this point in the history
  • Loading branch information
alepefe committed Nov 8, 2024
1 parent 205d1ad commit 28def04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
10 changes: 2 additions & 8 deletions api/src/infrastructure/postgres-survey-answers.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,8 @@ export class PostgresSurveyAnswerRepository
return this[methodName](widget, filterClause);
}

const [
supportsChart,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
supportsSingleValue, // No generic implementation for single value widgets for the time being
supportsMap,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
supportsNavigation, // No generic implementation navigation widgets for the time being
] = WidgetUtils.getSupportedVisualizations(widget);
const [supportsChart, supportsMap] =
WidgetUtils.getSupportedVisualizations(widget);

const dataPromises = [];
if (supportsChart === true) {
Expand Down
12 changes: 5 additions & 7 deletions shared/dto/widgets/widget.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ const isValidDefaultVisualization = (

const getSupportedVisualizations = (widget: BaseWidgetWithData) => {
let supportsChart = false;
let supportsSingleValue = false;
let supportsMap = false;
let supportsNavigation = false;
// No generic implementation for single value widgets for the time being
// let supportsSingleValue = false;
// No generic implementation navigation widgets for the time being
// let supportsNavigation = false;

const visualizationModes = widget.visualisations;
for (let idx = 0; idx < visualizationModes.length; idx++) {
Expand All @@ -38,16 +40,12 @@ const getSupportedVisualizations = (widget: BaseWidgetWithData) => {
visualizationMode === WIDGET_VISUALIZATIONS.PIE_CHART
) {
supportsChart = true;
} else if (visualizationMode === WIDGET_VISUALIZATIONS.SINGLE_VALUE) {
supportsSingleValue = true;
} else if (visualizationMode === WIDGET_VISUALIZATIONS.MAP) {
supportsMap = true;
} else if (visualizationMode === WIDGET_VISUALIZATIONS.NAVIGATION) {
supportsNavigation = true;
}
}

return [supportsChart, supportsSingleValue, supportsMap, supportsNavigation];
return [supportsChart, supportsMap];
};

export const WidgetUtils = {
Expand Down

0 comments on commit 28def04

Please sign in to comment.