-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathui.js
More file actions
47 lines (41 loc) · 1.57 KB
/
ui.js
File metadata and controls
47 lines (41 loc) · 1.57 KB
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
import {fetchCompanies} from "./api";
import {
ACCOUNT_EXECUTIVE_FIELD_NAME,
COMPANIES_TABLE_HEADERS,
COMPANY_NAME_FIELD_NAME,
CREATED_AT_FIELD_NAME,
REVENUE_YTD_FIELD_NAME,
STATUS_FIELD_NAME
} from "./constants";
export const makeTable = async () => {
const companies = await fetchCompanies();
// Print result of api call to the developer console
// Uncomment if you need it for debugging.
// While this method of logging variables of interest to the console is primitive, but often highly valuable debugging technique
// console.log(companies);
// Initialize new array and push a header row
const companiesToDisplay = [];
companiesToDisplay.push(COMPANIES_TABLE_HEADERS);
// Here we simply rearrange company fields in the order in which we want to display them in UI
companies.map(company => {
const row = [];
row.push(
company[COMPANY_NAME_FIELD_NAME],
company[STATUS_FIELD_NAME],
company[CREATED_AT_FIELD_NAME].substring(11,16),
company[REVENUE_YTD_FIELD_NAME].toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "),
company[ACCOUNT_EXECUTIVE_FIELD_NAME]
);
companiesToDisplay.push(row);
});
// Programmatically create html table
const table = document.createElement("table");
document.body.appendChild(table); // Drew the main table node on the document
companiesToDisplay.forEach(row => {
const tr = table.insertRow(); //Create a new row
row.forEach(column => {
const td = tr.insertCell();
td.innerText = column; // Take string from placeholder variable and append it to <tr> node
});
});
};