Skip to content

Skip columns based on an enum #58

@otopetrik

Description

@otopetrik

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 ... />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy