Skip to content

Commit 735d7cf

Browse files
committed
filter result
1 parent eddd7f8 commit 735d7cf

6 files changed

Lines changed: 361 additions & 87 deletions

File tree

.idea/workspace.xml

Lines changed: 249 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data-table/backend/routeHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function configureRoutes(options) {
2424
} else if (!schemaTypes.some((type => type.itemType === itemType))) {
2525
return {message: 'Invalid plugin configuration “itemType” (must be an existing node category or edge type)'};
2626
}
27-
if (!Array.isArray(properties) || properties.length === 0) {
27+
if (properties && (!Array.isArray(properties) || properties.length === 0)) {
2828
return {message: 'Invalid plugin configuration “properties” (must be a non-empty array of property names)'};
2929
}
3030
return null;

data-table/public/css/main.css

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,39 @@ body {
171171
}
172172

173173
.table--item_count {
174-
padding: 12px 20px 12px 20px;
174+
padding: 12px 20px 0 20px;
175175
color: #303030;
176176
font-size: 14px;
177177
line-height: 20px;
178178
}
179179

180+
.warning {
181+
padding: 20px;
182+
border-radius: 3px;
183+
border: 1px solid #FF7A01;
184+
display: flex;
185+
flex-wrap: nowrap;
186+
align-items: center;
187+
margin: 20px 20px 0 20px;
188+
}
189+
190+
.warning_icon {
191+
height: 28px;
192+
width: 28px;
193+
background-color: #FF7A01;
194+
border-radius: 100px;
195+
margin-right: 4px;
196+
}
197+
198+
/*.warning_img {
199+
height: 16px;
200+
width: 16px;
201+
background-color: #FFFFFF;
202+
}*/
203+
180204
.button__container {
181205
display: flex;
182-
padding: 20px 20px 16px 20px;
206+
padding: 40px 20px 16px 20px;
183207
justify-content: space-between;
184208
}
185209

899 Bytes
Loading

data-table/public/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<div id="table_title" class="table--title"></div>
4141
<div id="item_type" class="table--item_type"></div>
4242
<div id="item_count" class="table--item_count"></div>
43+
<div class="warning hide" id="warning">
44+
<img class="warning_icon" src="img/Outlined _ AV _ not_interested.png" alt="warning"/>
45+
<span id="warning_text"></span>
46+
47+
</div>
4348
<div class="button__container">
4449
<button class="btn btn__secondary hide" id="button-edit">EDIT COLUMNS</button>
4550
<button class="btn btn__primary hide" id="button-export">EXPORT CSV</button>

data-table/public/js/main.js

Lines changed: 80 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ window.onkeyup = (e) => {
3030
function makeRequest(verb = 'GET', url, body) {
3131
const xmlHttp = new XMLHttpRequest();
3232
// Return it as a Promise
33-
return new Promise(function(resolve, reject) {
34-
xmlHttp.onreadystatechange = function() {
33+
return new Promise(function (resolve, reject) {
34+
xmlHttp.onreadystatechange = function () {
3535
// Only run if the request is complete
3636
if (xmlHttp.readyState !== 4) {
3737
return;
@@ -76,7 +76,12 @@ function closeTab() {
7676

7777
function setQueryResult(result) {
7878
if (result.status === 200) {
79-
queryResult = result.body;
79+
queryResult = {truncatedByLimit: result.body.truncatedByLimit};
80+
if (pluginConfiguration.entityType && pluginConfiguration.entityType === 'edge') {
81+
queryResult.result = result.body.edges.filter(edge => edge.data.type === pluginConfiguration.itemType);
82+
} else {
83+
queryResult.result = result.body.nodes.filter(node => node.data.categories.includes(pluginConfiguration.itemType));
84+
}
8085
} else {
8186
handleError(result);
8287
}
@@ -85,7 +90,7 @@ function setQueryResult(result) {
8590
async function runQueryByID(query) {
8691
const result = await makeRequest(
8792
'POST',
88-
`/api/plugins/table/runQueryByIDPlugin`,
93+
`/plugins/table/api/runQueryByIDPlugin`,
8994
{query, queryParams}
9095
);
9196
setQueryResult(JSON.parse(result.response));
@@ -183,7 +188,7 @@ function setSchema(result) {
183188
async function getSchema() {
184189
const result = await makeRequest(
185190
'GET',
186-
`/api/plugins/table/getSchema?sourceKey=${queryParams.global.sourceKey}`,
191+
`/plugins/table/api/getSchema?sourceKey=${queryParams.global.sourceKey}`,
187192
null
188193
);
189194
setSchema(JSON.parse(result.response));
@@ -193,13 +198,12 @@ async function validatePluginConfiguration() {
193198
try {
194199
const result = await makeRequest(
195200
'POST',
196-
`/api/plugins/table/checkPluginsConfiguration`,
201+
`/plugins/table/api/checkPluginsConfiguration`,
197202
{results: schema}
198203
);
199204
pluginConfiguration = JSON.parse(result.response);
200-
console.log(pluginConfiguration);
201205
return true;
202-
} catch(e) {
206+
} catch (e) {
203207
handleError(e);
204208
}
205209
}
@@ -217,50 +221,87 @@ function truncateText(text, maxLength = 50) {
217221
}
218222

219223
function getFilteredSchema(schemaStructure) {
220-
if (queryResult.nodes.length > 0) {
221-
return schemaStructure.filter(result => {
222-
return queryResult.nodes[0].data.categories.includes(result.itemType);
224+
const properties = schemaStructure.find(item => item.itemType === pluginConfiguration.itemType).properties || [];
225+
let sortedProperties = [];
226+
if (pluginConfiguration.properties) {
227+
pluginConfiguration.properties.forEach(propertyName => {
228+
const property = properties.find(property => property.propertyKey === propertyName);
229+
if (property) {
230+
sortedProperties.push(property);
231+
}
223232
});
224233
} else {
225-
return schemaStructure.filter(result => {
226-
return queryResult.edges[0].data.type === result.itemType;
227-
});
234+
sortedProperties = sortAlphabetically(properties, 'propertyKey');
228235
}
236+
return sortedProperties;
237+
}
238+
239+
function sortAlphabetically(arr, objKey) {
240+
return arr.sort((a, b) => {
241+
const aK = objKey ? a[objKey] : a;
242+
const bK = objKey ? b[objKey] : b;
243+
const sanitizedA = typeof aK === 'string' ? aK.toLowerCase() : aK;
244+
const sanitizedB = typeof bK === 'string' ? bK.toLowerCase() : bK;
245+
return sanitizedA < sanitizedB ? -1 : sanitizedA > sanitizedB ? 1 : 0;
246+
});
229247
}
230248

231249
function getTableStructure(schemaStructure) {
232-
const filteredSchema = getFilteredSchema(schemaStructure);
233-
const sanitizedData = filteredSchema[0].properties.map(property => {
250+
const properties = getFilteredSchema(schemaStructure);
251+
const sanitizedData = properties.map(property => {
252+
let align = 'left';
253+
if (
254+
property.propertyType &&
255+
(property.propertyType.name === 'number' ||
256+
property.propertyType.name === 'date' ||
257+
property.propertyType.name === 'datetime')
258+
) {
259+
align = 'right';
260+
}
234261
return {
235262
title: property.propertyKey,
236263
field: property.propertyKey,
237-
align: 'left',
264+
align: align,
238265
titleFormatter: truncateColumnTitle
239266
};
240267
});
241-
return [{title: 'id', field: 'id', align: 'center'}, ...sanitizedData];
268+
return [{title: 'Row', field: 'row', align: 'right'}, {title: 'id', field: 'id', align: 'right'}, ...sanitizedData];
242269
}
243270

244271
function getTableData(queryResult) {
245-
return (queryResult.nodes.length > 0) ?
246-
queryResult.nodes.map(node => {
247-
return {...node.data.properties, 'id': node.id};
248-
}) :
249-
queryResult.edges.map(edge => edge.data.properties);
272+
return queryResult.result.map((item, index) => {
273+
for (let [key, value] of Object.entries(item.data.properties)) {
274+
if (typeof value === 'object') {
275+
if (value.value && (value.type === 'date' || value.type === 'datetime')) {
276+
item.data.properties[key] = new Date(value.value).toISOString();
277+
} else {
278+
item.data.properties[key] = value.value || value.original;
279+
}
280+
}
281+
}
282+
return {...item.data.properties, 'id': item.id, 'row': index + 1};
283+
});
250284
}
251285

252286
function getTooltipsHeader(column) {
253287
return column.getDefinition().title;
254288
}
255289

256290
function setTableTitle() {
291+
if (queryResult.truncatedByLimit && queryParams.global.limit === undefined) {
292+
document.getElementById('warning').classList.remove('hide');
293+
}
257294
document.getElementById('table_title').innerText = query.name;
258295
if (pluginConfiguration.entityType === undefined || pluginConfiguration.entityType === 'node') {
296+
document.getElementById('warning_text').innerText = `The query returned too many results. The ${
297+
queryResult.result.length} first results are displayed below.`;
259298
document.getElementById('item_type').innerText = `Node type : ${pluginConfiguration.itemType}`;
260-
document.getElementById('item_count').innerText = `Number of nodes : ${queryResult.nodes.length}`;
261-
} else if (pluginConfiguration.entityType === 'node') {
299+
document.getElementById('item_count').innerText = `Number of nodes : ${queryResult.result.length}`;
300+
} else if (pluginConfiguration.entityType === 'edge') {
301+
document.getElementById('warning_text').innerText = `The query returned too many results. The ${
302+
queryResult.result.length} first results are displayed below.`;
262303
document.getElementById('item_type').innerText = `Edge type : ${pluginConfiguration.itemType}`;
263-
document.getElementById('item_count').innerText = `Number of edges : ${queryResult.edges.length}`;
304+
document.getElementById('item_count').innerText = `Number of edges : ${queryResult.result.length}`;
264305
}
265306
}
266307

@@ -284,7 +325,6 @@ function clearFilter() {
284325
function filterTableColumns() {
285326
const list = document.getElementsByTagName('input');
286327
for (let i = 0; i < list.length; i++) {
287-
console.log(list[i]);
288328
if (list[i].checked) {
289329
table.showColumn(list[i].id);
290330
} else {
@@ -360,28 +400,31 @@ function addButtons() {
360400
}
361401

362402
function fillDataTable() {
363-
loaderElement.classList.remove('active');
364-
setTableTitle();
365403
tableStructure = getTableStructure(schema);
366404
const tableData = getTableData({...queryResult});
405+
console.log(tableData);
406+
console.log(tableStructure);
407+
if (tableData.length === 0) {
408+
return handleError({body: {message: 'No result was returned.'}});
409+
}
410+
loaderElement.classList.remove('active');
411+
setTableTitle();
367412
// create Tabulator on DOM element with id "example-table"
368413
table = new Tabulator('#table', {
369414
tooltipsHeader: getTooltipsHeader,
370415
layoutColumnsOnNewData: true,
371416
resizableColumns: false,
372417
pagination: 'local',
373-
paginationSize: 15,
374-
paginationSizeSelector: [8, 12, 16, 20],
418+
paginationSize: 10,
375419
movableColumns: true,
376-
placeholder: 'There was not matches for the filter',
420+
placeholder: 'No result was returned.',
377421
data: tableData, //assign data to table
378422
layout: 'fitDataFill', //fit columns to width of table
379423
columns: tableStructure,
380-
rowClick: function(e, row) { //trigger an alert message when the row is clicked
424+
rowClick: function (e, row) { //trigger an alert message when the row is clicked
381425
alert('Row ' + row.getData().id + ' Clicked!!!!');
382426
}
383427
});
384-
// addFilter();
385428
fillModalColumns();
386429
addButtons();
387430
}
@@ -390,13 +433,13 @@ async function getQuery() {
390433
try {
391434
return await makeRequest(
392435
'POST',
393-
`/api/plugins/table/getQuery`,
436+
`/plugins/table/api/getQuery`,
394437
{
395438
id: queryParams.global.queryId,
396439
sourceKey: queryParams.global.sourceKey
397440
}
398441
);
399-
} catch(e) {
442+
} catch (e) {
400443
handleError(e);
401444
}
402445
}
@@ -417,7 +460,7 @@ async function main() {
417460
await runQueryByID(query);
418461
fillDataTable();
419462
}
420-
} catch(e) {
463+
} catch (e) {
421464
handleError(e);
422465
}
423466

0 commit comments

Comments
 (0)