[yew-devel] Superseded: Re: [PATCH yew-comp/yew-widget-toolkit v2 0/2] add helpers to get a record via a Selection from a Store

Shannon Sterz s.sterz at proxmox.com
Fri Nov 21 17:16:17 CET 2025


Supersed-by: https://lore.proxmox.com/yew-devel/20251121161423.390869-1-s.sterz@proxmox.com/

On Thu Nov 6, 2025 at 3:47 PM CET, Shannon Sterz wrote:
> a very common pattern is to use a `Store` combined with a `Selection`.
> however, to get the record from a `Store` that has the same `Key` as is
> selected by the `Selection` is a little cumbersome. it requires
> dealing with several optional values. so many components implement a
> helper for that. it usually looks like this:
>
> ```rust
> fn get_selected_record(&self) -> Option<ApiToken> {
>     self.selection
>         .selected_key()
>         .and_then(|key| self.store.read().lookup_record(&key).cloned())
> }
>
> let Some(record) = self.get_selected_record() else {
>     return false;
> }
> ```
>
> to avoid duplicating this effort in every such component add new helper
> methods to the `Store`. they each take a `Selection` and either return
> an optional reference or an optional clone of the selected record.
> turning the above into:
>
> ```rust
> let Some(record) = self.store.selected_record(&self.selection) else {
>     return false;
> }
> ```
>
> there are also helpers that are prefixed with `multi_` to help deal with
> `Selection`s in multi-select mode by returning a vector of all selected
> entries.
>
> the second commit in this series is mostly for demonstrative purposes.
> sending this as an rfc as i am not sure if the naming of these functions
> is ideal or whether we want to add both helpers (instead of just one of
> them).
>
> proxmox-yew-widget-toolkit:
>
> Shannon Sterz (1):
>   store: add helper methods to extract a record via a selection
>
>  src/state/store.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 48 insertions(+), 1 deletion(-)
>
>
> proxmox-yew-comp:
>
> Shannon Sterz (1):
>   token panel: use new `selected_record` helper
>
>  src/token_panel.rs | 11 ++---------
>  1 file changed, 2 insertions(+), 9 deletions(-)
>
>
> Summary over all repositories:
>   2 files changed, 50 insertions(+), 10 deletions(-)
>
> --
> Generated by git-murpp 0.8.1





More information about the yew-devel mailing list