Skip to content

Commit

Permalink
Fix up typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Heenawter committed Jun 15, 2023
1 parent eed68ee commit 31e64af
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public';

import { ACTION_CLEAR_CONTROL } from '.';
import { ControlGroupStrings } from '../control_group_strings';
import { ClearableControlEmbeddable, ControlEmbeddable, DataControlInput } from '../../types';
import { ControlEmbeddable, DataControlInput, isClearableControl } from '../../types';
import { isControlGroup } from '../embeddable/control_group_helpers';

export interface ClearControlActionContext {
Expand Down Expand Up @@ -62,18 +62,14 @@ export class ClearControlAction implements Action<ClearControlActionContext> {
public async isCompatible({ embeddable }: ClearControlActionContext) {
if (isErrorEmbeddable(embeddable)) return false;
const controlGroup = embeddable.parent;
return Boolean(
controlGroup &&
isControlGroup(controlGroup) &&
embeddable instanceof ClearableControlEmbeddable
);
return Boolean(controlGroup && isControlGroup(controlGroup)) && isClearableControl(embeddable);
}

public async execute({ embeddable }: ClearControlActionContext) {
if (
!embeddable.parent ||
!isControlGroup(embeddable.parent) ||
!(embeddable instanceof ClearableControlEmbeddable)
!isClearableControl(embeddable)
) {
throw new IncompatibleActionError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '@kbn/es-query';
import { i18n } from '@kbn/i18n';
import { DataView, FieldSpec } from '@kbn/data-views-plugin/public';
import { IContainer } from '@kbn/embeddable-plugin/public';
import { Embeddable, IContainer } from '@kbn/embeddable-plugin/public';
import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { ReduxEmbeddableTools, ReduxToolsPackage } from '@kbn/presentation-util-plugin/public';

Expand All @@ -35,7 +35,7 @@ import {
OptionsListEmbeddableInput,
} from '../..';
import { pluginServices } from '../../services';
import { ClearableControlEmbeddable } from '../../types';
import { IClearableControl } from '../../types';
import { OptionsListControl } from '../components/options_list_control';
import { ControlsDataViewsService } from '../../services/data_views/types';
import { ControlsOptionsListService } from '../../services/options_list/types';
Expand Down Expand Up @@ -77,7 +77,10 @@ type OptionsListReduxEmbeddableTools = ReduxEmbeddableTools<
typeof optionsListReducers
>;

export class OptionsListEmbeddable extends ClearableControlEmbeddable<OptionsListEmbeddableInput> {
export class OptionsListEmbeddable
extends Embeddable<OptionsListEmbeddableInput, ControlOutput>
implements IClearableControl
{
public readonly type = OPTIONS_LIST_CONTROL;
public deferEmbeddableLoad = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
Filter,
} from '@kbn/es-query';
import { i18n } from '@kbn/i18n';
import { IContainer } from '@kbn/embeddable-plugin/public';
import { Embeddable, IContainer } from '@kbn/embeddable-plugin/public';
import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { DataView, DataViewField } from '@kbn/data-views-plugin/public';
import { ReduxEmbeddableTools, ReduxToolsPackage } from '@kbn/presentation-util-plugin/public';
Expand All @@ -36,7 +36,7 @@ import {
} from '../..';
import { pluginServices } from '../../services';
import { RangeSliderReduxState } from '../types';
import { ClearableControlEmbeddable } from '../../types';
import { IClearableControl } from '../../types';
import { ControlsDataService } from '../../services/data/types';
import { RangeSliderControl } from '../components/range_slider_control';
import { ControlsDataViewsService } from '../../services/data_views/types';
Expand Down Expand Up @@ -84,7 +84,10 @@ type RangeSliderReduxEmbeddableTools = ReduxEmbeddableTools<
typeof rangeSliderReducers
>;

export class RangeSliderEmbeddable extends ClearableControlEmbeddable<RangeSliderEmbeddableInput> {
export class RangeSliderEmbeddable
extends Embeddable<RangeSliderEmbeddableInput, ControlOutput>
implements IClearableControl
{
public readonly type = RANGE_SLIDER_CONTROL;
public deferEmbeddableLoad = true;

Expand Down Expand Up @@ -422,6 +425,10 @@ export class RangeSliderEmbeddable extends ClearableControlEmbeddable<RangeSlide
});
};

public clearSelections() {

This comment has been minimized.

Copy link
@Heenawter

Heenawter Jun 15, 2023

Author Contributor

This got lost when dealing with some conflicts after merging main - hence the current test failure.

this.dispatch.setSelectedRange(['', '']);
}

public reload = async () => {
try {
await this.runRangeSliderQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import _ from 'lodash';
import { debounceTime, first, map } from 'rxjs/operators';
import moment from 'moment-timezone';
import { IContainer } from '@kbn/embeddable-plugin/public';
import { Embeddable, IContainer } from '@kbn/embeddable-plugin/public';
import { ReduxEmbeddableTools, ReduxToolsPackage } from '@kbn/presentation-util-plugin/public';
import type { TimeRange } from '@kbn/es-query';
import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
Expand All @@ -21,7 +21,7 @@ import { TimeSliderControlEmbeddableInput } from '../../../common/time_slider/ty
import { pluginServices } from '../../services';
import { ControlsSettingsService } from '../../services/settings/types';
import { ControlsDataService } from '../../services/data/types';
import { ClearableControlEmbeddable, ControlOutput } from '../../types';
import { ControlOutput, IClearableControl } from '../../types';
import { ControlGroupContainer } from '../../control_group/embeddable/control_group_container';
import { TimeSlider, TimeSliderPrepend } from '../components';
import { timeSliderReducers } from '../time_slider_reducers';
Expand Down Expand Up @@ -51,7 +51,10 @@ type TimeSliderReduxEmbeddableTools = ReduxEmbeddableTools<
typeof timeSliderReducers
>;

export class TimeSliderControlEmbeddable extends ClearableControlEmbeddable<TimeSliderControlEmbeddableInput> {
export class TimeSliderControlEmbeddable
extends Embeddable<TimeSliderControlEmbeddableInput, ControlOutput>
implements IClearableControl
{
public readonly type = TIME_SLIDER_CONTROL;
public deferEmbeddedLoad = true;

Expand Down
10 changes: 6 additions & 4 deletions src/plugins/controls/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ export type ControlEmbeddable<
renderPrepend?: () => ReactNode | undefined;
};

export abstract class ClearableControlEmbeddable<
I extends ControlInput = ControlInput
> extends Embeddable<I, ControlOutput> {
public abstract clearSelections(): void;
export interface IClearableControl extends ControlEmbeddable {
clearSelections: () => void;
}

export const isClearableControl = (control: ControlEmbeddable): control is IClearableControl => {
return Boolean((control as IClearableControl).clearSelections);
};

/**
* Control embeddable editor types
*/
Expand Down

0 comments on commit 31e64af

Please sign in to comment.