-
Notifications
You must be signed in to change notification settings - Fork 919
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,9 +58,12 @@ | |
CoreStart, | ||
IUiSettingsClient, | ||
SavedObjectsStart, | ||
ApplicationStart, | ||
} from 'src/core/public'; | ||
|
||
import { DataSourceAttributes } from 'src/plugins/data_source/common/data_sources'; | ||
import { DataPublicPluginStart, LanguageServiceContract } from 'src/plugins/data/public'; | ||
import { first } from 'rxjs/operators'; | ||
import { getIndexPatternTitle } from '../../../data/common/index_patterns/utils'; | ||
import { LISTING_LIMIT_SETTING } from '../../common'; | ||
|
||
|
@@ -76,6 +79,7 @@ | |
interface FinderAttributes { | ||
title?: string; | ||
type: string; | ||
kibanaSavedObjectMeta?: string; | ||
} | ||
|
||
interface SavedObjectFinderState { | ||
|
@@ -122,6 +126,8 @@ | |
export type SavedObjectFinderUiProps = { | ||
savedObjects: CoreStart['savedObjects']; | ||
uiSettings: CoreStart['uiSettings']; | ||
data?: DataPublicPluginStart; | ||
application?: CoreStart['application']; | ||
} & SavedObjectFinderProps; | ||
|
||
class SavedObjectFinderUi extends React.Component< | ||
|
@@ -137,8 +143,29 @@ | |
showFilter: PropTypes.bool, | ||
}; | ||
|
||
public async getCurrentAppId() { | ||
return ( | ||
(await this.props?.application?.currentAppId$?.pipe(first()).toPromise()) ?? | ||
Promise.resolve(undefined) | ||
); | ||
} | ||
|
||
readonly languageService = this.props.data?.query?.queryString?.getLanguageService(); | ||
private isComponentMounted: boolean = false; | ||
|
||
private isSavedSearchLanguageSupported( | ||
languageId?: string, | ||
currentAppId?: string, | ||
languageService?: LanguageServiceContract | ||
) { | ||
if (!languageId || !currentAppId || !languageService) { | ||
return true; | ||
} | ||
return ( | ||
languageService?.getLanguage(languageId)?.supportedAppNames?.includes(currentAppId) ?? true | ||
); | ||
} | ||
|
||
private debouncedFetch = _.debounce(async (query: string) => { | ||
const metaDataMap = this.getSavedObjectMetaDataMap(); | ||
|
||
|
@@ -162,6 +189,8 @@ | |
return await client.get<DataSourceAttributes>('data-source', id); | ||
}; | ||
|
||
const currentAppId = await this.getCurrentAppId(); | ||
|
||
const savedObjects = await Promise.all( | ||
resp.savedObjects.map(async (obj) => { | ||
if (obj.type === 'index-pattern') { | ||
|
@@ -172,13 +201,24 @@ | |
getDataSource | ||
); | ||
return result; | ||
} else if (obj.type === 'search') { | ||
const sourceObject = JSON.parse( | ||
obj.attributes?.kibanaSavedObjectMeta?.searchSourceJSON ?? null | ||
); | ||
const languageId = sourceObject?.query?.language; | ||
if (this.isSavedSearchLanguageSupported(languageId, currentAppId, this.languageService)) { | ||
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. i wonder if it makes it a little bit more scalable/safer to just have this as a pass a function like from the dashboards it could be SavedObjectFinder: getSavedObjectFinder(
savedObjects,
uiSettings,
searchFilterFn: (obj) => {
const sourceObject = JSON.parse(
obj.attributes?.kibanaSavedObjectMeta?.searchSourceJSON ?? null);
const languageId = sourceObject?.query?.language;
services.data.languageService?.getLanguage(languageId)?.supportedAppNames?.includes(currentAppId) ?? true;
}
) 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. i think i only worry ensuring we dont end up adding more required plugins since i know a good amount of community members hit the APIs directly and even though this is the public side the saved objects plugin has been historically didn't need to care about the application which made it reliably abstracted and enforced a pattern for developers. do we forsee in issues with introducing these concepts of language service to the saved object finder? 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 overall change seems safe and the default behavior without the additional parameters remains unchanged for SavedObjectFinder. The saved_object_finder.test.tsx tests all use the default version of SavedObjectFinder without the optional parameters and the behavior remains unchanged. In the meanwhile I have created the issue #8122 , which we can use to create a more scalable version of the above when required. |
||
return obj; | ||
} | ||
} else { | ||
return obj; | ||
} | ||
}) | ||
); | ||
|
||
resp.savedObjects = savedObjects.filter((savedObject) => { | ||
if (!savedObject) { | ||
return false; | ||
} | ||
const metaData = metaDataMap[savedObject.type]; | ||
if (metaData.showSavedObject) { | ||
return metaData.showSavedObject(savedObject); | ||
|
@@ -571,9 +611,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 | ||
{...props} | ||
savedObjects={savedObject} | ||
uiSettings={uiSettings} | ||
data={data} | ||
application={application} | ||
/> | ||
); | ||
}; | ||
|
||
|
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.
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
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.
@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.