-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[embeddable] decouple FILTER_BY_MAP_EXTENT action from Embeddable fra…
…mework (#175262) Part of #175138 and prerequisite for #174960 PR decouples FILTER_BY_MAP_EXTENT action from Embeddable framework by migrating to sets of composable interfaces. ### Inheritance to composition Replace action context type with a type definition that is as narrow as possible. How do you know which properties are needed? Look through the action and find all usages of `embeddabe`. Add each usage to the narrowed type definition. ``` // original action context type. // Notice how type requires an Embeddable instance // when only a few properties from the embeddable are needed export interface FilterByMapExtentActionContext { embeddable: Embeddable<FilterByMapExtentInput>; } // new action context type. // Notice how type explicitly states what is used and // is no longer tied to an Embeddable (even though an Embeddable will pass the type guard) // Another point to highlight is use of 'Partial'. This indicates that API interfaces are not required export type FilterByMapExtentActionApi = HasType & Partial<HasDisableTriggers & HasParentApi<HasType> & HasVisualizeConfig>; // This is the new action context rewritten to inline types like HasType to make it clearer export type FilterByMapExtentActionApi = { type: string; disableTriggers?: boolean; parentApi?: { type: string }; getVis?: () => Vis<VisParam>; } ``` ### Migrating embeddable.parent?.type Action uses `embeddable.parent?.type` to customize the display name. For dashboards the display name would be "Filter dashboards by map bounds", otherwise the display name would be "Filter page by map bounds". To access `parentApi`, we must: 1) `HasParentApi` interface and `apiHasParentApi` type guard already exist at `packages/presentation/presentation_publishing/interfaces/has_parent_api.ts`, so we can just use those. 2) No compatibility changes are required since Embeddable already exposes `parentApi`. 3) Add `Partial<HasParentApi<HasType>>` to action compatibility definition. Using `Partial` because accessing `parentApi` is not required. 4) Access value like `api.parentApi?.type` ### Migrating embeddable.getInput().disableTriggers Action fails compatibility check when `embeddable.getInput().disableTriggers` returns `true`. To access `disableTriggers`, we must: 1) Define `HasDisableTriggers` interface and `apiHasDisableTriggers` type guard in the package `packages/presentation/presentation_publishing`. Adding interface and type guard to generic package folder since `input.disableTriggers` is not tied to any specific Embeddable implementation. *Naming convention: Use prefix `has` since `disableTriggers` is static. Use prefix `publishes` for dynamic values since value will be accesses via a subscription.* 2) Add compatibility changes to `src/plugins/embeddable/public/lib/embeddables/embeddable.tsx` so that an Embeddable instance exposes `disableTriggers`. 3) Add `Partial<HasDisableTriggers>` to action compatibility definition. Using `Partial` because accessing `disableTriggers` is not required. 4) Access value like `api.disableTriggers` ### Migrating embeddable.getVis() Action uses `embeddable.getVis()` to pass compatibility check when visualize embeddable is a region_map or tile_map To access `getVis`, we must: 1) Define `HasVisualizeConfig` interface and `apiHasVisualizeConfig` type guard in `src/plugins/visualizations/public/embeddable/interfaces`. Adding interface to the visualize plugin since `getVis` is only available for Visualization Embeddable. 2) No compatibility changes are required since Visualization Embeddable already exposes `getVis` method. 3) Add `Partial<HasVisualizeConfig>` to action compatibility definition. Using `Partial` because accessing `getVis` is not required. 4) Access value like `api.getVis()` --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
2a27b83
commit 4565b1b
Showing
13 changed files
with
88 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/presentation/presentation_publishing/interfaces/has_disable_triggers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export interface HasDisableTriggers { | ||
disableTriggers: boolean; | ||
} | ||
|
||
export const apiHasDisableTriggers = (api: unknown | null): api is HasDisableTriggers => { | ||
return Boolean(api && typeof (api as HasDisableTriggers).disableTriggers === 'boolean'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/plugins/visualizations/public/embeddable/interfaces/has_visualize_config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { VisParams } from '../../types'; | ||
import Vis from '../../vis'; | ||
|
||
export interface HasVisualizeConfig { | ||
getVis: () => Vis<VisParams>; | ||
} | ||
|
||
export const apiHasVisualizeConfig = (api: unknown): api is HasVisualizeConfig => { | ||
return Boolean(api && typeof (api as HasVisualizeConfig).getVis === 'function'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
x-pack/plugins/maps/public/trigger_actions/filter_by_map_extent/is_compatible.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters