mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat: export reports csv and xlsx (#286)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { ITableRow } from '@/interfaces';
|
||||
import { flatNestedTree } from '@/utils/deepdash';
|
||||
import { repeat } from 'lodash';
|
||||
|
||||
interface FlatNestTreeOpts {
|
||||
nestedPrefix?: string;
|
||||
nestedPrefixIndex?: number;
|
||||
}
|
||||
|
||||
export class FinancialTableStructure {
|
||||
/**
|
||||
* Converts the given table object with nested rows in flat rows.
|
||||
* @param {ITableRow[]}
|
||||
* @param {FlatNestTreeOpts}
|
||||
* @returns {ITableRow[]}
|
||||
*/
|
||||
public static flatNestedTree = (
|
||||
obj: ITableRow[],
|
||||
options?: FlatNestTreeOpts
|
||||
): ITableRow[] => {
|
||||
const parsedOptions = {
|
||||
nestedPrefix: ' ',
|
||||
nestedPrefixIndex: 0,
|
||||
...options,
|
||||
};
|
||||
const { nestedPrefixIndex, nestedPrefix } = parsedOptions;
|
||||
|
||||
return flatNestedTree(
|
||||
obj,
|
||||
(item, key, context) => {
|
||||
const cells = item.cells.map((cell, index) => {
|
||||
return {
|
||||
...cell,
|
||||
value:
|
||||
(context.depth > 1 && nestedPrefixIndex === index
|
||||
? repeat(nestedPrefix, context.depth)
|
||||
: '') + cell.value,
|
||||
};
|
||||
});
|
||||
return {
|
||||
...item,
|
||||
cells,
|
||||
};
|
||||
},
|
||||
parsedOptions
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user