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

Compute dashboard panel selection list lazily #187797

Merged

Conversation

eokoneyo
Copy link
Contributor

@eokoneyo eokoneyo commented Jul 8, 2024

Summary

Closes #187587

This PR changes how the dashboard panel selection items get computed, it had previously been computed eagerly, in this implementation panel selection items would only be computed when the user actually clicks the add panel button, with it's results cached so that subsequent interactions with the add panel button leverages the already computed data.

Notable Mention:
The options presented as the dashboard panel list now only comprise of uiActions specifically registered with the uiAction trigger ADD_PANEL_TRIGGER and specific dashboard visualisation types. See #187797 (comment) to follow the reasoning behind this.

That been said adding new panels to the dashboard, would be something along the following lines;

import { ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public';

 uiActions.attachAction(ADD_PANEL_TRIGGER, <registredActionId>);

// alternatively
// uiActions.addTriggerAction(ADD_PANEL_TRIGGER, ...someActionDefintion);

Visuals

Untitled.mov

How to test

  • Navigate to a dashboard of choice
  • Slow down your network speed using your browser dev tools, refresh your dashboard, and click on the “Add panel” button as soon as it is available (before the panels have a chance to load).
  • You should be presented with a loading indicator, that eventually is swapped out for the list of panels available for selection.

Checklist

Delete any items that are not applicable to this PR.

@eokoneyo eokoneyo added bug Fixes for quality problems that affect the customer experience Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas Project:Dashboard Usability Related to the Dashboard Usability initiative labels Jul 8, 2024
@eokoneyo eokoneyo self-assigned this Jul 8, 2024
@eokoneyo eokoneyo force-pushed the fix/resolve-187587-lazy-panel-option-loading branch from 5a9f898 to b73af33 Compare July 8, 2024 20:01
@eokoneyo
Copy link
Contributor Author

eokoneyo commented Jul 8, 2024

/ci

@eokoneyo eokoneyo force-pushed the fix/resolve-187587-lazy-panel-option-loading branch from b73af33 to 6b9e897 Compare July 9, 2024 11:59
@eokoneyo
Copy link
Contributor Author

eokoneyo commented Jul 9, 2024

/ci

@eokoneyo eokoneyo force-pushed the fix/resolve-187587-lazy-panel-option-loading branch from fb6628d to 461af98 Compare July 10, 2024 14:41
@eokoneyo
Copy link
Contributor Author

/ci

@eokoneyo eokoneyo marked this pull request as ready for review July 10, 2024 16:40
@eokoneyo eokoneyo requested a review from a team as a code owner July 10, 2024 16:40
@elasticmachine
Copy link
Contributor

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

@eokoneyo eokoneyo added the release_note:skip Skip the PR/issue when compiling release notes label Jul 10, 2024
@eokoneyo eokoneyo changed the title Compute dashboard panel selection list lazily instead of eagerly Compute dashboard panel selection list lazily Jul 10, 2024
@eokoneyo eokoneyo force-pushed the fix/resolve-187587-lazy-panel-option-loading branch 4 times, most recently from d77ca3e to fcf2f79 Compare July 15, 2024 09:17
@nickpeihl nickpeihl self-requested a review July 15, 2024 20:43
...panelGroup,
items: sortGroupPanelsByOrder<PanelSelectionMenuItem>(
(panelGroup.items ?? []).concat(
// TODO: actually add grouping to vis type alias so we wouldn't randomly display an unintended item
Copy link
Member

Choose a reason for hiding this comment

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

Is this TODO expected to be accomplished in this PR or in a separate PR?

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 say it outside the scope this PR, it would be handled in a different PR.

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 also very close to removing Vis type aliases from this menu entirely, as the new Embeddable system uses only the ADD_PANEL_TRIGGER trigger to determine what shows up here.

}
});

return _factoryGroupMap;
Copy link
Member

Choose a reason for hiding this comment

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

Interestingly, even with a platinum license, I'm not seeing any factories returned from the groupUnwrappedEmbeddableFactoriesMap. Many embeddables have migrated to React embeddables which do not apply here. The remaining class based embeddables are excluded by other conditionals, e.g. Lens canCreateNew returns false, Controls are containers, visualize exclusion is hard-coded.

Unless I'm missing something, we might be able to completely remove this function. But maybe we should wait until all class-based embeddables are removed? @nreese @ThomThomson what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Great research! I think we should be removing this kind of dead-code as soon as we possibly can.

Copy link
Member

@nickpeihl nickpeihl Jul 18, 2024

Choose a reason for hiding this comment

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

@eokoneyo and I discussed offline and we agreed to remove this groupUnwrappedEmbeddableFactoriesMap$ function from the code. There are currently only eight embeddables that are returned from the getEmbeddablesFactories method.

  1. dashboard - which is a container so it would be filtered out
  2. lens - which is filtered out because canCreateNew on the factory returns false.
  3. search - is also filtered out because canCreateNew returns false.
  4. visualization - is hard-coded to be filtered out
  5. controlGroup - is a container so it is filtered out

6 through 8. optionsList, rangeSlider, timeSlider which all return false from the canCreateNew method.

Additionally, all of these embeddables are in the process of being converted to React embeddables which are registered with the Add panel flyout using triggers. It is highly unlikely that Lens or Search embeddables will change the return value of their canCreateNew methods before the conversion to React embeddables is complete. So I am confident in removing this legacy function.

