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

[Dashboard] [Controls] Fix new controls causing unsaved changes bug #132850

Merged

Conversation

Heenawter
Copy link
Contributor

@Heenawter Heenawter commented May 24, 2022

Closes #132841

Summary

Before this change, when a new field was selected via creating a new control, the optional parentFieldName and childFieldName properties were being injected as undefined to the panels property of the controlGroupInput via the following code in control_editor.tsx:

...
onSelectField={(field) => {
  onTypeEditorChange({
    fieldName: field.name,
    parentFieldName: fieldRegistry?.[field.name].parentFieldName,
    childFieldName: fieldRegistry?.[field.name].childFieldName,
  }); 
...

However, when the control group panels are saved as JSON, all keys that have undefined values are dropped. This means that, when the control group inputs were compared in diffDashboardState, the old state would not have parent/childFieldName but they would both be undefined in the new state.

This PR prevents the initial injection by ensuring that both the parentFieldName and childFieldName have values before setting them. Therefore, we no longer have the issue of an undefined value being different than the key simply not existing in an object, so deepEqual works as expected.

Video

2022-05-24_ControlsUnsavedChangesCleared.mp4

Flaky Test Runner

image

Checklist

For maintainers

@Heenawter Heenawter added bug Fixes for quality problems that affect the customer experience Feature:Dashboard Dashboard related features release_note:fix Feature:Input Control Input controls visualization Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas loe:small Small Level of Effort impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. v8.3.0 labels May 24, 2022
@Heenawter Heenawter self-assigned this May 24, 2022
@Heenawter Heenawter force-pushed the fix-controls-unsaved-changes_2022-05-24 branch 3 times, most recently from 65b3b7f to 4ca5180 Compare May 24, 2022 23:06
describe('Dashboard options list integration', () => {
before(async () => {
await common.navigateToApp('dashboard');
await dashboard.gotoDashboardLandingPage();
await dashboard.clickNewDashboard();
await timePicker.setDefaultDataRange();
await elasticChart.setNewChartUiDebugFlag();
await dashboard.saveDashboard(DASHBOARD_NAME, { exitFromEditMode: false });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This bug was only present for existing dashboards, so need to save the dashboard before adding controls and testing to ensure that the unsaved changes badge can be cleared.

@Heenawter Heenawter force-pushed the fix-controls-unsaved-changes_2022-05-24 branch from 4ca5180 to d3859c9 Compare May 25, 2022 15:04
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #37 / console app console autocomplete feature with a missing comma in query should add a comma after the triple quoted strings

Metrics [docs]

Async chunks

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

id before after diff
controls 426.4KB 426.4KB +36.0B

History

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

cc @Heenawter

@Heenawter Heenawter marked this pull request as ready for review May 25, 2022 18:45
@Heenawter Heenawter requested a review from a team as a code owner May 25, 2022 18:45
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Really nice bugfix! Code only review and everything LGTM. Nice that it's mostly functional tests!

onTypeEditorChange({
fieldName: field.name,
parentFieldName: fieldRegistry?.[field.name].parentFieldName,
childFieldName: fieldRegistry?.[field.name].childFieldName,
...(parentFieldName && { parentFieldName }),
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@@ -102,6 +106,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
validateRange('placeholder', secondId, '100', '1200');
// data views should be properly propagated from the control group to the dashboard
expect(await filterBar.getIndexPatterns()).to.be('logstash-*,kibana_sample_data_flights');
await dashboard.clearUnsavedChanges();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice addition to call this after each test.

@Heenawter Heenawter merged commit f6086d9 into elastic:main May 25, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 25, 2022
@Heenawter Heenawter added auto-backport Deprecated: Automatically backport this PR after it's merged and removed backport:skip This commit does not require backporting labels Jun 8, 2022
@kibanamachine
Copy link
Contributor

⚪ Backport skipped

The pull request was not backported as there were no branches to backport to. If this is a mistake, please apply the desired version labels or run the backport tool manually.

Manual backport

To create the backport manually run:

node scripts/backport --pr 132850

Questions ?

Please refer to the Backport tool documentation

Heenawter added a commit to Heenawter/kibana that referenced this pull request Jun 8, 2022
…lastic#132850)

* Prevent injection of undefined parent/field names

* Add unsaved check to existing functional tests

(cherry picked from commit f6086d9)
@Heenawter Heenawter deleted the fix-controls-unsaved-changes_2022-05-24 branch June 8, 2022 16:34
@Heenawter Heenawter added backport:skip This commit does not require backporting and removed auto-backport Deprecated: Automatically backport this PR after it's merged labels Jun 8, 2022
Heenawter added a commit that referenced this pull request Jun 8, 2022
…132850) (#133922)

* Prevent injection of undefined parent/field names

* Add unsaved check to existing functional tests

(cherry picked from commit f6086d9)
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:Dashboard Dashboard related features Feature:Input Control Input controls visualization impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:small Small Level of Effort release_note:fix Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Dashboard][Controls] New Controls not Clearing Unsaved Changes Badge after Save
5 participants