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 unsaved changes bug on empty dashboard #155648

Conversation

Heenawter
Copy link
Contributor

@Heenawter Heenawter commented Apr 24, 2023

Summary

Before

When loading a dashboard with no panels but at least one control, the diffingMiddleware was not being fired - this caused a bug where making selections in the control (which were not saved into the dashboard) would not trigger unsaved changes on reload/refresh:

Screen.Recording.2023-04-24.at.10.29.11.AM.mov

After

This was because, when the dashboard had no children, no Redux state changes were being dispatched to the Dashboard container which meant that the middleware was never triggered - this is fixed by adding startWith(null) (reference) to the checkForUnsavedChangesSubject$ subscription so that it always fires on load.

Screen.Recording.2023-04-24.at.11.01.24.AM.mov

Checklist

For maintainers

@Heenawter Heenawter added bug Fixes for quality problems that affect the customer experience release_note:fix Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas loe:small Small Level of Effort impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. labels Apr 24, 2023
@Heenawter Heenawter self-assigned this Apr 24, 2023
@Heenawter Heenawter added v8.8.0 backport:skip This commit does not require backporting labels Apr 24, 2023
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

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
dashboard 433.8KB 433.9KB +26.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 17 19 +2
securitySolution 395 398 +3
total +5

Total ESLint disabled count

id before after diff
enterpriseSearch 18 20 +2
securitySolution 475 478 +3
total +5

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 April 24, 2023 17:39
@Heenawter Heenawter requested a review from a team as a code owner April 24, 2023 17:39
@elasticmachine
Copy link
Contributor

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

@cqliu1 cqliu1 self-requested a review April 24, 2023 21:02
Copy link
Contributor

@cqliu1 cqliu1 left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Tested this locally, and it works as described. Nice catch!

@Heenawter Heenawter merged commit 60fedce into elastic:main Apr 25, 2023
@Heenawter Heenawter deleted the fix-unsaved-changes-on-empty-dashboard_2023-04-24 branch April 25, 2023 15:05
Heenawter added a commit that referenced this pull request Apr 28, 2023
Closes #155777

## Summary

The `"replaces panel with incoming embeddable if id matches existing
panel"` test was **not** the flaky one, even though it was the one that
showed the failure; it was actually one of the previous `"pulls state
<...>"` tests that was failing, which was pretty confusing to catch 🤦

