Skip to content

Commit

Permalink
chore: adding NRBrowser and tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
rudouglas committed Jun 11, 2021
1 parent 951801b commit 1ce0b0f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 34 deletions.
18 changes: 15 additions & 3 deletions src/components/Tabs/Bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@ import React from 'react';
import PropTypes from 'prop-types';
import useMobileDetect from 'use-mobile-detect-hook';
import { css } from '@emotion/react';

import {
useTessen,
useInstrumentedData,
} from '@newrelic/gatsby-theme-newrelic';
import useTabs from './useTabs';

const MobileTabControl = ({ children }) => {
const [currentTab, setCurrentTab] = useTabs();

const tessen = useTessen();
useInstrumentedData(
{ actionName: 'oPackTabToggle', currentTab },
{ enabled: Boolean(currentTab) }
);
// eslint gets angry about using props from React.Children.map
/* eslint-disable react/prop-types */
return (
<select
onChange={(e) => setCurrentTab(e.target.value)}
onChange={(e) => {
setCurrentTab(e.target.value);
tessen.track('observabilityPack', `ObservabilityPackTabToggle`, {
oPackTabToggle: e.target.value,
});
}}
css={css`
width: 100%;
margin-bottom: 1em;
Expand Down
23 changes: 20 additions & 3 deletions src/components/Tabs/BarItem.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
import React from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/react';

import {
useTessen,
useInstrumentedData,
} from '@newrelic/gatsby-theme-newrelic';
import useTabs from './useTabs';

const BarItem = ({ index, children, id, count, disabled }) => {
const [currentTab, setCurrentTab] = useTabs();

const isSelected =
id === currentTab || (currentTab === undefined && index === 0);

const tessen = useTessen();
useInstrumentedData(
{
actionName: 'oPackTabToggle',
currentTab,
oPackTabCount: count,
},
{ enabled: Boolean(currentTab) }
);
return (
<button
role="tab"
aria-controls={id}
type="button"
onClick={() => !disabled && setCurrentTab(id)}
onClick={() => {
!disabled && setCurrentTab(id);
tessen.track('observabilityPack', `ObservabilityPackTabToggle`, {
oPackTabToggle: id,
oPackTabCount: count,
});
}}
css={css`
border: 0;
background: none;
Expand Down
57 changes: 29 additions & 28 deletions src/pages/observability-packs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import PackListTile from '../components/PackListTile';
import PackList from '../components/PackList';
import Select from '../components/Select';
import SegmentedControl from '../components/SegmentedControl';
import { SearchInput, useTessen } from '@newrelic/gatsby-theme-newrelic';
import {
SearchInput,
useTessen,
useInstrumentedData,
} from '@newrelic/gatsby-theme-newrelic';
import { useQueryParam, StringParam } from 'use-query-params';
import { useDebounce } from 'react-use';

Expand Down Expand Up @@ -42,12 +46,30 @@ const ObservabilityPacksPage = ({ data, location }) => {
const [querySearch, setQuerySearch] = useQueryParam('search', StringParam);
const [queryFilter, setQueryFilter] = useQueryParam('filter', StringParam);
const [querySort, setQuerySort] = useQueryParam('sort', StringParam);
const [view, setView] = useState(VIEWS.GRID);
useInstrumentedData(
{ actionName: 'oPackViewToggle', oPackViewState: view },
{ enabled: Boolean(view) }
);
useInstrumentedData(
{ actionName: 'oPackSort', oPackSortState: sortState },
{ enabled: Boolean(searchTerm) }
);
useInstrumentedData(
{ actionName: 'oPackFilter', oPackFilterState: containingFilterState },
{ enabled: Boolean(containingFilterState) }
);
useDebounce(
() => {
if (searchTerm && searchTerm !== '') {
tessen.track('observabilityPack', `ObservabilityPackSearch`, {
observabilityPackSearchTerm: searchTerm,
oPackSearchTerm: searchTerm,
});
if (typeof window !== 'undefined' && window.newrelic) {
window.newrelic.addPageAction('oPackSearch', {
oPackSearchTerm: searchTerm,
});
}
}
},
1000,
Expand All @@ -65,8 +87,6 @@ const ObservabilityPacksPage = ({ data, location }) => {
}
}, [querySearch, queryFilter, querySort]);

const [view, setView] = useState(VIEWS.GRID);

useEffect(() => {
setView(view);
}, [view]);
Expand Down Expand Up @@ -113,7 +133,6 @@ const ObservabilityPacksPage = ({ data, location }) => {
setQuerySort,
setQuerySearch,
]);

return (
<>
<DevSiteSeo title="Observability Packs" location={location} />
Expand Down Expand Up @@ -172,8 +191,8 @@ const ObservabilityPacksPage = ({ data, location }) => {
onChange={(e) => {
setSortState(e.target.value);
document.getElementById(e.target.id).blur();
tessen.track('observabilityPack', `ObservabilityPackFilter`, {
filter: containingFilterState,
tessen.track('observabilityPack', `ObservabilityPackSort`, {
oPackSortState: e.target.value,
});
}}
>
Expand All @@ -193,8 +212,8 @@ const ObservabilityPacksPage = ({ data, location }) => {
onChange={(e) => {
setContainingFilterState(e.target.value);
document.getElementById(e.target.id).blur();
tessen.track('observabilityPack', `ObservabilityPackSort`, {
sort: sortState,
tessen.track('observabilityPack', `ObservabilityPackFilter`, {
oPackFilterState: containingFilterState,
});
}}
>
Expand All @@ -211,7 +230,7 @@ const ObservabilityPacksPage = ({ data, location }) => {
onChange={(_e, view) => {
setView(view);
tessen.track('observabilityPack', `ObservabilityPackViewToggle`, {
viewToggle: view,
oPackViewState: view,
});
}}
/>
Expand Down Expand Up @@ -252,24 +271,6 @@ const ObservabilityPacksPage = ({ data, location }) => {
pack.logo ||
'https://via.placeholder.com/400x275.png?text=Image'
}
onClick={() => {
tessen.track(
'ObservabilityPack',
`ObservabilityPackClickThroughView`,
{
clickThroughFromView: view,
}
);
tessen.track(
'ObservabilityPack',
`ObservabilityPackClickThroughPack`,
{
clickThroughToPackSlug: pack.fields.slug,
clickThroughToPackId: pack.id,
clickThroughToPackName: pack.name,
}
);
}}
to={`${pack.fields.slug}`}
/>
);
Expand Down

0 comments on commit 1ce0b0f

Please sign in to comment.