Skip to content

Commit

Permalink
fix jobIds input
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Mar 21, 2024
1 parent 77896c0 commit 9be954f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { i18n } from '@kbn/i18n';
import { Subject, Subscription, type BehaviorSubject } from 'rxjs';
import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import type { IContainer } from '@kbn/embeddable-plugin/public';
import { embeddableInputToSubject } from '@kbn/embeddable-plugin/public';
import { embeddableOutputToSubject } from '@kbn/embeddable-plugin/public';
import type { MlEntityField } from '@kbn/ml-anomaly-utils';
import { EmbeddableAnomalyChartsContainer } from './embeddable_anomaly_charts_container_lazy';
Expand Down Expand Up @@ -43,6 +44,7 @@ export class AnomalyChartsEmbeddable extends AnomalyDetectionEmbeddable<
public readonly type: string = ANOMALY_EXPLORER_CHARTS_EMBEDDABLE_TYPE;

// API
public readonly jobIds: BehaviorSubject<JobId[] | undefined>;
public entityFields: BehaviorSubject<MlEntityField[] | undefined>;

private apiSubscriptions = new Subscription();
Expand All @@ -54,6 +56,12 @@ export class AnomalyChartsEmbeddable extends AnomalyDetectionEmbeddable<
) {
super(initialInput, services[2].anomalyDetectorService, services[1].data.dataViews, parent);

this.jobIds = embeddableInputToSubject<JobId[], AnomalyChartsEmbeddableInput>(
this.apiSubscriptions,
this,
'jobIds'
);

this.entityFields = embeddableOutputToSubject<MlEntityField[], AnomalyChartsEmbeddableOutput>(
this.apiSubscriptions,
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { AnomalyExplorerChartsEmbeddableType } from '../constants';
import type { MlEmbeddableBaseApi } from '../types';

export interface AnomalyChartsFieldSelectionApi {
jobIds: JobId[];
jobIds: PublishingSubject<JobId[]>;
entityFields: PublishingSubject<MlEntityField[] | undefined>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ export class AnomalySwimlaneEmbeddable extends AnomalyDetectionEmbeddable<
public readonly type: string = ANOMALY_SWIMLANE_EMBEDDABLE_TYPE;

// API
public viewBy: BehaviorSubject<string | undefined>;
public swimlaneType: BehaviorSubject<SwimlaneType | undefined>;
public perPage: BehaviorSubject<number | undefined>;
public fromPage: BehaviorSubject<number | undefined>;
public interval: BehaviorSubject<number | undefined>;
public readonly jobIds: BehaviorSubject<JobId[] | undefined>;
public readonly viewBy: BehaviorSubject<string | undefined>;
public readonly swimlaneType: BehaviorSubject<SwimlaneType | undefined>;
public readonly perPage: BehaviorSubject<number | undefined>;
public readonly fromPage: BehaviorSubject<number | undefined>;
public readonly interval: BehaviorSubject<number | undefined>;

private apiSubscriptions = new Subscription();

Expand All @@ -60,6 +61,12 @@ export class AnomalySwimlaneEmbeddable extends AnomalyDetectionEmbeddable<
) {
super(initialInput, services[2].anomalyDetectorService, services[1].data.dataViews, parent);

this.jobIds = embeddableInputToSubject<JobId[], AnomalySwimlaneEmbeddableInput>(
this.apiSubscriptions,
this,
'jobIds'
);

this.viewBy = embeddableInputToSubject<string, AnomalySwimlaneEmbeddableInput>(
this.apiSubscriptions,
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { AnomalySwimLaneEmbeddableType } from '../constants';
import type { AnomalySwimlaneEmbeddableUserInput, MlEmbeddableBaseApi } from '../types';

export interface AnomalySwimLaneComponentApi {
jobIds: JobId[];
jobIds: PublishingSubject<JobId[]>;
swimlaneType: PublishingSubject<SwimlaneType>;
viewBy: PublishingSubject<string>;
perPage: PublishingSubject<number>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
* 2.0.
*/

import { type DataView } from '@kbn/data-views-plugin/common';
import { type DataViewsContract } from '@kbn/data-views-plugin/public';
import {
Embeddable,
type EmbeddableInput,
type EmbeddableOutput,
type IContainer,
} from '@kbn/embeddable-plugin/public';
import { type DataView } from '@kbn/data-views-plugin/common';
import { type DataViewsContract } from '@kbn/data-views-plugin/public';
import type { BehaviorSubject } from 'rxjs';
import { firstValueFrom } from 'rxjs';
import { type AnomalyDetectorService } from '../../application/services/anomaly_detector_service';
import type { JobId } from '../../shared';
Expand All @@ -28,7 +29,8 @@ export abstract class AnomalyDetectionEmbeddable<
// Need to defer embeddable load in order to resolve data views
deferEmbeddableLoad = true;

public jobIds: JobId[] = [];
// API
public abstract jobIds: BehaviorSubject<JobId[] | undefined>;

protected constructor(
initialInput: Input,
Expand All @@ -46,8 +48,6 @@ export abstract class AnomalyDetectionEmbeddable<
protected async initializeOutput(initialInput: CommonInput) {
const { jobIds } = initialInput;

this.jobIds = jobIds;

try {
const jobs = await firstValueFrom(this.anomalyDetectorService.getJobs$(jobIds));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function createEditSwimlanePanelAction(
const { jobIds, viewBy, swimlaneType, panelTitle } = context.embeddable;

const result = await resolveAnomalySwimlaneUserInput(coreStart, deps.data.dataViews, {
jobIds,
jobIds: jobIds.getValue(),
swimlaneType: swimlaneType.getValue(),
viewBy: viewBy.getValue(),
title: panelTitle?.getValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function createOpenInExplorerAction(
return locator.getUrl({
page: 'explorer',
pageState: {
jobIds,
jobIds: jobIds.getValue(),
timeRange: getTimeRange(embeddable),
mlExplorerSwimlane: {
viewByFromPage: fromPage.getValue(),
Expand Down Expand Up @@ -148,7 +148,7 @@ export function createOpenInExplorerAction(
return locator.getUrl({
page: 'explorer',
pageState: {
jobIds,
jobIds: jobIds.getValue(),
timeRange: getTimeRange(embeddable),
// @ts-ignore QueryDslQueryContainer is not compatible with SerializableRecord
...(mlExplorerFilter ? ({ mlExplorerFilter } as SerializableRecord) : {}),
Expand Down

0 comments on commit 9be954f

Please sign in to comment.