Skip to content

Commit 0588a72

Browse files
committed
LKE-1744 move logic into a function
1 parent fed9a6f commit 0588a72

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

public/js/main.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ function getTableStructure(schemaStructure) {
338338
}
339339
return {
340340
title: property.propertyKey,
341-
// replace to avoid error in Tabulator
342-
field: property.propertyKey.replace(/\./g, 'dot'),
341+
field: escapeDotCharacters(property.propertyKey),
343342
align: align,
344343
titleFormatter: truncateTableText,
345344
headerSort: false,
@@ -369,9 +368,8 @@ function getTableData(queryResult) {
369368
item.data.properties[key] = value.value || value.original;
370369
}
371370
}
372-
// If one of the property key has a . we replace it by the string 'dot' to avoid an error in Tabulator
373371
if (key.includes('.')) {
374-
Object.defineProperty(item.data.properties, key.replace(/\./g, 'dot'),
372+
Object.defineProperty(item.data.properties, escapeDotCharacters(key),
375373
Object.getOwnPropertyDescriptor(item.data.properties, key));
376374
delete item.data.properties[key];
377375
}
@@ -462,11 +460,9 @@ function filterTableColumns() {
462460
const list = document.getElementsByTagName('input');
463461
for (let i = 0; i < list.length; i++) {
464462
if (list[i].checked) {
465-
// replace . by 'dot' to avoid bug in Tabulator
466-
table.showColumn(list[i].id.replace(/\./g, 'dot'));
463+
table.showColumn(escapeDotCharacters(list[i].id));
467464
} else {
468-
// replace . by 'dot' to avoid bug in Tabulator
469-
table.hideColumn(list[i].id.replace(/\./g, 'dot'));
465+
table.hideColumn(escapeDotCharacters(list[i].id));
470466
}
471467
}
472468
closeModal();
@@ -518,8 +514,7 @@ function showModal() {
518514
modal.style.opacity = '1';
519515
const list = document.getElementsByTagName('input');
520516
for (let i = 0; i < list.length; i++) {
521-
// replace . by 'dot' to avoid bug in Tabulator
522-
list[i].checked = table.getColumn(list[i].id.replace(/\./g, 'dot')).getVisibility();
517+
list[i].checked = table.getColumn(escapeDotCharacters(list[i].id)).getVisibility();
523518
}
524519
}
525520

@@ -668,6 +663,14 @@ function fillDataTable() {
668663
addButtons();
669664
}
670665

666+
/**
667+
* If one of the property key has a . we replace it by the string 'dot' to avoid an error in Tabulator
668+
* @param {string} value
669+
*/
670+
function escapeDotCharacters(value) {
671+
return value.replace(/\./g, 'dot');
672+
}
673+
671674
/**
672675
* get query configuration
673676
* @returns {Promise<any>}

0 commit comments

Comments
 (0)