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

UI-ButtonGroup: Add msg.enabled support, validate msg.payload before apply to selection #1089

Merged
merged 5 commits into from
Jul 23, 2024
Merged
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 docs/nodes/widgets/ui-button-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ controls:
example: true | false
description: Allow control over whether or not the button is clickable.
dynamic:
Disabled State:
payload: msg.enabled
structure: ["Boolean"]
Label:
payload: msg.ui_update.label
structure: ["String"]
Expand Down
1 change: 1 addition & 0 deletions nodes/widgets/locales/en-US/ui_button_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<script type="text/html" data-help-name="ui-button-group">
<p>A Node-RED node to show a switch with multiple buttons in the Node-RED Dashboard.</p>
<p>The active selection can be dynamically set by sending a <code>msg.payload</code> which matches a respective option's value.</p>
<p>To clear any selection, pass an empty array <code>[]</code> as <code>msg.payload</code>.</p>
<h3>Properties</h3>
<p><strong>Label:</strong><br/>
The label that will be displayed on the left side of the button group.</p>
Expand Down
1 change: 0 additions & 1 deletion nodes/widgets/ui_button_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = function (RED) {
beforeSend: function (msg) {
if (msg.ui_update) {
const update = msg.ui_update
console.log(update)
if (typeof update.options !== 'undefined') {
// dynamically set "options" property
statestore.set(group.getBase(), node, msg, 'options', update.options)
Expand Down
33 changes: 29 additions & 4 deletions ui/src/widgets/ui-button-group/UIButtonGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<label v-if="label" class="v-label">
{{ label }}
</label>
<v-btn-toggle v-model="selection" mandatory divided :rounded="props.rounded ? 'xl' : ''" :color="selectedColor" @update:model-value="onChange(selection)">
<v-btn-toggle v-model="selection" mandatory divided :rounded="props.rounded ? 'xl' : ''" :color="selectedColor" :disabled="!state.enabled" @update:model-value="onChange(selection)">
<v-btn v-for="option in options" :key="option.value" :value="option.value">
<template v-if="option.icon && option.label !== undefined && option.label !== ''" #prepend>
<v-icon size="x-large" :icon="`mdi-${option.icon.replace(/^mdi-/, '')}`" />
Expand Down Expand Up @@ -80,8 +80,17 @@ export default {
widgetId: this.id,
msg
})

// make sure our v-model is updated to reflect the value from Node-RED
this.selection = msg.payload
if (msg.payload !== undefined) {
if (Array.isArray(msg.payload) && msg.payload.length === 0) {
this.selection = null
} else {
if (this.findOptionByValue(msg.payload) !== null) {
this.selection = msg.payload
}
}
}
},
onLoad (msg) {
// update vuex store to reflect server-state
Expand All @@ -90,7 +99,15 @@ export default {
msg
})
// make sure we've got the relevant option selected on load of the page
this.selection = msg.payload
if (msg.payload !== undefined) {
if (Array.isArray(msg.payload) && msg.payload.length === 0) {
this.selection = null
} else {
if (this.findOptionByValue(msg.payload) !== null) {
this.selection = msg.payload
}
}
}
},
onDynamicProperty (msg) {
const updates = msg.ui_update
Expand Down Expand Up @@ -124,7 +141,7 @@ export default {
}
</script>

<style scoped>
<style>
.nrdb-ui-button-group-wrapper {
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -155,4 +172,12 @@ export default {
.nrdb-ui-button-group-wrapper .icon-only .v-btn__prepend {
margin-inline: 0;
}

.nrdb-ui-button-group-wrapper .v-btn.v-btn--disabled .v-btn__overlay {
opacity: 0.1;
}

.nrdb-ui-button-group-wrapper .v-btn-group .v-btn--disabled .v-btn__content {
color: rgb(var(--v-theme-on-group-background), var(--v-disabled-opacity));
}
</style>
Loading