* [yew-devel] [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState
@ 2025-05-07 9:11 Dominik Csapak
2025-05-07 9:11 ` [yew-devel] [PATCH yew-comp v2 2/4] wizard: factor out 'can progress' logic check to WizardState Dominik Csapak
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Dominik Csapak @ 2025-05-07 9:11 UTC (permalink / raw)
To: yew-devel
It fits better there, and we now have the ability to check this data
from the state. (Validity was already possible via the form context, but
it was a bit tedious).
No functional change intended.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* fix typo in commit message
src/wizard.rs | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/wizard.rs b/src/wizard.rs
index c7f9ff6..b816136 100644
--- a/src/wizard.rs
+++ b/src/wizard.rs
@@ -257,6 +257,8 @@ struct WizardState {
page: Option<Key>,
page_data: HashMap<Key, FormContext>,
page_list: Vec<Key>,
+ pages_valid: HashSet<Key>,
+ pages_lock: HashSet<Key>,
submit_callbacks: HashMap<Key, Callback<(), bool>>,
}
@@ -275,6 +277,16 @@ impl WizardState {
pub fn get_callback(&self, key: Option<&Key>) -> Option<Callback<(), bool>> {
key.and_then(|key| self.submit_callbacks.get(key).cloned())
}
+
+ /// Returns if the page for the given [`Key`] is valid
+ pub fn page_valid(&self, key: &Key) -> bool {
+ self.pages_valid.contains(key)
+ }
+
+ /// Returns if the page for the given [`Key`] is locked
+ pub fn page_locked(&self, key: &Key) -> bool {
+ self.pages_lock.contains(key)
+ }
}
impl WizardController {
@@ -284,6 +296,8 @@ impl WizardController {
page: None,
page_data: HashMap::new(),
page_list: Vec::new(),
+ pages_valid: HashSet::new(),
+ pages_lock: HashSet::new(),
submit_callbacks: HashMap::new(),
};
Self {
@@ -316,8 +330,6 @@ pub struct PwtWizard {
selection: Selection,
loading: bool, // set during submit
submit_error: Option<String>,
- pages_valid: HashSet<Key>,
- pages_lock: HashSet<Key>,
valid_data: Rc<Value>,
controller: WizardController,
@@ -354,8 +366,6 @@ impl Component for PwtWizard {
Self {
loading: false,
submit_error: None,
- pages_valid: HashSet::new(),
- pages_lock: HashSet::new(),
selection,
valid_data: Rc::new(json!({})),
controller,
@@ -507,10 +517,10 @@ impl Component for PwtWizard {
let tab_bar_item = page.tab_bar_item.clone().disabled(disabled);
if !disabled {
- if !self.pages_valid.contains(key) {
+ if !self.controller.read().page_valid(key) {
disabled = true;
}
- if self.pages_lock.contains(key) {
+ if self.controller.read().page_locked(key) {
disabled = true;
}
}
@@ -541,18 +551,20 @@ impl Component for PwtWizard {
impl PwtWizard {
fn change_page_valid(&mut self, page: &Key, valid: bool) {
+ let mut state = self.controller.write();
if valid {
- self.pages_valid.insert(page.clone());
+ state.pages_valid.insert(page.clone());
} else {
- self.pages_valid.remove(page);
+ state.pages_valid.remove(page);
}
}
fn change_page_lock(&mut self, page: &Key, lock: bool) {
+ let mut state = self.controller.write();
if lock {
- self.pages_lock.insert(page.clone());
+ state.pages_lock.insert(page.clone());
} else {
- self.pages_lock.remove(page);
+ state.pages_lock.remove(page);
}
}
--
2.39.5
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [yew-devel] [PATCH yew-comp v2 2/4] wizard: factor out 'can progress' logic check to WizardState
2025-05-07 9:11 [yew-devel] [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState Dominik Csapak
@ 2025-05-07 9:11 ` Dominik Csapak
2025-05-07 9:11 ` [yew-devel] [PATCH yew-comp v2 3/4] wizard: optimize enabled check for next button Dominik Csapak
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Dominik Csapak @ 2025-05-07 9:11 UTC (permalink / raw)
To: yew-devel
with that we have a single point where we can check if the current
form/page state should allow us to progress.
The existing logic was reversed to get a 'positive' variable
(can_progress vs next_is_disabled), so we have to adapt the used
variable names and checks a bit.
No functional change intended.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
no changes in v2
src/wizard.rs | 48 +++++++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/src/wizard.rs b/src/wizard.rs
index b816136..e33d3c6 100644
--- a/src/wizard.rs
+++ b/src/wizard.rs
@@ -287,6 +287,30 @@ impl WizardState {
pub fn page_locked(&self, key: &Key) -> bool {
self.pages_lock.contains(key)
}
+
+ fn can_progress(&self) -> bool {
+ let mut next_enabled = true;
+ let last_page = self.page_list.last().cloned();
+ for i in 0..=self.get_current_index().unwrap_or(0) {
+ match self.page_list.get(i) {
+ None => {
+ next_enabled = false;
+ break;
+ }
+ Some(key) => {
+ if !self.page_valid(key) && Some(key) != last_page.as_ref() {
+ next_enabled = false;
+ break;
+ }
+ if self.page_locked(key) {
+ next_enabled = false;
+ break;
+ }
+ }
+ }
+ }
+ next_enabled
+ }
}
impl WizardController {
@@ -611,28 +635,10 @@ impl PwtWizard {
Some(key) => props.pages.get_index_of(key).unwrap_or(0),
};
- let mut next_is_disabled = false;
- for i in 0..=page_num {
- match props.pages.get_index(i) {
- None => {
- next_is_disabled = true;
- break;
- }
- Some((key, _)) => {
- if !self.pages_valid.contains(key) && Some(key) != last_page.as_ref() {
- next_is_disabled = true;
- break;
- }
- if self.pages_lock.contains(key) {
- next_is_disabled = true;
- break;
- }
- }
- }
- }
+ let mut next_is_enabled = state.can_progress();
if self.loading {
- next_is_disabled = true;
+ next_is_enabled = false;
}
let next_page = props
@@ -675,7 +681,7 @@ impl PwtWizard {
.with_child(
Button::new(next_button_text)
.class(ColorScheme::Primary)
- .disabled(next_is_disabled)
+ .disabled(!next_is_enabled)
.onclick({
let link = ctx.link().clone();
let next_page = next_page.clone();
--
2.39.5
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [yew-devel] [PATCH yew-comp v2 3/4] wizard: optimize enabled check for next button
2025-05-07 9:11 [yew-devel] [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState Dominik Csapak
2025-05-07 9:11 ` [yew-devel] [PATCH yew-comp v2 2/4] wizard: factor out 'can progress' logic check to WizardState Dominik Csapak
@ 2025-05-07 9:11 ` Dominik Csapak
2025-05-07 9:11 ` [yew-devel] [PATCH yew-comp v2 4/4] wizard: fix form progressing when pressing enter Dominik Csapak
2025-05-08 9:16 ` [yew-devel] applied: [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState Dietmar Maurer
3 siblings, 0 replies; 5+ messages in thread
From: Dominik Csapak @ 2025-05-07 9:11 UTC (permalink / raw)
To: yew-devel
by first checking for `self.loading` since we don't have to iterate
over the wizard pages if that is true.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* fix typo in commit subject
* use simpler boolean expression instead of if/else
src/wizard.rs | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/src/wizard.rs b/src/wizard.rs
index e33d3c6..7990cf4 100644
--- a/src/wizard.rs
+++ b/src/wizard.rs
@@ -635,11 +635,7 @@ impl PwtWizard {
Some(key) => props.pages.get_index_of(key).unwrap_or(0),
};
- let mut next_is_enabled = state.can_progress();
-
- if self.loading {
- next_is_enabled = false;
- }
+ let next_is_enabled = !self.loading && state.can_progress();
let next_page = props
.pages
--
2.39.5
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [yew-devel] [PATCH yew-comp v2 4/4] wizard: fix form progressing when pressing enter
2025-05-07 9:11 [yew-devel] [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState Dominik Csapak
2025-05-07 9:11 ` [yew-devel] [PATCH yew-comp v2 2/4] wizard: factor out 'can progress' logic check to WizardState Dominik Csapak
2025-05-07 9:11 ` [yew-devel] [PATCH yew-comp v2 3/4] wizard: optimize enabled check for next button Dominik Csapak
@ 2025-05-07 9:11 ` Dominik Csapak
2025-05-08 9:16 ` [yew-devel] applied: [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState Dietmar Maurer
3 siblings, 0 replies; 5+ messages in thread
From: Dominik Csapak @ 2025-05-07 9:11 UTC (permalink / raw)
To: yew-devel
commit
d5f3c95 (wizard: allow enter to be used for switching to next page)
intended the current page to be progressed with enter the same way
the next button is pressed.
The check for this was wrong though, since not only the form context
validity is relevant, also the page_lock state and previous page
validity state.
To fix this, use the WizardState's `can_progress` check we now have
instead, which is also used to enable/disable the `next` button.
Fixes: d5f3c95 (wizard: allow enter to be used for switching to next page)
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
no changes in v2
src/wizard.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/wizard.rs b/src/wizard.rs
index 7990cf4..b01d641 100644
--- a/src/wizard.rs
+++ b/src/wizard.rs
@@ -523,9 +523,9 @@ impl Component for PwtWizard {
.class(Flex::Fill)
.form_context(form_ctx.clone())
.onsubmit(ctx.link().batch_callback({
- let form_ctx = form_ctx.clone();
+ let state = self.controller.clone();
move |_| {
- if !form_ctx.read().is_valid() {
+ if !state.read().can_progress() {
return None;
}
if let Some(page) = next_page.clone() {
--
2.39.5
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [yew-devel] applied: [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState
2025-05-07 9:11 [yew-devel] [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState Dominik Csapak
` (2 preceding siblings ...)
2025-05-07 9:11 ` [yew-devel] [PATCH yew-comp v2 4/4] wizard: fix form progressing when pressing enter Dominik Csapak
@ 2025-05-08 9:16 ` Dietmar Maurer
3 siblings, 0 replies; 5+ messages in thread
From: Dietmar Maurer @ 2025-05-08 9:16 UTC (permalink / raw)
To: Yew framework devel list at Proxmox, Dominik Csapak
applied all 4 patches
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-08 9:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-07 9:11 [yew-devel] [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState Dominik Csapak
2025-05-07 9:11 ` [yew-devel] [PATCH yew-comp v2 2/4] wizard: factor out 'can progress' logic check to WizardState Dominik Csapak
2025-05-07 9:11 ` [yew-devel] [PATCH yew-comp v2 3/4] wizard: optimize enabled check for next button Dominik Csapak
2025-05-07 9:11 ` [yew-devel] [PATCH yew-comp v2 4/4] wizard: fix form progressing when pressing enter Dominik Csapak
2025-05-08 9:16 ` [yew-devel] applied: [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState Dietmar Maurer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox