Skip to content

Commit

Permalink
chore: open guided install nerdlet in a card
Browse files Browse the repository at this point in the history
  • Loading branch information
mbazhlekova committed Sep 21, 2021
1 parent 9801745 commit 1b776d4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/components/InstallButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import React from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/react';
import { Button, Link, Icon } from '@newrelic/gatsby-theme-newrelic';
import getPackNr1Url from '../utils/get-pack-nr1-url';
import {
getPackNr1Url,
getGuidedInstallStackedNr1Url,
} from '../utils/get-pack-nr1-url';
import {
NR1_LOGIN_URL,
NR1_GUIDED_INSTALL_NERDLET,
Expand All @@ -15,7 +18,10 @@ import { quickstart } from '../types';
* @returns {String}
*/
const createInstallLink = (id, nerdletId) => {
const platformUrl = getPackNr1Url(id, nerdletId);
const platformUrl =
nerdletId === NR1_GUIDED_INSTALL_NERDLET
? getGuidedInstallStackedNr1Url(nerdletId)
: getPackNr1Url(id, nerdletId);
const url = new URL(
`?return_to=${encodeURIComponent(platformUrl)}`,
NR1_LOGIN_URL
Expand Down
34 changes: 30 additions & 4 deletions src/utils/get-pack-nr1-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const NERDLET_PATH = `launcher/nr1-core.explorer/`;
* @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, nerdletId, debug = false) => {
export const getPackNr1Url = (quickstartId, nerdletId, debug = false) => {
const pane = JSON.stringify({
nerdletId,
quickstartId,
Expand All @@ -24,9 +24,35 @@ const getPackNr1Url = (quickstartId, nerdletId, debug = false) => {
const local = debug ? 'packages=local&' : '';
const NR1_URL = debug ? NR1_BASE_URL_LOCAL : NR1_BASE_URL;

const url = new URL(`${NERDLET_PATH}?${local}pane=${hash}`, NR1_URL);
const packDetailsUrl = new URL(
`${NERDLET_PATH}?${local}pane=${hash}`,
NR1_URL
);

return url.href;
return packDetailsUrl.href;
};

module.exports = getPackNr1Url;
export const getGuidedInstallStackedNr1Url = (nerdletId, debug = false) => {
const pane = JSON.stringify({ nerdletId: 'nr1-core.listing' });
const card = JSON.stringify({ nerdletId });

const paneHash =
window && window.btoa
? btoa(pane)
: Buffer.from(pane, 'utf-8').toString('base64');

const cardHash =
window && window.btoa
? btoa(card)
: Buffer.from(card, 'utf-8').toString('base64');

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}`,
NR1_URL
);

return guidedInstallUrl.href;
};

0 comments on commit 1b776d4

Please sign in to comment.