Skip to content

FieldRegion & FieldZone filtering & sorting #3503

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

CarsonF
Copy link
Member

@CarsonF CarsonF commented Jun 18, 2025

Part of #3500

Copy link

coderabbitai bot commented Jun 18, 2025

📝 Walkthrough

Walkthrough

This change introduces enhanced and more granular filtering and sorting capabilities for the FieldRegion, FieldZone, and Project entities. It adds nested filter fields and corresponding sorting logic, enabling queries based on related entities such as directors and zones. The updates affect DTOs, repositories, and filter/sorter definitions, supporting complex, relation-aware queries.

Changes

Files/Groups Change Summary
src/components/field-region/dto/list-field-region.dto.ts Expanded FieldRegionFilters with nested id, director, and fieldZone filters; made filter publicly accessible in FieldRegionListInput.
src/components/field-region/field-region.repository.ts Introduced fieldRegionFilters and fieldRegionSorters for structured, nested filtering and sorting logic.
src/components/field-zone/dto/list-field-zone.dto.ts Added id and nested director filter fields to FieldZoneFilters; made filter public in FieldZoneListInput.
src/components/field-zone/field-zone.repository.ts Added fieldZoneFilters and fieldZoneSorters for modular filtering and sorting, including nested director logic.
src/components/project/dto/list-projects.dto.ts Added fieldRegion filter field to ProjectFilters.
src/components/project/project-filters.query.ts Added fieldRegion filter to projectFilters definition.
src/components/project/project.repository.ts Extended projectSorters with a sorter for fieldRegion.* properties using fieldRegionSorters.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/components/field-zone/field-zone.repository.ts (1)

135-137: Same concern as raised for FieldRegionRepository.list: protect against undefined filters to avoid brittle assumptions in fieldZoneFilters.

🧹 Nitpick comments (9)
src/components/project/project-filters.query.ts (1)

111-117: Add a description for the new fieldRegion filter to keep API docs consistent

Most of the existing filters include description text so the generated GraphQL schema is self-documenting.
Adding the same here keeps the public API consistent and discoverable.

