[Lens] Simplify state management from visualization#58279
[Lens] Simplify state management from visualization#58279wylieconlon merged 26 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/kibana-app (Team:KibanaApp) |
|
|
||
| renderLayerContextMenu?: (domElement: Element, props: VisualizationLayerConfigProps<T>) => void; | ||
|
|
||
| getLayerOptions: (props: VisualizationLayerConfigProps<T>) => VisualizationLayerConfigResult; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
For reviewers: The 'Add a configuration' button is no longer owned by the datasource.
| layerId, | ||
| dateRange, | ||
| }: PublicAPIProps<IndexPatternPrivateState>) { | ||
| renderDimensionTrigger: ( |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
For reviewers: This call to generateId() is important. I will write some other comments here explaining why.
| }) | ||
| ); | ||
| } | ||
| }} |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
For reviewers: This is an indentation change, not a behavior change.
x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/config_panel_wrapper.tsx
Show resolved
Hide resolved
| {datasourcePublicAPI && ( | ||
| <EuiFlexItem className="eui-textTruncate"> | ||
| <NativeRenderer | ||
| render={datasourcePublicAPI.renderLayerPanel} |
There was a problem hiding this comment.
For reviewers: This is an indentation change. renderLayerPanel currently renders the name of the index pattern on each layer.
x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/_dimension_panel.scss
Show resolved
Hide resolved
cchaos
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
| // sass-lint:disable-block no-important | |
| // Remove EuiButton's default shadow to make button more subtle | |
| // sass-lint:disable-block no-important |
|
@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. |
| datasourceId: 'testDatasource', | ||
| renderLayerPanel: jest.fn(), | ||
| renderDimensionPanel: jest.fn(), | ||
| // renderDimensionPanel: jest.fn(), |
There was a problem hiding this comment.
Reminder for commented out code.
| // 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) { |
There was a problem hiding this comment.
nitpick, we could probably do el?.blur
| props.togglePopover(); | ||
| }} | ||
| data-test-subj="lns-dimensionTrigger" | ||
| aria-label={i18n.translate('xpack.lens.configure.editConfig', { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 <></>; |
There was a problem hiding this comment.
Could we return null instead here?
| }; | ||
| }, | ||
|
|
||
| setDimension({ layerId, columnId, prevState }) { |
There was a problem hiding this comment.
nit: for readability we could change the order with matching removeDimension params order
| setDimension({ layerId, columnId, prevState }) { | |
| setDimension({ prevState, columnId, layerId }) { |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
|
Re-tested locally on Chrome, LGTM. |
* [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
* 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)
* 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) ...
* 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) ...



Release note
Lens now shows a warning when you have partially configured a visualization, such as a bar chart with only an X axis
Developer notes
This change is a combination of: