Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send user to guided install nerdlet #1663

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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