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

Fix inability to change the text of a Label input widget #1556

Conversation

ArturoManzoli
Copy link
Contributor

Fixes #1528

Copy link
Contributor

@ES-Alexander ES-Alexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does make the text changeable - nice! 😃

Can you explain the purpose of the Action URL parameter though? As far as I understand it the label is a fixed value during operation, and needing to edit it with edit mode seems equivalent to just editing the Action itself to use the relevant string.

If it's supposed to also serve as a solution to #1544 then it should be editable, but it seems more intuitive to me to keep that as a separate widget (e.g. a label is a displayed descriptor that the operator doesn't change, whereas an entry is an input). If it's just static text then I think the Action URL section should be removed.
Screenshot 2025-01-11 at 4 37 32 am

@ArturoManzoli
Copy link
Contributor Author

Can you explain the purpose of the Action URL parameter though? As far as I understand it the label is a fixed value during operation, and needing to edit it with edit mode seems equivalent to just editing the Action itself to use the relevant string.

You're right, this should be removed. It has a purpose, but it's not relevant to the current state of the system.
The data lake will have an 'interrupt' trigger that notifies all registered listeners about changes to the variable's value. With this, the label can be used for dynamic text or as a display for a variable's state.

@ES-Alexander
Copy link
Contributor

The data lake will have an 'interrupt' trigger that notifies all registered listeners about changes to the variable's value. With this, the label can be used for dynamic text or as a display for a variable's state.

Ok, but wouldn’t that be better to access via a template string as part of the label text? The listener(s) could be auto-registered when the label text is modified to include one or more such templates, and then it’s possible to have text around the variable value, instead of needing separate labels for that :-)

Displaying a single variable’s value seems like a job for the Very Generic Indicator. A Label widget seems more useful for static text and combinations of values. That said, we could conceivably combine those use-cases with a powerful enough string formatting language, if we decide that’s a worthwhile pursuit, but at that point it’s pretty much an equivalent of a custom mini-widget 🤷🏼‍♂️

@ArturoManzoli ArturoManzoli force-pushed the 1528-Input-label-has-no-way-to-change-text branch from 7baa54a to aea22c1 Compare January 10, 2025 19:53
@ArturoManzoli
Copy link
Contributor Author

Latest push: Now Label component is flagged as not having a Cockpit Action variable.

*** Test with a fresh label component

@ArturoManzoli
Copy link
Contributor Author

ArturoManzoli commented Jan 10, 2025

The data lake will have an 'interrupt' trigger that notifies all registered listeners about changes to the variable's value. With this, the label can be used for dynamic text or as a display for a variable's state.

Ok, but wouldn’t that be better to access via a template string as part of the label text? The listener(s) could be auto-registered when the label text is modified to include one or more such templates, and then it’s possible to have text around the variable value, instead of needing separate labels for that :-)

Displaying a single variable’s value seems like a job for the Very Generic Indicator. A Label widget seems more useful for static text and combinations of values. That said, we could conceivably combine those use-cases with a powerful enough string formatting language, if we decide that’s a worthwhile pursuit, but at that point it’s pretty much an equivalent of a custom mini-widget 🤷🏼‍♂️

As they are now, VGIs are designed to display data using a complete and user-friendly combination of a mini-widget container, numeric value, label, and icons.
The idea of having a mini-widget fragment (text or any ASCII char) that can be reactive to system changes can be quite useful.
Especially when creating a custom widget with regular inputs, this reactive text fragment can assist the user in making decisions based on environmental changes detected by sensors and subtly communicated within the custom widget they are operating.

