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

[VisBuilder] 2 way communication using UI actions and bug fixes #3732

Merged

Conversation

ashwin-pc
Copy link
Member

@ashwin-pc ashwin-pc commented Mar 30, 2023

Description

This PR add 2 way communication to VisBuilder And fixes a few bugs along the way. I've added comments to the section of the code that are bug fixes and not related to the UIActions change.

To add 2 way communication, the existing UI actions framework was reused and the existing actions were simply passed along transparently to the UI. The main task long term is to document and standardize these actions so that a variety of visualization types can use the same actions

Demo:

Screen.Recording.2023-03-30.at.6.49.08.PM.mov

Issues Resolved

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
    • yarn test:ftr
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

@codecov-commenter
Copy link

codecov-commenter commented Mar 30, 2023

Codecov Report

Merging #3732 (259de2f) into main (971165f) will increase coverage by 0.02%.
The diff coverage is 30.64%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #3732      +/-   ##
==========================================
+ Coverage   66.42%   66.44%   +0.02%     
==========================================
  Files        3209     3209              
  Lines       61733    61741       +8     
  Branches     9534     9537       +3     
==========================================
+ Hits        41005    41023      +18     
+ Misses      18441    18429      -12     
- Partials     2287     2289       +2     
Flag Coverage Δ
Linux 66.38% <30.64%> (+0.02%) ⬆️
Windows 66.38% <30.64%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/plugins/vis_builder/public/application/app.tsx 12.50% <ø> (ø)
...er/public/application/utils/get_top_nav_config.tsx 57.77% <ø> (ø)
...application/utils/use/use_saved_vis_builder_vis.ts 3.03% <0.00%> (+0.46%) ⬆️
...ilder/public/embeddable/vis_builder_embeddable.tsx 1.02% <0.00%> (+0.04%) ⬆️
...blic/embeddable/vis_builder_embeddable_factory.tsx 11.11% <0.00%> (ø)
src/plugins/vis_builder/public/plugin.ts 22.91% <0.00%> (-0.49%) ⬇️
...d_visualizations/saved_visualization_references.ts 0.00% <ø> (ø)
...uilder/public/application/components/workspace.tsx 6.45% <25.00%> (+2.88%) ⬆️
..._builder/public/saved_visualizations/transforms.ts 80.00% <66.66%> (-20.00%) ⬇️
...uilder/public/application/components/right_nav.tsx 12.50% <100.00%> (+3.80%) ⬆️
... and 2 more

... and 3 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
@ashwin-pc ashwin-pc force-pushed the feature/vis-builder-ui-actions branch from 8cbc8f8 to f4f2cf0 Compare April 5, 2023 17:24
Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

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

Looks good! I have a few clarifying questions and comments and a couple of minor requested changes. I still want to play with it a little locally, but my readthrough is done.

import { VIS_EVENT_TO_TRIGGER } from '../../../../visualizations/public';
import { UiActionsStart } from '../../../../ui_actions/public';

export const handleVisEvent = async (
Copy link
Member

Choose a reason for hiding this comment

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

Just a question, do we need to add error handling here?

Copy link
Member Author

Choose a reason for hiding this comment

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

How do see error handling being added here?

Copy link
Member

Choose a reason for hiding this comment

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

Mmm i am mostly thinking if it's possible that await uiActions.getTrigger() fail?

handleVisEvent(event, getUIActions(), indexPattern.timeFieldName);
}
})
);
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain more why we add the subscriptions to the events here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The underlying expression renderer may want to transmit user actions to the parent app, it does so by using the expression renderer's event bus. So when the parent application wants to listen to these events, it needs to subscribe to that bus. In the embeddable, the handler.events is that bus, and for ReactExpressionRenderer, the onEvent callback is that bus. In both cases, we want to listen to the event, condition it and trasmit a corresponding UI Action for the event. handleVisEvent is responsible for conditioning the event and transmitting the UIAction

Copy link
Member

Choose a reason for hiding this comment

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

Got it, thanks for the explainations!

// TODO: add indexPatterns as part of configuration
// indexPatterns?: IIndexPattern[];
editPath: string;
editUrl: string;
editable: boolean;
}

export type VisBuilderInput = SavedObjectEmbeddableInput;
Copy link
Member

Choose a reason for hiding this comment

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

nit: should we be more specific on the type name here? VisBuilderEmbeddableInput and VisBuilderEmbeddableOutput?

Think it would be clearer, but it's fine either way.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, that is much more explicit. However, since the UI state PR also affects the same files, i'd avoid making this change now though. Is that okay?

Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>

Co-authored-by: Josh Romero <rmerqg@amazon.com>
ashwin-pc and others added 6 commits April 14, 2023 14:41
Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>

Co-authored-by: Josh Romero <rmerqg@amazon.com>
…ent.ts


Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>

Co-authored-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

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

LGTM - a couple minor nits and opinions, but nothing blocking.

@@ -121,3 +121,7 @@ const OptionItem = ({ icon, title }: { icon: IconType; title: string }) => (
<span>{title}</span>
</>
);

// The app uses EuiResizableContainer that triggers a rerender for ever mouseover action.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// The app uses EuiResizableContainer that triggers a rerender for ever mouseover action.
// The app uses EuiResizableContainer that triggers a rerender for every mouseover action.

@@ -44,15 +46,17 @@ export const Workspace: FC = ({ children }) => {
async function loadExpression() {
const schemas = ui.containerConfig.data.schemas;

const noAggs = aggConfigs?.aggs?.length === 0;
const noAggs = (aggConfigs?.aggs?.length ?? 0) === 0;
Copy link
Member

Choose a reason for hiding this comment

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

opinion - this reads worse to me than

const noAggs = !aggConfigs?.aggs?.length;
or even
const noAggs = aggConfigs?.aggs?.length == false;

Also, for conditionals like this I'd prefer hasNoAggs.

@joshuarrrr joshuarrrr merged commit 1edb195 into opensearch-project:main Apr 17, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 17, 2023
* adds uiActions to visBuilder
* prevents multiple errors on load
* fixes visbuilder type errors
* fixes save
* updates changelog

---------

Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
(cherry picked from commit 1edb195)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
ashwin-pc pushed a commit that referenced this pull request Apr 17, 2023
…bug fixes (#3857)

* [VisBuilder] 2 way communication using UI actions and bug fixes (#3732)

* adds uiActions to visBuilder
* prevents multiple errors on load
* fixes visbuilder type errors
* fixes save
* updates changelog

---------

Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
(cherry picked from commit 1edb195)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

* add changelog

Signed-off-by: Josh Romero <rmerqg@amazon.com>

---------

Signed-off-by: Josh Romero <rmerqg@amazon.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
sikhote pushed a commit to sikhote/OpenSearch-Dashboards that referenced this pull request Apr 24, 2023
…search-project#3732)

* adds uiActions to visBuilder
* prevents multiple errors on load
* fixes visbuilder type errors
* fixes save
* updates changelog

---------

Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: David Sinclair <david@sinclair.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants