feat: flatten the nested columns of exported data

This commit is contained in:
Ahmed Bouhuolia
2024-05-02 15:38:57 +02:00
parent 55aab76c9b
commit 83a5010dc5
21 changed files with 392 additions and 97 deletions

View File

@@ -0,0 +1,27 @@
import { flatMap } from 'lodash';
/**
* Flattens the data based on a specified attribute.
* @param data - The data to be flattened.
* @param flattenAttr - The attribute to be flattened.
* @returns - The flattened data.
*/
export const flatDataCollections = (
data: Record<string, any>,
flattenAttr: string
): Record<string, any>[] => {
return flatMap(data, (item) =>
item[flattenAttr].map((entry) => ({
...item,
[flattenAttr]: entry,
}))
);
};
/**
* Gets the data accessor for a given column.
* @param col - The column to get the data accessor for.
* @returns - The data accessor.
*/
export const getDataAccessor = (col: any) => {
return col.group ? `${col.group}.${col.accessor}` : col.accessor;
};