mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-02 11:49:23 +00:00
breadcrumbs for datasets. creates util modules to building urns and validating them. known issue with last item in breadcrumbs for urns should probably not be a link
This commit is contained in:
parent
87048b9e23
commit
b8532abcf6
@ -3,6 +3,7 @@ import {
|
||||
createPrivacyCompliancePolicy,
|
||||
createSecuritySpecification
|
||||
} from 'wherehows-web/utils/datasets/functions';
|
||||
import { makeUrnBreadcrumbs } from 'wherehows-web/utils/entities';
|
||||
|
||||
const {
|
||||
Route,
|
||||
@ -216,64 +217,16 @@ export default Route.extend({
|
||||
});
|
||||
});
|
||||
|
||||
if (urn) {
|
||||
var index = urn.lastIndexOf('/');
|
||||
if (index != -1) {
|
||||
var listUrl = '/api/v1/list/datasets?urn=' + urn.substring(0, index + 1);
|
||||
$.get(listUrl, function (data) {
|
||||
if (data && data.status == "ok") {
|
||||
// renderDatasetListView(data.nodes, name);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (datasetCommentsComponent) {
|
||||
datasetCommentsComponent.getComments();
|
||||
}
|
||||
|
||||
// If urn exists, create a breadcrumb list
|
||||
// TODO: DSS-7068 Refactoring in progress , move this to a computed prop on a container component
|
||||
// FIXME: DSS-7068 browse.entity?urn route does not exist for last item in breadcrumb i.e. the dataset
|
||||
// currently being viewed. Should this even be a link in the first place?
|
||||
if (urn) {
|
||||
urn = urn.replace('<b>', '').replace('</b>', '');
|
||||
var index = urn.lastIndexOf("/");
|
||||
if (index != -1) {
|
||||
var name = urn.substring(index + 1);
|
||||
}
|
||||
// var breadcrumbs = [{"title": "DATASETS_ROOT", "urn": "1", destRoute: 'datasets.page'}];
|
||||
let breadcrumbs = [
|
||||
{
|
||||
route: 'datasets.page',
|
||||
text: 'datasets',
|
||||
model: 1
|
||||
}
|
||||
];
|
||||
var updatedUrn = urn.replace("://", "");
|
||||
var b = updatedUrn.split('/');
|
||||
for (var i = 0; i < b.length; i++) {
|
||||
if (i === 0) {
|
||||
breadcrumbs.push({
|
||||
text: b[i],
|
||||
// urn: "name/" + b[i] + "/page/1?urn=" + b[i] + ':///',
|
||||
model: [b[i], 1],
|
||||
queryParams: {urn: b[i] + ':///'},
|
||||
route: 'datasets.name.subpage'
|
||||
});
|
||||
} else if (i === (b.length - 1)) {
|
||||
breadcrumbs.push({
|
||||
text: b[i],
|
||||
model: id,
|
||||
route: 'datasets.dataset'
|
||||
});
|
||||
} else {
|
||||
breadcrumbs.push({
|
||||
text: b[i],
|
||||
// urn: "name/" + b[i] + "/page/1?urn=" + urn.split('/').splice(0, i + 3).join('/'),
|
||||
model: [b[i], 1],
|
||||
queryParams: {urn: urn.split('/').splice(0, i + 3).join('/')},
|
||||
route: 'datasets.name.subpage'
|
||||
});
|
||||
}
|
||||
}
|
||||
controller.set("breadcrumbs", breadcrumbs);
|
||||
set(controller, 'breadcrumbs', makeUrnBreadcrumbs(urn));
|
||||
}
|
||||
|
||||
// Get the list of ownerTypes from endpoint,
|
||||
|
||||
@ -55,9 +55,4 @@ $zebra: set-color(grey, light);
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
/// Owner last modified column in owner -table
|
||||
&__owner-last-mod {
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@
|
||||
onclick={{action "willEditUserName"
|
||||
owner}}>
|
||||
|
||||
<label class={{if (contains owner.source restrictedSources) "" "dataset-author-cell__name-tag"}}>
|
||||
<label class={{unless (contains owner.source restrictedSources) "dataset-author-cell__name-tag"}}>
|
||||
{{owner.userName}}
|
||||
</label>
|
||||
{{aupac-typeahead
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<ul class="breadcrumbs">
|
||||
{{#each breadcrumbs as |crumb|}}
|
||||
<li>
|
||||
{{crumb.text}}
|
||||
{{link-to crumb.crumb "browse.entity" "datasets" (query-params page=1 urn=crumb.urn)}}
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
<div class="feature-container">
|
||||
<article class="feature-card">
|
||||
{{#link-to featureCard.route}}
|
||||
<span class="feature-card-icon" title={{featureCard.title}}></span>
|
||||
<h3 class="feature-card__title">{{featureCard.title}}</h3>
|
||||
<div class="feature-card__description">
|
||||
{{featureCard.description}}
|
||||
|
||||
3
wherehows-web/app/utils/entities/index.js
Normal file
3
wherehows-web/app/utils/entities/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
import makeUrnBreadcrumbs from 'wherehows-web/utils/entities/make-urn-breadcrumbs';
|
||||
|
||||
export { makeUrnBreadcrumbs };
|
||||
33
wherehows-web/app/utils/entities/make-urn-breadcrumbs.js
Normal file
33
wherehows-web/app/utils/entities/make-urn-breadcrumbs.js
Normal file
@ -0,0 +1,33 @@
|
||||
import { urnRegex } from 'wherehows-web/utils/validators/urn';
|
||||
|
||||
/**
|
||||
* Takes a urn string and parse it into an array of breadcrumb objects with crumb, and urn as
|
||||
* properties.
|
||||
* Hierarchy is implied in element ordering
|
||||
* @param {String} urn
|
||||
* @return {Array.<{crumb, urn}>|null}
|
||||
*/
|
||||
export default urn => {
|
||||
const urnMatch = urnRegex.exec(urn);
|
||||
|
||||
if (urnMatch) {
|
||||
// Initial element in a match array from RegExp#exec is the full match, not needed here
|
||||
const urnParts = urnMatch.filter((match, index) => index);
|
||||
// Splits the 2nd captured group into an array of urn names and spreads into a new list
|
||||
const crumbs = [urnParts[0], ...urnParts[1].split('/')];
|
||||
|
||||
// Reduces the crumbs into a list of crumb names and urn paths
|
||||
return crumbs.reduce((breadcrumbs, crumb, index) => {
|
||||
const previousCrumb = breadcrumbs[index - 1];
|
||||
const breadcrumb = {
|
||||
crumb,
|
||||
// First item is root
|
||||
urn: !index ? `${crumb}:///` : `${previousCrumb.urn}${crumb}/`
|
||||
};
|
||||
|
||||
return [...breadcrumbs, breadcrumb];
|
||||
}, []);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
8
wherehows-web/app/utils/validators/urn.js
Normal file
8
wherehows-web/app/utils/validators/urn.js
Normal file
@ -0,0 +1,8 @@
|
||||
const urnRegex = /^([a-z_]+):\/{3}([a-z_\-\/]*)/i;
|
||||
/**
|
||||
* Asserts that a provided string matches the urn pattern above
|
||||
* @param {String} candidateUrn the string to test on
|
||||
*/
|
||||
export default candidateUrn => urnRegex.test(String(candidateUrn));
|
||||
|
||||
export { urnRegex };
|
||||
Loading…
x
Reference in New Issue
Block a user