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

[Visualize] First version of by-value visualize editor #72256

Merged
merged 18 commits into from
Aug 18, 2020

Conversation

majagrubic
Copy link
Contributor

@majagrubic majagrubic commented Jul 17, 2020

What is this?

This PR implements editing visualization by value inside dashboard and returning the edited visualization back to dashboard.

The idea is as follows:

  1. We take the embeddable input from the dashboard and pass it (along with the original embeddable id) to the visualize editor via state-transfer service
  2. Visualize editor reads the input from the state transfer service and renders the visualize embeddable (+ editor controls) from the input
  3. Once the changes are applied, visualize editor passes the updated input together with the original embeddable id back to the dashboard
  4. Dashboard updates the existing embeddable from the input it received

Note: Sharing of the visualization by-value doesn't work yet.

Implementation details

To support this flow, I introduced a new edit_by_value URL and a new visualize_byValue_editor. When editing visualization by value, there is no need to sync state from the URL, so the flow becomes a bit simpler. Common functionality was extracted to common components/functions, but some code duplication is probably still present.

What didn't change?

There should be no changes to the existing visualize editor. If something is wrong with editing visualizations from saved objects, it's likely a bug not a feature :)

How to test this?

  1. The main focus should be on testing the existing visualize editor and that nothing is broken.

  2. To test the new functionality, you'll need to set the showNewVisualizeFlow config value to true:

    showNewVisualizeFlow: schema.boolean({ defaultValue: false }),

    This requires a server restart!

  3. Once the flag has been enabled:
    a) create a dashboard
    b) create a new visualization (any visualization except Lens) and add it to dashboard
    c) from the panel action menu select "Edit visualization" -> this should trigger the new "by-value" editor

Where are functional/unit tests?

Incoming!

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@majagrubic majagrubic changed the title First version of new by-value editor [Visualize] First version of by-value visualize editor Jul 17, 2020
Fixing broken behavior and applying relevant changes

Adding changes to dashboard

Removing unnecessary empty line

Removing unnecessary deepClone

Fixing some stuff in dashboard container

Extracting logic into common components

Fixing eslint

Fix breadcrumbs

Fixing error in search interceptor

Reintroduce mistakenly removed empty lines

Renaming function
@majagrubic majagrubic force-pushed the visualize-by-value-editor branch from e693822 to b4972da Compare July 17, 2020 11:29
@majagrubic majagrubic requested review from ThomThomson, sulemanof and stratoula and removed request for ThomThomson July 20, 2020 20:17
@majagrubic majagrubic added Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 v7.10.0 release_note:roadmap Feature:Dashboard Dashboard related features Feature:Visualizations Generic visualization features (in case no more specific feature label is available) labels Jul 20, 2020
@majagrubic majagrubic marked this pull request as ready for review July 20, 2020 20:20
@majagrubic majagrubic requested a review from a team July 20, 2020 20:20
@majagrubic majagrubic requested a review from a team as a code owner July 20, 2020 20:20
@botelastic botelastic bot added the Feature:Embedding Embedding content via iFrame label Jul 20, 2020
@elasticmachine
Copy link
Contributor

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

@majagrubic majagrubic requested a review from Dosant July 20, 2020 20:20
@majagrubic
Copy link
Contributor Author

@elasticmachine merge upstream

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.

app arch changes code LGTM

@majagrubic majagrubic removed the request for review from Dosant July 21, 2020 12:50
Copy link
Contributor

@sulemanof sulemanof left a comment

Choose a reason for hiding this comment

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

Tested basic behavior of Visualize app, I can confirm it works well after these changes. I didn't notice any regressions, except next one:

  • the Save as button works incorrect when edit a visualization through a dashboard panel:

    save_as

    actual behavior - copies a vis without any requested info;
    expected behavior - modal appears:

    image

About edit_by_value feature, I noticed couple of confusing things:

  • using browser's back/forward buttons, I trap into an empty screen since the visualization can't be loaded without data. The same thing occur if I reload a page.

    back_button

    My suggestion is to play around with the url tracker (e.x. erase the visited visualize page or replace with the actual dashbord);

  • lack of visualization title when created through the dashboard in edit by value mode;

  • can't unlink from the saved search ( details here );

