Skip to content

Commit 6d428de

Browse files
fix: better way to wait for panel transition end
Before this change, we had a corner case when closing and reopening very fast a panel (example when a full redraw of a feature is needed, eg. switching from route to normal line), because the panel was considered closed, but the CSS transition was never run as the panel was in fact already in its final position. Co-authored-by: David Larlet <david@larlet.fr>
1 parent f21c81b commit 6d428de

File tree

5 files changed

+34
-52
lines changed

5 files changed

+34
-52
lines changed

umap/static/umap/css/form.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,6 @@ i.info {
549549
background-image: url('../img/16-white.svg');
550550
}
551551

552-
.with-transition {
553-
transition: all .7s;
554-
}
555-
556552
.umap-empty:before,
557553
.umap-to-polygon:before,
558554
.umap-clone:before,

umap/static/umap/js/modules/ui/panel.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ export class Panel {
5959
if (isOpen) {
6060
resolve(this)
6161
} else {
62-
this.container.addEventListener(
63-
'transitionend',
64-
() => {
65-
resolve(this)
66-
},
67-
{ once: true }
62+
Promise.all(
63+
this.container.getAnimations().map((animation) => animation.finished)
6864
)
65+
.then(() => {
66+
resolve(this)
67+
})
68+
.catch(() => {
69+
// Panel has been removed, so the DOM has changed, so the animations
70+
// were cancelled, we want the new panel callabck to be called anyway.
71+
resolve(this)
72+
})
6973
this.container.classList.add('on')
7074
}
7175
})

umap/static/umap/map.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ html[dir="rtl"] .leaflet-tooltip-pane>* {
2424
margin-inline-start: 5px;
2525
}
2626

27+
/* *********** */
28+
/* Generic */
29+
/* *********** */
30+
.with-transition {
31+
transition: all var(--transition);
32+
}
33+
2734
/* *********** */
2835
/* Map details */
2936
/* *********** */
@@ -1069,7 +1076,7 @@ ul.photon-autocomplete {
10691076
font-weight: bold;
10701077
}
10711078

