Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip columns based on an enum #58

Open
otopetrik opened this issue Nov 22, 2024 · 0 comments
Open

Skip columns based on an enum #58

otopetrik opened this issue Nov 22, 2024 · 0 comments

Comments

@otopetrik
Copy link

Data which represent a relation are often displayed in multiple places, but often without a column representing one side of the relation.

Example:

#[derive(leptos_struct_table::TableRow, Clone)]
#[table(sortable, impl_vec_data_provider)]
struct RoadTripRow {
    pub driver: AppRoute,
    pub car: AppRoute,
    #[table(format(string = "[year]-[month]-[day]T[hour]:[minute]:[second]"))]
    pub trip_begin: Option<OffsetDateTime>,
    #[table(format(string = "[year]-[month]-[day]T[hour]:[minute]:[second]"))]
    pub trip_end: Option<OffsetDateTime>,
    ...
}

(assume that AppRoute type implements leptos_struct_table::CellValue to render a hyperlink)

  • on the driver detail page, it is useful to display the table without driver column (all values are same, all link to the driver detail page itself).
  • on the car detail page, it is useful to display the table without car column (all values are same, all link to the car detail page itself).
  • on the list of road trips page, both driver and car columns are displayed.

Current solution is to duplicate the table as RoadTripRowFromDriver and RoadTripRowFromCar, and delete (or #[table(skip)]) one row in each copy.

It works, but maintenance is not ideal. With more relations in the system, it requires extra effort to keep all three table structures (for every relation) in sync,

It would be nice improvement, if something like the following were possible:

enum RoadTripRowMode {
    All,
    FromDriver,
    FromCar,
}

#[derive(leptos_struct_table::TableRow, Clone)]
#[table(sortable, impl_vec_data_provider)]
struct RoadTripRow {
   #[table(skip_if=RoadTripRowMode::FromDriver)]
    pub driver: AppRoute,
   #[table(skip_if=RoadTripRowMode::FromCar)]
    pub car: AppRoute,
    #[table(format(string = "[year]-[month]-[day]T[hour]:[minute]:[second]"))]
    pub trip_begin: Option<OffsetDateTime>,
    #[table(format(string = "[year]-[month]-[day]T[hour]:[minute]:[second]"))]
    pub trip_end: Option<OffsetDateTime>,
    ...
}

...

// on driver detail page
// <Table mode=RoadTripRowMode::FromDriver ... />
// on car detail page
// <Table mode=RoadTripRowMode::FromCar ... />
// on list of all road trips page
// <Table mode=RoadTripRowMode::All ... />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant