Skip to content

Commit

Permalink
[Discover] Support "Inspect" in saved search embeddables (elastic#202947
Browse files Browse the repository at this point in the history
)

- Closes elastic#202301

## Summary

This PR enables "Inspect" option for saved search Dashboard panels.

<img width="1619" alt="Screenshot 2024-12-04 at 16 02 33"
src="https://github.com/user-attachments/assets/a1eab597-4683-4069-b48f-b33b977db578">
<img width="1620" alt="Screenshot 2024-12-04 at 16 02 43"
src="https://github.com/user-attachments/assets/0dc734c3-f930-4397-9b68-69d959400924">
<img width="1618" alt="Screenshot 2024-12-04 at 16 03 03"
src="https://github.com/user-attachments/assets/460d8432-dc14-480e-b49d-81ab743815d2">



### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
jughosta authored Dec 5, 2024
1 parent 58f51fd commit 3f0008a
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { BehaviorSubject } from 'rxjs';

import type { Adapters } from '@kbn/inspector-plugin/common';
import { SearchSource } from '@kbn/data-plugin/common';
import type { DataView } from '@kbn/data-views-plugin/common';
import { DataTableRecord } from '@kbn/discover-utils';
Expand Down Expand Up @@ -58,6 +58,7 @@ export const getMockedSearchApi = ({
rows: new BehaviorSubject<DataTableRecord[]>([]),
totalHitCount: new BehaviorSubject<number | undefined>(0),
columnsMeta: new BehaviorSubject<Record<string, DatatableColumnMeta> | undefined>(undefined),
inspectorAdapters: new BehaviorSubject<Adapters>({}),
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export const getSearchEmbeddableFactory = ({
savedObjectId: savedObjectId$.getValue(),
discoverServices,
}),
getInspectorAdapters: () => searchEmbeddable.stateManager.inspectorAdapters.getValue(),
},
{
...titleComparators,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('initialize fetch', () => {
].map((hit) => buildDataTableRecord(hit, dataViewMock))
);
expect(stateManager.totalHitCount.getValue()).toEqual(2);
expect(stateManager.inspectorAdapters.getValue().requests).toBeDefined();
});

