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

Add target view utilities to operators #4076

Merged
merged 4 commits into from
Feb 9, 2024
Merged

Conversation

ritch
Copy link
Contributor

@ritch ritch commented Feb 9, 2024

Enables this usage for adding the ability to select the source of the "target view`. This is a pattern that exists in many plugins.

# common usage
class MyOperator(foo.Operator):
    def resolve_input(self, ctx):
       inputs = types.Object()
       inputs.select_view(ctx)

    def execute(self, ctx):
       selected_view = ctx.target_view()
       ctx.ops.set_view(view)

# advanced usage
view_target_property = ViewTargetProperty(ctx, view_type=Dropdown)
view_target_property.choices.entire_dataset.label = "My Custom Label"
view_target_property.choices.selected_samples.include = False # hide an option
inputs.define_property("view_target", view_target_property)
view = ctx.target_view("view_target")

Tested via this example operator.

Copy link

codecov bot commented Feb 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (release/v0.23.5@e236805). Click here to learn what that means.

Additional details and impacted files
@@                Coverage Diff                 @@
##             release/v0.23.5    #4076   +/-   ##
==================================================
  Coverage                   ?   15.99%           
==================================================
  Files                      ?      732           
  Lines                      ?    82060           
  Branches                   ?     1110           
==================================================
  Hits                       ?    13123           
  Misses                     ?    68937           
  Partials                   ?        0           
Flag Coverage Δ
app 15.99% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@benjaminpkane benjaminpkane left a comment

Choose a reason for hiding this comment

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

Tested. LGTM

@@ -501,6 +504,30 @@ def view(self):

return self._view

def target_view(self, param_name="view_target"):
Copy link
Contributor

@imanjra imanjra Feb 9, 2024

Choose a reason for hiding this comment

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

Should we call it param_name="CURRENT_VIEW" for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats the value - this is choosing which param name - ctx.params[param_name]

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh, yah true. Never mind 🙈

@@ -723,7 +757,11 @@ class Choices(View):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.choices = kwargs.get("choices", [])
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this is a breaking change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to make this entirely backwards compatible - a choice is only included now if it has a include = True - which is the default.

self._choices = kwargs.get("choices", [])

@property
def choices(self):
Copy link
Contributor Author

@ritch ritch Feb 9, 2024

Choose a reason for hiding this comment

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

This replaces the old choices attribute

@ritch ritch merged commit a394dd7 into release/v0.23.5 Feb 9, 2024
8 of 9 checks passed
@ritch ritch deleted the view-target-util branch February 9, 2024 21:51
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

Successfully merging this pull request may close these issues.

3 participants