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

[Dashboard First] Decouple Attribute Service and By Value Embeddables #74302

Merged

Conversation

ThomThomson
Copy link
Contributor

@ThomThomson ThomThomson commented Aug 4, 2020

Summary

This PR accomplishes 3 things:

  1. It decouples the attribute service from the concept of 'by value' or 'by reference' embeddables. For this, it includes an interface, ReferenceOrValueEmbeddable, which can be used by actions such as the unlink from library action [Dashboard First] Unlink from Library Action #73899 and the future add to library action. Implementing the interface, will allow any embeddable to opt into the embeddables by value paradigm. Upon implementation, embeddable authors could either use the attribute_service which requires their input to be in a specific format, or implement their interface in any other way.

  2. It moves the Attribute_service out of the embeddable plugin and in to the dashboard plugin in order to avoid coupling embeddables and saved objects.

  3. It contains an example implementation of the ReferenceOrValueEmbeddable, in the BookEmbeddable, and two example actions for adding a book to the library and unlinking a book from its library item.

Aug-10-2020 12-03-40

This PR closes #74297

Checklist

Delete any items that are not applicable to this PR.

For maintainers

…can be treated as either by reference or by value
@ThomThomson ThomThomson added Feature:Dashboard Dashboard related features Feature:Embedding Embedding content via iFrame Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.10.0 labels Aug 4, 2020
@ThomThomson ThomThomson marked this pull request as ready for review August 10, 2020 15:41
@ThomThomson ThomThomson requested a review from a team August 10, 2020 15:41
@ThomThomson ThomThomson requested a review from a team as a code owner August 10, 2020 15:41
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

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

Looks great! Just a few small questions.


