Ghost icon indicating copy to clipboard operation
Ghost copied to clipboard

Added location filter for members

Open mvxine opened this issue 11 months ago โ€ข 1 comments

fixes https://github.com/TryGhost/Ghost/issues/25557

What does this PR do?

Adds the ability to filter members by location (geolocation) in the Ghost Admin dashboard.

Why is this needed?

Users with large member bases need to filter members by geographic location to:

  • Identify and remove bot accounts that often originate from the same location
  • Segment audiences by region for targeted content strategies
  • Better understand the geographic distribution of their membership

How does it work?

The implementation adds a new "Location" filter option in the Basic filters group. Since geolocation is stored as a JSON string containing location data from GeoJS (country, city, region, etc.), the filter uses text-based operators:

  • is - exact match
  • contains - partial match (e.g., "Brazil", "California")
  • does not contain - exclude matches
  • starts with - prefix match
  • ends with - suffix match

This allows administrators to filter members using queries like geolocation:~'United States' to find all members from a specific country.

Changes

  • Added new filter definition: ghost/admin/app/components/members/filters/location.js
  • Exported the filter in ghost/admin/app/components/members/filters/index.js
  • Added LOCATION_FILTER to the Basic filters group in ghost/admin/app/components/members/filter.js

Testing

  • Navigate to Members in Ghost Admin
  • Click the Filter button
  • Select "Location" from the filter dropdown
  • Enter a location value (e.g., country name, city)
  • Verify that members are filtered correctly based on their geolocation data

[!NOTE] Adds a "Location" (geolocation) members filter with contains/starts/ends operators and integrates it into the Basic filters.

  • Admin โ€” Members Filters:
    • Add LOCATION_FILTER for geolocation (string) using CONTAINS_ONLY_RELATION_OPTIONS.
    • Include LOCATION_FILTER in Basic group in components/members/filter.js.
  • Relation Options:
    • Add CONTAINS_ONLY_RELATION_OPTIONS (contains, does-not-contain, starts-with, ends-with) and export via relation-options/index.js.
  • Exports:
    • Export location filter from components/members/filters/index.js.

Written by Cursor Bugbot for commit d073057bd8ece82bf4106664818b4d09edac7ca0. This will update automatically on new commits. Configure here.

mvxine avatar Dec 03 '25 18:12 mvxine

[!NOTE]

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds location-based member filtering by introducing a new LOCATION_FILTER constant (label "Location", name geolocation, valueType: "string") that uses a newly added CONTAINS_ONLY_RELATION_OPTIONS. The new filter is re-exported from components/members/filters/index.js and included in the Basic filter group. A new relation-options module contains-only.js is added and re-exported from relation-options/index.js.

Estimated code review effort

๐ŸŽฏ 2 (Simple) | โฑ๏ธ ~10 minutes

  • Check LOCATION_FILTER shape matches existing filters (label, name, valueType, relationOptions).
  • Confirm the property name geolocation is correct for member location storage.
  • Verify CONTAINS_ONLY_RELATION_OPTIONS contains the intended options (contains, does-not-contain, starts-with, ends-with).
  • Ensure export * from './location' and export * from './contains-only' correctly expose the new exports.
  • Files to spot-check:
    • ghost/admin/app/components/members/filters/location.js
    • ghost/admin/app/components/members/filter.js
    • ghost/admin/app/components/members/filters/relation-options/contains-only.js
    • ghost/admin/app/components/members/filters/index.js
    • ghost/admin/app/components/members/filters/relation-options/index.js

Pre-merge checks and finishing touches

โœ… Passed checks (5 passed)
Check name Status Explanation
Title check โœ… Passed The title accurately describes the main change: adding a location filter for members, which directly matches the primary objective of the PR.
Description check โœ… Passed The description comprehensively explains the change, its purpose, implementation details, and testing steps. It is clearly related to the changeset and provides context about the feature.
Linked Issues check โœ… Passed The PR successfully implements all coding requirements from issue #25557: adds location filter to Members UI with text-based operators (contains, does-not-contain, starts-with, ends-with) enabling member filtering by geolocation and bot account identification.
Out of Scope Changes check โœ… Passed All changes are directly scoped to implementing the location filter feature: new filter definition, exports, and integration into the Basic filters group. No unrelated modifications detected.
Docstring Coverage โœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
โœจ Finishing touches
  • [ ] ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

๐Ÿ“œ Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 70952a694cc6b60542ebf3cdaf91b49a8a498ffc and d073057bd8ece82bf4106664818b4d09edac7ca0.

๐Ÿ“’ Files selected for processing (3)
  • ghost/admin/app/components/members/filters/location.js (1 hunks)
  • ghost/admin/app/components/members/filters/relation-options/contains-only.js (1 hunks)
  • ghost/admin/app/components/members/filters/relation-options/index.js (1 hunks)
๐Ÿšง Files skipped from review as they are similar to previous changes (1)
  • ghost/admin/app/components/members/filters/location.js
โฐ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cursor Bugbot
๐Ÿ”‡ Additional comments (2)
ghost/admin/app/components/members/filters/relation-options/index.js (1)

2-2: LGTM!

The barrel export follows the established pattern and correctly exposes the new contains-only module.

ghost/admin/app/components/members/filters/relation-options/contains-only.js (1)

1-6: Missing "is" operator mentioned in PR description.

The PR description explicitly states the filter uses "text-based operators: is, contains, does not contain, starts with, and ends with." However, the implementation only includes 4 operators and is missing the "is" operator. Please verify whether:

  1. The "is" operator should be added to this array, or
  2. The PR description should be updated to reflect the actual operators supported

If "is" should be included, apply this diff:

 export const CONTAINS_ONLY_RELATION_OPTIONS = [
+    {label: 'is', name: 'is'},
     {label: 'contains', name: 'contains'},
     {label: 'does not contain', name: 'does-not-contain'},
     {label: 'starts with', name: 'starts-with'},
     {label: 'ends with', name: 'ends-with'}
 ];

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

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Dec 03 '25 18:12 coderabbitai[bot]