mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
fix: "null" value was not honoured in showLabel field
This commit is contained in:
parent
64068af393
commit
c5417178c4
3 changed files with 45 additions and 27 deletions
|
@ -63,7 +63,7 @@ export class Form extends Utils.WithEvents {
|
||||||
try {
|
try {
|
||||||
value = value[sub]
|
value = value[sub]
|
||||||
} catch {
|
} catch {
|
||||||
console.log(field)
|
console.debug(field)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
|
@ -142,50 +142,50 @@ export class MutatingForm extends Form {
|
||||||
slugKey: 'PropertyInput',
|
slugKey: 'PropertyInput',
|
||||||
labelKey: 'PropertyInput',
|
labelKey: 'PropertyInput',
|
||||||
}
|
}
|
||||||
for (const [key, definition] of Object.entries(SCHEMA)) {
|
for (const [key, defaults] of Object.entries(SCHEMA)) {
|
||||||
const schema = Utils.CopyJSON(definition)
|
const properties = Object.assign({}, defaults)
|
||||||
if (definition.type === Boolean) {
|
if (properties.type === Boolean) {
|
||||||
if (schema.nullable) schema.handler = 'NullableChoices'
|
if (properties.nullable) properties.handler = 'NullableChoices'
|
||||||
else schema.handler = 'Switch'
|
else properties.handler = 'Switch'
|
||||||
} else if (definition.type === 'Text') {
|
} else if (properties.type === 'Text') {
|
||||||
schema.handler = 'Textarea'
|
properties.handler = 'Textarea'
|
||||||
} else if (definition.type === Number) {
|
} else if (properties.type === Number) {
|
||||||
if (schema.step) schema.handler = 'Range'
|
if (properties.step) properties.handler = 'Range'
|
||||||
else schema.handler = 'IntInput'
|
else properties.handler = 'IntInput'
|
||||||
} else if (schema.choices) {
|
} else if (properties.choices) {
|
||||||
const text_length = schema.choices.reduce(
|
const text_length = properties.choices.reduce(
|
||||||
(acc, [_, label]) => acc + label.length,
|
(acc, [_, label]) => acc + label.length,
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
// Try to be smart and use MultiChoice only
|
// Try to be smart and use MultiChoice only
|
||||||
// for choices where labels are shorts…
|
// for choices where labels are shorts…
|
||||||
if (text_length < 40) {
|
if (text_length < 40) {
|
||||||
schema.handler = 'MultiChoice'
|
properties.handler = 'MultiChoice'
|
||||||
} else {
|
} else {
|
||||||
schema.handler = 'Select'
|
properties.handler = 'Select'
|
||||||
schema.selectOptions = schema.choices
|
properties.selectOptions = properties.choices
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'color':
|
case 'color':
|
||||||
case 'fillColor':
|
case 'fillColor':
|
||||||
schema.handler = 'ColorPicker'
|
properties.handler = 'ColorPicker'
|
||||||
break
|
break
|
||||||
case 'iconUrl':
|
case 'iconUrl':
|
||||||
schema.handler = 'IconUrl'
|
properties.handler = 'IconUrl'
|
||||||
break
|
break
|
||||||
case 'licence':
|
case 'licence':
|
||||||
schema.handler = 'LicenceChooser'
|
properties.handler = 'LicenceChooser'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customHandlers[key]) {
|
if (customHandlers[key]) {
|
||||||
schema.handler = customHandlers[key]
|
properties.handler = customHandlers[key]
|
||||||
}
|
}
|
||||||
// Input uses this key for its type attribute
|
// Input uses this key for its type attribute
|
||||||
delete schema.type
|
delete properties.type
|
||||||
this.defaultProperties[key] = schema
|
this.defaultProperties[key] = properties
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ export class MutatingForm extends Form {
|
||||||
getTemplate(helper) {
|
getTemplate(helper) {
|
||||||
let template
|
let template
|
||||||
if (helper.properties.inheritable) {
|
if (helper.properties.inheritable) {
|
||||||
const extraClassName = helper.get(true) === undefined ? ' undefined' : ''
|
const extraClassName = this.getter(helper.field) === undefined ? ' undefined' : ''
|
||||||
template = `
|
template = `
|
||||||
<div class="umap-field-${helper.name} formbox inheritable${extraClassName}">
|
<div class="umap-field-${helper.name} formbox inheritable${extraClassName}">
|
||||||
<div class="header" data-ref=header>
|
<div class="header" data-ref=header>
|
||||||
|
|
|
@ -80,11 +80,13 @@ class BaseElement {
|
||||||
this.input.value = ''
|
this.input.value = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
get(own) {
|
get() {
|
||||||
if (!this.properties.inheritable || own) return this.builder.getter(this.field)
|
if (!this.properties.inheritable) return this.builder.getter(this.field)
|
||||||
const path = this.field.split('.')
|
const path = this.field.split('.')
|
||||||
const key = path[path.length - 1]
|
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() {
|
toHTML() {
|
||||||
|
@ -1164,7 +1166,7 @@ Fields.MultiChoice = class extends BaseElement {
|
||||||
|
|
||||||
Fields.TernaryChoices = class extends Fields.MultiChoice {
|
Fields.TernaryChoices = class extends Fields.MultiChoice {
|
||||||
getDefault() {
|
getDefault() {
|
||||||
return 'null'
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
toJS() {
|
toJS() {
|
||||||
|
|
|
@ -210,3 +210,19 @@ def test_sortkey_impacts_datalayerindex(map, live_server, page):
|
||||||
assert "Z First" == first_listed_feature.text_content()
|
assert "Z First" == first_listed_feature.text_content()
|
||||||
assert "Y Second" == second_listed_feature.text_content()
|
assert "Y Second" == second_listed_feature.text_content()
|
||||||
assert "X Third" == third_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()
|
||||||
|
|
Loading…
Reference in a new issue