From b5cf5a3dd7bcad2b78570738a5c3f079a9d9e628 Mon Sep 17 00:00:00 2001 From: Zack Stickles Date: Thu, 19 Aug 2021 15:34:10 -0700 Subject: [PATCH] feat: update install pack button when nothing to install I decided to start updating the references to `pack` to be `quickstart`. --- src/components/InstallButton.js | 53 +++++++++++++++++------ src/templates/ObservabilityPackDetails.js | 7 +-- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/components/InstallButton.js b/src/components/InstallButton.js index f8f229d7b..4e76161b0 100644 --- a/src/components/InstallButton.js +++ b/src/components/InstallButton.js @@ -3,10 +3,14 @@ import PropTypes from 'prop-types'; import { Button, Link } from '@newrelic/gatsby-theme-newrelic'; import getPackNr1Url from '../utils/get-pack-nr1-url'; import { NR1_LOGIN_URL } from '../data/constants'; +import { quickstart } from '../types'; -/** @param {string} packId */ -const createInstallLink = (packId) => { - const platformUrl = getPackNr1Url(packId); +/** + * @param {String} id + * @returns {String} + */ +const createInstallLink = (id) => { + const platformUrl = getPackNr1Url(id); const url = new URL( `?return_to=${encodeURIComponent(platformUrl)}`, NR1_LOGIN_URL @@ -15,19 +19,40 @@ const createInstallLink = (packId) => { return url.href; }; -const InstallButton = ({ packId, ...props }) => ( - -); +/** + * @param {quickstart} quickstart + * @param {String} key + * @returns {Boolean} + */ +const hasComponent = (quickstart, key) => + quickstart[key] && quickstart[key].length > 0; + +const InstallButton = ({ quickstart, ...props }) => { + const hasInstallableComponent = + hasComponent(quickstart, 'dashboards') || + hasComponent(quickstart, 'alerts'); + + // If there is nothing to install AND no documentation, don't show this button. + if (!hasInstallableComponent && !hasComponent(quickstart, 'documentation')) { + return null; + } + + // If we have an install-able component, generate a URL. Otherwise, link to the + // first documentation supplied. + const url = hasInstallableComponent + ? createInstallLink(quickstart.id) + : quickstart.documentation[0].url; + + return ( + + ); +}; InstallButton.propTypes = { - packId: PropTypes.string.isRequired, + quickstart: quickstart.isRequired, + onClick: PropTypes.func.isRequired, }; export default InstallButton; diff --git a/src/templates/ObservabilityPackDetails.js b/src/templates/ObservabilityPackDetails.js index a8b607b6c..78dc53cbf 100644 --- a/src/templates/ObservabilityPackDetails.js +++ b/src/templates/ObservabilityPackDetails.js @@ -187,11 +187,6 @@ const emptyStateContent = (pack, tabName) => { ); }; -/** - * @param {Object} props - * @param {{ observabilityPacks: quickstart }} props.data - * @param {String} props.location - */ const ObservabilityPackDetails = ({ data, location }) => { const pack = data.observabilityPacks; const tessen = useTessen(); @@ -221,7 +216,7 @@ const ObservabilityPackDetails = ({ data, location }) => { gap: 1rem; `} > - +