-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainDataTableProducer.js
51 lines (48 loc) · 2.3 KB
/
mainDataTableProducer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// "mainDataTableProducer.js"
/**
* The above functions prepare and generate a main table with data by fetching, filtering, and parsing
* data from different sources.
*/
import { requestCategorySchemeData, fetchAndFilterArtefactsCollection } from "./dataFetcher.js";
import {getCountryAppearances, createUniqueConceptCollection } from "./dataParser.js";
import { initializeConceptsTable } from "./createConceptsTable.js";
import { initializeCountriesTable } from "./createCountriesTable.js";
import { setStorageData } from "./utils.js";
import { sessionKeys } from "./sessionStorageKeys.js";
/**
* Asynchronously prepares table rows based on the provided data frame IDs.
* @param {Array} dfIds - An array of data frame IDs to retrieve artefacts.
* @returns {Array} An array of table rows containing information about unique concepts.
*/
export async function fetchAndProcessConceptTableData(dfIds) {
const artefactsCollectionFiltered = await fetchAndFilterArtefactsCollection(dfIds);
const uniqueConceptsObject = artefactsCollectionFiltered.reduce(createUniqueConceptCollection, {});
setStorageData(sessionKeys.uniqueConcepts, uniqueConceptsObject);
const conceptDataForRows = Object.entries(uniqueConceptsObject).map(
([conceptId, dsObj]) => {
return {
conceptRoles: dsObj.conceptRoles.join(", "),
description: dsObj.description,
conceptId: conceptId,
conceptName: dsObj.name,
...dsObj.appearance,
};
}
);
return conceptDataForRows;
}
/**
* Creates and populates the main tables with data fetched from various sources.
* @returns An object containing the updates made to the concept table and countries table.
*/
export async function createAndPopulateMainTables() {
const mapDataflowsToStructure = await requestCategorySchemeData();
const dfIdFullList = mapDataflowsToStructure.map((link) => link.dfId);
setStorageData(sessionKeys.dfIdsFiltered, dfIdFullList);
setStorageData(sessionKeys.dfIdsAll, dfIdFullList);
const conceptDataForRows = await fetchAndProcessConceptTableData(dfIdFullList);
const updateConceptTable = await initializeConceptsTable(conceptDataForRows);
const countryDataForRows = getCountryAppearances([]);
const updateCountriesTable = initializeCountriesTable(countryDataForRows, dfIdFullList);
return {updateConceptTable, updateCountriesTable};
}