Skip to content

Commit

Permalink
Improvements to csv (#72)
Browse files Browse the repository at this point in the history
* if type is two words, replace the _ with space

* sort support level, and only show the different names if there's multiple

* modify data structure

* add utilities folder

* adjust to new data structure
  • Loading branch information
Deflaimun authored Sep 9, 2024
1 parent 52c4235 commit eda04cf
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 69 deletions.
19 changes: 19 additions & 0 deletions extensions/util/customStringify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function customStringify(obj) {
return JSON.stringify(obj, (key, value) => {
if (value instanceof Map) {
return {
type: 'Map',
value: Array.from(value.entries())
};
} else if (value instanceof Set) {
return {
type: 'Set',
value: Array.from(value)
};
} else if (typeof value === 'function') {
return value.toString();
} else {
return value;
}
}, 2);
}
160 changes: 91 additions & 69 deletions macros/rp-connect-components.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

module.exports.register = function (registry, context) {

function filterComponentTable() {
// Retrieve and standardize filter inputs
const nameInput = document.getElementById('componentTableSearch').value.trim().toLowerCase();
Expand Down Expand Up @@ -56,93 +55,116 @@ module.exports.register = function (registry, context) {

function processConnectors(parsedData) {
return parsedData.data.reduce((connectors, row) => {
const { connector, commercial_name, type, support_level, is_cloud_supported, is_licensed, url } = row;
let isCloudSupported = is_cloud_supported === 'y'
if (!connectors[connector]) {
connectors[connector] = {
types: new Map(),
supportLevels: new Map(),
isLicensed: is_licensed === 'y' ? 'Yes' : 'No',
isCloudConnectorSupported : isCloudSupported,
urls: new Set()
};
}
connectors[connector].types.set(capitalize(type), { url, isCloudSupported });
if (url) connectors[connector].urls.add(url);
if (!connectors[connector].supportLevels.has(support_level)) {
connectors[connector].supportLevels.set(support_level, new Set());
}
connectors[connector].supportLevels.get(support_level).add(commercial_name);
return connectors;
const { connector, commercial_name, type, support_level, is_cloud_supported, is_licensed, url } = row;
const isCloudSupported = is_cloud_supported === 'y';

if (!connectors[connector]) {
connectors[connector] = {
types: new Map(),
supportLevels: new Map(),
isLicensed: is_licensed === 'y' ? 'Yes' : 'No',
isCloudConnectorSupported: false,
urls: new Set()
};
}
connectors[connector].types.set(capitalize(type), { url });

// Check at the connector level if any type supports cloud
if (isCloudSupported) {
connectors[connector].isCloudConnectorSupported = true;
}

// Update supportLevels with commercial name and cloud support info
if (!connectors[connector].supportLevels.has(support_level)) {
connectors[connector].supportLevels.set(support_level, []);
}

connectors[connector].supportLevels.get(support_level).push({
commercial_name,
isCloudSupported
});

if (url) connectors[connector].urls.add(url);

return connectors;
}, {});
}
}


function generateConnectorsHTMLTable(connectors, isCloud) {
return Object.entries(connectors).map(([connector, details], id) => {

function generateConnectorsHTMLTable(connectors, isCloud) {
return Object.entries(connectors).map(([connector, details], id) => {
const { types, supportLevels, isCloudConnectorSupported, isLicensed, urls } = details;
const firstUrl = urls.size > 0 ? urls.values().next().value : null;

const typesArray = Array.from(types.entries())
.map(([type, { url, isCloudSupported }]) => {
if(isCloud){
if (isCloudSupported) {
return url ? `<a href="${url}/">${type}</a>` : `<span>${type}</span>`;
} else {
return '';
}
}
else{
.map(([type, { url }]) => {
return url ? `<a href="${url}/">${type}</a>` : `<span>${type}</span>`;
}
})
.filter(item => item !== '');

const typesStr = typesArray.join(', ');

const supportLevelStr = Array.from(supportLevels.entries())
.map(([level, names]) => `<p><b>${capitalize(level)}</b>: ${Array.from(names).join(', ')}</p>`)
.join('');
.sort(([levelA], [levelB]) => levelA.localeCompare(levelB)) // Sort by level alphabetically
.map(([level, commercialNames]) => {
let filteredNames = commercialNames;

if (isCloud) {
filteredNames = commercialNames
.filter(({ isCloudSupported }) => isCloudSupported)
.map(({ commercial_name }) => commercial_name);
} else {
filteredNames = commercialNames.map(({ commercial_name }) => commercial_name);
}
filteredNames = [...new Set(filteredNames)];
if (filteredNames.length === 0) return '';
if (supportLevels.size === 1) {
return `<p>${capitalize(level)}</p>`;
} else {
return `<p><b>${capitalize(level)}</b>: ${filteredNames.join(', ')}</p>`;
}
})
.filter(item => item !== '')
.join('');

const connectorNameHtml = firstUrl
? `<code><a href="${firstUrl}/">${connector}</a></code>`
: `<code><span>${connector}</span></code>`;
? `<code><a href="${firstUrl}/">${connector}</a></code>`
: `<code><span>${connector}</span></code>`;

if (isCloud) {
if (isCloudConnectorSupported) {
return `
<tr id="row-${id}">
<td class="tableblock halign-left valign-top" id="componentName-${id}">
<p class="tableblock">${connectorNameHtml}</p>
</td>
<td class="tableblock halign-left valign-top" id="componentType-${id}">
<p class="tableblock">${typesStr}</p>
</td>
</tr>`;
} else {
return '';
}
if (isCloudConnectorSupported && supportLevelStr.trim() !== '') {
return `
<tr id="row-${id}">
<td class="tableblock halign-left valign-top" id="componentName-${id}">
<p class="tableblock">${connectorNameHtml}</p>
</td>
<td class="tableblock halign-left valign-top" id="componentType-${id}">
<p class="tableblock">${typesStr}</p>
</td>
</tr>`;
} else {
return '';
}
} else {
return `
<tr id="row-${id}">
<td class="tableblock halign-left valign-top" id="componentName-${id}">
<p class="tableblock">${connectorNameHtml}</p>
</td>
<td class="tableblock halign-left valign-top" id="componentType-${id}">
<p class="tableblock">${typesStr}</p>
</td>
<td class="tableblock halign-left valign-top" id="componentSupport-${id}">
<p class="tableblock">${supportLevelStr.trim()}</p>
</td>
<td class="tableblock halign-left valign-top" id="componentLicense-${id}">
<p class="tableblock">${isLicensed}</p>
</td>
</tr>`;
return `
<tr id="row-${id}">
<td class="tableblock halign-left valign-top" id="componentName-${id}">
<p class="tableblock">${connectorNameHtml}</p>
</td>
<td class="tableblock halign-left valign-top" id="componentType-${id}">
<p class="tableblock">${typesStr}</p>
</td>
<td class="tableblock halign-left valign-top" id="componentSupport-${id}">
<p class="tableblock">${supportLevelStr.trim()}</p>
</td>
<td class="tableblock halign-left valign-top" id="componentLicense-${id}">
<p class="tableblock">${isLicensed}</p>
</td>
</tr>`;
}
}).filter(row => row !== '').join(''); // Filter out empty rows
}


}).filter(row => row !== '').join(''); // Filter out empty rows
}

let tabsCounter = 1; // Counter for generating unique IDs

Expand Down Expand Up @@ -220,7 +242,7 @@ module.exports.register = function (registry, context) {

const createOptions = (values) =>
Array.from(values)
.map(value => `<option selected value="${value}">${capitalize(value)}</option>`)
.map(value => `<option selected value="${value}">${capitalize(value).replace("_"," ")}</option>`)
.join('');

let tableHtml = `
Expand Down

0 comments on commit eda04cf

Please sign in to comment.