Conversation
There was a problem hiding this comment.
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 evaluatepageRulesarrays (with fallback to legacypageFilterfields). - Updates tooltip/action filtering to use
pageRuleswhen 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.
| if (rules.length === 0) return true; | ||
| return rules.every(r => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType)); |
There was a problem hiding this comment.
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.
| 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)); |
| if (tooltip.pageRules && tooltip.pageRules.length > 0) { | ||
| return checkPageRules(currentUrl, { pageRules: tooltip.pageRules }); | ||
| } |
There was a problem hiding this comment.
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.
| ? 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)); |
There was a problem hiding this comment.
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.
| return rules.every(r => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType)); | |
| return rules.every((r) => checkPageFilter(currentUrl, r.pageFilter, r.pageFilterType)); |
No description provided.