Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/plugins/vis_augmenter/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ export * from './saved_augment_vis';
export * from './test_constants';
export * from './triggers';
export * from './actions';
export { fetchVisEmbeddable } from './view_events_flyout';
export { setUISettings } from './services'; // Needed for plugin tests related to the CRUD saved object functions
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

export { ViewEventsFlyout } from './view_events_flyout';
export { EventVisEmbeddablesMap, EventVisEmbeddableItem } from './types';
export { fetchVisEmbeddable } from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,45 @@ function getValueAxisPositions(embeddable: VisualizeEmbeddable): { left: boolean
};
}

/**
* Fetching the base vis to show in the flyout, based on the saved object ID. Add constraints
* such that it is static and won't auto-refresh within the flyout.
* @param savedObjectId the saved object id of the base vis
*/
export async function fetchVisEmbeddable(savedObjectId: string): Promise<VisualizeEmbeddable> {
const embeddableVisFactory = getEmbeddable().getEmbeddableFactory('visualization');
const contextInput = {
filters: getQueryService().filterManager.getFilters(),
query: getQueryService().queryString.getQuery(),
timeRange: getQueryService().timefilter.timefilter.getTime(),
};

const embeddable = (await embeddableVisFactory?.createFromSavedObject(savedObjectId, {
...contextInput,
visAugmenterConfig: {
inFlyout: true,
flyoutContext: VisFlyoutContext.BASE_VIS,
},
} as VisualizeInput)) as VisualizeEmbeddable | ErrorEmbeddable;

if (embeddable instanceof ErrorEmbeddable) {
throw getErrorMessage(embeddable);
}

embeddable.updateInput({
// @ts-ignore
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - all @ts-ignore statements should have explanatory comments. I'm also curious why it's necessary here - is it because you're just passing a partial input?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was existing code moved here. The reason for the ignore here is that the embeddable is within a dashboard container that controls a refreshConfig field - this isn't included as part of the default embeddableInput that it resolves to, so IDEs complain about it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you either add that to a comment or open an issue?

refreshConfig: {
value: 0,
pause: true,
},
});

// By waiting for this to complete, embeddable.visLayers will be populated
await embeddable.populateVisLayers();

return embeddable;
}

/**
* Fetching the base vis to show in the flyout, based on the saved object ID. Add constraints
* such that it is static and won't auto-refresh within the flyout.
Expand All @@ -51,44 +90,15 @@ function getValueAxisPositions(embeddable: VisualizeEmbeddable): { left: boolean
* @param setVisEmbeddable custom hook used in base component
* @param setErrorMessage custom hook used in base component
*/
export async function fetchVisEmbeddable(
export async function fetchVisEmbeddableWithSetters(
savedObjectId: string,
setTimeRange: Function,
setVisEmbeddable: Function,
setErrorMessage: Function
): Promise<void> {
const embeddableVisFactory = getEmbeddable().getEmbeddableFactory('visualization');
try {
const contextInput = {
filters: getQueryService().filterManager.getFilters(),
query: getQueryService().queryString.getQuery(),
timeRange: getQueryService().timefilter.timefilter.getTime(),
};
setTimeRange(contextInput.timeRange);

const embeddable = (await embeddableVisFactory?.createFromSavedObject(savedObjectId, {
...contextInput,
visAugmenterConfig: {
inFlyout: true,
flyoutContext: VisFlyoutContext.BASE_VIS,
},
} as VisualizeInput)) as VisualizeEmbeddable | ErrorEmbeddable;

if (embeddable instanceof ErrorEmbeddable) {
throw getErrorMessage(embeddable);
}

embeddable.updateInput({
// @ts-ignore
refreshConfig: {
value: 0,
pause: true,
},
});

// By waiting for this to complete, embeddable.visLayers will be populated
await embeddable.populateVisLayers();

const embeddable = await fetchVisEmbeddable(savedObjectId);
setTimeRange(getQueryService().timefilter.timefilter.getTime());
setVisEmbeddable(embeddable);
} catch (err: any) {
setErrorMessage(String(err));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import { LoadingFlyoutBody } from './loading_flyout_body';
import { ErrorFlyoutBody } from './error_flyout_body';
import { EventsPanel } from './events_panel';
import { TimelinePanel } from './timeline_panel';
import { fetchVisEmbeddable, createEventEmbeddables, createTimelineEmbeddable } from './utils';
import {
fetchVisEmbeddableWithSetters,
createEventEmbeddables,
createTimelineEmbeddable,
} from './utils';
import { EventVisEmbeddablesMap } from './types';

interface Props {
Expand Down Expand Up @@ -56,7 +60,12 @@ export function ViewEventsFlyout(props: Props) {
}

useEffect(() => {
fetchVisEmbeddable(props.savedObjectId, setTimeRange, setVisEmbeddable, setErrorMessage);
fetchVisEmbeddableWithSetters(
props.savedObjectId,
setTimeRange,
setVisEmbeddable,
setErrorMessage
);
// adding all of the values to the deps array cause a circular re-render. we don't want
// to keep re-fetching the visEmbeddable after it is set.
/* eslint-disable react-hooks/exhaustive-deps */
Expand Down