Skip to content

Commit

Permalink
feat: allow to edit datalayer name in datalayers list
Browse files Browse the repository at this point in the history
fix #1995
  • Loading branch information
yohanboniface committed Dec 9, 2024
1 parent 97ff26b commit 1a3cd9f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions umap/static/umap/css/form.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.umap-form-inline {
display: inline;
}
input[type="text"], input[type="password"], input[type="date"],
input[type="datetime-local"], input[type="email"], input[type="number"],
input[type="search"], input[type="tel"], input[type="time"], input[type="file"],
Expand Down
9 changes: 7 additions & 2 deletions umap/static/umap/js/modules/umap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1423,9 +1423,14 @@ export default class Umap extends ServerStored {
const row = DomUtil.create('li', 'orderable', ul)
DomUtil.createIcon(row, 'icon-drag', translate('Drag to reorder'))
datalayer.renderToolbox(row)
const title = DomUtil.add('span', '', row, datalayer.options.name)
const builder = new U.FormBuilder(
datalayer,
[['options.name', { handler: 'EditableText' }]],
{ className: 'umap-form-inline' }
)
const form = builder.build()
row.appendChild(form)
row.classList.toggle('off', !datalayer.isVisible())
title.textContent = datalayer.options.name
row.dataset.id = stamp(datalayer)
})
const onReorder = (src, dst, initialIndex, finalIndex) => {
Expand Down
29 changes: 29 additions & 0 deletions umap/static/umap/js/umap.forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,35 @@ L.FormBuilder.CheckBox.include({
},
})

L.FormBuilder.EditableText = L.FormBuilder.Element.extend({
build: function () {
this.input = L.DomUtil.create('span', this.options.className || '', this.parentNode)
this.input.contentEditable = true
this.fetch()
L.DomEvent.on(this.input, 'input', this.sync, this)
L.DomEvent.on(this.input, 'keypress', this.onKeyPress, this)
},

getParentNode: function () {
return this.form
},

value: function () {
return this.input.textContent
},

fetch: function () {
this.input.textContent = this.toHTML()
},

onKeyPress: function (event) {
if (event.keyCode === 13) {
event.preventDefault()
this.input.blur()
}
},
})

L.FormBuilder.ColorPicker = L.FormBuilder.Input.extend({
colors: U.COLORS,
getParentNode: function () {
Expand Down
11 changes: 11 additions & 0 deletions umap/tests/integration/test_edit_datalayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,14 @@ def test_deleting_datalayer_should_remove_from_caption(
page.locator(".panel.right").get_by_title("Delete layer").click()
page.get_by_role("button", name="OK").click()
expect(panel.get_by_text("test datalayer")).to_be_hidden()


def test_can_edit_datalayer_name_in_list(live_server, openmap, datalayer, page):
page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit")
page.get_by_role("link", name="Manage layers").click()
page.get_by_text("test datalayer").click()
page.get_by_text("test datalayer").fill("test datalayer foobar")
page.get_by_role("button", name="Open browser").click()
expect(
page.locator(".panel.left").get_by_text("test datalayer foobar")
).to_be_visible()

0 comments on commit 1a3cd9f

Please sign in to comment.