28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
import { filterColumnTree } from '../../../../components/RealtimeTable/utils/columnUtils';
|
|
import { formatHeaderYear } from '../../../../components/RealtimeTable/utils/headerYearUtils';
|
|
|
|
export async function loadTemplateColumnTree(formType, sheet) {
|
|
const configForm = formType === 'FORM_3' ? 'PROJECT' : formType;
|
|
const { config } = await import(`../../../../components/RealtimeTable/constants/${configForm}/${sheet}.js`);
|
|
return config.config.columns;
|
|
}
|
|
|
|
export async function loadTemplateColumns(formType, sheet, excludedKeys = []) {
|
|
const tree = await loadTemplateColumnTree(formType, sheet);
|
|
const options = [];
|
|
const collect = (nodes, parents = []) => {
|
|
for (const node of nodes) {
|
|
const header = typeof node.header === 'string' ? formatHeaderYear(node.header) : '';
|
|
const path = [...parents, header].filter(Boolean);
|
|
if (node.columns?.length) collect(node.columns, path);
|
|
else if (node.accessorKey?.startsWith('data.'))
|
|
options.push({
|
|
key: node.accessorKey.slice(5),
|
|
label: path.join(' → '),
|
|
});
|
|
}
|
|
};
|
|
collect(filterColumnTree(tree, excludedKeys));
|
|
return options;
|
|
}
|