Skip to content

Fixed members-forward filter gating parity#26932

Merged
jonatansberg merged 1 commit intomainfrom
ber-3456-align-ember-react-filter-gating
Mar 25, 2026
Merged

Fixed members-forward filter gating parity#26932
jonatansberg merged 1 commit intomainfrom
ber-3456-align-ember-react-filter-gating

Conversation

@jonatansberg
Copy link
Member

@jonatansberg jonatansberg commented Mar 24, 2026

This updates members-forward so the Email filter group follows the same availability rule as Ember, based on whether member email sending is enabled. It also removes the extra React-only feedback gate, so Responded with feedback is available again with the More like this and Less like this operators whenever the Email filters are shown.

I added focused hook tests to cover that gating behavior.

ref https://linear.app/ghost/issue/BER-3456/responded-with-feedback-filter-is-missing-in-members-forward

Tested with yarn --cwd apps/posts vitest run src/views/members/use-member-filter-fields.test.ts and yarn --cwd apps/posts eslint src/views/members/use-member-filter-fields.ts src/views/members/components/members-filters.tsx src/views/members/use-member-filter-fields.test.ts.

ref https://linear.app/ghost/issue/BER-3456/responded-with-feedback-filter-is-missing-in-members-forward
React was hiding email filters behind config-only gates that Ember does not use, which removed the feedback filter and its operators from members-forward.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 24, 2026

Walkthrough

This pull request refactors the member filter configuration system by replacing browse config-based feature flags with a settings-based approach. The changes remove emailAnalyticsEnabled and audienceFeedbackEnabled flags and introduce emailFiltersEnabled, which is derived from the editor_default_email_recipients settings key. The newsletter feedback filter is now unconditionally included when email filters are enabled. Related test cases are updated to verify the new behavior with the refactored flags.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fixed members-forward filter gating parity' directly summarizes the main change: aligning the Email filter group availability rules between React (members-forward) and Ember implementations.
Description check ✅ Passed The description clearly explains the changes made: updating Email filter group availability rules, removing the React-only feedback gate, and adding test coverage for the gating behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ber-3456-align-ember-react-filter-gating

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.

@jonatansberg jonatansberg marked this pull request as ready for review March 24, 2026 13:06
Copy link
Contributor

@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: 1

🧹 Nitpick comments (1)
apps/posts/src/views/members/use-member-filter-fields.test.ts (1)

74-88: Good test coverage for the new gating logic.

The test correctly validates that the Email group and its fields (including newsletter_feedback) are present when emailFiltersEnabled is true.

Consider adding a complementary test to verify the Email group is absent when emailFiltersEnabled: false (or omitted), which would complete the boundary coverage for this gating behavior.

