feat(explore): Show confirmation modal if user exits Explore without saving changes (#19993)

* feat(explore): Show confirmation modal if user exits Explore without saving changes

* Fix calling cleanup func unnecessarily

* Fix comparing AdhocMetric instance with JSON object

* Replace sliceFormData with the initial form data
This commit is contained in:
Kamil Gabryjelski
2022-05-12 12:24:29 +02:00
committed by GitHub
parent 26c81a70e7
commit ca9766c109
5 changed files with 119 additions and 76 deletions

View File

@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { sanitizeFormData } from './formData';
import { sanitizeFormData, isEqualish } from './formData';
test('sanitizeFormData removes temporary control values', () => {
expect(
@@ -26,3 +26,25 @@ test('sanitizeFormData removes temporary control values', () => {
}),
).toEqual({ metrics: ['foo', 'bar'] });
});
test('isEqualish', () => {
// considers null, undefined, {} and [] as equal
expect(isEqualish(null, undefined)).toBe(true);
expect(isEqualish(null, [])).toBe(true);
expect(isEqualish(null, {})).toBe(true);
expect(isEqualish(undefined, {})).toBe(true);
// considers empty strings are the same as null
expect(isEqualish(undefined, '')).toBe(true);
expect(isEqualish(null, '')).toBe(true);
// considers deeply equal objects as equal
expect(isEqualish('', '')).toBe(true);
expect(isEqualish({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe(true);
// Out of order
expect(isEqualish({ a: 1, b: 2, c: 3 }, { b: 2, a: 1, c: 3 })).toBe(true);
// Actually not equal
expect(isEqualish({ a: 1, b: 2, z: 9 }, { a: 1, b: 2, c: 3 })).toBe(false);
});