Skip to content

Commit

Permalink
add dollar sign suffix to unified search publishing subject names
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Mar 14, 2024
1 parent 87ced12 commit 13857fe
Show file tree
Hide file tree
Showing 28 changed files with 111 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { PublishingSubject } from '../publishing_subject';

export interface PublishesUnifiedSearch {
isCompatibleWithUnifiedSearch?: () => boolean;
timeRange: PublishingSubject<TimeRange | undefined>;
filters: PublishingSubject<Filter[] | undefined>;
query: PublishingSubject<Query | AggregateQuery | undefined>;
timeRange$: PublishingSubject<TimeRange | undefined>;
filters$: PublishingSubject<Filter[] | undefined>;
query$: PublishingSubject<Query | AggregateQuery | undefined>;
}

export type PublishesWritableUnifiedSearch = PublishesUnifiedSearch & {
Expand All @@ -27,19 +27,19 @@ export const apiPublishesUnifiedSearch = (
): unknownApi is PublishesUnifiedSearch => {
return Boolean(
unknownApi &&
(unknownApi as PublishesUnifiedSearch)?.timeRange !== undefined &&
(unknownApi as PublishesUnifiedSearch)?.filters !== undefined &&
(unknownApi as PublishesUnifiedSearch)?.query !== undefined
(unknownApi as PublishesUnifiedSearch)?.timeRange$ !== undefined &&
(unknownApi as PublishesUnifiedSearch)?.filters$ !== undefined &&
(unknownApi as PublishesUnifiedSearch)?.query$ !== undefined
);
};

export const apiPublishesPartialUnifiedSearch = (
unknownApi: null | unknown
): unknownApi is Partial<PublishesUnifiedSearch> => {
return Boolean(
(unknownApi && (unknownApi as PublishesUnifiedSearch)?.timeRange !== undefined) ||
(unknownApi as PublishesUnifiedSearch)?.filters !== undefined ||
(unknownApi as PublishesUnifiedSearch)?.query !== undefined
(unknownApi && (unknownApi as PublishesUnifiedSearch)?.timeRange$ !== undefined) ||
(unknownApi as PublishesUnifiedSearch)?.filters$ !== undefined ||
(unknownApi as PublishesUnifiedSearch)?.query$ !== undefined
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ describe('filters notification action', () => {
getAllDataViews: jest.fn(),
getDashboardPanelFromId: jest.fn(),
},
filters: filtersSubject,
query: querySubject,
filters$: filtersSubject,
query$: querySubject,
},
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const isApiCompatible = (api: unknown | null): api is FiltersNotificationActionA

const compatibilityCheck = (api: EmbeddableApiContext['embeddable']) => {
if (!isApiCompatible(api) || getInheritedViewMode(api) !== 'edit') return false;
const query = api.query?.value;
const query = api.query$?.value;
return (
(api.filters?.value ?? []).length > 0 ||
(api.filters$?.value ?? []).length > 0 ||
(isOfQueryType(query) && query.query !== '') ||
isOfAggregateQueryType(query)
);
Expand Down Expand Up @@ -102,7 +102,7 @@ export class FiltersNotificationAction implements Action<EmbeddableApiContext> {
) {
if (!isApiCompatible(embeddable)) return;
return merge(
...[embeddable.query, embeddable.filters, getViewModeSubject(embeddable)].filter((value) =>
...[embeddable.query$, embeddable.filters$, getViewModeSubject(embeddable)].filter((value) =>
Boolean(value)
)
).subscribe(() => onChange(compatibilityCheck(embeddable), this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ describe('filters notification popover', () => {
getAllDataViews: jest.fn(),
getDashboardPanelFromId: jest.fn(),
},
filters: filtersSubject,
query: querySubject,
filters$: filtersSubject,
query$: querySubject,
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export function FiltersNotificationPopover({ api }: { api: FiltersNotificationAc

const editPanelAction = getEditPanelAction();

const filters = useMemo(() => api.filters?.value, [api]);
const filters = useMemo(() => api.filters$?.value, [api]);
const displayName = dashboardFilterNotificationActionStrings.getDisplayName();

const { queryString, queryLanguage } = useMemo(() => {
const query = api.query?.value;
const query = api.query$?.value;
if (!query) return {};
if (isOfQueryType(query)) {
if (typeof query.query === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ export const getDashboardLocatorParamsFromEmbeddable = (
): Partial<DashboardLocatorParams> => {
const params: DashboardLocatorParams = {};

const query = api.parentApi?.query?.value;
const query = api.parentApi?.query$?.value;
if (query && options.useCurrentFilters) {
params.query = query as Query;
}

// if useCurrentDashboardDataRange is enabled, then preserve current time range
// if undefined is passed, then destination dashboard will figure out time range itself
// for brush event this time range would be overwritten
const timeRange = api.timeRange?.value ?? api.parentApi?.timeRange?.value;
const timeRange = api.timeRange$?.value ?? api.parentApi?.timeRange$?.value;
if (timeRange && options.useCurrentDateRange) {
params.timeRange = timeRange;
}

// if useCurrentDashboardFilters enabled, then preserve all the filters (pinned, unpinned, and from controls)
// otherwise preserve only pinned
const filters = api.parentApi?.filters?.value ?? [];
const filters = api.parentApi?.filters$?.value ?? [];
params.filters = options.useCurrentFilters ? filters : filters?.filter((f) => isFilterPinned(f));

return params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export const initializeDashboard = async ({
}

const filters = new BehaviorSubject<Filter[] | undefined>(getCombinedFilters());
dashboardContainer.filters = filters;
dashboardContainer.filters$ = filters;

const inputFilters$ = dashboardContainer.getInput$().pipe(
startWith(dashboardContainer.getInput()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,29 +178,29 @@ export const legacyEmbeddableToApi = (
* to tell when given a legacy embeddable what it's input could contain. All existing actions treat these as optional
* so if the Embeddable is incapable of publishing unified search state (i.e. markdown) then it will just be ignored.
*/
const timeRange = inputKeyToSubject<TimeRange | undefined>('timeRange', true);
const timeRange$ = inputKeyToSubject<TimeRange | undefined>('timeRange', true);
const setTimeRange = (nextTimeRange?: TimeRange) =>
embeddable.updateInput({ timeRange: nextTimeRange });

const filters: BehaviorSubject<Filter[] | undefined> = new BehaviorSubject<Filter[] | undefined>(
const filters$: BehaviorSubject<Filter[] | undefined> = new BehaviorSubject<Filter[] | undefined>(
undefined
);
const query: BehaviorSubject<Query | AggregateQuery | undefined> = new BehaviorSubject<
const query$: BehaviorSubject<Query | AggregateQuery | undefined> = new BehaviorSubject<
Query | AggregateQuery | undefined
>(undefined);
// if this embeddable is a legacy filterable embeddable, publish changes to those filters to the panelFilters subject.
if (isFilterableEmbeddable(embeddable)) {
embeddable.untilInitializationFinished().then(() => {
filters.next(embeddable.getFilters());
query.next(embeddable.getQuery());
filters$.next(embeddable.getFilters());
query$.next(embeddable.getQuery());

subscriptions.add(
embeddable.getInput$().subscribe(() => {
if (!compareFilters(embeddable.filters.getValue() ?? [], embeddable.getFilters())) {
filters.next(embeddable.getFilters());
if (!compareFilters(embeddable.filters$.getValue() ?? [], embeddable.getFilters())) {
filters$.next(embeddable.getFilters());
}
if (!deepEqual(embeddable.query.getValue() ?? [], embeddable.getQuery())) {
query.next(embeddable.getQuery());
if (!deepEqual(embeddable.query$.getValue() ?? [], embeddable.getQuery())) {
query$.next(embeddable.getQuery());
}
})
);
Expand Down Expand Up @@ -238,10 +238,10 @@ export const legacyEmbeddableToApi = (
isEditingEnabled,
getTypeDisplayName,

timeRange,
timeRange$,
setTimeRange,
filters,
query,
filters$,
query$,
isCompatibleWithUnifiedSearch,

dataViews,
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/embeddable/public/lib/embeddables/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ export abstract class Embeddable<
dataViews: this.dataViews,
parentApi: this.parentApi,
panelTitle: this.panelTitle,
query: this.query,
query$: this.query$,
dataLoading: this.dataLoading,
filters: this.filters,
filters$: this.filters$,
blockingError: this.blockingError,
onPhaseChange: this.onPhaseChange,
setPanelTitle: this.setPanelTitle,
linkToLibrary: this.linkToLibrary,
hidePanelTitle: this.hidePanelTitle,
timeRange: this.timeRange,
timeRange$: this.timeRange$,
isEditingEnabled: this.isEditingEnabled,
panelDescription: this.panelDescription,
canLinkToLibrary: this.canLinkToLibrary,
Expand Down Expand Up @@ -163,15 +163,15 @@ export abstract class Embeddable<
public viewMode: LegacyEmbeddableAPI['viewMode'];
public parentApi: LegacyEmbeddableAPI['parentApi'];
public dataViews: LegacyEmbeddableAPI['dataViews'];
public query: LegacyEmbeddableAPI['query'];
public query$: LegacyEmbeddableAPI['query$'];
public panelTitle: LegacyEmbeddableAPI['panelTitle'];
public dataLoading: LegacyEmbeddableAPI['dataLoading'];
public filters: LegacyEmbeddableAPI['filters'];
public filters$: LegacyEmbeddableAPI['filters$'];
public onPhaseChange: LegacyEmbeddableAPI['onPhaseChange'];
public linkToLibrary: LegacyEmbeddableAPI['linkToLibrary'];
public blockingError: LegacyEmbeddableAPI['blockingError'];
public setPanelTitle: LegacyEmbeddableAPI['setPanelTitle'];
public timeRange: LegacyEmbeddableAPI['timeRange'];
public timeRange$: LegacyEmbeddableAPI['timeRange$'];
public hidePanelTitle: LegacyEmbeddableAPI['hidePanelTitle'];
public isEditingEnabled: LegacyEmbeddableAPI['isEditingEnabled'];
public canLinkToLibrary: LegacyEmbeddableAPI['canLinkToLibrary'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type FilterableEmbeddableInput = EmbeddableInput & {

export type EmbeddableHasTimeRange = Pick<
PublishesWritableUnifiedSearch,
'timeRange' | 'setTimeRange' | 'isCompatibleWithUnifiedSearch'
'timeRange$' | 'setTimeRange' | 'isCompatibleWithUnifiedSearch'
>;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe('custom time range badge action', () => {
action = new CustomTimeRangeBadge();
context = {
embeddable: {
timeRange: timeRangeSubject,
filters: new BehaviorSubject<Filter[] | undefined>(undefined),
query: new BehaviorSubject<Query | AggregateQuery | undefined>(undefined),
timeRange$: timeRangeSubject,
filters$: new BehaviorSubject<Filter[] | undefined>(undefined),
query$: new BehaviorSubject<Query | AggregateQuery | undefined>(undefined),
},
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class CustomTimeRangeBadge

public getDisplayName({ embeddable }: EmbeddableApiContext) {
if (!apiPublishesUnifiedSearch(embeddable)) throw new IncompatibleActionError();
const timeRange = embeddable.timeRange.value;
const timeRange = embeddable.timeRange$.value;
if (!timeRange) return '';
return renderToString(
<PrettyDuration
Expand All @@ -51,7 +51,7 @@ export class CustomTimeRangeBadge
onChange: (isCompatible: boolean, action: CustomTimeRangeBadge) => void
) {
if (!apiPublishesUnifiedSearch(embeddable)) return;
return embeddable.timeRange.subscribe((timeRange) => {
return embeddable.timeRange$.subscribe((timeRange) => {
onChange(Boolean(timeRange), this);
});
}
Expand All @@ -66,7 +66,7 @@ export class CustomTimeRangeBadge

public async isCompatible({ embeddable }: EmbeddableApiContext) {
if (apiPublishesUnifiedSearch(embeddable)) {
const timeRange = embeddable.timeRange.value;
const timeRange = embeddable.timeRange$.value;
return Boolean(timeRange);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ describe('Customize panel action', () => {

it('is compatible in view mode when API exposes writable unified search', async () => {
(context.embeddable as PublishesViewMode).viewMode = new BehaviorSubject<ViewMode>('view');
context.embeddable.timeRange = new BehaviorSubject<TimeRange | undefined>({
context.embeddable.timeRange$ = new BehaviorSubject<TimeRange | undefined>({
from: 'now-15m',
to: 'now',
});
context.embeddable.filters = new BehaviorSubject<Filter[] | undefined>([]);
context.embeddable.query = new BehaviorSubject<Query | AggregateQuery | undefined>(undefined);
context.embeddable.filters$ = new BehaviorSubject<Filter[] | undefined>([]);
context.embeddable.query$ = new BehaviorSubject<Query | AggregateQuery | undefined>(undefined);
expect(await action.isCompatible(context)).toBe(true);
});

Expand All @@ -61,7 +61,7 @@ describe('Customize panel action', () => {
it('opens overlay on parent if parent is an overlay tracker', async () => {
context.embeddable.parentApi = {
openOverlay: jest.fn(),
timeRange: undefined,
timeRange$: undefined,
clearOverlays: jest.fn(),
};
await action.execute(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ describe('customize panel editor', () => {

describe('local time range', () => {
it('renders local time picker if API supports it', async () => {
api.timeRange = new BehaviorSubject<TimeRange | undefined>({
api.timeRange$ = new BehaviorSubject<TimeRange | undefined>({
from: '',
to: '',
});
api.filters = new BehaviorSubject<Filter[] | undefined>([]);
api.query = new BehaviorSubject<Query | AggregateQuery | undefined>(undefined);
api.filters$ = new BehaviorSubject<Filter[] | undefined>([]);
api.query$ = new BehaviorSubject<Query | AggregateQuery | undefined>(undefined);
renderPanelEditor();

const customTimeRangeComponent = await screen.findByTestId(
Expand Down Expand Up @@ -194,25 +194,25 @@ describe('customize panel editor', () => {
});

test('renders local filters, if provided', async () => {
api.timeRange = new BehaviorSubject<TimeRange | undefined>(undefined);
api.filters = new BehaviorSubject<Filter[] | undefined>([
api.timeRange$ = new BehaviorSubject<TimeRange | undefined>(undefined);
api.filters$ = new BehaviorSubject<Filter[] | undefined>([
{
meta: {},
query: {},
$state: {},
},
] as Filter[]);
api.query = new BehaviorSubject<Query | AggregateQuery | undefined>(undefined);
api.query$ = new BehaviorSubject<Query | AggregateQuery | undefined>(undefined);

renderPanelEditor();
const customPanelQuery = await screen.findByTestId('panelCustomFiltersRow');
expect(customPanelQuery).toBeInTheDocument();
});

test('renders a local query, if provided', async () => {
api.timeRange = new BehaviorSubject<TimeRange | undefined>(undefined);
api.filters = new BehaviorSubject<Filter[] | undefined>([]);
api.query = new BehaviorSubject<Query | AggregateQuery | undefined>({
api.timeRange$ = new BehaviorSubject<TimeRange | undefined>(undefined);
api.filters$ = new BehaviorSubject<Filter[] | undefined>([]);
api.query$ = new BehaviorSubject<Query | AggregateQuery | undefined>({
query: 'field : value',
language: 'kql',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export function FiltersDetails({ editMode, api }: FiltersDetailsProps) {
const [queryLanguage, setQueryLanguage] = useState<'sql' | 'esql' | undefined>();
const dataViews = api.dataViews?.value ?? [];

const filters = useMemo(() => api.filters?.value ?? [], [api]);
const filters = useMemo(() => api.filters$?.value ?? [], [api]);

const [incompatibleQueryLanguage, setIncompatibleQueryLanguage] = useState(false);
const showEditButton = hasEditCapabilities(api) && editMode && !incompatibleQueryLanguage;

useMount(() => {
const localQuery = api.query?.value;
const localQuery = api.query$?.value;
if (localQuery) {
if (isOfQueryType(localQuery)) {
if (typeof localQuery.query === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class EditInLensAction implements Action<EmbeddableApiContext> {
const searchFilters = parentSearchSource?.getField('filter') ?? visFilters;
const searchQuery = parentSearchSource?.getField('query') ?? visQuery;
const title = vis.title || embeddable.panelTitle?.getValue();
const panelTimeRange = embeddable.timeRange?.getValue();
const panelTimeRange = embeddable.timeRange$?.getValue();
const updatedWithMeta = {
...navigateToLensConfig,
title,
Expand Down
Loading

0 comments on commit 13857fe

Please sign in to comment.