Skip to content

Correct FieldRegion's zone change to only migrate zone directors for that region #3502

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 1 commit into
base: field-region-filters
Choose a base branch
from

Conversation

CarsonF
Copy link
Member

@CarsonF CarsonF commented Jun 17, 2025

No description provided.

@CarsonF CarsonF force-pushed the project-member/region-zone-change-bug branch from a579fe1 to 124b401 Compare June 18, 2025 02:28
@CarsonF CarsonF changed the base branch from project-member/no-auto-inactivate-member-with-roles to develop June 18, 2025 02:28
Copy link

github-actions bot commented Jun 18, 2025

🗞 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.

@CarsonF CarsonF force-pushed the project-member/region-zone-change-bug branch from 124b401 to c56489f Compare June 18, 2025 14:37
@CarsonF CarsonF changed the base branch from develop to field-region-filters June 18, 2025 14:37
Copy link

coderabbitai bot commented Jun 18, 2025

📝 Walkthrough

Walkthrough

This change introduces enhanced filtering and sorting capabilities for FieldRegion, FieldZone, and Project entities. It adds nested filter and sorter support for related director and field zone/user entities, updates DTOs and repositories to use these new filters and sorters, and extends project member replacement logic to support region-based filtering.

Changes

Files/Groups Change Summary
src/components/field-region/dto/list-field-region.dto.ts
src/components/field-zone/dto/list-field-zone.dto.ts
Expanded filter DTOs: replaced fieldZoneId with id, added nested filters for director and fieldZone, and made filter fields public by removing { internal: true } from decorators.
src/components/field-region/field-region.repository.ts Added fieldRegionFilters and fieldRegionSorters for modular filtering/sorting, updated list method to use them, and enabled nested filtering/sorting on related entities.
src/components/field-zone/field-zone.repository.ts Added fieldZoneFilters and fieldZoneSorters for modular filtering/sorting, updated list method to use them, and enabled nested filtering/sorting on related director users.
src/components/project/dto/list-projects.dto.ts Added optional fieldRegion filter to ProjectFilters.
src/components/project/project-filters.query.ts Added sub-filter for fieldRegion using fieldRegionFilters to projectFilters.
src/components/project/project.repository.ts Added new sorter for fieldRegion using fieldRegionSorters to projectSorters.
src/components/project/project-member/project-member.gel.repository.ts
src/components/project/project-member/project-member.repository.ts
Extended replaceMembershipsOnOpenProjects method signatures to accept an optional region parameter and updated logic to filter by region if provided.
src/components/project/project-member/handlers/regions-zone-changes-applies-director-change-to-project-members.handler.ts Passed event.updated.id as a new argument to replaceMembershipsOnOpenProjects in the handler.

Possibly related PRs

  • SeedCompany/cord-api-v3#3495: Extends the same handler by introducing or modifying the RegionsZoneChangesAppliesDirectorChangeToProjectMembersHandler, directly relating to the handler updated in this PR.
✨ 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

🧹 Nitpick comments (4)
src/components/project/project.repository.ts (1)

460-476: Sorter duplication – consider extracting a helper

The new 'fieldRegion.*' sorter duplicates the “match / union / null fallback” pattern already present for primaryLocation.* and primaryPartnership.*. Extracting a small util (e.g. nestedSorter('fieldRegion', 'FieldRegion', fieldRegionSorters)) would DRY this file and reduce future maintenance.

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

15-20: Redundant & {} intersection – safe to drop.

director?: UserFilters & {} is equivalent to UserFilters; the empty intersection adds no value and slightly clutters the schema.

-  readonly director?: UserFilters & {};
+  readonly director?: UserFilters;
src/components/field-region/dto/list-field-region.dto.ts (1)

16-24: Same & {} nit & public exposure comment as FieldZone DTO.

  1. Drop the meaningless & {} intersections on director and fieldZone.
  2. Confirm that making filter public is deliberate; otherwise add internal: true.
-  readonly director?: UserFilters & {};
-  readonly fieldZone?: FieldZoneFilters & {};
+  readonly director?: UserFilters;
+  readonly fieldZone?: FieldZoneFilters;
src/components/field-region/field-region.repository.ts (1)

141-180: Variable re-use (node) may cause accidental shadowing.

Inside both custom sorters we alias noderegion, then immediately re-introduce a new node for the related entity.
Cypher allows this but readability & future edits suffer.

Consider distinct aliases:

