Skip to content

Commit

Permalink
feat: apply polyfills and refactor function components
Browse files Browse the repository at this point in the history
  • Loading branch information
rudouglas committed Jun 17, 2021
1 parent 122efa0 commit b9ac1eb
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 73 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"@newrelic/gatsby-theme-newrelic": "^2.4.4",
"@splitsoftware/splitio-react": "^1.2.0",
"@xstate/react": "^1.0.2",
"blob-polyfill": "^5.0.20210201",
"classnames": "^2.2.6",
"date-fns": "^2.16.1",
"diff": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion plugins/gatsby-source-newrelic-sdk/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ exports.createSchemaCustomization = ({ actions, schema }) => {
}
type NewRelicSdkPropTypeFunctionMeta {
returnValue: NewRelicSdkFunctionReturnValue!
returnValue: [NewRelicSdkFunctionReturnValue]!
arguments: [NewRelicSdkFunctionArgument!]!
}
Expand Down
14 changes: 3 additions & 11 deletions plugins/gatsby-source-newrelic-sdk/src/getPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ const SPECIAL_NUMBERS = [
'EPSILON',
];

const IGNORED_PROPERTIES = [
'prototype',
'length',
'name',
'propTypes',
'getDerivedStateFromProps',
'defaultProps',
];
const IGNORED_PROPERTIES = [];

