Skip to content

Commit

Permalink
refactor: moved dashboards into their own component
Browse files Browse the repository at this point in the history
  • Loading branch information
zstix committed Aug 23, 2021
1 parent 429ba4b commit 8d8a54f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
35 changes: 35 additions & 0 deletions src/components/quickstarts/QuickstartDashboards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { css } from '@emotion/react';
import pluralize from 'pluralize';
import Intro from '../Intro';
import ImageSlider from '../ImageSlider';
import { quickstart } from '../../types';

const QuickstartDashboards = ({ quickstart }) => (
<>
<Intro
css={css`
margin-bottom: 16px;
`}
>
{quickstart.name} quickstart contains{' '}
{pluralize('dashboard', quickstart.dashboards?.length ?? 0, true)}. These
interactive visualizations let you easily explore your data, understand
context, and resolve problems faster.
</Intro>

{quickstart.dashboards.map((dashboard, index) => (
<div key={index}>
<h3>{dashboard.name}</h3>
{dashboard.description && <p>{dashboard.description}</p>}
<ImageSlider height={400} images={dashboard.screenshots} />
</div>
))}
</>
);

QuickstartDashboards.propTypes = {
quickstart: quickstart.isRequired,
};

export default QuickstartDashboards;
40 changes: 2 additions & 38 deletions src/templates/ObservabilityPackDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PageLayout from '../components/PageLayout';
import Tabs from '../components/Tabs';
import EmptyTab from '../components/quickstarts/EmptyTab';
import QuickstartAlerts from '../components/quickstarts/QuickstartAlerts';
import QuickstartDashboards from '../components/quickstarts/QuickstartDashboards';
import {
Layout,
PageTools,
Expand All @@ -17,11 +18,8 @@ import {
Link,
} from '@newrelic/gatsby-theme-newrelic';
import ImageGallery from '../components/ImageGallery';
import Intro from '../components/Intro';
import InstallButton from '../components/InstallButton';
import ImageSlider from '../components/ImageSlider';
import Markdown from '../components/Markdown';
import pluralize from 'pluralize';
import { quickstart } from '../types';
import {
QUICKSTARTS_REPO,
Expand All @@ -44,40 +42,6 @@ const allowedElements = [
'hr',
];

/**
* @param {quickstart} pack
*/
const renderDashboards = (pack) => {
const content = pack.dashboards.map((dashboard, index) => (
<>
<h3 key={index}>{dashboard.name}</h3>
<ImageSlider height={400} images={dashboard.screenshots} />
{dashboard.description && (
<>
<h4>Description</h4>
<p>{dashboard.description}</p>
</>
)}
</>
));

return (
<>
<Intro
css={css`
margin-bottom: 16px;
`}
>
{pack.name} observability pack contains{' '}
{pluralize('dashboard', pack.dashboards?.length ?? 0, true)}. These
interactive visualizations let you easily explore your data, understand
context, and resolve problems faster.
</Intro>
{content}
</>
);
};

const ObservabilityPackDetails = ({ data, location }) => {
const pack = data.observabilityPacks;
const packUrl = pack.packUrl || QUICKSTARTS_REPO;
Expand Down Expand Up @@ -151,7 +115,7 @@ const ObservabilityPackDetails = ({ data, location }) => {
</Tabs.Page>
<Tabs.Page id="dashboards">
{pack.dashboards ? (
renderDashboards(pack)
<QuickstartDashboards quickstart={pack} />
) : (
<EmptyTab
quickstartUrl={pack.packUrl}
Expand Down

0 comments on commit 8d8a54f

Please sign in to comment.