Skip to content
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 @@ -9,7 +9,7 @@

import React, { useCallback, useMemo, useState } from 'react';
import type { DataTableRecord } from '@kbn/discover-utils/types';
import { AggregateQuery, Query } from '@kbn/es-query';
import type { AggregateQuery, Query, Filter } from '@kbn/es-query';
import type { SearchResponseWarning } from '@kbn/search-response-warnings';
import { MAX_DOC_FIELDS_DISPLAYED, SHOW_MULTIFIELDS } from '@kbn/discover-utils';
import {
Expand All @@ -30,7 +30,8 @@ import { useProfileAccessor } from '../../context_awareness';
interface DiscoverGridEmbeddableProps extends Omit<UnifiedDataTableProps, 'sampleSizeState'> {
sampleSizeState: number; // a required prop
totalHitCount?: number;
query?: AggregateQuery | Query;
query: AggregateQuery | Query | undefined;
filters: Filter[] | undefined;
interceptedWarnings?: SearchResponseWarning[];
onAddColumn: (column: string) => void;
onRemoveColumn: (column: string) => void;
Expand Down Expand Up @@ -65,6 +66,7 @@ export function DiscoverGridEmbeddable(props: DiscoverGridEmbeddableProps) {
onClose={() => setExpandedDoc(undefined)}
setExpandedDoc={setExpandedDoc}
query={props.query}
filters={props.filters}
/>
),
[
Expand All @@ -73,6 +75,7 @@ export function DiscoverGridEmbeddable(props: DiscoverGridEmbeddableProps) {
props.onFilter,
props.onRemoveColumn,
props.query,
props.filters,
props.savedSearchId,
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
SORT_DEFAULT_ORDER_SETTING,
isLegacyTableEnabled,
} from '@kbn/discover-utils';
import { Filter } from '@kbn/es-query';
import {
FetchContext,
useBatchedOptionalPublishingSubjects,
Expand All @@ -27,7 +26,6 @@ import { SortOrder } from '@kbn/saved-search-plugin/public';
import { SearchResponseIncompleteWarning } from '@kbn/search-response-warnings/src/types';
import { DataGridDensity, DataLoadingState, useColumns } from '@kbn/unified-data-table';
import { DocViewFilterFn } from '@kbn/unified-doc-viewer/types';

import { DiscoverGridSettings } from '@kbn/saved-search-plugin/common';
import useObservable from 'react-use/lib/useObservable';
import { DiscoverDocTableEmbeddable } from '../../components/doc_table/create_doc_table_embeddable';
Expand Down Expand Up @@ -69,8 +67,8 @@ export function SearchEmbeddableGridComponent({
savedSearch,
savedSearchId,
interceptedWarnings,
query,
filters,
apiQuery,
apiFilters,
fetchContext,
rows,
totalHitCount,
Expand All @@ -90,6 +88,12 @@ export function SearchEmbeddableGridComponent({
stateManager.grid
);

// `api.query$` and `api.filters$` are the initial values from the saved search SO (as of now)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If api.query$ and api.filters$ already contain the saved search values, why are we switching to searchSource below?

Copy link
Copy Markdown
Contributor Author

@jughosta jughosta Oct 23, 2024

Choose a reason for hiding this comment

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

It seemed less verbose to me. Okay, I am going to keep the variables but reassign them to api values 4615e64

// `fetchContext.query` and `fetchContext.filters` are Dashboard's query and filters

const savedSearchQuery = apiQuery;
const savedSearchFilters = apiFilters;

const [panelTitle, panelDescription, savedSearchTitle, savedSearchDescription] =
useBatchedOptionalPublishingSubjects(
api.panelTitle,
Expand Down Expand Up @@ -137,7 +141,10 @@ export function SearchEmbeddableGridComponent({
settings: grid,
});

const dataSource = useMemo(() => createDataSource({ dataView, query }), [dataView, query]);
const dataSource = useMemo(
() => createDataSource({ dataView, query: savedSearchQuery }),
[dataView, savedSearchQuery]
);
const timeRange = useMemo(
() => (fetchContext ? getTimeRangeFromFetchContext(fetchContext) : undefined),
[fetchContext]
Expand All @@ -146,8 +153,8 @@ export function SearchEmbeddableGridComponent({
const cellActionsMetadata = useAdditionalCellActions({
dataSource,
dataView,
query,
filters,
query: savedSearchQuery,
filters: savedSearchFilters,
Comment on lines +156 to +157
Copy link
Copy Markdown
Contributor Author

@jughosta jughosta Oct 22, 2024

Choose a reason for hiding this comment

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

I think I kept this as it was before. We might want to consider including the current Dashboard filters for cell actions too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah it's hard to say which behaviour is best for this. It's something worth discussing at least.

timeRange,
});

Expand Down Expand Up @@ -229,7 +236,7 @@ export function SearchEmbeddableGridComponent({
<DiscoverDocTableEmbeddableMemoized
{...sharedProps}
{...onStateEditedProps}
filters={savedSearch.searchSource.getField('filter') as Filter[]}
filters={savedSearchFilters}
isEsqlMode={isEsql}
isLoading={Boolean(loading)}
sharedItemTitle={panelTitle || savedSearchTitle}
Expand Down Expand Up @@ -258,7 +265,8 @@ export function SearchEmbeddableGridComponent({
isPlainRecord={isEsql}
loadingState={Boolean(loading) ? DataLoadingState.loading : DataLoadingState.loaded}
maxAllowedSampleSize={getMaxAllowedSampleSize(discoverServices.uiSettings)}
query={savedSearch.searchSource.getField('query')}
query={savedSearchQuery}
filters={savedSearchFilters}
savedSearchId={savedSearchId}
searchTitle={panelTitle || savedSearchTitle}
services={discoverServices}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

it('navigates to context view from embeddable', async () => {
await common.navigateToApp('discover');
await header.waitUntilLoadingHasFinished();
await filterBar.addFilter({ field: 'extension.raw', operation: 'is', value: 'jpg' });
await header.waitUntilLoadingHasFinished();
await discover.saveSearch('my search');
await header.waitUntilLoadingHasFinished();

Expand Down Expand Up @@ -134,6 +137,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
log.debug('document table length', nrOfDocs);
return nrOfDocs === 6;
});
await filterBar.hasFilter('extension.raw', 'jpg', false);
});
});
}