Skip to content
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

Filter Saved Search Based on AppName Supported by Language #7999

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ const getEmptyScreenProps = (
getFactory: embeddable.getEmbeddableFactory,
notifications,
overlays,
SavedObjectFinder: getSavedObjectFinder(savedObjects, uiSettings),
SavedObjectFinder: getSavedObjectFinder(
Copy link
Member

Choose a reason for hiding this comment

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

oh sorry about. not catching this earlier. im not sure if we want to update the interface like this as it might be a breaking change for any plugin using this.

i see the saved objects plugin gets started up with the services and with it is the data plugin. potentially the same with the services.application? that way we don't need to update the interface. since i can see it already touches a bunch of plugins within OSD. But no positive any plugins outside this repo (non-OpenSearch project and OpenSearch project)

https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/plugins/saved_objects/public/plugin.ts#L57

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kavilla I tried this approach, however I see the downstream applications are directly importing the component without using the pluginStart props. Hence I decided against it.

savedObjects,
uiSettings,
services.data,
services.application
),
});
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ export const getNavActions = (
getFactory: embeddable.getEmbeddableFactory,
notifications,
overlays,
SavedObjectFinder: getSavedObjectFinder(savedObjects, uiSettings),
SavedObjectFinder: getSavedObjectFinder(
savedObjects,
uiSettings,
services.data,
services.application
),
});
}
};
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,12 @@
embeddable,
} = plugins;

const SavedObjectFinder = getSavedObjectFinder(core.savedObjects, core.uiSettings);
const SavedObjectFinder = getSavedObjectFinder(

Check warning on line 570 in src/plugins/dashboard/public/plugin.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/plugin.tsx#L570

Added line #L570 was not covered by tests
core.savedObjects,
core.uiSettings,
plugins.data,
core.application
);

const changeViewAction = new ReplacePanelAction(
core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export const getDQLLanguageConfig = (
},
showDocLinks: true,
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer'],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export const getLuceneLanguageConfig = (
},
showDocLinks: true,
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer'],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ export interface LanguageConfig {
};
showDocLinks?: boolean;
editorSupportedAppNames?: string[];
supportedAppNames?: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function OpenSearchPanel({ onClose, makeUrl }: Props) {
services: {
core: { uiSettings, savedObjects, application },
addBasePath,
data,
},
} = useOpenSearchDashboards<DiscoverViewServices>();

Expand Down Expand Up @@ -87,6 +88,7 @@ export function OpenSearchPanel({ onClose, makeUrl }: Props) {
name: i18n.translate('discover.savedSearch.savedObjectName', {
defaultMessage: 'Saved search',
}),
includeFields: ['kibanaSavedObjectMeta'],
},
]}
onChoose={(id) => {
Expand All @@ -95,6 +97,8 @@ export function OpenSearchPanel({ onClose, makeUrl }: Props) {
}}
uiSettings={uiSettings}
savedObjects={savedObjects}
application={application}
data={data}
/>
</EuiFlyoutBody>
<EuiFlyoutFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class SearchEmbeddableFactory
}),
type: 'search',
getIconForSavedObject: () => 'search',
includeFields: ['kibanaSavedObjectMeta'],
};

constructor(private getStartServices: () => Promise<StartServices>) {}
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/embeddable/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl
notifications={core.notifications}
application={core.application}
inspector={inspector}
SavedObjectFinder={getSavedObjectFinder(core.savedObjects, core.uiSettings)}
SavedObjectFinder={getSavedObjectFinder(
core.savedObjects,
core.uiSettings,
data,
core.application
)}
/>
);

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/query_enhancements/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class QueryEnhancementsPlugin
showDocLinks: false,
editor: enhancedPPLQueryEditor,
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'data-explorer'],
};
queryString.getLanguageService().registerLanguage(pplLanguageConfig);

Expand All @@ -98,6 +99,7 @@ export class QueryEnhancementsPlugin
showDocLinks: false,
editor: enhancedSQLQueryEditor,
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'data-explorer'],
};
queryString.getLanguageService().registerLanguage(sqlLanguageConfig);

Expand Down
49 changes: 46 additions & 3 deletions src/plugins/saved_objects/public/finder/saved_object_finder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@
CoreStart,
IUiSettingsClient,
SavedObjectsStart,
ApplicationStart,
} from 'src/core/public';

import { DataSourceAttributes } from 'src/plugins/data_source/common/data_sources';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { first } from 'rxjs/operators';
import { getIndexPatternTitle } from '../../../data/common/index_patterns/utils';
import { LISTING_LIMIT_SETTING } from '../../common';

Expand All @@ -76,6 +79,7 @@
interface FinderAttributes {
title?: string;
type: string;
kibanaSavedObjectMeta?: string;
}