widget.options = {
newWidget.options = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already fixed in the other PR, right? In this case, this one should be rebased over master to include those changes.

variableType: 'string' | 'boolean' | 'number'
/**
* Action parameter
*/
dataLakeVariable: DataLakeVariable
variableType: 'string' | 'boolean' | 'number' | 'none'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use DataLakeVariable | null here to preserve type checking.

@@ -68,25 +66,9 @@ onMounted(() => {
color: '#FFFFFF',
align: 'center',
},
variableType: 'string',
dataLakeVariable: undefined,
variableType: 'none',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The language offers us null, which states that the value was explicitly nulled. It fits perfectly here.

@@ -361,6 +361,7 @@ const dataLakeVariableError = ref<string[]>([])
watch(
() => widgetStore.elementToShowOnDrawer,
(newValue) => {
console.log('🚀 ~ newValue:', newValue)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dev test log should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops

Comment on lines 75 to 89
if (props.miniWidget.options.dataLakeVariable) {
listenerId = listenDataLakeVariable(props.miniWidget.options.dataLakeVariable?.name, (value) => {
miniWidget.value.options.layout.text = value as string
})
miniWidget.value.options.layout.text = widgetStore.getMiniWidgetLastValue(miniWidget.value.hash) as string
}
})

onUnmounted(() => {
if (miniWidget.value.options.dataLakeVariable) {
deleteDataLakeVariable(miniWidget.value.options.dataLakeVariable.id)
if (listenerId) {
unlistenDataLakeVariable(miniWidget.value.options.dataLakeVariable.name, listenerId)
}
}
Copy link
Member

@rafaellehmkuhl rafaellehmkuhl Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't understand why this block of code was removed. Isn't the Label component supposed to follow the value of a data-lake variable?

Edit: I just read the conversations, but I don't follow. If the label is static, it shouldn't be an Input Widget, right? In case so, it should be renamed to Static Label so it does not confuse users.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafaellehmkuhl my understanding is it is currently static, but in future will be able to display one or more datalake variables, e.g. as a template string: "Custom: {{ datalake.custom_var }} ({{ datalake.other_var }})".

That said, a label never directly accepts input, so I don't think it should be considered as an Input Widget (but I've also generally mentioned in other discussions that Input Widgets seem like they'd make more sense as just a sub-field of Mini Widgets, and should be usable in all the same places, but that seems an overly broad scope change for this PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty much it.
Since we're not using this part right now, it should be removed.

@ES-Alexander ES-Alexander added the docs-needed Change needs to be documented label Jan 13, 2025
@ArturoManzoli ArturoManzoli force-pushed the 1528-Input-label-has-no-way-to-change-text branch from aea22c1 to 372e25c Compare January 13, 2025 22:31
@@ -186,7 +186,7 @@ export type CustomWidgetElementOptions = {
/**
* Variable type
*/
variableType: 'string' | 'boolean' | 'number'
variableType: 'string' | 'boolean' | 'number' | null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of replicating this same type over and over, could we export the 'string' | 'boolean' | 'number' from the data-lake file and import it here?

Copy link
Contributor

@ES-Alexander ES-Alexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest push: Now Label component is flagged as not having a Cockpit Action variable.

*** Test with a fresh label component

This successfully removed the Cockpit Action part, but seems to have also removed the ability/field to specify the text?

Screenshot 2025-01-14 at 5 05 49 pm

@ArturoManzoli ArturoManzoli force-pushed the 1528-Input-label-has-no-way-to-change-text branch from 372e25c to d443649 Compare January 14, 2025 09:38
Copy link
Contributor

@ES-Alexander ES-Alexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked the code, but the functionality seems to work as expected - nice! :-)

@rafaellehmkuhl rafaellehmkuhl merged commit 9db9628 into bluerobotics:master Jan 15, 2025
11 checks passed
@rafaellehmkuhl rafaellehmkuhl changed the title Bug Fix: "label" input widget has no way to change the text Fix inability to change the text of a Label input widget Jan 15, 2025
@ES-Alexander ES-Alexander added docs-complete Change documentation has been completed and removed docs-needed Change needs to be documented labels Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-complete Change documentation has been completed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: "label" input widget has no way to change the text
3 participants