[pdm-devel] [PATCH yew-comp 2/2] token_panel: implement a token panel
Shannon Sterz
s.sterz at proxmox.com
Thu Oct 2 17:30:12 CEST 2025
On Sat Sep 27, 2025 at 7:07 PM CEST, Thomas Lamprecht wrote:
> Am 26.09.25 um 10:50 schrieb Dominik Csapak:
>>> +async fn load_api_tokens() -> Result<Vec<ApiToken>, Error> {
>>> + let url = "/access/users/?include_tokens=1";
>>> + let users: Vec<UserWithTokens> = crate::http_get(url, None).await?;
>>> + let mut list: Vec<ApiToken> = Vec::new();
>>> +
>>> + for user in users.into_iter() {
>>> + list.extend(user.tokens)
>>> + }
>>> +
>>> + Ok(list)
>>
>> could also be written as
>>
>> Ok(users.into_iter().map(|user| user.tokens))
>
> That misses a collect and that tokens is a list too, but while it cannot
> be written that way, one can do it almost like this using:
>
> Ok(users.into_iter().flat_map(|user| user.tokens).collect())
>
> I made a follow-up commit doing so.
thanks for that!
> Am 26.09.25 um 10:50 schrieb Dominik Csapak:
>>> + Dialog::new(tr!("Token Secret"))
>>> + .with_child(
>>> + Column::new()
>>> + .with_child(
>>> + InputPanel::new()
>>> + .padding(4)
>>> + .with_large_field(
>>> + tr!("Token ID"),
>>> + DisplayField::new()
>>> + .value(AttrValue::from(
>>> + secret["tokenid"].as_str().unwrap_or("").to_owned(),
>>> + ))
>>> + .border(true),
>>> + )
>>> + .with_large_field(
>>> + tr!("Secret"),
>>> + DisplayField::new()
>>> + .value(AttrValue::from(
>>> + secret["value"].as_str().unwrap_or("").to_owned(),
>>> + ))
>>> + .border(true),
>>> + ),
>>> + )
>>> + .with_child(
>>> + Container::new()
>>> + .style("opacity", "0")
>>> + .with_child(AttrValue::from(
>>> + secret["value"].as_str().unwrap_or("").to_owned(),
>>> + ))
>>> + .into_html_with_ref(self.secret_node_ref.clone()),
>>
>> does this actually work as a copy input?
>>
>> AFAICS: copy_to_clipboard wants to cast the noderef to a
>> HtmlInputElement, and i don't think a container qualifies for that?
>
> Would probably be better to rename it to something like
> copy_input_element_to_clipboard then, and add a new function
> copy_text_content_to_clipoard that simply takes the noderef's
> textContent [0]. As of is this rather confusing, doesn't help
> that the copy_to_clipboard fn silently ignores if it fails to
> cast the element.
>
> [0]: https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
>
>>
>> couldn't we simply show the secret in a disabled textfield and use that for copying? then we don't have to add some extra 'hidden' container with the secret?
>
> There is already a field displaying the secret above, which should
> be usable? The whole thing seems like a useless indirection.
i did use that originally but some recent changes to how node refs work
meant i could not use the display field as it didn't support node refs
anymore. this code stems from peat, where i needed to fix that up
quickly to be able to build a new version that didn't include any sudden
regressions, this is what i came up with at the time.
which also means: this does work, but it's not nice.
imo the proper solution however is to use the new clipboard api that is
now in stable web-sys [1,2]. fabian packaged a new web-sys version this
week, so i'd adapt to it unless someone objects to that.
note that `execCommand` used by copy_to_clipboard is
deprecated [2].
[1]: https://docs.rs/web-sys/0.3.76/web_sys/struct.Clipboard.html
[2]: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText
[3]: https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
> Btw. I know this mirrors the original and I added the copy button there,
> but nowadays I'd prefer having a icon-only+tooltip button to the right of
> the input field for both fields.
makes sense, i can look into that while i'm at it. but imo, we should
come up with a more consistent way of treating buttons with icons in
general. most buttons in pdm don't use any icons at all.
More information about the pdm-devel
mailing list