Skip to content

allow multiple page rules#99

Open
floooat wants to merge 1 commit intomasterfrom
feat/multiple-page-rules
Open

allow multiple page rules#99
floooat wants to merge 1 commit intomasterfrom
feat/multiple-page-rules

Conversation

@floooat
Copy link
Contributor

@floooat floooat commented Mar 23, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 23, 2026 11:49
Copy link
Contributor

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

Adds support for evaluating multiple page-based matching rules (in addition to the existing single pageFilter + pageFilterType) for actions/tooltips.

Changes:

  • Introduces checkPageRules() helper to evaluate pageRules arrays (with fallback to legacy pageFilter fields).
  • Updates tooltip/action filtering to use pageRules when provided.
  • Bumps package version to 15.2.7.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/GleapTooltipManager.js Uses pageRules to decide whether a tooltip applies to the current URL.
src/GleapPageFilter.js Adds checkPageRules() wrapper to evaluate multiple rules and preserve legacy behavior.
src/Gleap.js Switches action gating from single checkPageFilter call to checkPageRules.
package.json Version bump for release.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +89 to +90
if (rules.length === 0) return true;
return rules.every(r => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType));
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

rules.every(...) requires all rules to match the same currentUrl, which will make many realistic multi-rule configurations impossible (e.g., two 'is' rules for different pages can never both be true). If the intent of “multiple page rules” is “match any of these rules”, switch to rules.some(...), or add an explicit operator (e.g., match: 'any' | 'all') to avoid locking in the wrong semantics.

Suggested change
if (rules.length === 0) return true;
return rules.every(r => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType));
// Determine how multiple rules should be combined: 'any' (OR) or 'all' (AND).
const rulesMatchMode =
action && (action.pageRulesMatch === 'all' || action.pageRulesMatch === 'any')
? action.pageRulesMatch
: 'any';
if (rules.length === 0) return true;
if (rulesMatchMode === 'all') {
return rules.every(r => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType));
}
return rules.some(r => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType));

Copilot uses AI. Check for mistakes.
Comment on lines +430 to +432
if (tooltip.pageRules && tooltip.pageRules.length > 0) {
return checkPageRules(currentUrl, { pageRules: tooltip.pageRules });
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

When tooltip.pageRules is present, this early return bypasses the existing tooltip.page logic entirely. If pageRules is meant to extend (not replace) the legacy page behavior, consider combining them (e.g., evaluate both and apply a clearly defined AND/OR), or explicitly document/encode precedence (e.g., deprecate page when pageRules is set) to prevent unexpected behavior when both are configured.

Copilot uses AI. Check for mistakes.
? action.pageRules
: (action.pageFilter ? [{ pageFilter: action.pageFilter, pageFilterType: action.pageFilterType }] : []);
if (rules.length === 0) return true;
return rules.every(r => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType));
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

For consistency with common JS style/lint rules and to avoid per-repo lint failures, consider adding parentheses around the arrow parameter ((r) => ...). This is especially relevant in shared libraries where consumers may run stricter linters.

Suggested change
return rules.every(r => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType));
return rules.every((r) => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType));

Copilot uses AI. Check for mistakes.
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