interface SavedObjectFinderState {
Expand Down Expand Up @@ -122,6 +126,8 @@
export type SavedObjectFinderUiProps = {
savedObjects: CoreStart['savedObjects'];
uiSettings: CoreStart['uiSettings'];
data: DataPublicPluginStart;
application: CoreStart['application'];
} & SavedObjectFinderProps;

class SavedObjectFinderUi extends React.Component<
Expand All @@ -137,10 +143,17 @@
showFilter: PropTypes.bool,
};

public async getCurrentAppId() {
const appId = await this.props.application.currentAppId$.pipe(first()).toPromise();
return appId;

Check warning on line 148 in src/plugins/saved_objects/public/finder/saved_object_finder.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects/public/finder/saved_object_finder.tsx#L147-L148

Added lines #L147 - L148 were not covered by tests
}

readonly languageService = this.props.data.query.queryString.getLanguageService();
private isComponentMounted: boolean = false;

private debouncedFetch = _.debounce(async (query: string) => {
const metaDataMap = this.getSavedObjectMetaDataMap();
const currentAppId = await this.getCurrentAppId();

Check warning on line 156 in src/plugins/saved_objects/public/finder/saved_object_finder.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects/public/finder/saved_object_finder.tsx#L156

Added line #L156 was not covered by tests

const fields = Object.values(metaDataMap)
.map((metaData) => metaData.includeFields || [])
Expand All @@ -162,7 +175,7 @@
return await client.get<DataSourceAttributes>('data-source', id);
};

const savedObjects = await Promise.all(
let savedObjects = await Promise.all(

Check warning on line 178 in src/plugins/saved_objects/public/finder/saved_object_finder.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects/public/finder/saved_object_finder.tsx#L178

Added line #L178 was not covered by tests
resp.savedObjects.map(async (obj) => {
if (obj.type === 'index-pattern') {
const result = { ...obj };
Expand All @@ -178,6 +191,25 @@
})
);

// Filter search objects whose language are not supported by the current Application
savedObjects = savedObjects.filter((obj) => {

Check warning on line 195 in src/plugins/saved_objects/public/finder/saved_object_finder.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects/public/finder/saved_object_finder.tsx#L195

Added line #L195 was not covered by tests
LDrago27 marked this conversation as resolved.
Show resolved Hide resolved
if (obj.type === 'search') {
if (obj.attributes?.kibanaSavedObjectMeta) {
const sourceObject = JSON.parse(obj.attributes?.kibanaSavedObjectMeta?.searchSourceJSON);
const languageId = sourceObject.query.language;

Check warning on line 199 in src/plugins/saved_objects/public/finder/saved_object_finder.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects/public/finder/saved_object_finder.tsx#L198-L199

Added lines #L198 - L199 were not covered by tests

const languageProperties = this.languageService.getLanguage(languageId);

Check warning on line 201 in src/plugins/saved_objects/public/finder/saved_object_finder.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects/public/finder/saved_object_finder.tsx#L201

Added line #L201 was not covered by tests

if (languageProperties?.supportedAppNames.includes(currentAppId)) {
LDrago27 marked this conversation as resolved.
Show resolved Hide resolved
return true;

Check warning on line 204 in src/plugins/saved_objects/public/finder/saved_object_finder.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects/public/finder/saved_object_finder.tsx#L204

Added line #L204 was not covered by tests
} else {
return false;

Check warning on line 206 in src/plugins/saved_objects/public/finder/saved_object_finder.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects/public/finder/saved_object_finder.tsx#L206

Added line #L206 was not covered by tests
}
}
}
return true;

Check warning on line 210 in src/plugins/saved_objects/public/finder/saved_object_finder.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects/public/finder/saved_object_finder.tsx#L210

Added line #L210 was not covered by tests
});

resp.savedObjects = savedObjects.filter((savedObject) => {
const metaData = metaDataMap[savedObject.type];
if (metaData.showSavedObject) {
Expand Down Expand Up @@ -571,9 +603,20 @@
}
}

const getSavedObjectFinder = (savedObject: SavedObjectsStart, uiSettings: IUiSettingsClient) => {
const getSavedObjectFinder = (
savedObject: SavedObjectsStart,
uiSettings: IUiSettingsClient,
data: DataPublicPluginStart,
application: ApplicationStart
) => {
return (props: SavedObjectFinderProps) => (
<SavedObjectFinderUi {...props} savedObjects={savedObject} uiSettings={uiSettings} />
<SavedObjectFinderUi

Check warning on line 613 in src/plugins/saved_objects/public/finder/saved_object_finder.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects/public/finder/saved_object_finder.tsx#L613

Added line #L613 was not covered by tests
{...props}
savedObjects={savedObject}
uiSettings={uiSettings}
data={data}
application={application}
/>
Copy link
Member

Choose a reason for hiding this comment

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

@kavilla If we want to do a quick fix for this breaking change, we could make the new parameters optional.

data?: DataPublicPluginStart,
application?: ApplicationStart

Copy link
Collaborator Author

@LDrago27 LDrago27 Sep 9, 2024

Choose a reason for hiding this comment

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

Thanks @sejli I have taken your idea and made the new parameters as optional. Therefore if you don't pass in these params they should work in a similar way as before.

To highlight the non breaking nature of changes I have reverted back the changes made to the test where we were using it without the new params to ensure it does n't break the functionality elsewhere.

);
};

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
setEmbeddable,
setNotifications,
setDocLinks,
setDataStart,
} from './services';
import {
VISUALIZE_EMBEDDABLE_TYPE,
Expand Down Expand Up @@ -192,6 +193,7 @@
chrome: core.chrome,
overlays: core.overlays,
});
setDataStart(data);

Check warning on line 196 in src/plugins/visualizations/public/plugin.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/visualizations/public/plugin.ts#L196

Added line #L196 was not covered by tests
setSavedAugmentVisLoader(savedAugmentVisLoader);
setI18n(core.i18n);
setTypes(types);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/visualizations/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ export const [getSavedAugmentVisLoader, setSavedAugmentVisLoader] = createGetter
>('savedAugmentVisLoader');

export const [getDocLinks, setDocLinks] = createGetterSetter<DocLinksStart>('docLinks');

export const [getDataStart, setDataStart] = createGetterSetter<DataPublicPluginStart>('DataStart');
4 changes: 4 additions & 0 deletions src/plugins/visualizations/public/wizard/new_vis_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { EuiModal } from '@elastic/eui';
import { i18n } from '@osd/i18n';

import { METRIC_TYPE, UiStatsMetricType } from '@osd/analytics';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { ApplicationStart, IUiSettingsClient, SavedObjectsStart } from '../../../../core/public';
import { SearchSelection } from './search_selection';
import { TypeSelection } from './type_selection';
Expand All @@ -55,6 +56,7 @@ interface TypeSelectionProps {
outsideVisualizeApp?: boolean;
stateTransfer?: EmbeddableStateTransfer;
originatingApp?: string;
data: DataPublicPluginStart;
}

interface TypeSelectionState {
Expand Down Expand Up @@ -112,6 +114,8 @@ class NewVisModal extends React.Component<TypeSelectionProps, TypeSelectionState
visType={this.state.visType}
uiSettings={this.props.uiSettings}
savedObjects={this.props.savedObjects}
application={this.props.application}
data={this.props.data}
/>
</EuiModal>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import { EuiModalBody, EuiModalHeader, EuiModalHeaderTitle } from '@elastic/eui'
import { i18n } from '@osd/i18n';
import { FormattedMessage } from '@osd/i18n/react';
import React from 'react';
import { IUiSettingsClient, SavedObjectsStart } from '../../../../../core/public';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { ApplicationStart, IUiSettingsClient, SavedObjectsStart } from '../../../../../core/public';

import { SavedObjectFinderUi } from '../../../../saved_objects/public';
import { VisType } from '../../vis_types';
Expand All @@ -42,6 +43,8 @@ interface SearchSelectionProps {
visType: VisType;
uiSettings: IUiSettingsClient;
savedObjects: SavedObjectsStart;
data: DataPublicPluginStart;
application: ApplicationStart;
}

export class SearchSelection extends React.Component<SearchSelectionProps> {
Expand Down Expand Up @@ -85,6 +88,7 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
defaultMessage: 'Saved search',
}
),
includeFields: ['kibanaSavedObjectMeta'],
},
{
type: 'index-pattern',
Expand All @@ -100,6 +104,8 @@ export class SearchSelection extends React.Component<SearchSelectionProps> {
fixedPageSize={this.fixedPageSize}
uiSettings={this.props.uiSettings}
savedObjects={this.props.savedObjects}
application={this.props.application}
data={this.props.data}
/>
</EuiModalBody>
</React.Fragment>
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/visualizations/public/wizard/show_new_vis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
getUsageCollector,
getApplication,
getEmbeddable,
getDataStart,
} from '../services';

export interface ShowNewVisModalParams {
Expand Down Expand Up @@ -90,6 +91,7 @@ export function showNewVisModal({
savedObjects={getSavedObjects()}
usageCollection={getUsageCollector()}
application={getApplication()}
data={getDataStart()}
/>
</I18nProvider>
);
Expand Down
Loading