Skip to content

Commit

Permalink
[Legacy Controls] Decouple DEPRECATION_BADGE action from Embeddable…
Browse files Browse the repository at this point in the history
… framework (#175928)

Part of #175138

## Summary

This PR decouples the `DEPRECATION_BADGE` action (which is used
specifically for the legacy input controls panel) from Embeddable
framework by migrating to sets of composable interfaces.

**Testing:**
Since the legacy input control vis is deprecated and doesn't show up in
the "Add panel" menu anymore, you need to navigate to `<base
url>/app/visualize#/create?type=input_control_vis` in order to create
this panel type for testing.

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
Heenawter and kibanamachine authored Jan 31, 2024
1 parent 31026a0 commit b6fbae2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
54 changes: 41 additions & 13 deletions src/plugins/input_control_vis/public/deprecation_badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,36 @@
* Side Public License, v 1.
*/

import { ViewMode } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import {
apiCanAccessViewMode,
CanAccessViewMode,
EmbeddableApiContext,
getInheritedViewMode,
getViewModeSubject,
} from '@kbn/presentation-publishing';
import { Action } from '@kbn/ui-actions-plugin/public';
import { apiHasVisualizeConfig, HasVisualizeConfig } from '@kbn/visualizations-plugin/public';

import { Embeddable, ViewMode } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import { VisualizeInput } from '@kbn/visualizations-plugin/public';
import { INPUT_CONTROL_VIS_TYPE } from './input_control_vis_type';

export const ACTION_DEPRECATION_BADGE = 'ACTION_INPUT_CONTROL_DEPRECATION_BADGE';
const ACTION_DEPRECATION_BADGE = 'ACTION_INPUT_CONTROL_DEPRECATION_BADGE';

export interface DeprecationBadgeActionContext {
embeddable: Embeddable<VisualizeInput>;
}
type InputControlDeprecationActionApi = CanAccessViewMode & HasVisualizeConfig;

const isApiCompatible = (api: unknown | null): api is InputControlDeprecationActionApi =>
Boolean(apiCanAccessViewMode(api) && apiHasVisualizeConfig(api));

const compatibilityCheck = (api: EmbeddableApiContext['embeddable']) => {
return (
isApiCompatible(api) &&
getInheritedViewMode(api) === ViewMode.EDIT &&
api.getVis().type.name === INPUT_CONTROL_VIS_TYPE
);
};

export class InputControlDeprecationBadge implements Action<DeprecationBadgeActionContext> {
export class InputControlDeprecationBadge implements Action<EmbeddableApiContext> {
public id = ACTION_DEPRECATION_BADGE;
public type = ACTION_DEPRECATION_BADGE;
public disabled = true;
Expand All @@ -40,11 +57,22 @@ export class InputControlDeprecationBadge implements Action<DeprecationBadgeActi
});
}

public async isCompatible({ embeddable }: DeprecationBadgeActionContext) {
return (
embeddable.getInput().viewMode === ViewMode.EDIT &&
embeddable.getInput()?.savedVis?.type === 'input_control_vis'
);
public async isCompatible({ embeddable }: EmbeddableApiContext) {
return compatibilityCheck(embeddable);
}

public couldBecomeCompatible({ embeddable }: EmbeddableApiContext) {
return isApiCompatible(embeddable) && embeddable.getVis().type.name === INPUT_CONTROL_VIS_TYPE;
}

public subscribeToCompatibilityChanges(
{ embeddable }: EmbeddableApiContext,
onChange: (isCompatible: boolean, action: Action<EmbeddableApiContext>) => void
) {
if (!isApiCompatible(embeddable)) return;
return getViewModeSubject(embeddable)?.subscribe(() => {
onChange(compatibilityCheck(embeddable), this);
});
}

public async execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import { InputControlVisDependencies } from './plugin';
import { toExpressionAst } from './to_ast';
import { InputControlVisParams } from './types';

export const INPUT_CONTROL_VIS_TYPE = 'input_control_vis';

export function createInputControlVisTypeDefinition(
deps: InputControlVisDependencies,
readOnly: boolean
): VisTypeDefinition<InputControlVisParams> {
const ControlsTab = getControlsTab(deps);

return {
name: 'input_control_vis',
name: INPUT_CONTROL_VIS_TYPE,
title: i18n.translate('inputControl.register.controlsTitle', {
defaultMessage: 'Input controls',
}),
Expand Down
1 change: 1 addition & 0 deletions src/plugins/input_control_vis/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@kbn/config-schema",
"@kbn/ui-actions-plugin",
"@kbn/embeddable-plugin",
"@kbn/presentation-publishing",
],
"exclude": [
"target/**/*",
Expand Down

0 comments on commit b6fbae2

Please sign in to comment.