Skip to content

Commit

Permalink
feat: load treatments from split for contribute buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Sep 3, 2020
1 parent 0595bcb commit cd9007f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/components/RelatedContentModules/Contribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import PropTypes from 'prop-types';
import { css } from '@emotion/core';
import { Button, ExternalLink, Icon } from '@newrelic/gatsby-theme-newrelic';
import { graphql, useStaticQuery } from 'gatsby';
import useTreatment from '../../hooks/useTreatment';
import { useTrack } from '@splitsoftware/splitio-react';
import { SPLITS } from '../../data/constants';
import Section from './Section';

const Contribute = ({ pageContext }) => {
Expand All @@ -16,6 +19,9 @@ const Contribute = ({ pageContext }) => {
}
`);

const { treatment, config } = useTreatment(SPLITS.CONTRIBUTE_BUTTONS);
const track = useTrack();

const { fileRelativePath } = pageContext;

const {
Expand All @@ -35,8 +41,14 @@ const Contribute = ({ pageContext }) => {
css={css`
margin-right: 0.5rem;
`}
variant={Button.VARIANT.PRIMARY}
disabled={treatment === 'control'}
variant={config?.issues || Button.VARIANT.NORMAL}
size={Button.SIZE.SMALL}
onClick={() =>
track('related_content.contribute_action_clicked', null, {
button: 'issues',
})
}
>
<Icon
name={Icon.TYPE.GITHUB}
Expand All @@ -49,8 +61,14 @@ const Contribute = ({ pageContext }) => {
<Button
as={ExternalLink}
href={`${repository}/tree/main/${fileRelativePath}`}
variant={Button.VARIANT.NORMAL}
disabled={treatment === 'control'}
variant={config?.edit || Button.VARIANT.NORMAL}
size={Button.SIZE.SMALL}
onClick={() =>
track('related_content.contribute_action_clicked', null, {
button: 'edit',
})
}
>
<Icon
name={Icon.TYPE.EDIT}
Expand Down
4 changes: 4 additions & 0 deletions src/data/constants.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const githubBaseUrl = 'https://github.com/newrelic/developer-website';

export const SPLITS = {
CONTRIBUTE_BUTTONS: 'developer-website_right-rail-buttons',
};

0 comments on commit cd9007f

Please sign in to comment.