From b9ac1ebd6d81464c372c958fe7f773ff52fabcde Mon Sep 17 00:00:00 2001 From: rudouglas Date: Thu, 17 Jun 2021 15:25:08 +0100 Subject: [PATCH] feat: apply polyfills and refactor function components --- package.json | 1 - .../gatsby-source-newrelic-sdk/gatsby-node.js | 2 +- .../src/getPropTypes.js | 14 +---- .../src/getTypeDefs.js | 9 +-- .../src/mockGlobals.js | 11 ++-- src/components/FunctionDefinition.js | 62 +++++++++++-------- src/components/PropList.js | 40 ++++++------ src/data/constants.js | 2 +- src/data/nav.yml | 2 - src/hooks/useSDK.js | 2 +- 10 files changed, 72 insertions(+), 73 deletions(-) diff --git a/package.json b/package.json index 987b6fd99..49ed016fe 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/plugins/gatsby-source-newrelic-sdk/gatsby-node.js b/plugins/gatsby-source-newrelic-sdk/gatsby-node.js index 944a65f65..773b34f6d 100644 --- a/plugins/gatsby-source-newrelic-sdk/gatsby-node.js +++ b/plugins/gatsby-source-newrelic-sdk/gatsby-node.js @@ -88,7 +88,7 @@ exports.createSchemaCustomization = ({ actions, schema }) => { } type NewRelicSdkPropTypeFunctionMeta { - returnValue: NewRelicSdkFunctionReturnValue! + returnValue: [NewRelicSdkFunctionReturnValue]! arguments: [NewRelicSdkFunctionArgument!]! } diff --git a/plugins/gatsby-source-newrelic-sdk/src/getPropTypes.js b/plugins/gatsby-source-newrelic-sdk/src/getPropTypes.js index b4e38fbf7..7b20f6947 100644 --- a/plugins/gatsby-source-newrelic-sdk/src/getPropTypes.js +++ b/plugins/gatsby-source-newrelic-sdk/src/getPropTypes.js @@ -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; @@ -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': { diff --git a/plugins/gatsby-source-newrelic-sdk/src/getTypeDefs.js b/plugins/gatsby-source-newrelic-sdk/src/getTypeDefs.js index 0f5dca12f..27249d9e2 100644 --- a/plugins/gatsby-source-newrelic-sdk/src/getTypeDefs.js +++ b/plugins/gatsby-source-newrelic-sdk/src/getTypeDefs.js @@ -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) => { diff --git a/plugins/gatsby-source-newrelic-sdk/src/mockGlobals.js b/plugins/gatsby-source-newrelic-sdk/src/mockGlobals.js index b00514b60..76fd9ff63 100644 --- a/plugins/gatsby-source-newrelic-sdk/src/mockGlobals.js +++ b/plugins/gatsby-source-newrelic-sdk/src/mockGlobals.js @@ -1,6 +1,4 @@ const noop = () => {}; -const Blob = require('blob-polyfill').Blob; -const fetch = require("node-fetch"); global.Element = { prototype: { @@ -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, +}); diff --git a/src/components/FunctionDefinition.js b/src/components/FunctionDefinition.js index 59b9105a6..13bcf27b9 100644 --- a/src/components/FunctionDefinition.js +++ b/src/components/FunctionDefinition.js @@ -5,28 +5,36 @@ import { graphql } from 'gatsby'; const FunctionDefinition = ({ className, arguments: params, returnValue }) => { return ( - - function{' '} - {params.length > 0 ? '(' : '()'} - {params.length > 0 && ( - - {params.map((param, i) => ( -
- - {param.type.startsWith('...') ? `...${param.name}` : param.name} - :{' '} - - {param.type} - {i !== params.length - 1 ? ', ' : ' '} - -
- ))} -
- )} - {params.length > 0 && )} - => - {returnValue.type} -
+ (params.length > 0 || returnValue.length > 0) && ( + + function{' '} + {params.length > 0 ? '(' : '()'} + {params.length > 0 && ( + + {params.map((param, i) => ( +
+ + {param.type.startsWith('...') + ? `...${param.name}` + : param.name} + :{' '} + + {param.type} + {i !== params.length - 1 ? ', ' : ' '} + +
+ ))} +
+ )} + {params.length > 0 && )} + {returnValue.length > 0 && ( + <> + => + {returnValue[0].type} + + )} +
+ ) ); }; @@ -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` @@ -53,6 +64,7 @@ export const query = graphql` fragment FunctionDefinition_returnValue on NewRelicSdkFunctionReturnValue { type + description } `; diff --git a/src/components/PropList.js b/src/components/PropList.js index b2f6bdc43..b5db1f161 100644 --- a/src/components/PropList.js +++ b/src/components/PropList.js @@ -44,25 +44,27 @@ const PropTypeInfo = ({ type }) => { } case 'oneOf': return ( - - {'<'} - One of - - {type.meta.constants.map((constant) => ( -
- - {constant}, - -
- ))} -
- {'>'} -
+ type.meta.constants.length > 0 && ( + + {'<'} + One of + + {type.meta.constants.map((constant) => ( +
+ + {constant}, + +
+ ))} +
+ {'>'} +
+ ) ); case 'oneOfType': return type.meta.types.map((type, idx) => ( diff --git a/src/data/constants.js b/src/data/constants.js index 4ae52eedd..8c0235c98 100644 --- a/src/data/constants.js +++ b/src/data/constants.js @@ -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'; diff --git a/src/data/nav.yml b/src/data/nav.yml index 9646daa1a..ebbafcd0a 100644 --- a/src/data/nav.yml +++ b/src/data/nav.yml @@ -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 diff --git a/src/hooks/useSDK.js b/src/hooks/useSDK.js index 6e7bd1ca6..1f937110b 100644 --- a/src/hooks/useSDK.js +++ b/src/hooks/useSDK.js @@ -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 }), });