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

Also remove nested inclusions when removing a subtree #5720

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/re_log_types/src/path/entity_path_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,22 @@ impl EntityPathFilter {
);
}

/// Remove a subtree and any existing rules that it would match.
///
/// Because most-specific matches win, if we only add a subtree exclusion
/// it can still be overridden by existing inclusions. This method ensures
/// that not only do we add a subtree exclusion, but clear out any existing
/// inclusions or (now redundant) exclusions that would match the subtree.
pub fn remove_subtree_and_matching_rules(&mut self, clone: EntityPath) {
let new_exclusion = EntityPathRule::including_subtree(clone);

// Remove any rule that is a subtree of the new exclusion.
self.rules
.retain(|rule, _| !new_exclusion.matches(&rule.path));

self.rules.insert(new_exclusion, RuleEffect::Exclude);
}

/// Remove any rule for the given entity path (ignoring whether or not that rule includes the subtree).
pub fn remove_rule_for(&mut self, entity_path: &EntityPath) {
self.rules.retain(|rule, _| rule.path != *entity_path);
Expand Down
12 changes: 12 additions & 0 deletions crates/re_space_view/src/space_view_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ impl SpaceViewContents {
}
}

/// Remove a subtree and any existing rules that it would match.
///
/// Because most-specific matches win, if we only add a subtree exclusion
/// it can still be overridden by existing inclusions. This method ensures
/// that not only do we add a subtree exclusion, but clear out any existing
/// inclusions or (now redundant) exclusions that would match the subtree.
pub fn remove_subtree_and_matching_rules(&self, ctx: &ViewerContext<'_>, path: EntityPath) {
let mut new_entity_path_filter = self.entity_path_filter.clone();
new_entity_path_filter.remove_subtree_and_matching_rules(path);
self.set_entity_path_filter(ctx, &new_entity_path_filter);
}

pub fn add_entity_exclusion(&self, ctx: &ViewerContext<'_>, rule: EntityPathRule) {
// TODO(emilk): ignore new rule if it is already covered by existing rules (noop)
let mut new_entity_path_filter = self.entity_path_filter.clone();
Expand Down
5 changes: 2 additions & 3 deletions crates/re_viewport/src/context_menu/actions/remove.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use re_entity_db::InstancePath;
use re_log_types::EntityPathRule;
use re_viewer_context::{ContainerId, Contents, Item, SpaceViewId};

use crate::context_menu::{ContextMenuAction, ContextMenuContext};
Expand Down Expand Up @@ -48,9 +47,9 @@ impl ContextMenuAction for RemoveAction {
instance_path: &InstancePath,
) {
if let Some(space_view) = ctx.viewport_blueprint.space_view(space_view_id) {
space_view.contents.add_entity_exclusion(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be wise to also remove the old foot-gunny add_entity_exclusion, or rewrite it to never include the subtree (i.e. take an entity path instead of a EntityPathRule)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered it, but I found the behavior that it gives in the query editor-view to still be useful.

In that view we give much clearer visibillity into all the rules that are in effect and the fact that 1 click = 1 rule modification matches what a user also does when hand-editing the expressions, where I would expect them to manually delete the inclusion lines rather than having them deleted automagically once they've typed a subtree removal expression.

space_view.contents.remove_subtree_and_matching_rules(
ctx.viewer_context,
EntityPathRule::including_subtree(instance_path.entity_path.clone()),
instance_path.entity_path.clone(),
);
}
}
Expand Down
8 changes: 3 additions & 5 deletions crates/re_viewport/src/viewport_blueprint_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use smallvec::SmallVec;

use re_entity_db::InstancePath;
use re_log_types::EntityPath;
use re_log_types::EntityPathRule;
use re_space_view::SpaceViewBlueprint;
use re_types::blueprint::components::Visible;
use re_ui::{drag_and_drop::DropTarget, list_item::ListItem, ReUi};
Expand Down Expand Up @@ -600,10 +599,9 @@ impl Viewport<'_, '_> {
"Remove group and all its children from the space view",
);
if response.clicked() {
space_view.contents.add_entity_exclusion(
ctx,
EntityPathRule::including_subtree(entity_path.clone()),
);
space_view
.contents
.remove_subtree_and_matching_rules(ctx, entity_path.clone());
}

response | vis_response
Expand Down
Loading