Skip to content

Commit

Permalink
fixed skip_sort
Browse files Browse the repository at this point in the history
  • Loading branch information
maccesch committed Nov 2, 2023
1 parent 92cb3cd commit 0a1be91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "leptos-struct-table-macro"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
authors = ["Marc-Stefan Cassola"]
description = "Macros for the leptos-struct-table crate."
Expand Down
24 changes: 16 additions & 8 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ fn get_data_provider_logic(
..
} = **f;

if (skip_sort || skip) && !f.key {
if (skip) && !f.key {
continue;
}

Expand Down Expand Up @@ -398,13 +398,15 @@ fn get_data_provider_logic(
});
}

column_value_cmp_arms.push(quote! {
(#column_value_enum::#column_name_variant(a), #column_value_enum::#column_name_variant(b)) => a.partial_cmp(b),
});
if !skip_sort {
column_value_cmp_arms.push(quote! {
(#column_value_enum::#column_name_variant(a), #column_value_enum::#column_name_variant(b)) => a.partial_cmp(b),
});

column_value_get_arms.push(quote! {
#column_name_enum::#column_name_variant => #column_value_enum::#column_name_variant(self.#getter),
});
column_value_get_arms.push(quote! {
#column_name_enum::#column_name_variant => #column_value_enum::#column_name_variant(self.#getter),
});
}
}

assert!(
Expand Down Expand Up @@ -614,6 +616,12 @@ impl ToTokens for TableComponentDeriveInput {
let column_value_variant = quote! { #column_value_enum::#column_name_variant };
let column_name_variant = quote! { #column_name_enum::#column_name_variant };

let on_click_handling = if sortable && !f.skip_sort {
quote! { on_click=on_head_click.clone() }
} else {
quote! { on_click=|_| () }
};

titles.push(quote! {
<#head_renderer
class=Signal::derive(move || class_provider.clone().head_cell(column_sort.clone()(#column_name_variant), #head_class))
Expand All @@ -627,7 +635,7 @@ impl ToTokens for TableComponentDeriveInput {
sorting().iter().position(|(field, _)| *field == #column_name_variant)
})
sort_direction=Signal::derive(move || column_sort.clone()(#column_name_variant))
on_click=on_head_click.clone()
#on_click_handling
>
#title
</#head_renderer>
Expand Down

0 comments on commit 0a1be91

Please sign in to comment.