Skip to content

Commit

Permalink
account for new underscored routes in Amphora (#95)
Browse files Browse the repository at this point in the history
* account for new underscored routes in Amphora

* implemented PR feedback
  • Loading branch information
amycheng authored Feb 7, 2018
1 parent b1165e3 commit 8ec7fc7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/services/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ var dom = require('@nymag/dom'),
_ = require('lodash'),
references = require('./references');

/**
* Checks that the string is a route while accounting for underscored routes
* @param {string} string
* @param {string} route
* @return {boolean}
*/
function isRouteUri(string, route) {
var routeFormat = '\/[_]?' + route + '\/';

return !!string.match(routeFormat);
}

/**
* Return information about the parent space logic
* @param {string} spaceRef reference to the space components
Expand All @@ -14,7 +26,7 @@ export function findSpaceParentUriAndList(spaceRef) {
parentUri = parentEl.getAttribute('data-uri'),
parentListName = parentList.getAttribute('data-editable');

if (parentUri.indexOf('/pages/') > -1) {
if (isRouteUri(parentUri, 'pages')) {
parentUri = parentEl.getAttribute('data-layout-uri');
}

Expand All @@ -38,7 +50,7 @@ function getAvailableComponents(store, parentEl, list) {
var parentUri = parentEl.getAttribute('data-uri'),
parentName, componentList, include, exclude;

if (parentUri.indexOf('/pages/') > -1) {
if (isRouteUri(parentUri, 'pages')) {
parentUri = parentEl.getAttribute('data-layout-uri');
}

Expand Down Expand Up @@ -164,7 +176,9 @@ function isSpaceLogic(uri) {
* @return {Element}
*/
function getSpaceElFromLogic(prefix, logicEl) {
return dom.closest(logicEl, `[data-uri^="${prefix}/components/clay-space"]`);
var el = dom.closest(logicEl, `[data-uri^="${prefix}/components/clay-space"], [data-uri^="${prefix}/_components/clay-space"]`);

return el;
}

module.exports.spaceInComponentList = spaceInComponentList;
Expand Down

0 comments on commit 8ec7fc7

Please sign in to comment.