From 8ec7fc7a481b2a53a342111eb8f3e26a45db97cf Mon Sep 17 00:00:00 2001 From: Amy Cheng Date: Wed, 7 Feb 2018 15:26:02 -0500 Subject: [PATCH] account for new underscored routes in Amphora (#95) * account for new underscored routes in Amphora * implemented PR feedback --- src/services/utils.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/services/utils.js b/src/services/utils.js index 7b55f9b..7a6ea6d 100644 --- a/src/services/utils.js +++ b/src/services/utils.js @@ -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 @@ -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'); } @@ -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'); } @@ -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;