diff --git a/scripts/list-quickstart-urls.js b/scripts/list-quickstart-urls.js index 3ad2cf631..0b5106e6f 100644 --- a/scripts/list-quickstart-urls.js +++ b/scripts/list-quickstart-urls.js @@ -1,4 +1,4 @@ -const getPackNr1Url = require('../src/utils/get-pack-nr1-url'); +const { getPackNr1Url } = require('../src/utils/get-pack-nr1-url'); const quickstarts = require('../src/data/quickstarts.json'); const fs = require('fs'); diff --git a/src/components/InstallButton.js b/src/components/InstallButton.js index d83847b50..300f40f3b 100644 --- a/src/components/InstallButton.js +++ b/src/components/InstallButton.js @@ -2,23 +2,26 @@ import React from 'react'; import PropTypes from 'prop-types'; import { css } from '@emotion/react'; import { Button, Link, Icon } from '@newrelic/gatsby-theme-newrelic'; -import { NR1_LOGIN_URL } from '../data/constants'; -import { quickstart } from '../types'; - -const { +import { getPackNr1Url, getGuidedInstallStackedNr1Url, -} = require('../utils/get-pack-nr1-url'); +} from '../utils/get-pack-nr1-url'; +import { + NR1_LOGIN_URL, + NR1_GUIDED_INSTALL_NERDLET, + NR1_PACK_DETAILS_NERDLET, +} from '../data/constants'; +import { quickstart } from '../types'; /** * @param {String} id * @param {String} nerdletId * @returns {String} */ -const createInstallLink = (id, hasGuidedInstall) => { +const createInstallLink = (id, nerdletId, hasGuidedInstall) => { const platformUrl = hasGuidedInstall - ? getGuidedInstallStackedNr1Url() - : getPackNr1Url(id); + ? getGuidedInstallStackedNr1Url(nerdletId) + : getPackNr1Url(id, nerdletId); const url = new URL( `?return_to=${encodeURIComponent(platformUrl)}`, NR1_LOGIN_URL @@ -47,10 +50,14 @@ const InstallButton = ({ quickstart, ...props }) => { if (!hasInstallableComponent && !hasComponent(quickstart, 'documentation')) { return null; } + + const nerdletId = hasGuidedInstall + ? NR1_GUIDED_INSTALL_NERDLET + : NR1_PACK_DETAILS_NERDLET; // If we have an install-able component, generate a URL. Otherwise, link to the // first documentation supplied. const url = hasInstallableComponent - ? createInstallLink(quickstart.id, hasGuidedInstall) + ? createInstallLink(quickstart.id, nerdletId, hasGuidedInstall) : quickstart.documentation[0].url; return ( diff --git a/src/utils/get-pack-nr1-url.js b/src/utils/get-pack-nr1-url.js index 98c3a2b24..b83de81fd 100644 --- a/src/utils/get-pack-nr1-url.js +++ b/src/utils/get-pack-nr1-url.js @@ -1,22 +1,17 @@ -const { - NR1_PACK_DETAILS_NERDLET, - NR1_GUIDED_INSTALL_NERDLET, - NR1_EXPLORER_NERDLET, -} = require('../data/constants'); - // FIXME: update this to production URL when deployed / launched const NR1_BASE_URL = 'https://staging-one.newrelic.com'; const NR1_BASE_URL_LOCAL = 'https://dev-one.newrelic.com'; const NERDLET_PATH = `launcher/nr1-core.explorer/`; +const NR1_EXPLORER_NERDLET = 'nr1-core.listing'; /** * @param {string} quickstartId The ID for an observability pack. * @param {boolean} [debug] If set to true, this will add `packages=local`. * @returns {string} The URL for the pack details within the platform. */ -const getPackNr1Url = (quickstartId, debug = false) => { +const getPackNr1Url = (quickstartId, nerdletId, debug = false) => { const pane = JSON.stringify({ - nerdletId: NR1_PACK_DETAILS_NERDLET, + nerdletId, quickstartId, }); @@ -30,24 +25,19 @@ const getPackNr1Url = (quickstartId, debug = false) => { const local = debug ? 'packages=local&' : ''; const NR1_URL = debug ? NR1_BASE_URL_LOCAL : NR1_BASE_URL; - const packDetailsUrl = new URL( - `${NERDLET_PATH}?${local}pane=${hash}`, - NR1_URL - ); + const url = new URL(`${NERDLET_PATH}?${local}pane=${hash}`, NR1_URL); - return packDetailsUrl.href; + return url.href; }; -/** - * @param {boolean} [debug] If set to true, this will add `packages=local`. - * @returns {string} The URL for the pack details within the platform. - */ -const getGuidedInstallStackedNr1Url = (debug = false) => { +const getGuidedInstallStackedNr1Url = (nerdletId, debug = false) => { const pane = JSON.stringify({ nerdletId: NR1_EXPLORER_NERDLET }); - const card = JSON.stringify({ nerdletId: NR1_GUIDED_INSTALL_NERDLET }); + const card = JSON.stringify({ + nerdletId, + }); - const paneHash = - window && window.btoa + const hash = + typeof window !== 'undefined' && window.btoa ? btoa(pane) : Buffer.from(pane, 'utf-8').toString('base64'); @@ -59,12 +49,12 @@ const getGuidedInstallStackedNr1Url = (debug = false) => { const local = debug ? 'packages=local&' : ''; const NR1_URL = debug ? NR1_BASE_URL_LOCAL : NR1_BASE_URL; - const guidedInstallUrl = new URL( - `${NERDLET_PATH}?${local}pane=${paneHash}&cards[0]=${cardHash}`, + const url = new URL( + `${NERDLET_PATH}?${local}pane=${hash}&cards[0]=${cardHash}`, NR1_URL ); - return guidedInstallUrl.href; + return url.href; }; module.exports = { getPackNr1Url, getGuidedInstallStackedNr1Url };