@eokoneyo eokoneyo force-pushed the fix/resolve-187587-lazy-panel-option-loading branch 2 times, most recently from 2d3e6a2 to 1a90316 Compare July 19, 2024 15:07
@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 19, 2024

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #34 / dashboard app - group 6 dashboard add ES|QL chart should add an ES|QL datatable chart when the ES|QL panel action is clicked
  • [job] [logs] FTR Configs #34 / dashboard app - group 6 dashboard add ES|QL chart should add an ES|QL datatable chart when the ES|QL panel action is clicked

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
dashboard 614 616 +2

Async chunks

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

id before after diff
dashboard 533.2KB 532.8KB -375.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
dashboard 10 9 -1

References to deprecated APIs

id before after diff
dashboard 48 47 -1

Total ESLint disabled count

id before after diff
dashboard 10 9 -1

History

cc @eokoneyo

Copy link
Member

@nickpeihl nickpeihl left a comment

Choose a reason for hiding this comment

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

lgtm! Thanks for removing the code handling the class-based embeddables. it is far simpler to read and removes a lot of legacy logic that is no longer needed.

code review and tested with both basic and premium licenses to verify the panel types appear correctly.

@eokoneyo eokoneyo force-pushed the fix/resolve-187587-lazy-panel-option-loading branch 2 times, most recently from 495f2b8 to 34f09a0 Compare July 23, 2024 09:11
@eokoneyo eokoneyo requested a review from a team as a code owner July 23, 2024 09:11
@eokoneyo eokoneyo force-pushed the fix/resolve-187587-lazy-panel-option-loading branch from 34f09a0 to ffac8d7 Compare July 23, 2024 09:13
@eokoneyo eokoneyo force-pushed the fix/resolve-187587-lazy-panel-option-loading branch from ffac8d7 to 0550869 Compare July 23, 2024 10:23
Comment on lines 35 to 55
export async function isCreateActionCompatible(
core: CoreStart,
editorFrameService: EditorFrameService
) {
let isCompatible: boolean = core.uiSettings.get(ENABLE_ESQL);

if (isCompatible && !getDatasourceMap() && !getVisualizationMap()) {
const [visualizationMap, datasourceMap] = await Promise.all([
editorFrameService.loadVisualizations(),
editorFrameService.loadDatasources(),
]);

if (visualizationMap && datasourceMap) {
setDatasourceMap(datasourceMap);
setVisualizationMap(visualizationMap);
} else {
isCompatible = false;
}
}

return isCompatible;
Copy link
Contributor Author

@eokoneyo eokoneyo Jul 23, 2024

Choose a reason for hiding this comment

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

Given this PR introduces change to fetch only UIActions registered with the trigger ADD_PANEL_TRIGGER it resulted in required data dependency that would have previously been made available when the classic lens Embeddable isEditable method gets invoked (v8.14.3/x-pack/plugins/lens/public/embeddable/embeddable_factory.ts#L70-L73) being missing as evident in the failing test above. The above change ensures that the required data is articulated as a dependency of the action and exists before the action's execute method is invoked.

@eokoneyo eokoneyo force-pushed the fix/resolve-187587-lazy-panel-option-loading branch 3 times, most recently from 956193c to efe7994 Compare July 23, 2024 14:32
@eokoneyo eokoneyo force-pushed the fix/resolve-187587-lazy-panel-option-loading branch from efe7994 to 9f3258a Compare July 24, 2024 19:20
Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

Tested and reviewed for Lens code. LGTM 👌🏼

Comment on lines 39 to 55
let isCompatible: boolean = core.uiSettings.get(ENABLE_ESQL);

if (isCompatible && (!getDatasourceMap() || !getVisualizationMap())) {
const [visualizationMap, datasourceMap] = await Promise.all([
editorFrameService.loadVisualizations(),
editorFrameService.loadDatasources(),
]);

if (visualizationMap && datasourceMap) {
setDatasourceMap(datasourceMap);
setVisualizationMap(visualizationMap);
} else {
isCompatible = false;
}
}

return isCompatible;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why introduce a side effect in the compatibility check?
Would it be best to move it within the execution flow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thought process here is, preemptively verify before execution that we'd have the data required to add the panel. Should this instead run at the execution point and we get no data back, the experience would mirror the failing test 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.

After speaking with @dej611 on slack we decided it's acceptable to have this side effect in the execution flow and halt the execution flow if it so happens that the required data dependency isn't available. 1017c76 addresses this change.

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
dashboard 614 616 +2

Async chunks

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

id before after diff
dashboard 533.4KB 533.1KB -328.0B
lens 1.5MB 1.5MB +188.0B
total -140.0B

Page load bundle

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

id before after diff
lens 50.0KB 50.2KB +187.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
dashboard 10 9 -1

References to deprecated APIs

id before after diff
dashboard 48 47 -1

Total ESLint disabled count

id before after diff
dashboard 10 9 -1

History

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

cc @eokoneyo

@eokoneyo eokoneyo requested a review from dej611 July 26, 2024 08:29
Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

Tested locally on Safari and it works 👍

@eokoneyo eokoneyo merged commit 6ddffb5 into elastic:main Jul 26, 2024
31 checks passed
@eokoneyo eokoneyo deleted the fix/resolve-187587-lazy-panel-option-loading branch July 26, 2024 11:54
@kibanamachine kibanamachine added v8.16.0 backport:skip This commit does not require backporting labels Jul 26, 2024
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 bug Fixes for quality problems that affect the customer experience Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Project:Dashboard Usability Related to the Dashboard Usability initiative release_note:skip Skip the PR/issue when compiling release notes Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add panel flyout does not load panel types
8 participants