* [yew-devel] [PATCH proxmox{-yew-widget-toolkit, -yew-comp} v3 0/3] use Schema to populate field properties @ 2025-10-09 13:31 Hannes Laimer 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-widget-toolkit v3 1/1] form: expose NumberTypeInfo Hannes Laimer ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: Hannes Laimer @ 2025-10-09 13:31 UTC (permalink / raw) To: yew-devel The idea is to have things like description or enum/selection items only specified in one place. This is preparatory for a series adding basic firewall intergration into PDM. But this also makes sense on its own so I am sending it separate from that. v3, thanks @Dietmar for the pointer: - move this into proxmox-yew-comp - add translation for the description on the Schema Not super sure if there speaks something agains trying to translate the descriptions saved on the API schema. If we don't want that just skip 2/2 of the yew-comp patches. * we need to bump the pwt dep since we need the exposed NumberTypeInfo for the yew-comp patches proxmox-yew-widget-toolkit: Hannes Laimer (1): form: expose NumberTypeInfo src/widget/form/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) proxmox-yew-comp: Hannes Laimer (2): schema_validation: use Schema to populate field properties of number, check- and combobox schema_validation: add translated description as tooltip to field and checkbox src/schema_validation.rs | 102 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) Summary over all repositories: 2 files changed, 102 insertions(+), 2 deletions(-) -- Generated by git-murpp 0.8.1 _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel ^ permalink raw reply [flat|nested] 9+ messages in thread
* [yew-devel] [PATCH proxmox-yew-widget-toolkit v3 1/1] form: expose NumberTypeInfo 2025-10-09 13:31 [yew-devel] [PATCH proxmox{-yew-widget-toolkit, -yew-comp} v3 0/3] use Schema to populate field properties Hannes Laimer @ 2025-10-09 13:31 ` Hannes Laimer 2025-10-10 8:18 ` [yew-devel] applied: " Dietmar Maurer 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-comp v3 1/2] schema_validation: use Schema to populate field properties of number, check- and combobox Hannes Laimer 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-comp v3 2/2] schema_validation: add translated description as tooltip to field and checkbox Hannes Laimer 2 siblings, 1 reply; 9+ messages in thread From: Hannes Laimer @ 2025-10-09 13:31 UTC (permalink / raw) To: yew-devel We need this to be public because we need it in the generic trait impl for SchemaValidation in proxmox-yew-comp. Signed-off-by: Hannes Laimer <h.laimer@proxmox.com> --- src/widget/form/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/form/mod.rs b/src/widget/form/mod.rs index 669c774..6fd1353 100644 --- a/src/widget/form/mod.rs +++ b/src/widget/form/mod.rs @@ -53,7 +53,7 @@ pub use form::Form; pub use form::PwtForm; mod number; -pub use number::Number; +pub use number::{Number, NumberTypeInfo}; #[doc(hidden)] pub use number::PwtNumber; -- 2.47.3 _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel ^ permalink raw reply [flat|nested] 9+ messages in thread
* [yew-devel] applied: [PATCH proxmox-yew-widget-toolkit v3 1/1] form: expose NumberTypeInfo 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-widget-toolkit v3 1/1] form: expose NumberTypeInfo Hannes Laimer @ 2025-10-10 8:18 ` Dietmar Maurer 0 siblings, 0 replies; 9+ messages in thread From: Dietmar Maurer @ 2025-10-10 8:18 UTC (permalink / raw) To: Yew framework devel list at Proxmox [-- Attachment #1.1: Type: text/plain, Size: 69 bytes --] applied, but added docs It is now pub, so we need documentation... [-- Attachment #1.2: Type: text/html, Size: 697 bytes --] [-- Attachment #2: Type: text/plain, Size: 160 bytes --] _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel ^ permalink raw reply [flat|nested] 9+ messages in thread
* [yew-devel] [PATCH proxmox-yew-comp v3 1/2] schema_validation: use Schema to populate field properties of number, check- and combobox 2025-10-09 13:31 [yew-devel] [PATCH proxmox{-yew-widget-toolkit, -yew-comp} v3 0/3] use Schema to populate field properties Hannes Laimer 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-widget-toolkit v3 1/1] form: expose NumberTypeInfo Hannes Laimer @ 2025-10-09 13:31 ` Hannes Laimer 2025-10-10 8:32 ` Dietmar Maurer 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-comp v3 2/2] schema_validation: add translated description as tooltip to field and checkbox Hannes Laimer 2 siblings, 1 reply; 9+ messages in thread From: Hannes Laimer @ 2025-10-09 13:31 UTC (permalink / raw) To: yew-devel The idea is to have things like enum/selection items, defaults or property string validations only specified in one place. Signed-off-by: Hannes Laimer <h.laimer@proxmox.com> --- src/schema_validation.rs | 99 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/src/schema_validation.rs b/src/schema_validation.rs index af28705..fbdf96d 100644 --- a/src/schema_validation.rs +++ b/src/schema_validation.rs @@ -2,7 +2,13 @@ use std::cell::RefCell; use std::collections::HashMap; use proxmox_schema::Schema; -use pwt::widget::form::{InputType, ValidateFn}; +use pwt::{ + props::FieldBuilder, + state::Store, + widget::form::{InputType, NumberTypeInfo, ValidateFn}, +}; +use serde_json::Value; +use yew::AttrValue; pub trait SchemaValidation { fn schema(mut self, schema: &'static Schema) -> Self @@ -33,12 +39,24 @@ impl SchemaValidation for pwt::widget::form::Field { self.max = s.maximum.map(|v| v as f64); self.step = Some(1.0); self.input_type = InputType::Number; + if let Some(value) = s.default { + self.set_placeholder(value.to_string()); + } } Schema::Number(s) => { self.min = s.minimum; self.max = s.maximum; self.step = Some(1.0); self.input_type = InputType::Number; + if let Some(value) = s.default { + self.set_placeholder(value.to_string()); + } + } + Schema::String(s) => { + self.set_tip(s.description.to_string()); + if let Some(default) = s.default { + self.set_placeholder(default.to_string()); + } } _ => {} } @@ -60,3 +78,82 @@ impl SchemaValidation for pwt::widget::form::Field { self.set_validate(validate); } } + +impl SchemaValidation for pwt::widget::form::Checkbox { + fn set_schema(&mut self, schema: &'static Schema) { + if let Schema::Boolean(s) = schema { + if let Some(value) = s.default { + self.set_default(value); + } + } + } +} + +impl SchemaValidation for pwt::widget::form::Combobox { + fn set_schema(&mut self, schema: &'static Schema) { + if let Schema::String(s) = schema { + if let Some(proxmox_schema::ApiStringFormat::Enum(e)) = s.format { + let items: Vec<AttrValue> = e + .iter() + .map(|entry| entry.value.to_string().into()) + .collect(); + self.set_items(items.into()); + } + if let Some(value) = s.default { + self.set_placeholder(value); + } + } + self.set_validate(move |(value, _store): &(String, Store<AttrValue>)| { + schema.parse_simple_value(value)?; + Ok(()) + }); + } +} + +// Generic implementation for Number<T> +impl<T> SchemaValidation for pwt::widget::form::Number<T> +where + T: NumberTypeInfo, +{ + fn set_schema(&mut self, schema: &'static Schema) { + match schema { + Schema::Integer(s) => { + if let Some(minimum) = s.minimum { + if let Ok(min_value) = T::value_to_number(&Value::Number(minimum.into())) { + self.min = Some(min_value); + } + } + if let Some(maximum) = s.maximum { + if let Ok(max_value) = T::value_to_number(&Value::Number(maximum.into())) { + self.max = Some(max_value); + } + } + if let Some(default) = s.default { + self.set_placeholder(default.to_string()); + } + } + Schema::Number(s) => { + if let Some(minimum) = s.minimum { + if let Ok(min_value) = T::value_to_number(&Value::from(minimum)) { + self.min = Some(min_value); + } + } + if let Some(maximum) = s.maximum { + if let Ok(max_value) = T::value_to_number(&Value::from(maximum)) { + self.max = Some(max_value); + } + } + if let Some(default) = s.default { + self.set_placeholder(default.to_string()); + } + } + _ => {} + } + + self.set_validate(move |value: &T| { + let value_str = value.to_string(); + schema.parse_simple_value(&value_str)?; + Ok(()) + }); + } +} -- 2.47.3 _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [yew-devel] [PATCH proxmox-yew-comp v3 1/2] schema_validation: use Schema to populate field properties of number, check- and combobox 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-comp v3 1/2] schema_validation: use Schema to populate field properties of number, check- and combobox Hannes Laimer @ 2025-10-10 8:32 ` Dietmar Maurer 2025-10-10 10:46 ` Thomas Lamprecht 2025-10-10 12:43 ` Hannes Laimer 0 siblings, 2 replies; 9+ messages in thread From: Dietmar Maurer @ 2025-10-10 8:32 UTC (permalink / raw) To: Yew framework devel list at Proxmox, Hannes Laimer partially applied. - setting placeholder is OK - setting tips from description is problematic, because those description are basically for developers and have no translations, so I think its not worth to do it. - setting field default values form schema default is most times not what you need (depends highly on your input form logic) - setting validator for Number makes no sense (schema.parse_simple_value() does not add any advantage, because values are already parsed - correct me if I am wrong) - auto-generating Combobox is usually not what we want, because we display translated, annotated items... - Dietmar _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [yew-devel] [PATCH proxmox-yew-comp v3 1/2] schema_validation: use Schema to populate field properties of number, check- and combobox 2025-10-10 8:32 ` Dietmar Maurer @ 2025-10-10 10:46 ` Thomas Lamprecht 2025-10-10 12:43 ` Hannes Laimer 1 sibling, 0 replies; 9+ messages in thread From: Thomas Lamprecht @ 2025-10-10 10:46 UTC (permalink / raw) To: Yew framework devel list at Proxmox, Dietmar Maurer, Hannes Laimer Am 10.10.25 um 10:32 schrieb Dietmar Maurer: > partially applied. > > - setting placeholder is OK > > - setting tips from description is problematic, because those description are basically for developers and have no translations, so I think its not worth to do it. > > - setting field default values form schema default is most times not what you need (depends highly on your input form logic) > > - setting validator for Number makes no sense (schema.parse_simple_value() does not add any advantage, because values are already parsed - correct me if I am wrong) > > - auto-generating Combobox is usually not what we want, because we display translated, annotated items... I agree with all of those points. While re-using schema info is naturally great, it has a somewhat limited applications for frontend UI. _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [yew-devel] [PATCH proxmox-yew-comp v3 1/2] schema_validation: use Schema to populate field properties of number, check- and combobox 2025-10-10 8:32 ` Dietmar Maurer 2025-10-10 10:46 ` Thomas Lamprecht @ 2025-10-10 12:43 ` Hannes Laimer 2025-10-10 13:51 ` Dietmar Maurer 1 sibling, 1 reply; 9+ messages in thread From: Hannes Laimer @ 2025-10-10 12:43 UTC (permalink / raw) To: Dietmar Maurer, Yew framework devel list at Proxmox On 10/10/25 10:32, Dietmar Maurer wrote: > partially applied. > > - setting placeholder is OK > > - setting tips from description is problematic, because those > description are basically for developers and have no translations, so I > think its not worth to do it. > > - setting field default values form schema default is most times not > what you need (depends highly on your input form logic) > > - setting validator for Number makes no sense > (schema.parse_simple_value() does not add any advantage, because values > are already parsed - correct me if I am wrong) > > - auto-generating Combobox is usually not what we want, because we > display translated, annotated items... > hmm, we can still do that though. for combobox items specifically I feel like having it still adds some value. There are places where we don't, and a later .items() does override whatever we took from the schema if we want to set them ourself. We don't for example for firewall logging levels or firewall policies like DROP, REJECT, ACCEPT. Also having the default as a placeholder automatically is, if nothing else, convenient. tbh, I'm not super sure how often we do this, so may not be warranted to have a general thing if only these two end up using it. > - Dietmar > > _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [yew-devel] [PATCH proxmox-yew-comp v3 1/2] schema_validation: use Schema to populate field properties of number, check- and combobox 2025-10-10 12:43 ` Hannes Laimer @ 2025-10-10 13:51 ` Dietmar Maurer 0 siblings, 0 replies; 9+ messages in thread From: Dietmar Maurer @ 2025-10-10 13:51 UTC (permalink / raw) To: Hannes Laimer; +Cc: Yew framework devel list at Proxmox [-- Attachment #1.1: Type: text/plain, Size: 628 bytes --] We don't for example for firewall logging levels or firewall policies like DROP, REJECT, ACCEPT. Also having the default as a placeholder automatically is, if nothing else, convenient. tbh, I'm not super sure how often we do this, so may not be warranted to have a general thing if only these two end up using it. Good example. I guess a good UI would explain the difference between DROP and REJECT: DROP => Silently discard the packet. REJECT => Reject packet and send an error message back. Just write a small helper (combobo_from_schema(..)). If it turns out to be useful, we can still add it to the schema helper. [-- Attachment #1.2: Type: text/html, Size: 2807 bytes --] [-- Attachment #2: Type: text/plain, Size: 160 bytes --] _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel ^ permalink raw reply [flat|nested] 9+ messages in thread
* [yew-devel] [PATCH proxmox-yew-comp v3 2/2] schema_validation: add translated description as tooltip to field and checkbox 2025-10-09 13:31 [yew-devel] [PATCH proxmox{-yew-widget-toolkit, -yew-comp} v3 0/3] use Schema to populate field properties Hannes Laimer 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-widget-toolkit v3 1/1] form: expose NumberTypeInfo Hannes Laimer 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-comp v3 1/2] schema_validation: use Schema to populate field properties of number, check- and combobox Hannes Laimer @ 2025-10-09 13:31 ` Hannes Laimer 2 siblings, 0 replies; 9+ messages in thread From: Hannes Laimer @ 2025-10-09 13:31 UTC (permalink / raw) To: yew-devel Signed-off-by: Hannes Laimer <h.laimer@proxmox.com> --- src/schema_validation.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/schema_validation.rs b/src/schema_validation.rs index fbdf96d..dfbd92f 100644 --- a/src/schema_validation.rs +++ b/src/schema_validation.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use proxmox_schema::Schema; use pwt::{ + gettext, props::FieldBuilder, state::Store, widget::form::{InputType, NumberTypeInfo, ValidateFn}, @@ -39,6 +40,7 @@ impl SchemaValidation for pwt::widget::form::Field { self.max = s.maximum.map(|v| v as f64); self.step = Some(1.0); self.input_type = InputType::Number; + self.set_tip(gettext(s.description)); if let Some(value) = s.default { self.set_placeholder(value.to_string()); } @@ -48,6 +50,7 @@ impl SchemaValidation for pwt::widget::form::Field { self.max = s.maximum; self.step = Some(1.0); self.input_type = InputType::Number; + self.set_tip(gettext(s.description)); if let Some(value) = s.default { self.set_placeholder(value.to_string()); } -- 2.47.3 _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-10-10 13:52 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-10-09 13:31 [yew-devel] [PATCH proxmox{-yew-widget-toolkit, -yew-comp} v3 0/3] use Schema to populate field properties Hannes Laimer 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-widget-toolkit v3 1/1] form: expose NumberTypeInfo Hannes Laimer 2025-10-10 8:18 ` [yew-devel] applied: " Dietmar Maurer 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-comp v3 1/2] schema_validation: use Schema to populate field properties of number, check- and combobox Hannes Laimer 2025-10-10 8:32 ` Dietmar Maurer 2025-10-10 10:46 ` Thomas Lamprecht 2025-10-10 12:43 ` Hannes Laimer 2025-10-10 13:51 ` Dietmar Maurer 2025-10-09 13:31 ` [yew-devel] [PATCH proxmox-yew-comp v3 2/2] schema_validation: add translated description as tooltip to field and checkbox Hannes Laimer
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.