Skip to content

Commit

Permalink
[dfv2] update query UI based on fbs updates
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Oct 2, 2024
1 parent ab6e266 commit 390a53a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::collections::HashSet;

use crate::dataframe_ui::HideColumnAction;
use crate::view_query_v2::{EventColumn, QueryV2};
use crate::view_query_v2::QueryV2;
use re_chunk_store::{ColumnDescriptor, ColumnSelector};
use re_log_types::{EntityPath, TimeInt, TimelineName};
use re_types::blueprint::{components, datatypes};
use re_types_core::ComponentName;
use re_viewer_context::{SpaceViewSystemExecutionError, ViewerContext};

// Accessors wrapping reads/writes to the blueprint store.
Expand Down Expand Up @@ -49,73 +48,43 @@ impl QueryV2 {

// clearing the range filter is equivalent to setting it to the default -inf/+inf
self.query_property
.clear_blueprint_component::<components::RangeFilter>(ctx);
.clear_blueprint_component::<components::FilterByRange>(ctx);
}

pub(crate) fn range_filter(&self) -> Result<(TimeInt, TimeInt), SpaceViewSystemExecutionError> {
#[allow(clippy::map_unwrap_or)]
Ok(self
.query_property
.component_or_empty::<components::RangeFilter>()?
.component_or_empty::<components::FilterByRange>()?
.map(|range_filter| (range_filter.start.into(), range_filter.end.into()))
.unwrap_or((TimeInt::MIN, TimeInt::MAX)))
}

pub(super) fn save_range_filter(&self, ctx: &ViewerContext<'_>, start: TimeInt, end: TimeInt) {
if (start, end) == (TimeInt::MIN, TimeInt::MAX) {
self.query_property
.clear_blueprint_component::<components::RangeFilter>(ctx);
.clear_blueprint_component::<components::FilterByRange>(ctx);
} else {
self.query_property
.save_blueprint_component(ctx, &components::RangeFilter::new(start, end));
.save_blueprint_component(ctx, &components::FilterByRange::new(start, end));
}
}

pub(crate) fn filter_by_event_active(&self) -> Result<bool, SpaceViewSystemExecutionError> {
Ok(self
.query_property
.component_or_empty::<components::FilterByEventActive>()?
.map_or(false, |comp| *comp.0))
}

pub(super) fn save_filter_by_event_active(&self, ctx: &ViewerContext<'_>, active: bool) {
self.query_property
.save_blueprint_component(ctx, &components::FilterByEventActive(active.into()));
}

pub(crate) fn filter_event_column(
pub(crate) fn filter_by_event(
&self,
) -> Result<Option<EventColumn>, SpaceViewSystemExecutionError> {
) -> Result<Option<components::FilterByEvent>, SpaceViewSystemExecutionError> {
Ok(self
.query_property
.component_or_empty::<components::ComponentColumnSelector>()?
.map(|comp| {
let components::ComponentColumnSelector(datatypes::ComponentColumnSelector {
entity_path,
component,
}) = comp;

EventColumn {
entity_path: EntityPath::from(entity_path.as_str()),
component_name: ComponentName::from(component.as_str()),
}
}))
.component_or_empty::<components::FilterByEvent>()?)
}

pub(super) fn save_filter_event_column(
pub(super) fn save_filter_by_event(
&self,
ctx: &ViewerContext<'_>,
event_column: EventColumn,
filter_by_event: &components::FilterByEvent,
) {
let EventColumn {
entity_path,
component_name,
} = event_column;

let component = components::ComponentColumnSelector::new(&entity_path, component_name);

self.query_property
.save_blueprint_component(ctx, &component);
.save_blueprint_component(ctx, filter_by_event);
}

pub(crate) fn latest_at_enabled(&self) -> Result<bool, SpaceViewSystemExecutionError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@ mod blueprint_io;
mod ui;

use re_chunk_store::ColumnDescriptor;
use re_log_types::EntityPath;
use re_types::blueprint::archetypes;
use re_types_core::ComponentName;
use re_viewer_context::{SpaceViewId, SpaceViewSystemExecutionError, ViewerContext};
use re_viewport_blueprint::ViewProperty;

/// Struct to hold the point-of-view column used for the filter by event.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct EventColumn {
pub(crate) entity_path: EntityPath,
pub(crate) component_name: ComponentName,
}

/// Wrapper over the `DataframeQueryV2` blueprint archetype that can also display some UI.
pub(crate) struct QueryV2 {
query_property: ViewProperty,
Expand Down
39 changes: 19 additions & 20 deletions crates/viewer/re_space_view_dataframe/src/view_query_v2/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use re_chunk_store::{ColumnDescriptor, ColumnSelector};
use re_log_types::{
EntityPath, ResolvedTimeRange, TimeInt, TimeType, TimeZone, Timeline, TimelineName,
};
use re_types::blueprint::components;
use re_types_core::{ComponentName, ComponentNameSet};
use re_ui::{list_item, UiExt};
use re_viewer_context::{SpaceViewId, SpaceViewSystemExecutionError, TimeDragValue, ViewerContext};

use crate::view_query_v2::{EventColumn, QueryV2};
use crate::view_query_v2::QueryV2;

// UI implementation
impl QueryV2 {
Expand Down Expand Up @@ -135,24 +136,24 @@ impl QueryV2 {
// Read stuff
//

let mut filter_by_event_active = self.filter_by_event_active()?;
let original_filter_by_event = self.filter_by_event()?;

let original_event_column = self.filter_event_column()?;
let (event_entity, event_component) =
original_event_column.clone().map_or((None, None), |col| {
(Some(col.entity_path), Some(col.component_name))
});
let (mut active, event_entity, event_component) = original_filter_by_event
.as_ref()
.map(|filter| {
(
filter.active(),
Some(filter.entity_path()),
Some(filter.component_name()),
)
})
.unwrap_or((false, None, None));

//
// Filter active?
//

if ui
.re_checkbox(&mut filter_by_event_active, "Filter by event from:")
.changed()
{
self.save_filter_by_event_active(ctx, filter_by_event_active);
}
ui.re_checkbox(&mut active, "Filter by event from:");

//
// Event entity
Expand Down Expand Up @@ -207,7 +208,7 @@ impl QueryV2 {
// UI for event entity and component
//

ui.add_enabled_ui(filter_by_event_active, |ui| {
ui.add_enabled_ui(active, |ui| {
ui.spacing_mut().item_spacing.y = 0.0;

ui.list_item_flat_noninteractive(list_item::PropertyContent::new("Entity").value_fn(
Expand Down Expand Up @@ -241,13 +242,11 @@ impl QueryV2 {
// Save event if changed
//

let event_column = EventColumn {
entity_path: event_entity,
component_name: event_component,
};
let filter_by_event =
components::FilterByEvent::new(active, &event_entity, event_component);

if original_event_column.as_ref() != Some(&event_column) {
self.save_filter_event_column(ctx, event_column);
if original_filter_by_event.as_ref() != Some(&filter_by_event) {
self.save_filter_by_event(ctx, &filter_by_event);
}

Ok(())
Expand Down

0 comments on commit 390a53a

Please sign in to comment.