diff --git a/umap/static/umap/js/modules/form/builder.js b/umap/static/umap/js/modules/form/builder.js index 01fe8bb8..d0461036 100644 --- a/umap/static/umap/js/modules/form/builder.js +++ b/umap/static/umap/js/modules/form/builder.js @@ -63,7 +63,7 @@ export class Form extends Utils.WithEvents { try { value = value[sub] } catch { - console.log(field) + console.debug(field) } } return value @@ -142,50 +142,50 @@ export class MutatingForm extends Form { slugKey: 'PropertyInput', labelKey: 'PropertyInput', } - for (const [key, definition] of Object.entries(SCHEMA)) { - const schema = Utils.CopyJSON(definition) - if (definition.type === Boolean) { - if (schema.nullable) schema.handler = 'NullableChoices' - else schema.handler = 'Switch' - } else if (definition.type === 'Text') { - schema.handler = 'Textarea' - } else if (definition.type === Number) { - if (schema.step) schema.handler = 'Range' - else schema.handler = 'IntInput' - } else if (schema.choices) { - const text_length = schema.choices.reduce( + for (const [key, defaults] of Object.entries(SCHEMA)) { + const properties = Object.assign({}, defaults) + if (properties.type === Boolean) { + if (properties.nullable) properties.handler = 'NullableChoices' + else properties.handler = 'Switch' + } else if (properties.type === 'Text') { + properties.handler = 'Textarea' + } else if (properties.type === Number) { + if (properties.step) properties.handler = 'Range' + else properties.handler = 'IntInput' + } else if (properties.choices) { + const text_length = properties.choices.reduce( (acc, [_, label]) => acc + label.length, 0 ) // Try to be smart and use MultiChoice only // for choices where labels are shorts… if (text_length < 40) { - schema.handler = 'MultiChoice' + properties.handler = 'MultiChoice' } else { - schema.handler = 'Select' - schema.selectOptions = schema.choices + properties.handler = 'Select' + properties.selectOptions = properties.choices } } else { switch (key) { case 'color': case 'fillColor': - schema.handler = 'ColorPicker' + properties.handler = 'ColorPicker' break case 'iconUrl': - schema.handler = 'IconUrl' + properties.handler = 'IconUrl' break case 'licence': - schema.handler = 'LicenceChooser' + properties.handler = 'LicenceChooser' break } } if (customHandlers[key]) { - schema.handler = customHandlers[key] + properties.handler = customHandlers[key] } // Input uses this key for its type attribute - delete schema.type - this.defaultProperties[key] = schema + delete properties.type + this.defaultProperties[key] = properties } } @@ -203,7 +203,7 @@ export class MutatingForm extends Form { getTemplate(helper) { let template if (helper.properties.inheritable) { - const extraClassName = helper.get(true) === undefined ? ' undefined' : '' + const extraClassName = this.getter(helper.field) === undefined ? ' undefined' : '' template = `
diff --git a/umap/static/umap/js/modules/form/fields.js b/umap/static/umap/js/modules/form/fields.js index 4a709e2e..7dc6a6d7 100644 --- a/umap/static/umap/js/modules/form/fields.js +++ b/umap/static/umap/js/modules/form/fields.js @@ -80,11 +80,13 @@ class BaseElement { this.input.value = '' } - get(own) { - if (!this.properties.inheritable || own) return this.builder.getter(this.field) + get() { + if (!this.properties.inheritable) return this.builder.getter(this.field) const path = this.field.split('.') const key = path[path.length - 1] - return this.obj.getOption(key) || SCHEMA[key]?.default + const value = this.obj.getOption(key) + if (value === undefined) return SCHEMA[key]?.default + return value } toHTML() { @@ -1164,7 +1166,7 @@ Fields.MultiChoice = class extends BaseElement { Fields.TernaryChoices = class extends Fields.MultiChoice { getDefault() { - return 'null' + return null } toJS() { diff --git a/umap/tests/integration/test_edit_map.py b/umap/tests/integration/test_edit_map.py index 64d8fb13..7bc6ca5f 100644 --- a/umap/tests/integration/test_edit_map.py +++ b/umap/tests/integration/test_edit_map.py @@ -210,3 +210,19 @@ def test_sortkey_impacts_datalayerindex(map, live_server, page): assert "Z First" == first_listed_feature.text_content() assert "Y Second" == second_listed_feature.text_content() assert "X Third" == third_listed_feature.text_content() + + +def test_hover_tooltip_setting_should_be_persistent(live_server, map, page): + map.settings["properties"]["showLabel"] = None + map.edit_status = Map.ANONYMOUS + map.save() + page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") + page.get_by_role("button", name="Map advanced properties").click() + page.get_by_text("Default interaction options").click() + expect(page.get_by_text("on hover")).to_be_visible() + expect(page.locator(".umap-field-showLabel")).to_match_aria_snapshot(""" + - text: Display label + - button "clear" + - text: always never on hover + """) + expect(page.locator(".umap-field-showLabel input[value=null]")).to_be_checked()