Skip to content

Commit

Permalink
fix: Get the headers dynamically and filter out the field not needed …
Browse files Browse the repository at this point in the history
…for the table
  • Loading branch information
john-ghatas committed May 16, 2020
1 parent e2e240f commit 99a31f4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
38 changes: 38 additions & 0 deletions lib/public/views/Logs/ColumnNames/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/**
* Get the corresponding key and column name with the correct spelling
* @param {String} item Unconverted subkey passed
* @returns {String} converted column name to add to the headers array
*/
const getColumnName = (item) => {
switch (item){
case 'title':
return 'Title';
case 'entryId':
return 'Entry ID';
case 'authorID':
return 'Author';
case 'creationTime':
return 'Creation Time';
case 'origin':
return 'Origin';
case 'subtype':
return 'Subtype';
default:
break;
}
};

export default getColumnName;
21 changes: 19 additions & 2 deletions lib/public/views/Logs/Logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* or submit itself to any jurisdiction.
*/
import { Observable, fetchClient } from '/js/src/index.js';
import getColumnName from './ColumnNames/index.js';

/**
* Model representing handlers for homePage.js
Expand All @@ -28,7 +29,7 @@ export default class Overview extends Observable {
this.data = [];
this.filtered = [];
this.error = false;
this.headers = ['ID', 'Author ID', 'Title', 'Creation Time'];
this.headers = [];
}

/**
Expand All @@ -42,6 +43,21 @@ export default class Overview extends Observable {
if (result.data) {
this.data = result.data;
this.filtered = [...result.data];

// TODO: Kijken naar een effecientere manier
this.data.forEach((object) => {
const keys = Object.keys(object)
.filter((single) => {
switch (single){
case 'content':
case 'tags':
break;
default:
return single;
}
});
this.headers = keys.map((column) => getColumnName(column));
});
this.error = false;
} else {
this.error = true;
Expand Down Expand Up @@ -95,8 +111,9 @@ export default class Overview extends Observable {
getDataWithoutTags() {
const subentries = this.filtered.map((entry) => {
const columnData = Object.keys(entry).map((subkey) => {
const currentColumn = getColumnName(subkey);
// Filter out the field not needed for the table
if (subkey !== 'tags' && subkey !== 'content' && subkey !== 'origin' && subkey !== 'subtype') {
if (this.headers.includes(currentColumn)) {
if (subkey === 'creationTime') {
return new Date(entry[subkey]).toLocaleString();
}
Expand Down

0 comments on commit 99a31f4

Please sign in to comment.