const getArgs = (propType) =>
(propType.__reflect__.find(({ args }) => args) || {}).args;
Expand Down Expand Up @@ -121,10 +114,9 @@ const getTypeMeta = (name, propType, { component }) => {

switch (getRawTypeName(propType)) {
case 'func':
console.log(propTypeDocs.tags);
return {
returnValue: (propTypeDocs.tags || {}).returnValue || {
type: 'undefined',
},
returnValue: (propTypeDocs.tags || {}).return || [],
arguments: (propTypeDocs.tags || {}).param || [],
};
case 'shape': {
Expand Down
9 changes: 1 addition & 8 deletions plugins/gatsby-source-newrelic-sdk/src/getTypeDefs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const IGNORED_TYPE_DEFS = [
'Object',
'ReactNode',
'Event',
'number',
'string',
'boolean',
];
const IGNORED_TYPE_DEFS = [];

const flatten = (arr) => [].concat(...arr);
const uniqBy = (arr, key) => {
Expand Down
11 changes: 7 additions & 4 deletions plugins/gatsby-source-newrelic-sdk/src/mockGlobals.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const noop = () => {};
const Blob = require('blob-polyfill').Blob;
const fetch = require("node-fetch");

global.Element = {
prototype: {
Expand Down Expand Up @@ -55,7 +53,12 @@ global.window = {
requestAnimationFrame: global.requestAnimationFrame,
cancelAnimationFrame: global.cancelAnimationFrame,
};

function Blob() {
return { size: null };
}
global.Blob = Blob;

global.fetch = fetch;
global.fetch = () => ({
catch: noop,
then: noop,
});
62 changes: 37 additions & 25 deletions src/components/FunctionDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,36 @@ import { graphql } from 'gatsby';

const FunctionDefinition = ({ className, arguments: params, returnValue }) => {
return (
<CodeDef className={className}>
<CodeDef.Keyword>function</CodeDef.Keyword>{' '}
<CodeDef.Bracket>{params.length > 0 ? '(' : '()'}</CodeDef.Bracket>
{params.length > 0 && (
<CodeDef.Block>
{params.map((param, i) => (
<div key={i}>
<CodeDef.Identifier>
{param.type.startsWith('...') ? `...${param.name}` : param.name}
:{' '}
</CodeDef.Identifier>
<CodeDef.Type>{param.type}</CodeDef.Type>
{i !== params.length - 1 ? ', ' : ' '}
<CodeDef.Comment text={param.description} />
</div>
))}
</CodeDef.Block>
)}
{params.length > 0 && <CodeDef.Bracket>)</CodeDef.Bracket>}
<CodeDef.Operator> => </CodeDef.Operator>
<CodeDef.Type>{returnValue.type}</CodeDef.Type>
</CodeDef>
(params.length > 0 || returnValue.length > 0) && (
<CodeDef className={className}>
<CodeDef.Keyword>function</CodeDef.Keyword>{' '}
<CodeDef.Bracket>{params.length > 0 ? '(' : '()'}</CodeDef.Bracket>
{params.length > 0 && (
<CodeDef.Block>
{params.map((param, i) => (
<div key={i}>
<CodeDef.Identifier>
{param.type.startsWith('...')
? `...${param.name}`
: param.name}
:{' '}
</CodeDef.Identifier>
<CodeDef.Type>{param.type}</CodeDef.Type>
{i !== params.length - 1 ? ', ' : ' '}
<CodeDef.Comment text={param.description} />
</div>
))}
</CodeDef.Block>
)}
{params.length > 0 && <CodeDef.Bracket>)</CodeDef.Bracket>}
{returnValue.length > 0 && (
<>
<CodeDef.Operator> => </CodeDef.Operator>
<CodeDef.Type>{returnValue[0].type}</CodeDef.Type>
</>
)}
</CodeDef>
)
);
};

Expand All @@ -39,9 +47,12 @@ FunctionDefinition.propTypes = {
description: PropTypes.string,
})
).isRequired,
returnValue: PropTypes.shape({
type: PropTypes.string.isRequired,
}).isRequired,
returnValue: PropTypes.arrayOf(
PropTypes.shape({
type: PropTypes.string,
description: PropTypes.string,
})
).isRequired,
};

export const query = graphql`
Expand All @@ -53,6 +64,7 @@ export const query = graphql`
fragment FunctionDefinition_returnValue on NewRelicSdkFunctionReturnValue {
type
description
}
`;

Expand Down
40 changes: 21 additions & 19 deletions src/components/PropList.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,27 @@ const PropTypeInfo = ({ type }) => {
}
case 'oneOf':
return (
<CodeDef
css={css`
max-height: 320px;
overflow-y: scroll;
`}
>
<CodeDef.Bracket>{'<'}</CodeDef.Bracket>
<CodeDef.Keyword>One of</CodeDef.Keyword>
<CodeDef.Block>
{type.meta.constants.map((constant) => (
<div key={constant}>
<CodeDef.Identifier key={constant}>
{constant},
</CodeDef.Identifier>
</div>
))}
</CodeDef.Block>
<CodeDef.Bracket>{'>'}</CodeDef.Bracket>
</CodeDef>
type.meta.constants.length > 0 && (
<CodeDef
css={css`
max-height: 320px;
overflow-y: scroll;
`}
>
<CodeDef.Bracket>{'<'}</CodeDef.Bracket>
<CodeDef.Keyword>One of</CodeDef.Keyword>
<CodeDef.Block>
{type.meta.constants.map((constant) => (
<div key={constant}>
<CodeDef.Identifier key={constant}>
{constant},
</CodeDef.Identifier>
</div>
))}
</CodeDef.Block>
<CodeDef.Bracket>{'>'}</CodeDef.Bracket>
</CodeDef>
)
);
case 'oneOfType':
return type.meta.types.map((type, idx) => (
Expand Down
2 changes: 1 addition & 1 deletion src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const SPLIT_TRACKING_EVENTS = {
};

export const SDK_BASE_URL =
'https://d1zobbh8kytrtv.cloudfront.net/platform/wanda--wanda-ec-ui--nr1-docs';
'https://d1zobbh8kytrtv.cloudfront.net/platform/doc-app';
2 changes: 0 additions & 2 deletions src/data/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@
url: '/components/dropdown-section'
- title: Form
url: '/components/form'
- title: MultilineTextField
url: '/components/multiline-text-field'
- title: Radio
url: '/components/radio'
- title: RadioGroup
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSDK.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const useSDK = () => {

useEffect(() => {}, [sdkLoaded]);

useScript(`${SDK_BASE_URL}-${release}.js`, {
useScript(`${SDK_BASE_URL}-${release}-dev.js`, {
onError: () => setSdkLoaded({ loaded: false, error: 'failed to load' }),
onLoad: () => setSdkLoaded({ loaded: true, error: null }),
});
Expand Down

0 comments on commit b9ac1eb

Please sign in to comment.