@@ -48,6 +53,9 @@ export const VisualizeApp = () => {

return (
<Switch>
<Route exact path={`${VisualizeConstants.EDIT_BY_VALUE_PATH}`}>
<VisualizeByValueEditor />
Copy link
Contributor

Choose a reason for hiding this comment

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

What if you try instead to use the same <VisualizeEditor /> at this route, but use another effects inside when you trap into /edit_by_value path? It seems this will help to get rid of VisualizeEditorCommon ccomponent and code duplications between VisualizeByValueEditor <---> VisualizeEditor

Copy link
Contributor Author

@majagrubic majagrubic Jul 22, 2020

Choose a reason for hiding this comment

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

I am not sure how? Hooks need to be run in order and they don't like branching statements. I thought having separate components was actually cleaner.

eventEmitter,
byValueVisInstance
);
const { isEmbeddableRendered, currentAppState } = useEditorUpdates(
Copy link
Contributor

Choose a reason for hiding this comment

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

The useEditorUpdates subscribes on the appState updates (which can be changed through the url).
Seems you don't need that subscription at all?

delete savedVis.savedSearchId;
delete vis.data.savedSearchId;
} else {
// TODO: something to do for when it's not a saved vis?
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be resolved before merging?
Unlinking isn't working right now in edit_by_value mode.

unlink

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd really like to keep this PR as small as possible and build on it incrementally. I believe for the first pass it can work without saved search linking/unlinking.

@mistic
Copy link
Member

mistic commented Aug 10, 2020

@elasticmachine merge upstream

@majagrubic
Copy link
Contributor Author

majagrubic commented Aug 13, 2020

Hey @sulemanof, this should be ready for another review. I addressed 3 main concerns from the last review:

  1. The problem with "Save As" appeared only if you upgrade from "old flow" to the "new flow" -> this shouldn't affect the existing visualize editor (but is still fixed, nonetheless)

  2. Unlinking saved search works now

  3. As for the getting stuck in the "edit_by_value" empty mode: @ThomThomson and I had a chat about this; the proper solution would include storing the vis in local storage, which we decided against when building state transfer service -> it would basically involve ditching state transfer service and coming up with a better solution; the hack we came up with is just: if there's no input when initializing the editor, we just return back to dashboard; we even change the breadcrumbs when opening the visualize editor from the dashboard, so that it's prefixed by "Dashboard" -> that way we make it more explicit that the user is still inside the dashboard space

As for two separate editors, I'd like to keep it this way for now. I think the separation of concerns is pretty good and it's following the implementation of the original visualize editor.

Also, another side note: This is not getting released soon, so we can make incremental changes in the meantime.

@majagrubic majagrubic requested a review from sulemanof August 13, 2020 15:08
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.

Tested in chrome, and spent a little while going over the code.

This is looking quite stable overall! Splitting up the editor into three components actually resulted in far less code duplication than I thought it would, which is good to see.

One issue that I noticed is that editing a by reference visualization, then hitting save and return will duplicate the embeddable. I think what's happening here is that the visualize editor is accidentally putting the by value version of the embeddable into the state transfer service when it should just save the vis by reference and redirect back to dashboard.

Aug-14-2020 15-41-23

Other than that, I have some additional small comments/suggestions that could be handled in this PR, or in a follow-up.

Unified Config Setting: It would be awesome for us to tie all of the embeddable by value changes behind a single config setting. I added one to the dashboard start contract recently and will update my lens PR to reference that one.

allowByValueEmbeddables: schema.boolean({ defaultValue: false }),

Attribute Service / Interface: Most likely a follow up PR, but implementing the ReferenceOrValueEmbeddable interface should be a priority so visualize embeddables work correctly with the unlink & add to library actions right out of the gate. Additionally, it'll be good to keep in mind that using the attribute service can make this implementation a lot easier.

Cancel Button: Should be a super easy addition in another PR. #70650

Save and return / Save as I think it's important to allow the user to opt out of the by value paradigm through the editor if they want to. To that end, I switched the menu bar UI in the Lens PR to include both the 'save and return' and 'save as' buttons, any time the user has arrived from a dashboard. This results in greater consistency as well, and it would be ideal if the menus worked the same in both visualize and lens.

Dashboard breadcrumb: Great implementation on this one, I'm definitely going to do the same in the lens PR. Wondering how hard it would be to make the dashboard breadcrumb into a link, which would do the same thing as the above mentioned cancel button.

Let me know when I can re-review, very excited to get this in!

@majagrubic
Copy link
Contributor Author

majagrubic commented Aug 17, 2020

Thanks for review @ThomThomson ! great catch about the duplicate embeddable being created, I believe this has been fixed now. To address some other concerns:
Unified Config Setting -> I'm not sure if a plugin can read config settings from another plugin. From my understanding, each plugin will have to have its own
Attribute Service / Interface: -> definitely the next item on my todo list
Save as -> I think this is related to the previous item; it will basically be "add to library functionality"
Dashboard breadcrumb -> I think the problem is the same as the one above; it's not possible to access dashboard link from visualize plugin

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
visualize 311 +3 308

async chunks size

id value diff baseline
visualize 693.8KB +16.4KB 677.4KB

page load bundle size

id value diff baseline
dashboard 687.9KB +169.0B 687.7KB
embeddable 428.7KB +179.0B 428.6KB
navigation 164.7KB +26.0B 164.7KB
visualizations 409.0KB +15.0B 409.0KB
visualize 31.0KB +36.0B 30.9KB
total +425.0B

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.

The duplication issue is fixed, and everything is working well - super excited to get this in!
LGTM.

A few notes for the followup PR questions:

Unified Config Setting: I actually exposed this setting in the dashboard start contract specifically so that other plugins can get access to it. The Lens PR doesn't have its own config setting anymore, and is using the dashboard one instead.

Dashboard breadcrumb: We actually already have an easy way to get back to the dashboard due to the 'originatingApp' parameter. It could call something like this:
coreStart.application.navigateToApp(embeddableEditorIncomingState?.originatingApp);

ThomThomson added a commit to ThomThomson/kibana that referenced this pull request Aug 17, 2020
@majagrubic majagrubic merged commit 9bef317 into elastic:master Aug 18, 2020
@majagrubic majagrubic deleted the visualize-by-value-editor branch August 18, 2020 10:19
majagrubic pushed a commit that referenced this pull request Aug 18, 2020
* First version of new by-value editor

Fixing broken behavior and applying relevant changes

Adding changes to dashboard

Removing unnecessary empty line

Removing unnecessary deepClone

Fixing some stuff in dashboard container

Extracting logic into common components

Fixing eslint

Fix breadcrumbs

Fixing error in search interceptor

Reintroduce mistakenly removed empty lines

Renaming function

* Adding missing null check

* Making typescript play nicely

* Fixing failing tests

* Applying PR comments

* Fixing eslint errors

* Fix save as behavior

* Fixing HTMLElement type

* Passing in setOriginatingApp parameter

* Redirect back to dashboard if input is missing

* Fixing i18n error

* Unlink saved search

* Fix duplicating embeddable by reference

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 18, 2020
* master:
  Skip failing test in CI (elastic#75266)
  [Task Manager] time out work when it overruns in poller (elastic#74980)
  [Drilldowns] misc improvements & fixes (elastic#75276)
  Small README note on bumping memory for builds (elastic#75247)
  [Security Solution][Detections] Adds exception modal tests (elastic#74596)
  [Dashboard] Sample data link does not work (elastic#75262)
  [Dashboard First] Unlink from Library Action With ReferenceOrValueEmbeddable (elastic#74905)
  [Form lib] Fix issue where serializer on fields are called on every change (elastic#75166)
  convert processor labels to sentence case (elastic#75278)
  [Monaco] Refactor the way XJSON grammar checker gets registered (elastic#75160)
  Clarify no documents error message when filtering by is_training (elastic#75227)
  [Lens] Fix crash when two layers xychart  switches to pie (elastic#75267)
  [Observability Homepage] Fix console error because of side effect (elastic#75258)
  [Usage Collection] Add `legacy=true` option to the /api/stats request in the docs (elastic#75146)
  [ML] Functional tests - re-activate DFA test suites (elastic#75257)
  GS providers improvements (elastic#75174)
  [Visualize] First version of by-value visualize editor (elastic#72256)
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 Feature:Visualizations Generic visualization features (in case no more specific feature label is available) 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.

7 participants