-  fieldRegion: filter.sub(() => fieldRegionFilters)((sub) =>
+  fieldRegion: filter.sub(() => fieldRegionFilters, {
+    description: 'Only projects whose field region matches these filters',
+  })((sub) =>
src/components/project/dto/list-projects.dto.ts (1)

138-140: Document the fieldRegion filter field

Other FilterFields have a description, which shows up in the GraphQL docs and helps clients know what the field does. Consider adding one for parity.

-  @FilterField(() => FieldRegionFilters)
+  @FilterField(() => FieldRegionFilters, {
+    description: 'Only projects whose field region matches these filters',
+  })
src/components/project/project.repository.ts (1)

461-476: Repeated sorter pattern could be abstracted

primaryLocation.*, primaryPartnership.*, and now fieldRegion.* all share the same “match or return null” union pattern. Extracting this into a small helper (e.g. defineRelationshipSorter(rel, label, sorters)) would DRY up the repository and make adding the next nested sorter trivial.

No code change required in this PR.

src/components/field-zone/dto/list-field-zone.dto.ts (1)

18-20: Missing descriptions on new filter fields

id and director lack description metadata, unlike similar filters elsewhere. Adding them improves generated docs.

 @IdField({ optional: true, description: 'Filter by zone id' })
 ...
 @FilterField(() => UserFilters, {
   description: 'Only zones directed by users matching these filters',
 })
src/components/field-region/dto/list-field-region.dto.ts (1)

16-24: Add descriptions for new properties & verify public exposure

  1. Provide description text for id, director, and fieldZone to align with other DTOs.
  2. The filter field is now public (internal flag removed). Ensure this breaking-schema change is intentional.
-  @IdField({ optional: true })
+  @IdField({ optional: true, description: 'Filter by region id' })
 ...
-  @FilterField(() => UserFilters)
+  @FilterField(() => UserFilters, {
+    description: 'Only regions directed by users matching these filters',
+  })
 ...
-  @FilterField(() => FieldZoneFilters)
+  @FilterField(() => FieldZoneFilters, {
+    description: 'Only regions whose field zone matches these filters',
+  })
src/components/field-region/field-region.repository.ts (2)

141-157: Alias shadowing in nested filter match blocks can lead to hard-to-trace bugs

Both sub-filters reuse the "node" alias for the inner entity while the outer entity is silently renamed to "outer".
If another developer later nests additional filters/sorters that also expect "node" to be the outer alias, queries will silently break.
Consider using distinct aliases (directorNode, fieldZoneNode, …) or a helper that guarantees alias uniqueness.


159-180: Duplicate sorter scaffolding – opportunity for a shared helper

The two blocks are 100 % identical aside from relationship name and delegated sorters.
Extracting a higher-order helper (nestedSorter('director', userSorters) / nestedSorter('zone', fieldZoneSorters)) would:

  • eliminate duplication,
  • enforce a uniform pattern across repositories, and
  • make future maintenance (e.g., tweaking with / match structure) one-shot.

No functional issue, purely maintainability.

src/components/field-zone/field-zone.repository.ts (2)

156-165: DRY up director sub-filter logic

The director sub-filter here duplicates the pattern already defined in fieldRegionFilters and (potentially) other repositories.
Extract a shared helper (e.g., directorSubFilter()) so any change to the relationship pattern or aliasing is done once.


167-178: Shared nested sorter helper would trim repetition

Mirrors the comment on fieldRegionSorters: consider a reusable nestedSorter utility to generate these boilerplate blocks and ensure consistency.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6cdf774 and 98b9c24.

📒 Files selected for processing (7)
  • src/components/field-region/dto/list-field-region.dto.ts (2 hunks)
  • src/components/field-region/field-region.repository.ts (3 hunks)
  • src/components/field-zone/dto/list-field-zone.dto.ts (2 hunks)
  • src/components/field-zone/field-zone.repository.ts (3 hunks)
  • src/components/project/dto/list-projects.dto.ts (2 hunks)
  • src/components/project/project-filters.query.ts (2 hunks)
  • src/components/project/project.repository.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/components/project/dto/list-projects.dto.ts (1)
src/common/filter-field.ts (1)
  • FilterField (11-31)
src/components/project/project-filters.query.ts (3)
src/components/field-region/field-region.repository.ts (1)
  • fieldRegionFilters (141-157)
src/core/database/query/filters.ts (1)
  • sub (243-272)
src/core/database/query/matching.ts (1)
  • ACTIVE (33-33)
src/components/field-region/dto/list-field-region.dto.ts (4)
src/components/field-zone/dto/list-field-zone.dto.ts (1)
  • InputType (22-30)
src/components/user/dto/list-users.dto.ts (1)
  • InputType (35-41)
src/common/id-field.ts (2)
  • IdField (9-19)
  • ID (24-25)
src/common/filter-field.ts (1)
  • FilterField (11-31)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: E2E Tests (neo4j 3/6)
  • GitHub Check: E2E Tests (neo4j 6/6)
  • GitHub Check: E2E Tests (neo4j 1/6)
  • GitHub Check: E2E Tests (neo4j 4/6)
  • GitHub Check: E2E Tests (neo4j 2/6)
  • GitHub Check: E2E Tests (neo4j 5/6)
  • GitHub Check: Unit
  • GitHub Check: Clean
  • GitHub Check: lint
  • GitHub Check: Generate (base)
  • GitHub Check: Generate (head)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
src/components/field-zone/dto/list-field-zone.dto.ts (1)

15-20: Exposing the filter publicly – confirm this is intentional

FieldZoneFilters was previously internal; removing { internal: true } makes it part of the public GraphQL schema.
Double-check that this is the desired API change and that clients are prepared for the new filter argument.

src/components/field-region/field-region.repository.ts (1)

118-123: Handle undefined filter argument to avoid runtime blows

input.filter may legitimately be undefined.
fieldRegionFilters(undefined) relies on internal defaults that could change and would currently yield a runtime TypeError if the util starts touching properties. Guard at the call-site to make the contract explicit.

-      .apply(fieldRegionFilters(input.filter))
+      .apply(fieldRegionFilters(input.filter ?? {}))

Copy link

🗞 GraphQL Summary

View schema changes
@@ -1736,11 +1736,18 @@
   id: ID!
   name: SecuredString!
 }
 
+input FieldRegionFilters {
+  director: UserFilters
+  fieldZone: FieldZoneFilters
+  id: ID
+}
+
 input FieldRegionListInput {
   """The number of items to return in a single page"""
   count: Int! = 25
+  filter: FieldRegionFilters
 
   """The order in which to sort the list"""
   order: Order! = ASC
 
@@ -1774,11 +1781,17 @@
   id: ID!
   name: SecuredString!
 }
 
+input FieldZoneFilters {
+  director: UserFilters
+  id: ID
+}
+
 input FieldZoneListInput {
   """The number of items to return in a single page"""
   count: Int! = 25
+  filter: FieldZoneFilters
 
   """The order in which to sort the list"""
   order: Order! = ASC
 
@@ -4845,8 +4858,9 @@
 
 input ProjectFilters {
   """Only projects created within this time range"""
   createdAt: DateTimeFilter
+  fieldRegion: FieldRegionFilters
 
   """
   Only projects that the requesting user is an active member of. false does nothing.
   """

⚠️ Dangerous Changes

  • An optional field filter on input type FieldRegionListInput was added.
  • An optional field filter on input type FieldZoneListInput was added.
  • An optional field fieldRegion on input type ProjectFilters was added.

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.

1 participant