📝 Suggested test case for completeness
it('hides the Email group when email sending is disabled', () => {
    const {result} = renderHook(() => useMemberFilterFields({
        emailFiltersEnabled: false,
        siteTimezone: 'UTC'
    }));

    const emailGroup = result.current.find(group => group.group === 'Email');

    expect(emailGroup).toBeUndefined();
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/posts/src/views/members/use-member-filter-fields.test.ts` around lines
74 - 88, Add a complementary test to ensure the Email group is hidden when email
sending is disabled: in the same test file use-member-filter-fields.test.ts, add
a test that calls renderHook(() => useMemberFilterFields({emailFiltersEnabled:
false, siteTimezone: 'UTC'})) and asserts that result.current.find(group =>
group.group === 'Email') is undefined (or toBeUndefined()). This verifies the
gating logic in useMemberFilterFields for the false/omitted emailFiltersEnabled
case and completes boundary coverage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/posts/src/views/members/components/members-filters.tsx`:
- Line 60: The emailFiltersEnabled computation incorrectly treats undefined
(when settingsData hasn't loaded) as enabled; update the logic around the
emailFiltersEnabled variable to first ensure settings are present/loaded (e.g.,
check settings or settingsData truthiness) or treat undefined as a safe default
('disabled') before calling getSettingValue, then only mark enabled when
getSettingValue(settings, 'editor_default_email_recipients') === a
non-'disabled' value; locate the emailFiltersEnabled declaration and adjust the
condition to guard against undefined settings using the getSettingValue call.

---

Nitpick comments:
In `@apps/posts/src/views/members/use-member-filter-fields.test.ts`:
- Around line 74-88: Add a complementary test to ensure the Email group is
hidden when email sending is disabled: in the same test file
use-member-filter-fields.test.ts, add a test that calls renderHook(() =>
useMemberFilterFields({emailFiltersEnabled: false, siteTimezone: 'UTC'})) and
asserts that result.current.find(group => group.group === 'Email') is undefined
(or toBeUndefined()). This verifies the gating logic in useMemberFilterFields
for the false/omitted emailFiltersEnabled case and completes boundary coverage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ca0662ca-ae23-4806-a1eb-ac50590d092e

📥 Commits

Reviewing files that changed from the base of the PR and between 5893981 and 088cef6.

📒 Files selected for processing (3)
  • apps/posts/src/views/members/components/members-filters.tsx
  • apps/posts/src/views/members/use-member-filter-fields.test.ts
  • apps/posts/src/views/members/use-member-filter-fields.ts

const settings = settingsData?.settings || [];
const paidMembersEnabled = getSettingValue<boolean>(settings, 'paid_members_enabled') === true;
const emailAnalyticsEnabled = configData?.config?.emailAnalytics === true;
const emailFiltersEnabled = getSettingValue<string>(settings, 'editor_default_email_recipients') !== 'disabled';
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Handle the case when settings haven't loaded yet.

When settingsData is still loading, getSettingValue returns undefined, and undefined !== 'disabled' evaluates to true. This could briefly show email filters before settings load, even if they should be hidden.

🛡️ Proposed fix
-    const emailFiltersEnabled = getSettingValue<string>(settings, 'editor_default_email_recipients') !== 'disabled';
+    const editorDefaultEmailRecipients = getSettingValue<string>(settings, 'editor_default_email_recipients');
+    const emailFiltersEnabled = editorDefaultEmailRecipients !== undefined && editorDefaultEmailRecipients !== 'disabled';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const emailFiltersEnabled = getSettingValue<string>(settings, 'editor_default_email_recipients') !== 'disabled';
const editorDefaultEmailRecipients = getSettingValue<string>(settings, 'editor_default_email_recipients');
const emailFiltersEnabled = editorDefaultEmailRecipients !== undefined && editorDefaultEmailRecipients !== 'disabled';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/posts/src/views/members/components/members-filters.tsx` at line 60, The
emailFiltersEnabled computation incorrectly treats undefined (when settingsData
hasn't loaded) as enabled; update the logic around the emailFiltersEnabled
variable to first ensure settings are present/loaded (e.g., check settings or
settingsData truthiness) or treat undefined as a safe default ('disabled')
before calling getSettingValue, then only mark enabled when
getSettingValue(settings, 'editor_default_email_recipients') === a
non-'disabled' value; locate the emailFiltersEnabled declaration and adjust the
condition to guard against undefined settings using the getSettingValue call.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 088cef65e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const settings = settingsData?.settings || [];
const paidMembersEnabled = getSettingValue<boolean>(settings, 'paid_members_enabled') === true;
const emailAnalyticsEnabled = configData?.config?.emailAnalytics === true;
const emailFiltersEnabled = getSettingValue<string>(settings, 'editor_default_email_recipients') !== 'disabled';

Choose a reason for hiding this comment

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

P2 Badge Guard email filter gate until settings are loaded

getSettingValue returns null when /settings/ has not resolved (or the key is missing), so null !== 'disabled' makes emailFiltersEnabled true by default. That means the Email filter group is exposed before settings are known, and on a failed settings fetch it can stay visible even when member email is actually disabled, allowing users to create filters that should be gated off. Gate this on loaded settings (or a non-null setting value) before enabling the Email group.

Useful? React with 👍 / 👎.

@jonatansberg jonatansberg merged commit 24ad511 into main Mar 25, 2026
33 checks passed
@jonatansberg jonatansberg deleted the ber-3456-align-ember-react-filter-gating branch March 25, 2026 08:13
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