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

feat: allow to edit datalayer name in datalayers list #2349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading