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

[Control Group] Add Button & Minimal Editor Settings #151161

Conversation

ThomThomson
Copy link
Contributor

@ThomThomson ThomThomson commented Feb 14, 2023

Closes #151198

Summary

Adds an "add" button that shows up to the right of the Control Group if configured. Also adds a system for fetching settings from consumers, and adds settings that can hide or show pieces of the Control editor flyout.

Also adds an example showing how to use these new systems.

Simplified Editor

@ThomThomson ThomThomson added release_note:enhancement Feature:Dashboard Dashboard related features Feature:Input Control Input controls visualization Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas loe:medium Medium Level of Effort impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. v8.8.0 labels Feb 14, 2023
@ThomThomson ThomThomson marked this pull request as ready for review February 15, 2023 18:13
@ThomThomson ThomThomson requested review from a team as code owners February 15, 2023 18:13
@elasticmachine
Copy link
Contributor

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

@andreadelrio
Copy link
Contributor

@ThomThomson could the showAddButton prop take any React node in case consumers want to pass a different type of button or a button with text instead of a EuiButtonIcon?

@jennypavlova jennypavlova self-requested a review February 15, 2023 18:41
@ThomThomson
Copy link
Contributor Author

@andreadelrio that very much depends on how flexible we want this button to be. As I see it, there are currently two options to get this add dialog to show up:

  1. pass in the showAddButton prop as true. This will show the default design of the button in the default location.
  2. On click of any button with any design, placed in any location call controlGroupApi.openAddDataControlFlyout from the control group API.

Allowing showAddButton to take any react node would add a third option:

  1. Pass in a react node to show any button in the default location.

Do you think this third option would be used often? I think it might be better to ensure that the default design / location is ideal for the largest number of use-cases for consistency, but to leave that workaround using the API open and accessible.

@andreadelrio
Copy link
Contributor

@andreadelrio that very much depends on how flexible we want this button to be. As I see it, there are currently two options to get this add dialog to show up:

  1. pass in the showAddButton prop as true. This will show the default design of the button in the default location.
  2. On click of any button with any design, placed in any location call controlGroupApi.openAddDataControlFlyout from the control group API.

Allowing showAddButton to take any react node would add a third option:

  1. Pass in a react node to show any button in the default location.

Do you think this third option would be used often? I think it might be better to ensure that the default design / location is ideal for the largest number of use-cases for consistency, but to leave that workaround using the API open and accessible.

I agree. Let's leave it as-is then. Consumers that want to use the default design/location can opt for (1), otherwise they can do (2).

@ThomThomson
Copy link
Contributor Author

Here is the default button design:

Screen Shot test

Thanks for the guidance @andreadelrio!

@Heenawter Heenawter self-requested a review February 15, 2023 22:05
Copy link
Contributor

@Heenawter Heenawter 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 + tested new example + tested Maps timeslider. Everything worked great - just left one tiny nit about the new button 👍

Comment on lines 160 to 166
<EuiButtonIcon
size="s"
iconSize="m"
display="base"
iconType={'plusInCircle'}
onClick={() => controlGroup.openAddDataControlFlyout()}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We should probably add an aria-label here, since it's an icon-only button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good call! Added!

@@ -99,6 +100,10 @@ export const ControlEditor = ({
dataViews: { getIdsWithTitle, getDefaultId, get },
controls: { getControlFactory },
} = pluginServices.getServices();

const { useEmbeddableSelector: select } = useControlGroupContainerContext();
const editorConfig = select((state) => state.componentState.editorConfig);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need to change this in this PR, but we should probably structure all the different hide<...> options list settings the same way... i.e. something like:

optionsListConfig: { 
     hideActionBar?: boolean,
     hideExclude?: boolean,
     ...
}

I think that would be a whole lot cleaner than it currently is 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good call - likely we should change that! Especially because it's only used via code. Might do that in a follow--up!

Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

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

Infrastructure UI (Hosts View) changes look good! We don't use the edit functionality at the moment and everything works as expected. It could be interesting for us to try the edit functionality maybe in the future.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

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
controls 266 268 +2

Async chunks

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

id before after diff
controls 178.4KB 179.2KB +772.0B
infra 1.3MB 1.3MB +18.0B
maps 2.7MB 2.7MB +24.0B
securitySolution 13.8MB 13.8MB +18.0B
total +832.0B

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
controls 9 11 +2

Page load bundle

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

id before after diff
controls 32.1KB 32.1KB +46.0B
Unknown metric groups

API count

id before after diff
controls 270 272 +2

History

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

Copy link
Contributor

@logeekal logeekal left a comment

Choose a reason for hiding this comment

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

Functionality working great.. But in security solution, I am seeing a little lag ( see video below ). Since in your example it is running fine, it could be something I am doing wrong or maybe because of number of fields in the dataview mapping.

Screen.Recording.2023-02-23.at.13.26.35.mov

export interface ControlGroupSettings {
showAddButton?: boolean;
staticDataViewId?: string;
editorConfig?: {
Copy link
Contributor

Choose a reason for hiding this comment

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

🥳

updateTitle={(newTitle) => (controlInput.title = newTitle)}
updateWidth={(defaultControlWidth) => this.updateInput({ defaultControlWidth })}
updateGrow={(defaultControlGrow: boolean) => this.updateInput({ defaultControlGrow })}
onSave={(type) => {
Copy link
Contributor

@logeekal logeekal Feb 23, 2023

Choose a reason for hiding this comment

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

nit: should it be a useCallback function?

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 think that useCallback is not required in this case due to openAddDataControlFlyout being an imperative function call and not a react component, so it gets rendered once as part of the useMountPoint call, and is in a different react tree.

@ThomThomson
Copy link
Contributor Author

ThomThomson commented Feb 23, 2023

@logeekal, thanks for the review! For the performance issue, I believe it is indeed the number of fields in the data view. In #151231, I updated the field list to use EUI Selectable which is virtualized and should support many more fields without creating browser lag.

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

kibana-gis changes LGTM
code review

@ThomThomson ThomThomson merged commit f77f924 into elastic:main Feb 23, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Feb 23, 2023
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:Dashboard Dashboard related features Feature:Input Control Input controls visualization impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:medium Medium Level of Effort release_note:enhancement Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Controls] Allow Consumers to Hide Pieces of Editor
9 participants