Skip to content

Commit

Permalink
Adjustment to get uri's to show right in guidance
Browse files Browse the repository at this point in the history
and in description fields.
One tweak to prevent click to get popup Reference Guide from triggering new tab instance of DH in browser.
  • Loading branch information
ddooley committed Feb 4, 2025
1 parent e15e90f commit c50a510
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
47 changes: 44 additions & 3 deletions lib/DataHarmonizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class DataHarmonizer {
);
this.columnHelpEntries = options.columnHelpEntries || [
'column',
'slot_uri',
'description',
'guidance',
'examples',
Expand Down Expand Up @@ -176,7 +177,7 @@ class DataHarmonizer {
(field) => field.title === field_reference
);
$('#field-description-text').html(
urlToClickableAnchor(this.getComment(field))
this.getComment(field)
);
$('#field-description-modal').modal('show');
});
Expand Down Expand Up @@ -1037,6 +1038,30 @@ class DataHarmonizer {
hotInstance.render(); // Render the table to apply changes
}

renderSemanticID(curieOrURI, as_markup = false) {
if (curieOrURI) {
if (curieOrURI.toLowerCase().startsWith('http')) {
if (as_markup)
return `[${curieOrURI}](${curieOrURI})`;

return `<a href="${curieOrURI}" target="_blank">${curieOrURI}</a>`;
}
else if (curieOrURI.includes(':')) {
const [prefix, reference] = curieOrURI.split(':',2);
if (prefix && reference && (prefix in this.schema.prefixes)) {
// Lookup curie
let url = this.schema.prefixes[prefix]['prefix_reference'] + reference;
if (as_markup)
return `[${curieOrURI}](${url})`;
return `<a href="${url}" target="_blank">${curieOrURI}</a>`;
}
else
return `${curieOrURI}`;
}
}
return '';
}

/**
* Presents reference guide in a popup.
* @param {String} mystyle simple css stylesheet commands to override default.
Expand Down Expand Up @@ -1088,9 +1113,11 @@ class DataHarmonizer {
for (const slot of section.children) {
const slot_dict = this.getCommentDict(slot);

const slot_uri = this.renderSemanticID(slot_dict.slot_uri);

row_html += '<tr>';
if (this.columnHelpEntries.includes('column')) {
row_html += `<td class="label">${slot_dict.title}</td>`;
row_html += `<td class="label">${slot_dict.title}<br/>${slot_uri}</td>`;
}
if (this.columnHelpEntries.includes('description')) {
row_html += `<td>${slot_dict.description}</td>`;
Expand Down Expand Up @@ -1868,6 +1895,15 @@ class DataHarmonizer {
)}</strong>: ${field.title || field.name}</p>`;
}

// Requires markup treatment of URLS. Issue: this is getting rendered
// wrong.
const slot_uri = this.renderSemanticID(field.slot_uri, true);
if (field.slot_uri && this.columnHelpEntries.includes('slot_uri')) {
ret += `<p><strong data-i18n="help-sidebar__column">${i18next.t(
'help-sidebar__slot_uri'
)}</strong>: ${slot_uri}</p>`;
}

if (field.description && this.columnHelpEntries.includes('description')) {
ret += `<p><strong data-i18n="help-sidebar__description">${i18next.t(
'help-sidebar__description'
Expand Down Expand Up @@ -1907,7 +1943,8 @@ class DataHarmonizer {
let guide = {
title: field.title,
name: field.name,
description: field.description || '',
slot_uri: field.slot_uri,
description: urlToClickableAnchor(field.description) || '',
guidance: '',
examples: '',
sources: '',
Expand Down Expand Up @@ -1979,6 +2016,10 @@ class DataHarmonizer {
})
.join('\n');

// Makes full URIs that aren't in markup into <a href>
if (guide.guidance)
guide.guidance = urlToClickableAnchor(guide.guidance);

if (field.examples && field.examples.length) {
let examples = [];
let first_item = true;
Expand Down
4 changes: 4 additions & 0 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,10 @@ class Toolbar {
for (const dh in this.context.dhs) {
this.context.dhs[dh].renderReference();
}
// Prevents another popup on repeated click if user focuses away from
// previous popup.
return false;

}

showError(prefix, message) {
Expand Down
4 changes: 4 additions & 0 deletions web/translations/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@
"en": "Column",
"fr": "Colonne"
},
"help-sidebar__slot_uri": {
"en": "Semantic ID",
"fr": "ID sémantique"
},
"help-sidebar__description": {
"en": "Description",
"fr": "Description"
Expand Down

0 comments on commit c50a510

Please sign in to comment.