Skip to content

Commit

Permalink
feat: Add PlatformStateContext and NerdletStateContext
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 3, 2020
1 parent 0b608d7 commit 0355d26
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 40 deletions.
100 changes: 60 additions & 40 deletions src/components/ComponentExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import styles from './ComponentExample.module.scss';
import root from 'react-shadow';
import { CSS_BUNDLE } from '../utils/sdk';

const platformStateContextMock = {
timeRange: {
begin_time: null,
duration: 1800000,
end_time: null,
},
};

const nerdletStateContextMock = {
entityGuid: 'MTIzNDU2fEZPT3xCQVJ8OTg3NjU0MzIx',
};

const TRAILING_SEMI = /;\s*$/;

const EXAMPLE_CSS = `
Expand Down Expand Up @@ -99,6 +111,10 @@ const ComponentExample = ({
}) => {
const [stylesLoaded, setStylesLoaded] = useState(false);
const ToastManager = window.__NR1_SDK__.ToastManager;
const {
PlatformStateContext,
NerdletStateContext,
} = window.__NR1_SDK__.default;
const { live } = example.options;
let formattedCode;

Expand All @@ -109,47 +125,51 @@ const ComponentExample = ({
}

return (
<div className={className}>
<h3 className={styles.title}>{example.label}</h3>
<LiveProvider
scope={{
...window.__NR1_SDK__.default,
navigation: {
// eslint-disable-next-line no-empty-function
getOpenLauncherLocation() {},
},
}}
code={formattedCode}
theme={github}
disabled={!live}
>
{live && (
<root.div className={styles.preview}>
<link
rel="stylesheet"
href={CSS_BUNDLE}
onLoad={() => setStylesLoaded(true)}
/>
<style type="text/css">{EXAMPLE_CSS}</style>
{useToastManager && (
<div className="nr1-ComponentExample-ToastManager">
<ToastManager />
</div>
)}
{stylesLoaded ? (
<LivePreview
className="nr1-ComponentExample"
style={previewStyle}
/>
) : (
'Loading...'
<PlatformStateContext.Provider value={platformStateContextMock}>
<NerdletStateContext.Provider value={nerdletStateContextMock}>
<div className={className}>
<h3 className={styles.title}>{example.label}</h3>
<LiveProvider
scope={{
...window.__NR1_SDK__.default,
navigation: {
// eslint-disable-next-line no-empty-function
getOpenLauncherLocation() {},
},
}}
code={formattedCode}
theme={github}
disabled={!live}
>
{live && (
<root.div className={styles.preview}>
<link
rel="stylesheet"
href={CSS_BUNDLE}
onLoad={() => setStylesLoaded(true)}
/>
<style type="text/css">{EXAMPLE_CSS}</style>
{useToastManager && (
<div className="nr1-ComponentExample-ToastManager">
<ToastManager />
</div>
)}
{stylesLoaded ? (
<LivePreview
className="nr1-ComponentExample"
style={previewStyle}
/>
) : (
'Loading...'
)}
</root.div>
)}
</root.div>
)}
<LiveEditor style={{ fontSize: '0.75rem' }} />
{live && <LiveError className={styles.error} />}
</LiveProvider>
</div>
<LiveEditor style={{ fontSize: '0.75rem' }} />
{live && <LiveError className={styles.error} />}
</LiveProvider>
</div>
</NerdletStateContext.Provider>
</PlatformStateContext.Provider>
);
};

Expand Down
13 changes: 13 additions & 0 deletions src/data/sidenav.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,18 @@
"url": "/components/nrql-query"
}
]
},
{
"displayName": "Platform APIs",
"children": [
{
"displayName": "NerdletStateContext",
"url": "/components/nerdlet-state-context"
},
{
"displayName": "PlatformStateContext",
"url": "/components/platform-state-context"
}
]
}
]
7 changes: 7 additions & 0 deletions src/markdown-pages/components/nerdlet-state-context.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
path: '/components/nerdlet-state-context'
title: 'NerdletStateContext'
description: 'A NerdletStateContext component!'
component: 'NerdletStateContext'
template: 'ReferenceTemplate'
---
7 changes: 7 additions & 0 deletions src/markdown-pages/components/platform-state-context.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
path: '/components/platform-state-context'
title: 'PlatformStateContext'
description: 'A PlatformStateContext component!'
component: 'PlatformStateContext'
template: 'ReferenceTemplate'
---

0 comments on commit 0355d26

Please sign in to comment.