Skip to content

Commit

Permalink
added factor support to js functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon McArthur authored and Brandon McArthur committed Feb 15, 2024
1 parent 390aed2 commit 2f01a86
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/Panel/PanelGraphicWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable react/jsx-no-useless-fragment */
import React, { useState, useEffect } from 'react';
import PanelGraphic from './PanelGraphic';
import { panelSrcGetter, snakeCase } from '../../utils';
import { getLabelFromFactor, panelSrcGetter, snakeCase } from '../../utils';
import { useDisplayInfo } from '../../slices/displayInfoAPI';

interface PanelGraphicProps {
data: Datum;
Expand All @@ -24,10 +25,19 @@ const PanelGraphicWrapper: React.FC<PanelGraphicProps> = ({
panelKey,
fileName,
}) => {
const { data: displayInfo } = useDisplayInfo();
const [panelSrc, setPanelSrc] = useState('');

const sourceFunc = async (func: PanelFunction) => {
const res = await func(data);
const dataWithFactorLabels = Object.keys(data).reduce((acc, key) => {
const foundFactor = displayInfo?.metas?.find((curMeta) => curMeta.varname === key && curMeta.type === 'factor');
if (foundFactor) {
const factorLabel = getLabelFromFactor(data[key] as number, foundFactor.levels as string[]);
return { ...acc, [key]: factorLabel };
}
return { ...acc, [key]: data[key] };
}, {});

const res = await func(dataWithFactorLabels);
setPanelSrc(res);
return res;
};
Expand Down

0 comments on commit 2f01a86

Please sign in to comment.