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

[Lens] Simplify state management from visualization #58279

Merged
merged 26 commits into from
Mar 17, 2020

Conversation

wylieconlon
Copy link
Contributor

@wylieconlon wylieconlon commented Feb 21, 2020

Release note

Lens now shows a warning when you have partially configured a visualization, such as a bar chart with only an X axis

Screenshot 2020-03-11 17 10 35

Developer notes

This change is a combination of:

  • Making the right side configuration panel consistent for all visualizations
  • Drag & drop behavior is not just for one datasource- any datasource can now use this
  • Visualizations now have a way of knowing when they have empty columns, which was not possible before

@wylieconlon wylieconlon added Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens labels Feb 21, 2020
@elasticmachine
Copy link
Contributor

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

@wylieconlon wylieconlon marked this pull request as ready for review March 6, 2020 23:31
@wylieconlon wylieconlon requested review from a team, timroes and mbondyra March 6, 2020 23:31
renderLayerContextMenu?: (domElement: Element, props: VisualizationLayerConfigProps<T>) => void;

getLayerOptions: (props: VisualizationLayerConfigProps<T>) => VisualizationLayerConfigResult;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: This line of code is one of the key changes. Visualizations are no longer allowed to have a renderDimensionPanel method, and instead provide an object that defines what the right side panel does https://github.com/elastic/kibana/pull/58279/files#diff-6ae9ccca58dffda903f0e2042bcf455bR258

renderDimensionTrigger: (domElement: Element, props: DatasourceDimensionTriggerProps<T>) => void;
renderDimensionEditor: (domElement: Element, props: DatasourceDimensionEditorProps<T>) => void;
canHandleDrop: (props: DatasourceDimensionDropProps<T>) => boolean;
onDrop: (props: DatasourceDimensionDropHandlerProps<T>) => boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: one of the best changes I've done here is to make drag & drop behavior and popover behavior into a feature of the Lens editor, not a feature of the data source. This will let us add new datasources.

<EuiLink
className="lnsPopoverEditor__link"
onClick={() => {
setPopoverOpen(!isPopoverOpen);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: Notice that we have removed EuiPopover from the dimension editor. This logic is moved into the Editor Frame.

id="xpack.lens.configure.emptyConfig"
defaultMessage="Drop a field here"
/>
</EuiButtonEmpty>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: The 'Add a configuration' button is no longer owned by the datasource.

layerId,
dateRange,
}: PublicAPIProps<IndexPatternPrivateState>) {
renderDimensionTrigger: (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: renderDimensionTrigger is only rendering the clickable link. It has almost no behavior any more.

<EuiSpacer size="s" />

{dimensions.map((dimension, index) => {
const newId = generateId();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: This call to generateId() is important. I will write some other comments here explaining why.

})
);
}
}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: Notice that the generated ID is used multiple times in the drop interaction. This guarantees that both the datasource and visualization agree on the ID.

el.blur();
}

onRemove();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: This is an indentation change, not a behavior change.