Basically, because we are [running the unsaved changes check on load
now](#155648), depending on the
timing of the `debounce` on the `checkForUnsavedChangesSubject$`
subscription it would sometimes run for the `"pulls state <...>"` tests
(but not always) - so whenever it **would** run, because the mocked
`loadDashboardStateFromSavedObject` was only returning a partial
Dashboard input, this would result in trying to get the property of
`undefined` when checking for filter changes, panel changes, etc.

This is fixed by ensuring that the `loadDashboardStateFromSavedObject`
returns a complete Dashboard input, with all the required keys, for all
of the relevant tests. Note that, since you can't test Jest unit tests
using the flaky test runner, I was able to run it multiple times by
surrounding all the tests with the following in order to ensure that it
was no longer flaky:

```typescript
for (const i of Array(x)
  .fill(null)
  .map((_, i) => i)) {
  describe(`test run ${i}`, () => {
    <...> // all the tests go here
  });
};
```

I did this with `x = 200`, and the entire test suite passed 200 times in
a row 👍

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 28, 2023
Closes elastic#155777

## Summary

The `"replaces panel with incoming embeddable if id matches existing
panel"` test was **not** the flaky one, even though it was the one that
showed the failure; it was actually one of the previous `"pulls state
<...>"` tests that was failing, which was pretty confusing to catch 🤦

Basically, because we are [running the unsaved changes check on load
now](elastic#155648), depending on the
timing of the `debounce` on the `checkForUnsavedChangesSubject$`
subscription it would sometimes run for the `"pulls state <...>"` tests
(but not always) - so whenever it **would** run, because the mocked
`loadDashboardStateFromSavedObject` was only returning a partial
Dashboard input, this would result in trying to get the property of
`undefined` when checking for filter changes, panel changes, etc.

This is fixed by ensuring that the `loadDashboardStateFromSavedObject`
returns a complete Dashboard input, with all the required keys, for all
of the relevant tests. Note that, since you can't test Jest unit tests
using the flaky test runner, I was able to run it multiple times by
surrounding all the tests with the following in order to ensure that it
was no longer flaky:

```typescript
for (const i of Array(x)
  .fill(null)
  .map((_, i) => i)) {
  describe(`test run ${i}`, () => {
    <...> // all the tests go here
  });
};
```

I did this with `x = 200`, and the entire test suite passed 200 times in
a row 👍

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 5779773)
kibanamachine added a commit that referenced this pull request Apr 28, 2023
# Backport

This will backport the following commits from `main` to `8.8`:
- [[Dashboard] Fix flaky Dashboard create tests
(#156085)](#156085)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Hannah
Mudge","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-04-28T14:14:12Z","message":"[Dashboard]
Fix flaky Dashboard create tests (#156085)\n\nCloses
https://github.com/elastic/kibana/issues/155777\r\n\r\n##
Summary\r\n\r\nThe `\"replaces panel with incoming embeddable if id
matches existing\r\npanel\"` test was **not** the flaky one, even though
it was the one that\r\nshowed the failure; it was actually one of the
previous `\"pulls state\r\n<...>\"` tests that was failing, which was
pretty confusing to catch 🤦\r\n\r\nBasically, because we are [running
the unsaved changes check on
load\r\nnow](#155648), depending
on the\r\ntiming of the `debounce` on the
`checkForUnsavedChangesSubject# Backport

This will backport the following commits from `main` to `8.8`:
- [[Dashboard] Fix flaky Dashboard create tests
(#156085)](#156085)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT \r\nsubscription it would sometimes run for the `\"pulls
state <...>\"` tests\r\n(but not always) - so whenever it **would** run,
because the mocked\r\n`loadDashboardStateFromSavedObject` was only
returning a partial\r\nDashboard input, this would result in trying to
get the property of\r\n`undefined` when checking for filter changes,
panel changes, etc.\r\n\r\nThis is fixed by ensuring that the
`loadDashboardStateFromSavedObject`\r\nreturns a complete Dashboard
input, with all the required keys, for all\r\nof the relevant tests.
Note that, since you can't test Jest unit tests\r\nusing the flaky test
runner, I was able to run it multiple times by\r\nsurrounding all the
tests with the following in order to ensure that it\r\nwas no longer
flaky:\r\n\r\n```typescript\r\nfor (const i of Array(x)\r\n
.fill(null)\r\n .map((_, i) => i)) {\r\n describe(`test run ${i}`, () =>
{\r\n <...> // all the tests go here\r\n });\r\n};\r\n```\r\n\r\nI did
this with `x = 200`, and the entire test suite passed 200 times in\r\na
row 👍\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"57797731905b0303eec9059e398388826c88fa5f","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Presentation","loe:days","release_note:skip","impact:critical","v8.8.0","v8.9.0"],"number":156085,"url":"https://github.com/elastic/kibana/pull/156085","mergeCommit":{"message":"[Dashboard]
Fix flaky Dashboard create tests (#156085)\n\nCloses
https://github.com/elastic/kibana/issues/155777\r\n\r\n##
Summary\r\n\r\nThe `\"replaces panel with incoming embeddable if id
matches existing\r\npanel\"` test was **not** the flaky one, even though
it was the one that\r\nshowed the failure; it was actually one of the
previous `\"pulls state\r\n<...>\"` tests that was failing, which was
pretty confusing to catch 🤦\r\n\r\nBasically, because we are [running
the unsaved changes check on
load\r\nnow](#155648), depending
on the\r\ntiming of the `debounce` on the
`checkForUnsavedChangesSubject# Backport

This will backport the following commits from `main` to `8.8`:
- [[Dashboard] Fix flaky Dashboard create tests
(#156085)](#156085)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT \r\nsubscription it would sometimes run for the `\"pulls
state <...>\"` tests\r\n(but not always) - so whenever it **would** run,
because the mocked\r\n`loadDashboardStateFromSavedObject` was only
returning a partial\r\nDashboard input, this would result in trying to
get the property of\r\n`undefined` when checking for filter changes,
panel changes, etc.\r\n\r\nThis is fixed by ensuring that the
`loadDashboardStateFromSavedObject`\r\nreturns a complete Dashboard
input, with all the required keys, for all\r\nof the relevant tests.
Note that, since you can't test Jest unit tests\r\nusing the flaky test
runner, I was able to run it multiple times by\r\nsurrounding all the
tests with the following in order to ensure that it\r\nwas no longer
flaky:\r\n\r\n```typescript\r\nfor (const i of Array(x)\r\n
.fill(null)\r\n .map((_, i) => i)) {\r\n describe(`test run ${i}`, () =>
{\r\n <...> // all the tests go here\r\n });\r\n};\r\n```\r\n\r\nI did
this with `x = 200`, and the entire test suite passed 200 times in\r\na
row 👍\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"57797731905b0303eec9059e398388826c88fa5f"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156085","number":156085,"mergeCommit":{"message":"[Dashboard]
Fix flaky Dashboard create tests (#156085)\n\nCloses
https://github.com/elastic/kibana/issues/155777\r\n\r\n##
Summary\r\n\r\nThe `\"replaces panel with incoming embeddable if id
matches existing\r\npanel\"` test was **not** the flaky one, even though
it was the one that\r\nshowed the failure; it was actually one of the
previous `\"pulls state\r\n<...>\"` tests that was failing, which was
pretty confusing to catch 🤦\r\n\r\nBasically, because we are [running
the unsaved changes check on
load\r\nnow](#155648), depending
on the\r\ntiming of the `debounce` on the
`checkForUnsavedChangesSubject# Backport

This will backport the following commits from `main` to `8.8`:
- [[Dashboard] Fix flaky Dashboard create tests
(#156085)](#156085)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT \r\nsubscription it would sometimes run for the `\"pulls
state <...>\"` tests\r\n(but not always) - so whenever it **would** run,
because the mocked\r\n`loadDashboardStateFromSavedObject` was only
returning a partial\r\nDashboard input, this would result in trying to
get the property of\r\n`undefined` when checking for filter changes,
panel changes, etc.\r\n\r\nThis is fixed by ensuring that the
`loadDashboardStateFromSavedObject`\r\nreturns a complete Dashboard
input, with all the required keys, for all\r\nof the relevant tests.
Note that, since you can't test Jest unit tests\r\nusing the flaky test
runner, I was able to run it multiple times by\r\nsurrounding all the
tests with the following in order to ensure that it\r\nwas no longer
flaky:\r\n\r\n```typescript\r\nfor (const i of Array(x)\r\n
.fill(null)\r\n .map((_, i) => i)) {\r\n describe(`test run ${i}`, () =>
{\r\n <...> // all the tests go here\r\n });\r\n};\r\n```\r\n\r\nI did
this with `x = 200`, and the entire test suite passed 200 times in\r\na
row 👍\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"57797731905b0303eec9059e398388826c88fa5f"}}]}]
BACKPORT-->

Co-authored-by: Hannah Mudge <[email protected]>
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 impact:low Addressing this issue will have a low 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.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants