Skip to content

Commit

Permalink
chore: send user to guided install nerdlet
Browse files Browse the repository at this point in the history
  • Loading branch information
mbazhlekova committed Sep 20, 2021
1 parent 47054af commit 749b9d0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
21 changes: 17 additions & 4 deletions src/components/InstallButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ 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 { NR1_LOGIN_URL } from '../data/constants';
import {
NR1_LOGIN_URL,
NR1_GUIDED_INSTALL_NERDLET,
NR1_PACK_DETAILS_NERDLET,
} from '../data/constants';
import { quickstart } from '../types';

/**
* @param {String} id
* @returns {String}
*/
const createInstallLink = (id) => {
const platformUrl = getPackNr1Url(id);
const createInstallLink = (id, nerdletId) => {
const platformUrl = getPackNr1Url(id, nerdletId);
const url = new URL(
`?return_to=${encodeURIComponent(platformUrl)}`,
NR1_LOGIN_URL
Expand All @@ -31,15 +35,24 @@ const hasComponent = (quickstart, key) =>
const InstallButton = ({ quickstart, ...props }) => {
const hasInstallableComponent = hasComponent(quickstart, 'installPlans');

const hasGuidedInstall =
hasInstallableComponent &&
quickstart.installPlans.length === 1 &&
quickstart.installPlans[0].id.includes('guided-install');

// If there is nothing to install AND no documentation, don't show this button.
if (!hasInstallableComponent && !hasComponent(quickstart, 'documentation')) {
return null;
}

const destinationNerdletId = 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)
? createInstallLink(quickstart.id, destinationNerdletId)
: quickstart.documentation[0].url;

return (
Expand Down
3 changes: 3 additions & 0 deletions src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const NR1_BASE_URL_LOCAL = 'https://dev-one.newrelic.com';
export const NR1_PACK_DETAILS_NERDLET =
'catalog-pack-details.catalog-pack-contents';

export const NR1_GUIDED_INSTALL_NERDLET =
'nr1-install-newrelic.nr1-install-newrelic';

export const QUICKSTART_SUPPORT_LEVELS = {
NEWRELIC: 'NEWRELIC',
VERIFIED: 'VERIFIED',
Expand Down
10 changes: 3 additions & 7 deletions src/utils/get-pack-nr1-url.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
NR1_BASE_URL,
NR1_BASE_URL_LOCAL,
NR1_PACK_DETAILS_NERDLET,
} from '../data/constants';
import { NR1_BASE_URL, NR1_BASE_URL_LOCAL } from '../data/constants';

const NERDLET_PATH = `launcher/nr1-core.explorer/`;

Expand All @@ -11,9 +7,9 @@ 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, debug = false) => {
const getPackNr1Url = (quickstartId, nerdletId, debug = false) => {
const pane = JSON.stringify({
nerdletId: NR1_PACK_DETAILS_NERDLET,
nerdletId,
quickstartId,
});

Expand Down

0 comments on commit 749b9d0

Please sign in to comment.