Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[embeddable] decouple FILTER_BY_MAP_EXTENT action from Embeddable framework #175262

Merged
merged 7 commits into from
Jan 25, 2024

Conversation

nreese
Copy link
Contributor

@nreese nreese commented Jan 22, 2024

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()

@nreese nreese changed the title [embeddable] convert FILTER_BY_MAP_EXTENT action to embeddables api [embeddable] decouple FILTER_BY_MAP_EXTENT action from Embeddable framework Jan 22, 2024
@nreese
Copy link
Contributor Author

nreese commented Jan 23, 2024

/ci

@nreese nreese marked this pull request as ready for review January 23, 2024 19:18
@nreese nreese requested review from a team as code owners January 23, 2024 19:18
@nreese nreese added Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas release_note:skip Skip the PR/issue when compiling release notes Feature:Embeddables Relating to the Embeddable system v8.13.0 labels Jan 23, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@botelastic botelastic bot added the Feature:Embedding Embedding content via iFrame label Jan 23, 2024
Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visualization changes work for me!

@nreese
Copy link
Contributor Author

nreese commented Jan 25, 2024

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #6 / Saved Objects Management export transforms isExportable API "after all" hook for "excludes objects if isExportable throws"
  • [job] [logs] FTR Configs #42 / security APIs - Audit Log Audit Log logs audit events when reading and writing saved objects
  • [job] [logs] FTR Configs #39 / Serverless Common UI - Examples Field formats example "before all" hook for "renders field formats example 1"
  • [job] [logs] FTR Configs #85 / Serverless Common UI - Management Index Management Create enrich policy "before all" hook for "shows create enrich policies page and docs link"
  • [job] [logs] FTR Configs #56 / Serverless Common UI - Platform Security Avatar menu "before all" hook for "is displayed"

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
dashboard 419 420 +1
embeddable 97 98 +1
lens 1239 1240 +1
links 115 116 +1
maps 1107 1126 +19
presentationPanel 78 79 +1
visualizations 372 373 +1
total +25

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/presentation-publishing 105 109 +4
embeddable 420 421 +1
visualizations 805 809 +4
total +9

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
maps 2.9MB 2.9MB -1.0KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
embeddable 60.5KB 60.7KB +130.0B
maps 47.3KB 48.0KB +720.0B
visualizations 57.2KB 57.3KB +111.0B
total +961.0B
Unknown metric groups

API count

id before after diff
@kbn/presentation-publishing 139 143 +4
embeddable 520 521 +1
visualizations 836 840 +4
total +9

async chunk count

id before after diff
maps 29 28 -1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review only, LGTM! This is a great example of how to convert an action. Also, great work on the step-by-step instructions on the PR description.

@nreese nreese merged commit 4565b1b into elastic:main Jan 25, 2024
22 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jan 25, 2024
CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
…mework (elastic#175262)

Part of elastic#175138 and prerequisite
for elastic#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Embeddables Relating to the Embeddable system Feature:Embedding Embedding content via iFrame project:embeddableRebuild release_note:skip Skip the PR/issue when compiling release notes Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants