-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[ML][Embeddables Rebuild] Migrate Change Point Charts embeddable #182246
[ML][Embeddables Rebuild] Migrate Change Point Charts embeddable #182246
Conversation
Pinging @elastic/ml-ui (:ml) |
x-pack/plugins/aiops/public/embeddable/change_point_chart/initialize_chane_point_controls.ts
Outdated
Show resolved
Hide resolved
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.
Tested and LGTM. Agree about renaming the embeddable
folder and just spotted the typo in the filename.
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.
Great work! It's really nice to see more embeddable conversions coming along!
Left a few nits and comments.
const blockingError = new BehaviorSubject<Error | undefined>(undefined); | ||
|
||
const dataViews$ = new BehaviorSubject<DataView[] | undefined>([ | ||
await deps.data.dataViews.get(state.dataViewId), |
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.
nit: if you're storing a dataViewId
, it should really be stored as a reference
. This is so that if a user exports the Dashboard, the data view used in your change point chart is exported as well. You can take a look at examples/embeddable_examples/public/react_embeddables/field_list/field_list_react_embeddable.tsx
to see how to accomplish this.
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.
Added in 9323cbf
api.partitions | ||
); | ||
|
||
const reload$ = useMemo( |
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.
This is a neat way to translate the fetch pipe into a lastReloadRequestTime
. If this ends up being a common pattern, we could make a helper for it - something like useFetch(api)
- which would return all of the fetch context as reactive vars.
|
||
let embeddingOrigin; | ||
if (apiHasExecutionContext(parentApi)) { | ||
embeddingOrigin = parentApi.executionContext.type; |
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.
I'm wondering why you're using the executionContext
type here instead of the parentApi.type
?
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.
good question, are there any differences/preferences for that?
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.
We don't have formal best practices around this, but I think the execution context should really only be used for things that are related to data. Like the inspector, telemetry etc. For any other reason - checking if something is rendered on Dashboard etc, the Embeddable parent type should be used.
tagging @nreese for some discussion here.
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.
agree. Use parentApi.type
if you need to identify the parent
|
||
export async function resolveEmbeddableChangePointUserInput( | ||
coreStart: CoreStart, | ||
pluginStart: AiopsPluginStartDeps, | ||
input?: EmbeddableChangePointChartInput | ||
): Promise<EmbeddableChangePointChartExplicitInput> { | ||
input?: ChangePointEmbeddableState |
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.
Would it be possible to rename this file? ExplicitInput
is a concept that is very much tied to the old system.
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.
renamed in 9323cbf
const { overlays } = coreStart; | ||
|
||
return new Promise(async (resolve, reject) => { | ||
try { | ||
const modalSession = overlays.openModal( | ||
const flyoutSession = overlays.openFlyout( |
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.
nit: If you're opening a flyout, you can let the Dashboard know. This allows the Dashboard to blur other panels, disable buttons on the top of the page, and close the flyout if the user navigates away.
You can do this with the following code:
if (apiHasParentApi(api) && tracksOverlays(api.parentApi)) {
api.parentApi.openOverlay(overlay, { focusedPanelId: api.uuid });
}
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.
Added in 585cfae
onRenderComplete?: () => void; | ||
}>; | ||
|
||
export interface ChangePointComponentApi { |
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.
Nit: every item you put in here is completely exposed to any other panel or action in the page's context. This isn't necessarily bad, but I'd recommend trying to avoid putting internal state management details on the embeddable's API if possible.
This can be accomplished by passing these things down as props, or by passing a separate stateManager
object. You can even pass these things to an editor etc internally without having them on the external API.
maxSeriesToPlot?: number; | ||
} | ||
|
||
export type ChangePointEmbeddableRuntimeState = ChangePointEmbeddableState & |
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.
Why are the time range and titles only part of the runtime state? Usually these would be part of the SerializedState
because custom panel time ranges and panel titles are saved into the Dashboard.
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.
updated in 9d47fe5
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.
LGTM
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.
Tested latest styling changes (resize of charts, focus for panel when being edited) and LGTM
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
Unknown metric groupsasync chunk count
ESLint disabled line counts
References to deprecated APIs
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @darnautov |
Summary
Closes #174963
Checklist