Skip to content

Conversation

mihow
Copy link
Collaborator

@mihow mihow commented Jul 4, 2025

Summary

Enable several needed filter methods for source image collections to the UI, using raw IDs.

image

List of Changes

  • Exposes deployment_ids filter to the UI - very helpful, but currently requires Django admin to use
  • New filter for station_ids - requested by partner
  • New filter for event_ids - required for testing tracking
  • Method for specifying a custom serialization & deserialization for form fields in the UI
  • New "Advanced Filter" section in the source image collection form

Implementation Details

This is a simple way to allow filtering by related data using existing UI components. However a custom validator was added for comma separated integers, as well as a way to serialize & deserialize JSON lists to & from the API.

@Copilot Copilot AI review requested due to automatic review settings July 4, 2025 21:50
Copy link

netlify bot commented Jul 4, 2025

Deploy Preview for antenna-preview ready!

Name Link
🔨 Latest commit 846957f
🔍 Latest deploy log https://app.netlify.com/projects/antenna-preview/deploys/6892843157ae000008ed639b
😎 Deploy Preview https://deploy-preview-895--antenna-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 61 (🟢 up 1 from production)
Accessibility: 80 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables advanced filtering options on source image collections by introducing utilities for parsing and validating comma-separated integer lists, updating the frontend form to include new filter fields, and extending the backend to accept and apply event_ids and research_site_ids.

  • Added validateInteger, parseIntegerList, formatIntegerList, and validateIntegerList utilities.
  • Extended CollectionDetailsForm with "Advanced Filters" fields and wired up toApiValue/toFormValue transformations.
  • Updated Django models and serializers to accept and filter by event_ids and research_site_ids.
  • Added an ID column in the entities table for better sorting and display.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ui/src/utils/fieldProcessors.ts Introduced integer list parsing/formatting/validation utilities
ui/src/pages/project/entities/entities-columns.tsx Added id column to the entities table
ui/src/pages/project/entities/details-form/collection-details-form.tsx Integrated new filter fields and refactored integer validation in the collection details form
ui/src/components/form/types.ts Extended FieldConfig type with toApiValue and toFormValue
ami/main/models.py Updated sampling methods and _filter_sample to handle event_ids and research_site_ids
ami/main/api/serializers.py Added event_ids and research_site_ids to the common kwargs serializer
Comments suppressed due to low confidence (2)

ui/src/utils/fieldProcessors.ts:23

  • Add unit tests covering parseIntegerList, formatIntegerList, and validateIntegerList to ensure these utilities handle edge cases (empty strings, invalid tokens) correctly.
export const parseIntegerList = (

ami/main/models.py:3146

  • [nitpick] Switching to *args, **kwargs hides the expected filter parameters and reduces readability; consider restoring explicit parameters (hour_start, hour_end, etc.) in the signature for clarity.
    def get_queryset(

if (!value || value.trim() === '') return undefined // Optional field
const pattern = /^\s*\d+\s*(?:\s*,\s*\d+\s*)*$/
if (!pattern.test(value)) {
return 'Enter comma-separated integers (e.g., 1, 2, 3).'
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

Use the translate function for this error message to ensure consistency with localization (e.g., translate(STRING.MESSAGE_INTEGER_LIST_INVALID)).

Copilot uses AI. Check for mistakes.

@annavik
Copy link
Member

annavik commented Jul 5, 2025

Thanks Michael, this is great! I just tweaked the labels a bit.

Some thoughts:

  • I think we should first introduce the station filters and see if that is enough, before we add site filtering. I want to keep the form as simple as possible and I suspect filtering by station might solve the problem for the partner :)
  • I think the advanced filter section is making the form a bit too complicated. I like the idea and I think we should split up filters this way moving forward, but I think advanced filters should only be visible on demand. Since that requires some more work, I wonder if I good start could be we just add a row to the current filter section? As the next step, I would like to collapse this section a bit and add a "Show more" button?
Screenshot 2025-07-05 at 15 07 11

@annavik annavik force-pushed the feat/advanced-collection-filters-2 branch from 74269f1 to 5d33718 Compare July 5, 2025 13:33
mihow and others added 2 commits July 21, 2025 17:39
@mihow
Copy link
Collaborator Author

mihow commented Jul 22, 2025

Thanks Michael, this is great! I just tweaked the labels a bit.

Some thoughts:

  • I think we should first introduce the station filters and see if that is enough, before we add site filtering. I want to keep the form as simple as possible and I suspect filtering by station might solve the problem for the partner :)
  • I think the advanced filter section is making the form a bit too complicated. I like the idea and I think we should split up filters this way moving forward, but I think advanced filters should only be visible on demand. Since that requires some more work, I wonder if I good start could be we just add a row to the current filter section? As the next step, I would like to collapse this section a bit and add a "Show more" button?
Screenshot 2025-07-05 at 15 07 11

Thanks @annavik! I agree with you and I look forward to a Show More button here. The Site filter will be really convenient when we add it because you only need to specify one Site instead of looking up all the Station IDs. But I agree that just Station IDs & Session IDs keeps it more flexible and just one row of new fields.

Another option (for a follow-up PR) is to add a general config with a JSON editor. Then we don't have to restrict any functionality and encourage users to switch away from Antenna back to their own scripts, etc. That would be my preference across the site (hidden by default). I think this is a common pattern, where the UI provides a visual config builder for basic things, but then lets you switch to the advanced/code mode to edit some syntax directly (QGIS, NewRelic, LabelStudio, Overleaf, Weights & Biases, any WYSIWYG editor, are some examples that come to mind).

@mihow mihow merged commit bc565b1 into main Aug 5, 2025
8 checks passed
@mihow mihow deleted the feat/advanced-collection-filters-2 branch August 5, 2025 22:28
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.

2 participants