Skip to content

Commit

Permalink
Use savedObjects client to fetch notebook visualizations
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <[email protected]>
  • Loading branch information
ps48 committed Nov 1, 2024
1 parent 39bb832 commit 614a4cb
Showing 1 changed file with 77 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@
*/

import {
EuiSmallButton,
EuiSmallButtonIcon,
EuiComboBoxOptionOption,
EuiCompressedFormRow,
EuiContextMenu,
EuiContextMenuPanelDescriptor,
EuiFlexGroup,
EuiFlexItem,
EuiCompressedFormRow,
EuiHorizontalRule,
EuiIcon,
EuiLink,
EuiPanel,
EuiPopover,
EuiSmallButton,
EuiSmallButtonIcon,
EuiSpacer,
EuiText,
htmlIdGenerator,
} from '@elastic/eui';
import filter from 'lodash/filter';
import moment from 'moment';
import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
import { CoreStart, MountPoint, SavedObjectsStart } from '../../../../../../../src/core/public';
import {
CoreStart,
MountPoint,
SavedObjectsFindOptions,
SavedObjectsStart,
} from '../../../../../../../src/core/public';
import {
DashboardContainerInput,
DashboardStart,
Expand All @@ -40,6 +45,7 @@ import {
import { ParaType } from '../../../../../common/types/notebooks';
import { uiSettingsService } from '../../../../../common/utils';
import { dataSourceFilterFn } from '../../../../../common/utils/shared';
import { coreRefs } from '../../../../framework/core_refs';
import PPLService from '../../../../services/requests/ppl';
import { SavedObjectsActions } from '../../../../services/saved_objects/saved_object_client/saved_objects_actions';
import { ObservabilitySavedVisualization } from '../../../../services/saved_objects/saved_object_client/types';
Expand Down Expand Up @@ -160,45 +166,78 @@ export const Paragraphs = forwardRef((props: ParagraphProps, ref) => {
}));

const fetchVisualizations = async () => {
let opt1: EuiComboBoxOptionOption[] = [];
let opt2: EuiComboBoxOptionOption[] = [];
await http
.get(`${NOTEBOOKS_API_PREFIX}/visualizations/${dataSourceMDSId ?? ''}`)
.then((res) => {
opt1 = res.savedVisualizations.map((vizObject) => ({
label: vizObject.label,
key: vizObject.key,
className: 'VISUALIZATION',
}));
})
.catch((err) => console.error('Fetching dashboard visualization issue', err.body.message));
if (dataSourceEnabled) {
let opts: EuiComboBoxOptionOption[] = [];
const vizOptions: SavedObjectsFindOptions = {
type: 'visualization',
...(coreRefs.application?.capabilities?.workspaces?.enabled
? { workspaces: coreRefs.workspaces?.currentWorkspace$.getValue()?.name }
: {}),
};
await coreRefs.savedObjectsClient
?.find(vizOptions)
.then((res) => {
opts = res.savedObjects.map((vizObject) => ({
label: vizObject.attributes.title,
key: vizObject.id,
className: 'VISUALIZATION',
}));
})
.catch((error) => {
console.error('Issue is fetching visualizations', error);
});

const allVisualizations = [{ label: 'Dashboards Visualizations', options: opts }];
setVisOptions(allVisualizations);

await SavedObjectsActions.getBulk<ObservabilitySavedVisualization>({
objectType: ['savedVisualization'],
})
.then((res) => {
opt2 = res.observabilityObjectList
.filter((visualization) => !visualization.savedVisualization.application_id)
.map((visualization) => ({
label: visualization.savedVisualization.name,
key: visualization.objectId,
className: 'OBSERVABILITY_VISUALIZATION',
const selectedObject = filter([...opts], {
key: para.visSavedObjId,
});
if (selectedObject.length > 0) {
setVisType(selectedObject.className);
setSelectedVisOption(selectedObject);
}
} else {
let opt1: EuiComboBoxOptionOption[] = [];
let opt2: EuiComboBoxOptionOption[] = [];
await http
.get(`${NOTEBOOKS_API_PREFIX}/visualizations/${dataSourceMDSId ?? ''}`)
.then((res) => {
opt1 = res.savedVisualizations.map((vizObject) => ({
label: vizObject.label,
key: vizObject.key,
className: 'VISUALIZATION',
}));
})
.catch((err) => console.error('Fetching dashboard visualization issue', err.body.message));

await SavedObjectsActions.getBulk<ObservabilitySavedVisualization>({
objectType: ['savedVisualization'],
})
.catch((err) => console.error('Fetching observability visualization issue', err));
.then((res) => {
opt2 = res.observabilityObjectList
.filter((visualization) => !visualization.savedVisualization.application_id)
.map((visualization) => ({
label: visualization.savedVisualization.name,
key: visualization.objectId,
className: 'OBSERVABILITY_VISUALIZATION',
}));
})
.catch((err) => console.error('Fetching observability visualization issue', err));

const allVisualizations = [
{ label: 'Dashboards Visualizations', options: opt1 },
{ label: 'Observability Visualizations', options: opt2 },
];
setVisOptions(allVisualizations);
const allVisualizations = [
{ label: 'Dashboards Visualizations', options: opt1 },
{ label: 'Observability Visualizations', options: opt2 },
];
setVisOptions(allVisualizations);

const selectedObject = filter([...opt1, ...opt2], {
key: para.visSavedObjId,
});
if (selectedObject.length > 0) {
setVisType(selectedObject.className);
setSelectedVisOption(selectedObject);
const selectedObject = filter([...opt1, ...opt2], {
key: para.visSavedObjId,
});
if (selectedObject.length > 0) {
setVisType(selectedObject.className);
setSelectedVisOption(selectedObject);
}
}
};

Expand Down

0 comments on commit 614a4cb

Please sign in to comment.