Config sheet: Always show advanced params only if changed from default (#2888)

Improve code from #2313.
Closes #2879.

---------

Signed-off-by: Florian Hotze <dev@florianhotze.com>
dependabot/npm_and_yarn/bundles/org.openhab.ui.habot/web/multi-b9e91432f9
Florian Hotze 2024-12-03 21:08:39 +01:00 committed by GitHub
parent d432f3bde7
commit 1258cf0e6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 5 deletions

View File

@ -99,6 +99,10 @@ export default {
return this.parameters.length > 0 && this.parameters.some((p) => p.advanced)
},
displayedParameters () {
function notNullNotUndefined (value) {
return value !== null && value !== undefined
}
if (!this.parameters.length) return []
let finalParameters = [...this.parameters]
if (this.parameterGroups && this.parameterGroups.some((g) => g.context === 'action')) {
@ -108,11 +112,13 @@ export default {
})
}
if (this.showAdvanced) return finalParameters // show all parameters
// exclude advanced parameters, if:
// - a default value is defined and the actual value differs from the default value
// - no default value is defined and the param has a value
return finalParameters.filter((p) => !p.advanced ||
(p.default !== undefined && this.configuration[p.name] !== undefined && this.configuration[p.name] !== null ? this.configuration[p.name].toString() !== p.default : this.configuration[p.name] !== undefined))
// exclude advanced parameters:
return finalParameters.filter((p) =>
// parameter is not advanced: always show
!p.advanced ||
// parameter is advanced: show only if default is defined and value is different from default
(notNullNotUndefined(p.default) && notNullNotUndefined(this.configuration[p.name]) && this.configuration[p.name].toString() !== p.default)
)
}
},
methods: {