it('should catch and emit error', async () => {
Expand Down
16 changes: 9 additions & 7 deletions src/plugins/discover/public/embeddable/initialize_fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function initializeFetch({
stateManager: SearchEmbeddableStateManager;
discoverServices: DiscoverServices;
}) {
const requestAdapter = new RequestAdapter();
const inspectorAdapters = { requests: new RequestAdapter() };
let abortController: AbortController | undefined;

const fetchSubscription = combineLatest([fetch$(api), api.savedSearch$, api.dataViews])
Expand Down Expand Up @@ -127,7 +127,7 @@ export function initializeFetch({
const searchSourceQuery = savedSearch.searchSource.getField('query');

// Log request to inspector
requestAdapter.reset();
inspectorAdapters.requests.reset();

try {
api.dataLoading.next(true);
Expand Down Expand Up @@ -156,7 +156,7 @@ export function initializeFetch({
filters: fetchContext.filters,
dataView,
abortSignal: currentAbortController.signal,
inspectorAdapters: discoverServices.inspector,
inspectorAdapters,
data: discoverServices.data,
expressions: discoverServices.expressions,
profilesManager: discoverServices.profilesManager,
Expand All @@ -181,9 +181,9 @@ export function initializeFetch({
abortSignal: currentAbortController.signal,
sessionId: searchSessionId,
inspector: {
adapter: requestAdapter,
title: i18n.translate('discover.embeddable.inspectorRequestDataTitle', {
defaultMessage: 'Data',
adapter: inspectorAdapters.requests,
title: i18n.translate('discover.embeddable.inspectorTableRequestTitle', {
defaultMessage: 'Table',
}),
description: i18n.translate('discover.embeddable.inspectorRequestDescription', {
defaultMessage:
Expand All @@ -195,7 +195,7 @@ export function initializeFetch({
})
);
const interceptedWarnings: SearchResponseWarning[] = [];
discoverServices.data.search.showWarnings(requestAdapter, (warning) => {
discoverServices.data.search.showWarnings(inspectorAdapters.requests, (warning) => {
interceptedWarnings.push(warning);
return true; // suppress the default behaviour
});
Expand Down Expand Up @@ -225,6 +225,8 @@ export function initializeFetch({

stateManager.rows.next(next.rows ?? []);
stateManager.totalHitCount.next(next.hitCount);
stateManager.inspectorAdapters.next(inspectorAdapters);

api.fetchWarnings$.next(next.warnings ?? []);
api.fetchContext$.next(next.fetchContext);
if (Object.hasOwn(next, 'columnsMeta')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { pick } from 'lodash';
import deepEqual from 'react-fast-compare';
import { BehaviorSubject, combineLatest, map, Observable, skip } from 'rxjs';

import type { Adapters } from '@kbn/inspector-plugin/common';
import { ISearchSource, SerializedSearchSourceFields } from '@kbn/data-plugin/common';
import { DataView } from '@kbn/data-views-plugin/common';
import { DataTableRecord } from '@kbn/discover-utils/types';
Expand Down Expand Up @@ -116,6 +116,7 @@ export const initializeSearchEmbeddableApi = async (
const rows$ = new BehaviorSubject<DataTableRecord[]>([]);
const columnsMeta$ = new BehaviorSubject<DataTableColumnsMeta | undefined>(undefined);
const totalHitCount$ = new BehaviorSubject<number | undefined>(undefined);
const inspectorAdapters$ = new BehaviorSubject<Adapters>({});

/**
* The state manager is used to modify the state of the saved search - this should never be
Expand All @@ -134,6 +135,7 @@ export const initializeSearchEmbeddableApi = async (
totalHitCount: totalHitCount$,
viewMode: savedSearchViewMode$,
density: density$,
inspectorAdapters: inspectorAdapters$,
};

/** The saved search should be the source of truth for all state */
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/discover/public/embeddable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { DataTableRecord } from '@kbn/discover-utils/types';
import type { DefaultEmbeddableApi } from '@kbn/embeddable-plugin/public';
import { HasInspectorAdapters } from '@kbn/inspector-plugin/public';
import {
EmbeddableApiContext,
HasEditCapabilities,
Expand Down Expand Up @@ -47,6 +48,7 @@ export type SearchEmbeddableState = Pick<
rows: DataTableRecord[];
columnsMeta: DataTableColumnsMeta | undefined;
totalHitCount: number | undefined;
inspectorAdapters: Record<string, unknown>;
};

export type SearchEmbeddableStateManager = {
Expand All @@ -55,7 +57,7 @@ export type SearchEmbeddableStateManager = {

export type SearchEmbeddableSerializedAttributes = Omit<
SearchEmbeddableState,
'rows' | 'columnsMeta' | 'totalHitCount' | 'searchSource'
'rows' | 'columnsMeta' | 'totalHitCount' | 'searchSource' | 'inspectorAdapters'
> &
Pick<SerializableSavedSearch, 'serializedSearchSource'>;

Expand Down Expand Up @@ -98,6 +100,7 @@ export type SearchEmbeddableApi = DefaultEmbeddableApi<
PublishesWritableUnifiedSearch &
HasInPlaceLibraryTransforms &
HasTimeRange &
HasInspectorAdapters &
Partial<HasEditCapabilities & PublishesSavedObjectId>;

export interface PublishesSavedSearch {
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -2600,7 +2600,6 @@
"discover.documentsAriaLabel": "Documents",
"discover.docViews.logsOverview.title": "Aperçu du log",
"discover.dropZoneTableLabel": "Abandonner la zone pour ajouter un champ en tant que colonne dans la table",
"discover.embeddable.inspectorRequestDataTitle": "Données",
"discover.embeddable.inspectorRequestDescription": "Cette requête interroge Elasticsearch afin de récupérer les données pour la recherche.",
"discover.embeddable.search.dataViewError": "Vue de données {indexPatternId} manquante",
"discover.embeddable.search.displayName": "rechercher",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -2599,7 +2599,6 @@
"discover.documentsAriaLabel": "ドキュメント",
"discover.docViews.logsOverview.title": "ログ概要",
"discover.dropZoneTableLabel": "フィールドを列として表に追加するには、ゾーンをドロップします",
"discover.embeddable.inspectorRequestDataTitle": "データ",
"discover.embeddable.inspectorRequestDescription": "このリクエストはElasticsearchにクエリーをかけ、検索データを取得します。",
"discover.embeddable.search.dataViewError": "データビュー{indexPatternId}が見つかりません",
"discover.embeddable.search.displayName": "検索",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2590,7 +2590,6 @@
"discover.documentsAriaLabel": "文档",
"discover.docViews.logsOverview.title": "日志概览",
"discover.dropZoneTableLabel": "放置区域以将字段作为列添加到表中",
"discover.embeddable.inspectorRequestDataTitle": "数据",
"discover.embeddable.inspectorRequestDescription": "此请求将查询 Elasticsearch 以获取搜索的数据。",
"discover.embeddable.search.dataViewError": "缺少数据视图 {indexPatternId}",
"discover.embeddable.search.displayName": "搜索",
Expand Down

0 comments on commit 3f0008a

Please sign in to comment.