public async wrapAttributes(
newAttributes: SavedObjectAttributes,
useRefType: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be an explicit parameter? can we somehow figure this from attributes?

Copy link
Contributor Author

@ThomThomson ThomThomson Aug 10, 2020

Choose a reason for hiding this comment

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

The wrap attributes method on the attribute service is meant to transform given attributes in the exact same shape into either of the two input types. This means that somewhere there has to be an explicit switch to determine which one to use. This could potentially be split into two methods, but that would only shift the logic to the editor.

const onSave = async (props: OnSaveProps): Promise<SaveResult> => {
try {
const wrappedInput = (await this.wrapAttributes(input.attributes, true)) as RefType;
wrappedInput.title = props.newTitle;
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this assignment needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The title is assigned here because adding an embeddable to the library via the attribute service shows a save modal with the opportunity to name (or re-name) the saved object.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is not a saved object rename, but just embeddable panel title change? isn't it?
Is this expected?

Copy link
Contributor Author

@ThomThomson ThomThomson Aug 12, 2020

Choose a reason for hiding this comment

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

This modal shows up when adding an item to the library. That item (when it is by value) usually doesn't yet have a saved object title.

When the item already has a saved object title, like in a case where it was previously in the library, you are given the option to change the name. An improvement here would be duplicate detection, which will be added in the follow up PR which adds the actual 'add to library' action.

For book embeddables, the titling is a little strange, which is what you're picking up on I believe. They have a saved Object title input.title and a book title input.attributes.title. In the add flyout, they are referred to by their book title.

Edit: The title actually should be taken from the savedObjectAttributes. I have pushed an update that makes this much more aligned.

Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

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

Tested this on an example scenario, works as expected. I really like moving attributeService away from embeddable plugin. I am not sure dashboard plugin is the right place to put in though. But for now, since we don't plan to use it outside the dashboard, it should be fine.

@ThomThomson
Copy link
Contributor Author

I agree about the dashboard plugin not being a permanent home for attributeService. In the future, it might be worth creating a new plugin for all of the 'by reference or by value' code. Other than that, I can't think of a better place for now.

@Dosant Dosant self-requested a review August 11, 2020 15:38
Copy link
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

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

LGTM, tested example plugin.
One question I am curious about: #74302 (comment)

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

code LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
dashboard 174 +1 173
embeddable 92 +1 91
total +2

page load bundle size

id value diff baseline
dashboard 687.7KB +8.3KB 679.4KB
embeddable 427.2KB -1.5KB 428.7KB
total +6.8KB

History

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

@ThomThomson ThomThomson merged commit 2e5140d into elastic:master Aug 12, 2020
ThomThomson added a commit to ThomThomson/kibana that referenced this pull request Aug 12, 2020
…elastic#74302)

* Added an interface that determines if an embeddable can be treated as either by reference or by value
ThomThomson added a commit that referenced this pull request Aug 12, 2020
…#74302) (#74895)

* Added an interface that determines if an embeddable can be treated as either by reference or by value
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 13, 2020
* master: (28 commits)
  [Task manager] Prevents edge case where already running tasks are reschedule every polling interval (elastic#74606)
  [Security Solution] Fix the status of timelines' bulk actions (elastic#74560)
  Data plugin: Suggested enhance pattern (elastic#74505)
  Use jest.useFakeTimers instead of hard coded timeout for tooltip tests. (elastic#74642)
  [Security Solution][lists] Adds tests for exception lists and items part 2 (elastic#74815)
  [Security Solution][Resolver] fix presentation role on edgeline (elastic#74869)
  [Security Solution][Detections] Refactor ML calls for newest ML permissions (elastic#74582)
  [bin/kibana-plugin] support KP plugins instead (elastic#74604)
  Reduce number of indexed fields in index pattern saved object (elastic#74817)
  [reporting] Pass along generic parameters in high-order route handler (elastic#74892)
  Migrated last pieces of legacy fixture code (elastic#74470)
  Empty index patterns page re-design  (elastic#68819)
  [babel] coalese some versions to prevent breaking yarn install (elastic#74864)
  [Dashboard First] Decouple Attribute Service and By Value Embeddables (elastic#74302)
  Revert "[reporting] Pass along generic parameters in high-order route handler" (elastic#74891)
  [reporting] Pass along generic parameters in high-order route handler (elastic#74879)
  [src/dev/build] implement a getBuildNumber() mock (elastic#74881)
  [Enterprise Search] Add solution-level side navigation (elastic#74705)
  [DOCS] Canvas docs 7.9 refresh (elastic#74000)
  [Security Solution][Resolver]Enzyme test related events closing (elastic#74811)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 13, 2020
…le-buffer-with-update-of-same-id

* upstream/master: (37 commits)
  [Task manager] Prevents edge case where already running tasks are reschedule every polling interval (elastic#74606)
  [Security Solution] Fix the status of timelines' bulk actions (elastic#74560)
  Data plugin: Suggested enhance pattern (elastic#74505)
  Use jest.useFakeTimers instead of hard coded timeout for tooltip tests. (elastic#74642)
  [Security Solution][lists] Adds tests for exception lists and items part 2 (elastic#74815)
  [Security Solution][Resolver] fix presentation role on edgeline (elastic#74869)
  [Security Solution][Detections] Refactor ML calls for newest ML permissions (elastic#74582)
  [bin/kibana-plugin] support KP plugins instead (elastic#74604)
  Reduce number of indexed fields in index pattern saved object (elastic#74817)
  [reporting] Pass along generic parameters in high-order route handler (elastic#74892)
  Migrated last pieces of legacy fixture code (elastic#74470)
  Empty index patterns page re-design  (elastic#68819)
  [babel] coalese some versions to prevent breaking yarn install (elastic#74864)
  [Dashboard First] Decouple Attribute Service and By Value Embeddables (elastic#74302)
  Revert "[reporting] Pass along generic parameters in high-order route handler" (elastic#74891)
  [reporting] Pass along generic parameters in high-order route handler (elastic#74879)
  [src/dev/build] implement a getBuildNumber() mock (elastic#74881)
  [Enterprise Search] Add solution-level side navigation (elastic#74705)
  [DOCS] Canvas docs 7.9 refresh (elastic#74000)
  [Security Solution][Resolver]Enzyme test related events closing (elastic#74811)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Dashboard Dashboard related features Feature:Embedding Embedding content via iFrame release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Dashboard First] Add / Unlink Actions Require Specifically Shaped Input
6 participants