Skip to content

Commit

Permalink
read filters, query, and timeRange from parentApi
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Jan 31, 2024
1 parent 2649807 commit c1761b6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ const mockDataPoints = [
];

const mockEmbeddableApi = {
localFilters: new BehaviorSubject([]),
localQuery: new BehaviorSubject({ query: 'test', language: 'kuery' }),
localTimeRange: new BehaviorSubject({ from: 'now-15m', to: 'now' }),
parentApi: {
localFilters: new BehaviorSubject([]),
localQuery: new BehaviorSubject({ query: 'test', language: 'kuery' }),
localTimeRange: new BehaviorSubject({ from: 'now-15m', to: 'now' }),
}
};

const mockNavigateToUrl = jest.fn(() => Promise.resolve());
Expand Down Expand Up @@ -289,20 +291,22 @@ describe('UrlDrilldown', () => {
{ id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' },
{ id: 'yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy' },
]),
localFilters: new BehaviorSubject([
{
meta: {
alias: 'asdf',
disabled: false,
negate: false,
parentApi: {
localFilters: new BehaviorSubject([
{
meta: {
alias: 'asdf',
disabled: false,
negate: false,
},
},
},
]),
localQuery: new BehaviorSubject({
language: 'C++',
query: 'std::cout << 123;',
}),
localTimeRange: new BehaviorSubject({ from: 'FROM', to: 'TO' }),
]),
localQuery: new BehaviorSubject({
language: 'C++',
query: 'std::cout << 123;',
}),
localTimeRange: new BehaviorSubject({ from: 'FROM', to: 'TO' }),
},
panelTitle: new BehaviorSubject('The Title'),
savedObjectId: new BehaviorSubject('SAVED_OBJECT_ID'),
uuid: 'the-id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ describe('getContextScopeValues()', () => {

test('returns values when provided', () => {
const embeddableApi = {
localFilters: new BehaviorSubject([
{
meta: {
alias: 'asdf',
disabled: false,
negate: false,
parentApi: {
localFilters: new BehaviorSubject([
{
meta: {
alias: 'asdf',
disabled: false,
negate: false,
},
},
},
]),
localQuery: new BehaviorSubject({
language: 'C++',
query: 'std::cout << 123;',
}),
localTimeRange: new BehaviorSubject({ from: 'FROM', to: 'TO' }),
]),
localQuery: new BehaviorSubject({
language: 'C++',
query: 'std::cout << 123;',
}),
localTimeRange: new BehaviorSubject({ from: 'FROM', to: 'TO' }),
},
panelTitle: new BehaviorSubject('title1'),
savedObjectId: new BehaviorSubject('1234'),
uuid: 'test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getFlattenedObject } from '@kbn/std';
import type { Filter, AggregateQuery, Query, TimeRange } from '@kbn/es-query';
import type {
EmbeddableApiContext,
HasParentApi,
HasUniqueId,
PublishesPanelTitle,
PublishesSavedObjectId,
Expand Down Expand Up @@ -67,7 +68,8 @@ export const getContextScopeValues = (context: Partial<EmbeddableApiContext>): C
PublishesPanelTitle &
PublishesSavedObjectId &
PublishesLocalUnifiedSearch &
PublishesDataViews
PublishesDataViews &
HasParentApi
>;
const dataViewIds = api.dataViews?.value
? (api.dataViews?.value.map((dataView) => dataView.id).filter(Boolean) as string[])
Expand All @@ -78,9 +80,9 @@ export const getContextScopeValues = (context: Partial<EmbeddableApiContext>): C
id: api.uuid,
title: api.panelTitle?.value ?? api.defaultPanelTitle?.value,
savedObjectId: api.savedObjectId?.value,
query: api.localQuery?.value,
timeRange: api.localTimeRange?.value,
filters: api.localFilters?.value,
query: api.parentApi?.localQuery?.value,
timeRange: api.localTimeRange?.value ?? api.parentApi?.localTimeRange?.value,
filters: api.parentApi?.localFilters?.value,
indexPatternIds: dataViewIds.length > 1 ? dataViewIds : undefined,
indexPatternId: dataViewIds.length === 1 ? dataViewIds[0] : undefined,
}),
Expand Down

0 comments on commit c1761b6

Please sign in to comment.