1072-
.leaflet-overlay-pane > svg {
1079+
.leaflet-overlay-pane>svg {
10731080
z-index: var(--zindex-orphan-marker);
10741081
}
10751082

umap/static/umap/vars.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
--zindex-orphan-marker: 401;
6565

6666
--block-shadow: 0 1px 7px var(--color-mediumGray);
67+
--transition: 300ms;
6768
}
69+
6870
.dark {
6971
--background-color: var(--color-darkGray);
7072
--text-color: #efefef;

umap/tests/integration/test_import.py

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ def test_layers_list_is_updated(live_server, tilelayer, page):
2222
page.locator("[name=layer-id]").select_option(label="Import in a new layer")
2323
page.get_by_role("button", name="Manage layers").click()
2424
page.get_by_role("button", name="Add a layer").click()
25-
page.locator('input[name="name"]').click()
2625
page.locator('input[name="name"]').fill("foobar")
27-
page.wait_for_timeout(300) # Time for the input debounce.
26+
page.wait_for_timeout(300) # Wait for the input throttling.
2827
page.get_by_role("button", name=f"Import data ({modifier}+I)").click()
2928
# Should still work
3029
page.locator("[name=layer-id]").select_option(label="Import in a new layer")
@@ -108,9 +107,7 @@ def test_import_geojson_from_textarea(tilelayer, live_server, page):
108107
expect(markers).to_have_count(0)
109108
expect(paths).to_have_count(0)
110109
expect(layers).to_have_count(0)
111-
button = page.get_by_title("Import data")
112-
expect(button).to_be_visible()
113-
button.click()
110+
page.get_by_title("Import data").click()
114111
textarea = page.locator(".umap-import textarea")
115112
path = Path(__file__).parent.parent / "fixtures/test_upload_data.json"
116113
textarea.fill(path.read_text())
@@ -133,9 +130,7 @@ def test_import_invalid_data(tilelayer, live_server, page):
133130
expect(markers).to_have_count(0)
134131
expect(paths).to_have_count(0)
135132
expect(layers).to_have_count(0)
136-
button = page.get_by_title("Import data")
137-
expect(button).to_be_visible()
138-
button.click()
133+
page.get_by_title("Import data").click()
139134
textarea = page.locator(".umap-import textarea")
140135
textarea.fill("invalid data")
141136
for format in ["geojson", "csv", "gpx", "kml", "georss", "osm", "umap"]:
@@ -153,9 +148,7 @@ def test_import_kml_from_textarea(tilelayer, live_server, page):
153148
expect(markers).to_have_count(0)
154149
expect(paths).to_have_count(0)
155150
expect(layers).to_have_count(0)
156-
button = page.get_by_title("Import data")
157-
expect(button).to_be_visible()
158-
button.click()
151+
page.get_by_title("Import data").click()
159152
textarea = page.locator(".umap-import textarea")
160153
path = Path(__file__).parent.parent / "fixtures/test_upload_data.kml"
161154
textarea.fill(path.read_text())
@@ -177,9 +170,7 @@ def test_import_gpx_from_textarea(tilelayer, live_server, page, settings):
177170
expect(markers).to_have_count(0)
178171
expect(paths).to_have_count(0)
179172
expect(layers).to_have_count(0)
180-
button = page.get_by_title("Import data")
181-
expect(button).to_be_visible()
182-
button.click()
173+
page.get_by_title("Import data").click()
183174
textarea = page.locator(".umap-import textarea")
184175
path = Path(__file__).parent.parent / "fixtures/test_upload_data.gpx"
185176
textarea.fill(path.read_text())
@@ -234,9 +225,7 @@ def test_import_osm_from_textarea(tilelayer, live_server, page):
234225
markers = page.locator(".leaflet-marker-icon")
235226
expect(markers).to_have_count(0)
236227
expect(layers).to_have_count(0)
237-
button = page.get_by_title("Import data")
238-
expect(button).to_be_visible()
239-
button.click()
228+
page.get_by_title("Import data").click()
240229
textarea = page.locator(".umap-import textarea")
241230
path = Path(__file__).parent.parent / "fixtures/test_upload_data_osm.json"
242231
textarea.fill(path.read_text())
@@ -254,9 +243,7 @@ def test_import_csv_from_textarea(tilelayer, live_server, page):
254243
markers = page.locator(".leaflet-marker-icon")
255244
expect(markers).to_have_count(0)
256245
expect(layers).to_have_count(0)
257-
button = page.get_by_title("Import data")
258-
expect(button).to_be_visible()
259-
button.click()
246+
page.get_by_title("Import data").click()
260247
textarea = page.locator(".umap-import textarea")
261248
path = Path(__file__).parent.parent / "fixtures/test_upload_data.csv"
262249
textarea.fill(path.read_text())
@@ -422,9 +409,7 @@ def test_import_geometry_collection(live_server, page, tilelayer):
422409
expect(markers).to_have_count(0)
423410
expect(paths).to_have_count(0)
424411
expect(layers).to_have_count(0)
425-
button = page.get_by_title("Import data")
426-
expect(button).to_be_visible()
427-
button.click()
412+
page.get_by_title("Import data").click()
428413
textarea = page.locator(".umap-import textarea")
429414
textarea.fill(json.dumps(data))
430415
page.locator('select[name="format"]').select_option("geojson")
@@ -477,9 +462,7 @@ def test_import_geometry_collection_in_feature(live_server, page, tilelayer):
477462
expect(markers).to_have_count(0)
478463
expect(paths).to_have_count(0)
479464
expect(layers).to_have_count(0)
480-
button = page.get_by_title("Import data")
481-
expect(button).to_be_visible()
482-
button.click()
465+
page.get_by_title("Import data").click()
483466
textarea = page.locator(".umap-import textarea")
484467
textarea.fill(json.dumps(data))
485468
page.locator('select[name="format"]').select_option("geojson")
@@ -513,9 +496,7 @@ def test_import_multipolygon(live_server, page, tilelayer):
513496
paths = page.locator("path")
514497
expect(paths).to_have_count(0)
515498
expect(layers).to_have_count(0)
516-
button = page.get_by_title("Import data")
517-
expect(button).to_be_visible()
518-
button.click()
499+
page.get_by_title("Import data").click()
519500
textarea = page.locator(".umap-import textarea")
520501
textarea.fill(json.dumps(data))
521502
page.locator('select[name="format"]').select_option("geojson")
@@ -545,9 +526,7 @@ def test_import_multipolyline(live_server, page, tilelayer):
545526
paths = page.locator("path")
546527
expect(paths).to_have_count(0)
547528
expect(layers).to_have_count(0)
548-
button = page.get_by_title("Import data")
549-
expect(button).to_be_visible()
550-
button.click()
529+
page.get_by_title("Import data").click()
551530
textarea = page.locator(".umap-import textarea")
552531
textarea.fill(json.dumps(data))
553532
page.locator('select[name="format"]').select_option("geojson")
@@ -577,9 +556,7 @@ def test_import_false_multipoint(live_server, page, tilelayer):
577556
markers = page.locator(".leaflet-marker-icon")
578557
expect(markers).to_have_count(0)
579558
expect(layers).to_have_count(0)
580-
button = page.get_by_title("Import data")
581-
expect(button).to_be_visible()
582-
button.click()
559+
page.get_by_title("Import data").click()
583560
textarea = page.locator(".umap-import textarea")
584561
textarea.fill(json.dumps(data))
585562
page.locator('select[name="format"]').select_option("geojson")
@@ -1056,9 +1033,7 @@ def test_import_osm_relation(tilelayer, live_server, page):
10561033
paths = page.locator("path")
10571034
expect(paths).to_have_count(0)
10581035
expect(layers).to_have_count(0)
1059-
button = page.get_by_title("Import data")
1060-
expect(button).to_be_visible()
1061-
button.click()
1036+
page.get_by_title("Import data").click()
10621037
textarea = page.locator(".umap-import textarea")
10631038
file_path = Path(__file__).parent.parent / "fixtures/test_import_osm_relation.json"
10641039
textarea.fill(file_path.read_text())
@@ -1076,9 +1051,7 @@ def test_import_georss_from_textarea(tilelayer, live_server, page):
10761051
markers = page.locator(".leaflet-marker-icon")
10771052
expect(markers).to_have_count(0)
10781053
expect(layers).to_have_count(0)
1079-
button = page.get_by_title("Import data")
1080-
expect(button).to_be_visible()
1081-
button.click()
1054+
page.get_by_title("Import data").click()
10821055
textarea = page.locator(".umap-import textarea")
10831056
path = Path(__file__).parent.parent / "fixtures/test_upload_georss.xml"
10841057
textarea.fill(path.read_text())

0 commit comments

Comments
 (0)