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

Experiment Session Filter #1260

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open

Experiment Session Filter #1260

wants to merge 32 commits into from

Conversation

stephherbers
Copy link
Contributor

Description

A new and much improved filter ticket
Design doc here

Screenshot 2025-02-27 at 2 54 40 PM

Using django-filter turned out to be a bit more complicated than I thought- I still think it's worth looking into, but not worth blocking the rollout of this feature.

I still would like to work on getting the column types in the html templated so this can be used elsewhere in the codebase, but that can be a followup ticket as well

User Impact

It will make querying the data much easier and granular and hopefully they will not have to export the data just to filter it.

Also the filters are in the url so users can copy and send the link to others with the filters applied which I bet will come in handy

Demo

Loom video

Docs and Changelog

changelog yes indeed

@codecov-commenter
Copy link

codecov-commenter commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 13.54167% with 83 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/experiments/filters.py 15.38% 55 Missing ⚠️
apps/experiments/views/experiment.py 10.00% 27 Missing ⚠️
apps/experiments/models.py 0.00% 1 Missing ⚠️
Additional details and impacted files

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@snopoke snopoke left a comment

Choose a reason for hiding this comment

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

This is looking great @stephherbers. Some comments but nothing major.

},
});

showTabContent('allsessions');
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this need to be added? Also it won't work if the user doesn't have 'view_chat' permissions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right this is a weird permissions thing-- without this there, when a user navigates to the experiment page just the tabs are shown. Then to see the sessions the user has to click a different tab (like events) and then click sessions again to see the sessions

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I think somewhere the tab is being hidden unexpectedly rather. It should be showing up by default, since the allsessions tab is checked by default

Copy link
Contributor

@snopoke snopoke left a comment

Choose a reason for hiding this comment

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

Looking great. I'm going to test this out locally tomorrow before approving.

from apps.chat.models import Chat, ChatMessage


def build_participant_filter(operator, value):
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a style note (no need to take action at this point):

These could be made generic by extracting the field name:

def build_string_filter(field_name, operator, value):
    ...

participant_filter = build_string_filter("participant__identifier", operator, value)

Copy link
Contributor

@snopoke snopoke left a comment

Choose a reason for hiding this comment

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

One comment on the filter query for tags and then I did some testing locally and put together a QA doc: https://docs.google.com/document/d/1u5BHH4bKjggG3XZMk_-Y7oke6ft6nlxZb-J3cuE46Uk/edit?tab=t.0

It's mostly small stuff but I think it'd be good to get the 'MUST' section done before merging.

)
.filter(matching_tag_count=len(selected_tags))
.values_list("id", flat=True)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a simpler way of doing this is to use an exists query:

content_type = ContentType.objects.get_for_model(Chat)
conditions = Q()
for tag in selected_tags:
  conditions &= Exists(
    CustomTaggedItem.objects.filter(
        object_id=OuterRef("id"),
        content_type_id=content_type,
        tag__name=name,
    )
  )
return conditions

if tags_query := self.request.GET.get("tags"):
tags = tags_query.split("&")
query_set = query_set.filter(chat__tags__name__in=tags).distinct()
for i in range(30): # arbitrary number higher than any # of filters we'd expect
Copy link
Contributor

@SmittieC SmittieC Mar 10, 2025

Choose a reason for hiding this comment

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

we could also do a while loop here. Something like

idx = 0
while True:
   ...
   idx += 1

Copy link
Contributor

Choose a reason for hiding this comment

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

It was originally a while loop. I suggested changing it to a for loop to avoid any chance of runaway

Copy link
Contributor

Choose a reason for hiding this comment

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

what about doing

while filter_column and filter_operator and filter_value:
   ...

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.

4 participants