-  .with('node as region')
-  .match([
-    node('region'),
-    relation('out', '', 'director', ACTIVE),
-    node('node', 'User'),
+  .with('node as region')
+  .match([
+    node('region'),
+    relation('out', '', 'director', ACTIVE),
+    node('directorNode', 'User'),
   ])
-  .apply(sortWith(userSorters, input)),
+  .apply(sortWith(userSorters, { ...input, base: 'directorNode' })),

You’ll avoid confusion and accidental clashes with other chained helpers.

📜 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 c56489f.

📒 Files selected for processing (10)
  • 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-member/handlers/regions-zone-changes-applies-director-change-to-project-members.handler.ts (1 hunks)
  • src/components/project/project-member/project-member.gel.repository.ts (2 hunks)
  • src/components/project/project-member/project-member.repository.ts (2 hunks)
  • src/components/project/project.repository.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/components/project/dto/list-projects.dto.ts (1)
src/common/filter-field.ts (1)
  • FilterField (11-31)
src/components/project/project-member/project-member.repository.ts (1)
src/common/id-field.ts (1)
  • ID (24-25)
src/components/field-zone/dto/list-field-zone.dto.ts (4)
src/components/field-region/dto/list-field-region.dto.ts (1)
  • InputType (26-34)
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)
src/components/field-zone/field-zone.repository.ts (4)
src/core/database/query/sorting.ts (2)
  • sortWith (61-85)
  • defineSorters (129-159)
src/components/user/user.repository.ts (2)
  • userFilters (391-410)
  • userSorters (412-426)
src/core/database/query/filters.ts (1)
  • sub (243-272)
src/core/database/query/matching.ts (1)
  • ACTIVE (33-33)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: Generate (head)
  • GitHub Check: Generate (base)
  • GitHub Check: lint
  • GitHub Check: E2E Tests (neo4j 6/6)
  • GitHub Check: E2E Tests (neo4j 4/6)
  • GitHub Check: E2E Tests (neo4j 5/6)
  • GitHub Check: Clean
  • GitHub Check: E2E Tests (neo4j 1/6)
  • GitHub Check: E2E Tests (neo4j 2/6)
  • GitHub Check: E2E Tests (neo4j 3/6)
  • GitHub Check: Unit
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (10)
src/components/project/project-member/handlers/regions-zone-changes-applies-director-change-to-project-members.handler.ts (1)

32-37: Let’s retry with a PCRE2-based grep to catch any 3-arg calls:

#!/bin/bash
# Find any replaceMembershipsOnOpenProjects calls with exactly 3 args
rg --pcre2 --no-heading --line-number \
   'replaceMembershipsOnOpenProjects\(\s*[^,]+,\s*[^,]+,\s*[^,]+\s*\)' \
   src

This will list any invocations still using the old 3-argument signature.

src/components/project/dto/list-projects.dto.ts (1)

138-141: FieldRegion filter added cleanly

@FilterField(() => FieldRegionFilters) integrates seamlessly with existing filters and keeps type-safety. No concerns.

src/components/project/project.repository.ts (1)

37-38: Missing unused-import lint suppression

fieldRegionSorters is only referenced inside the new sorter block; import is fine. Just make sure your linter isn’t warning about the default export name clash (fieldRegionSorters vs existing sorters).

src/components/project/project-filters.query.ts (1)

111-117: Filter wired correctly

Filter definition mirrors other nested filters and leverages fieldRegionFilters – looks solid.

src/components/project/project-member/project-member.repository.ts (1)

208-241: Region-scoped replacement logic LGTM

Appending the optional fieldRegion constraint keeps the Cypher query consistent and backward compatible (undefined spreads to {}). Nice touch making the status filter explicit too.

src/components/project/project-member/project-member.gel.repository.ts (1)

80-87: Confirm all call-sites pass an explicit region (or undefined).

db.run requires every parameter declared in e.params to be present in the object you pass.
If any existing caller omits the fourth argument altogether, TypeScript will compile (because it’s optional), but the runtime parameter object will lack the region key, causing EdgeDB to throw “Parameter region is missing”.

Two quick mitigations:

-    return await this.db.run(this.replaceMembershipsOnOpenProjectsQuery, {
-      oldDirector,
-      newDirector,
-      role,
-      region,
-    });
+    return await this.db.run(this.replaceMembershipsOnOpenProjectsQuery, {
+      oldDirector,
+      newDirector,
+      role,
+      // Ensure the key is always present.
+      region: region ?? null,
+    });

and (more importantly) audit every invocation of replaceMembershipsOnOpenProjects after this change.

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

28-29: Re-expose filter publicly – verify GraphQL surface area.

Removing { internal: true } makes filter visible to API consumers.
If that is intended – great. If not, restore the flag:

-  @FilterField(() => FieldZoneFilters)
+  @FilterField(() => FieldZoneFilters, { internal: true })

Double-check the API contract before merging.

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

113-125: Good swap to explicit filter / sortWith pipeline.

Moving away from the generic sorter improves clarity and keeps pagination deterministic.
Nice job.

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

156-178: Missing default sorter for base props (e.g. name).

fieldZoneSorters currently only handles director.*.
Calling list with sort: 'name' will fall back to the generic base-prop branch within defineSorters; however that branch relies on FieldZone.BaseNodeProps being populated. If name isn’t in BaseNodeProps, sorting will silently break.

Either:

  1. Ensure name is in BaseNodeProps, or
  2. Add an explicit matcher:
 export const fieldZoneSorters = defineSorters(FieldZone, {
+  name: (query) => query.return('node.name as sortValue'),
   'director.*': (query, input) =>

128-140: 👍 Explicit filters & sorters before pagination.

The new pipeline (fieldZoneFiltersfieldZoneSorters ➜ paginate) is clearer and prevents accidental cartesian products.

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