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

[8.16] [Discover] Support "Inspect" in saved search embeddables (#202947) #203090

Merged
merged 1 commit into from
Dec 5, 2024
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
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 @@ -186,6 +186,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 @@ -114,6 +114,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 @@ -132,6 +133,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 @@ -90,6 +92,7 @@ export type SearchEmbeddableApi = DefaultEmbeddableApi<
PublishesUnifiedSearch &
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 @@ -2863,7 +2863,6 @@
"discover.docViews.logsOverview.title": "Aperçu du log",
"discover.docViews.table.scoreSortWarningTooltip": "Filtrez sur _score pour pouvoir récupérer les valeurs correspondantes.",
"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 @@ -2861,7 +2861,6 @@
"discover.docViews.logsOverview.title": "ログ概要",
"discover.docViews.table.scoreSortWarningTooltip": "_scoreの値を取得するには、並べ替える必要があります。",
"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 @@ -2864,7 +2864,6 @@
"discover.docViews.logsOverview.title": "日志概览",
"discover.docViews.table.scoreSortWarningTooltip": "要检索 _score 的值,必须按其筛选。",
"discover.dropZoneTableLabel": "放置区域以将字段作为列添加到表中",
"discover.embeddable.inspectorRequestDataTitle": "数据",
"discover.embeddable.inspectorRequestDescription": "此请求将查询 Elasticsearch 以获取搜索的数据。",
"discover.embeddable.search.dataViewError": "缺少数据视图 {indexPatternId}",
"discover.embeddable.search.displayName": "搜索",
Expand Down
Loading