-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UIAPPS-104 Create a UI Extensions react
package
#94
Changes from 4 commits
5dd7e51
df17b3f
2e0b4ec
3be5cfc
94da58a
2d7ca54
147af1e
8412100
b4d6743
93759e8
bb85f91
a979fdf
ba9c1e3
81e7130
30f57bd
f7b5b45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@datadog/ui-extensions-react': minor | ||
'@datadog/ui-extensions-sdk': minor | ||
--- | ||
|
||
Create a new package for UI Extensions with the React framework. | ||
|
||
This package provides helpers that make working with the SDK in React a bit easier. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,21 @@ We use [`changesets`][] to help with normal package releases. | |
When a normal PR is merged, [`changsets`][] will keep track of any [changeset][]s in this long-running PR. | ||
When we're ready to release some number of packages, we can merge this long-running PR and [`changesets`][] will release all packages with a [changeset][]. | ||
|
||
## `@datadog/ui-extensions-*` packages | ||
|
||
These packages are all released at the same version. | ||
The intention is to make it so App Developers have an easier time with updates. | ||
If we say, | ||
"Check out this wonderful feature in 0.36.0!" | ||
App Developers should be able to update whatever `@datadog/ui-extensions-*` packages they have to 0.36.0 and be on their way. | ||
|
||
The alternative would be to allow different versions for each package. | ||
That allows more flexibility and lower version churn at the expense of confusion with version updates. | ||
A similar example to the above might be worded like, | ||
"Check out this wonderful feature in 0.36.0 of `@datadog/ui-extensions-sdk`, 2.3.0 of `@datadog/ui-extensions-react`, 1.46.0 of `@datadog/ui-extensions-vue`, etc." | ||
While that's a model that many other groups of packages follow, | ||
we're opting for keeping all the versions the same. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔊 |
||
|
||
[`auto`]: https://intuit.github.io/auto/ | ||
[`changesets`]: https://github.com/changesets/changesets | ||
[changeset]: https://github.com/changesets/changesets/blob/main/docs/detailed-explanation.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { useContext } from '@datadog/ui-extensions-react'; | ||
import { init, EventType } from '@datadog/ui-extensions-sdk'; | ||
import './../index.css'; | ||
import React from 'react'; | ||
|
@@ -13,12 +14,13 @@ const client = init(); | |
function Widget() { | ||
const [metric, setMetric] = useState('system.cpu.idle'); | ||
const [broadcastClickCount, setBroadcastClickCount] = useState(0); | ||
const result = useContext(client); | ||
|
||
useEffect(() => { | ||
client.getContext().then(c => { | ||
setMetric(c.widget?.definition.options?.metric); | ||
}); | ||
if (result.type === 'initialized') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ It kind of feels like we should take this opportunity to show some decent patterns for dealing with the other two states: initializing, and handshake failure. I didn't want to make too big of a change in case that wasn't wanted. What do y'all think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The funny thing is that when the frame is in loading or error state, the iframe is invisible so it almost doesn't matter what the app does, short of blowing up. The right pattern is honestly probably just
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right! Makes me wish we didn't have to do something about those other states and could just return the context only. Maybe what would be more useful for actually rendering a component is not the hook for context, but a component that passes down the context once it's ready and only renders once it has a context. So you'd do something like: import { WithContext } from '@datadog/ui-extensions-react';
import { Context, init } from '@datadog/ui-extensions-sdk';
type WidgetProps = {
context: Context;
};
function Widget(props: WidgetProps) {
// Work with the actual `Context` in `props.context`.
…
}
export default function render() {
ReactDOM.render(
<React.StrictMode>
<WithContext client={client}>
<Widget />
</WithContext>
</React.StrictMode>,
document.getElementById('root')
);
} Or something, general idea being that the hook isn't as helpful as it could be since it's still too low-level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe, we just don't deal with the error at all and the return type of |
||
setMetric(result.context.widget?.definition.options.metric); | ||
} | ||
|
||
useEffect(() => { | ||
client.events.on( | ||
EventType.DASHBOARD_CUSTOM_WIDGET_OPTIONS_CHANGE, | ||
({ metric }) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
coverage | ||
dist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool!