-
-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
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 withoutdriver
column (all values are same, all link to thedriver
detail page itself). - on the
car
detail page, it is useful to display the table withoutcar
column (all values are same, all link to thecar
detail page itself). - on the list of road trips page, both
driver
andcar
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
Labels
No labels