Skip to content

Commit

Permalink
fix: type
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Jan 16, 2025
1 parent f713632 commit 962d650
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@ import { useMemo } from 'react';
import { convertValue } from 'capture-core/converters/serverToClient';
import type { StageDataElement, StageDataElementClient } from '../../../../types/common.types';

const convertToClientDataElement = (dataElement: StageDataElement): StageDataElementClient => {
const { options, type, ...rest } = dataElement;

const convertedOptions = options
? Object.entries(options).map(([key, value]) => ({
value: convertValue(key, type),
text: value,
}))
: [];

return {
...rest,
type,
options: convertedOptions,
};
};

export const useClientDataElements = (dataElements: Array<StageDataElement>) =>
useMemo < Array<StageDataElementClient>>(() => {
if (!dataElements) {
useMemo(() => {
if (!dataElements || !Array.isArray(dataElements)) {
return [];
}
return dataElements.map(convertToClientDataElement);

return dataElements.map <StageDataElementClient>(
(dataElement: StageDataElement) => {
const {
options,
type,
...rest
} = dataElement;

const convertedOptions = options
? Object.entries(options).map(([key, value]) => ({
value: convertValue(key, type),
text: value,
})) : undefined;

return {
...rest,
type,
options: convertedOptions,
};
});
}, [dataElements]);
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ const formatRowForView = (row: Object, dataElements: Array<StageDataElementClien
acc[id] = value;
} else {
const dataElement = getDataElement(stageDataElement, type);
console.log('dataElement', dataElement);
acc[id] = convertClientToList(value, type, dataElement);
}
return acc;
Expand Down

0 comments on commit 962d650

Please sign in to comment.