{datasourcePublicAPI && (
<EuiFlexItem className="eui-textTruncate">
<NativeRenderer
render={datasourcePublicAPI.renderLayerPanel}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: This is an indentation change. renderLayerPanel currently renders the name of the index pattern on each layer.

@wylieconlon wylieconlon requested a review from a team as a code owner March 9, 2020 21:04
Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Something really funky is happening to the config panel.

The sizes of the dimension panels are wrong
Screen Shot 2020-03-10 at 10 00 35 AM

and when there's a configuration, it's gets even funkier
Screen Shot 2020-03-10 at 10 01 19 AM

Also I found a rogue )

Screen Shot 2020-03-10 at 10 00 04 AM

x-pack/legacy/plugins/lens/public/_config_panel.scss Outdated Show resolved Hide resolved
Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

The styles seem to be back in place now. I do think that ConfigPanelWrapper could be broken down into smaller components since the file is quite large. And same with the PopoverEditor which I got quite lost in trying ensure class name updates and consistency. But testing in the UI, it all seems to be back where it was so 🤷‍♀ .


.lnsConfigPanel__addLayerBtn {
color: transparentize($euiColorMediumShade, .3);
// sass-lint:disable-block no-important
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// sass-lint:disable-block no-important
// Remove EuiButton's default shadow to make button more subtle
// sass-lint:disable-block no-important

@mbondyra
Copy link
Contributor

mbondyra commented Mar 13, 2020

@wylieconlon I think when it comes to the behaviour, I have nothing else to add. I checked on master and I think that the bug 1 behaves better there (or I actually am not seeing the bug there), the rest is the same.

renderLayerPanel: jest.fn(),
renderDimensionPanel: jest.fn(),
// renderDimensionPanel: jest.fn(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Reminder for commented out code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// activeElement does not have blur so, we need to do some casting + safeguards.
const el = (document.activeElement as unknown) as { blur: () => void };

if (el && el.blur) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick, we could probably do el?.blur

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

props.togglePopover();
}}
data-test-subj="lns-dimensionTrigger"
aria-label={i18n.translate('xpack.lens.configure.editConfig', {
Copy link
Contributor

Choose a reason for hiding this comment

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

We're trying not to have two i18n.translate calls with the same id in it, since it's prone to introduce errors where default messages vary later on. Could we please just call this once and store it within a variable that is used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not possible to have two i18n IDs with different default messages. It's checked automatically. How important is this?

const layerId = props.layerId;
const currentIndexPattern =
props.state.indexPatterns[props.state.layers[layerId]?.indexPatternId];
const operationFieldSupportMatrix = getOperationFieldSupportMatrix(props);
Copy link
Contributor

@mbondyra mbondyra Mar 13, 2020

Choose a reason for hiding this comment

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

Shouldn't it have to be memoized just like it was before? 🤔 I noticed you memoized the whole component but as the function output depends on currentIndexPattern and filterOperations, maybe it's worth to do it too?

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 would like it to be memoized, but I couldn't find a way to do it safely. Each dimension needs to be memoized separately.

const datasourcePublicAPI = framePublicAPI.datasourceLayers[layerId];
const layerConfigProps = {
if (!datasourcePublicAPI) {
return <></>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we return null instead here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

};
},

setDimension({ layerId, columnId, prevState }) {
Copy link
Contributor

@mbondyra mbondyra Mar 13, 2020

Choose a reason for hiding this comment

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

nit: for readability we could change the order with matching removeDimension params order

Suggested change
setDimension({ layerId, columnId, prevState }) {
setDimension({ prevState, columnId, layerId }) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@wylieconlon wylieconlon requested review from mbondyra and timroes March 16, 2020 19:36
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@mbondyra
Copy link
Contributor

Re-tested locally on Chrome, LGTM.

Copy link
Contributor

@timroes timroes left a comment

Choose a reason for hiding this comment

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

Checked code, LGTM

@wylieconlon wylieconlon merged commit caed9ba into elastic:master Mar 17, 2020
@wylieconlon wylieconlon deleted the lens/simplify-configuration branch March 17, 2020 13:57
wylieconlon pushed a commit that referenced this pull request Mar 17, 2020
* [Lens] Declarative right panel

* Fix memoized operations

* Add error checking

* Fix dimension panel tests

* More updates

* Fix all editor frame tests

* Fix jest tests

* Fix bug with removing dimension

* Update tests

* Fix frame tests

* Fix all tests I could find

* Remove debugger

* Style config panels

* Update i18n

* Fix dashboard test

* Fix bug when switching index patterns
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 17, 2020
* master:
  [SIEM] Adds 'Closes one signal when more than one opened signals are selected' test again (elastic#60380)
  [SIEM][Detections Engine] - Add rule markdown field to rule create, detail, and edit flows (elastic#60108)
  [Fleet] Add config revision to fleet agents (elastic#60292)
  Allow kbn-config-schema to ignore unknown keys (elastic#59560)
  [ML] Functional tests - disable df analytics clone tests
  skip flaky suite (elastic#58643) (elastic#58991)
  [FTR] Add support for --include and --exclude files via tags (elastic#60123)
  [SIEM] Fix link on overview page (elastic#60348)
  skip flaky test (elastic#60369)
  [Endpoint] Adds take action dropdown and tests to alert details flyout (elastic#59242)
  [Lens] Simplify state management from visualization (elastic#58279)
  Changing default type to start and allowing it to be configured by the event category (elastic#60323)
  [ML] Adds the class_assignment_objective to classification (elastic#60358)
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 17, 2020
* master: (51 commits)
  do not update cell background if is label cell (elastic#60308)
  FTR configurable test users (elastic#52431)
  [Reporting] Wholesale moves client to newest-platform (elastic#58945)
  [Ingest] Support `show_user` package registry flag (elastic#60338)
  [SIEM] Adds 'Closes one signal when more than one opened signals are selected' test again (elastic#60380)
  [SIEM][Detections Engine] - Add rule markdown field to rule create, detail, and edit flows (elastic#60108)
  [Fleet] Add config revision to fleet agents (elastic#60292)
  Allow kbn-config-schema to ignore unknown keys (elastic#59560)
  [ML] Functional tests - disable df analytics clone tests
  skip flaky suite (elastic#58643) (elastic#58991)
  [FTR] Add support for --include and --exclude files via tags (elastic#60123)
  [SIEM] Fix link on overview page (elastic#60348)
  skip flaky test (elastic#60369)
  [Endpoint] Adds take action dropdown and tests to alert details flyout (elastic#59242)
  [Lens] Simplify state management from visualization (elastic#58279)
  Changing default type to start and allowing it to be configured by the event category (elastic#60323)
  [ML] Adds the class_assignment_objective to classification (elastic#60358)
  [TSVB] fix text color when using custom background color (elastic#60261)
  Fix import to timefilter from in TSVB (elastic#60296)
  [NP] Get rid of usage redirectWhenMissing service (elastic#59777)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 17, 2020
* alerting/view-in-app: (53 commits)
  fixed typo
  handle optional alerting plugin
  do not update cell background if is label cell (elastic#60308)
  FTR configurable test users (elastic#52431)
  [Reporting] Wholesale moves client to newest-platform (elastic#58945)
  [Ingest] Support `show_user` package registry flag (elastic#60338)
  [SIEM] Adds 'Closes one signal when more than one opened signals are selected' test again (elastic#60380)
  [SIEM][Detections Engine] - Add rule markdown field to rule create, detail, and edit flows (elastic#60108)
  [Fleet] Add config revision to fleet agents (elastic#60292)
  Allow kbn-config-schema to ignore unknown keys (elastic#59560)
  [ML] Functional tests - disable df analytics clone tests
  skip flaky suite (elastic#58643) (elastic#58991)
  [FTR] Add support for --include and --exclude files via tags (elastic#60123)
  [SIEM] Fix link on overview page (elastic#60348)
  skip flaky test (elastic#60369)
  [Endpoint] Adds take action dropdown and tests to alert details flyout (elastic#59242)
  [Lens] Simplify state management from visualization (elastic#58279)
  Changing default type to start and allowing it to be configured by the event category (elastic#60323)
  [ML] Adds the class_assignment_objective to classification (elastic#60358)
  [TSVB] fix text color when using custom background color (elastic#60261)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants