Skip to content

Commit

Permalink
chore: type definitions for packs
Browse files Browse the repository at this point in the history
  • Loading branch information
zstix committed Aug 19, 2021
1 parent e64c83e commit b56876f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ export const NR1_BASE_URL = 'https://staging-one.newrelic.com';

export const NR1_PACK_DETAILS_NERDLET =
'catalog-pack-details.catalog-pack-contents';

export const QUICKSTART_SUPPORT_LEVELS = {
NEWRELIC: 'NEWRELIC',
VERIFIED: 'VERIFIED',
COMMUNITY: 'COMMUNITY',
};
27 changes: 23 additions & 4 deletions src/templates/ObservabilityPackDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import ImageSlider from '../components/ImageSlider';
import getPackUrl from '../utils/get-pack-url';
import Markdown from '../components/Markdown';
import pluralize from 'pluralize';
import { quickstart } from '../types';
import { QUICKSTART_SUPPORT_LEVELS } from '../data/constants';

const allowedElements = [
'h1',
Expand All @@ -39,20 +41,23 @@ const allowedElements = [
];

const SUPPORT_CONTENT = {
NEWRELIC: {
[QUICKSTART_SUPPORT_LEVELS.NEWRELIC]: {
title: 'Built by New Relic',
content: `Need help? [Visit our Support Center](https://support.newrelic.com) or check out our community forum, [the Explorers Hub](https://discuss.newrelic.com).`,
},
VERIFIED: {
[QUICKSTART_SUPPORT_LEVELS.VERIFIED]: {
title: 'Verified by New Relic',
content: `Need help? [Visit our Support Center](https://support.newrelic.com) or check out our community forum, [the Explorers Hub](https://discuss.newrelic.com).`,
},
COMMUNITY: {
[QUICKSTART_SUPPORT_LEVELS.COMMUNITY]: {
title: 'Built by the community',
content: `Need help? Visit our community forum, [the Explorers Hub](https://discuss.newrelic.com) to find an answer or post a question.`,
},
};

/**
* @param {quickstart} pack
*/
const renderDashboards = (pack) => {
const content = pack.dashboards.map((dashboard, index) => (
<>
Expand Down Expand Up @@ -84,6 +89,9 @@ const renderDashboards = (pack) => {
);
};

/**
* @param {quickstart} pack
*/
const renderAlerts = (pack) => {
const alertContent = pack.alerts.map((alert, index) => (
<>
Expand Down Expand Up @@ -115,6 +123,10 @@ const renderAlerts = (pack) => {
);
};

/**
* @param {quickstart} pack
* @param {String} tabName
*/
const emptyStateContent = (pack, tabName) => {
return (
<div
Expand Down Expand Up @@ -175,6 +187,11 @@ 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();
Expand Down Expand Up @@ -341,7 +358,9 @@ const ObservabilityPackDetails = ({ data, location }) => {
};

ObservabilityPackDetails.propTypes = {
data: PropTypes.object,
data: PropTypes.shape({
observabilityPacks: quickstart,
}),
location: PropTypes.object.isRequired,
};

Expand Down
37 changes: 37 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import PropTypes from 'prop-types';
import { QUICKSTART_SUPPORT_LEVELS } from './data/constants';

// NOTE: while creating a recursive data structure is feasible,
// it is not very performant.
Expand All @@ -12,3 +13,39 @@ export const link = PropTypes.shape({
export const pageContext = PropTypes.shape({
fileRelativePath: PropTypes.string,
});

export const quickstartDashboard = PropTypes.shape({
name: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
screenshots: PropTypes.arrayOf(PropTypes.string),
});

export const quickstartAlert = PropTypes.shape({
name: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
type: PropTypes.oneOf(['BASELINE', 'OUTLIER', 'STATIC']).isRequired,
details: PropTypes.string,
});

export const quickstartDocumentation = PropTypes.shape({
name: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
description: PropTypes.string,
});

export const quickstart = PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
level: PropTypes.oneOf(QUICKSTART_SUPPORT_LEVELS).isRequired,
description: PropTypes.string.isRequired,
authors: PropTypes.arrayOf(PropTypes.string).isRequired,
summary: PropTypes.string,
iconUrl: PropTypes.string,
logoUrl: PropTypes.string,
websiteUrl: PropTypes.string,
tags: PropTypes.arrayOf(PropTypes.string),
dashboards: PropTypes.arrayOf(quickstartDashboard),
alerts: PropTypes.arrayOf(quickstartAlert),
documentation: PropTypes.arrayOf(quickstartDocumentation),
});

0 comments on commit b56876f

Please sign in to comment.