Skip to content

Store object selector in database for use in frontend highlighter - #1053

Merged
pattonwebz merged 9 commits into
developfrom
william/pro-170-add-axe-selector-to-database-for-improved-frontend
Jul 8, 2025
Merged

Store object selector in database for use in frontend highlighter#1053
pattonwebz merged 9 commits into
developfrom
william/pro-170-add-axe-selector-to-database-for-improved-frontend

Conversation

@pattonwebz

@pattonwebz pattonwebz commented Jul 3, 2025

Copy link
Copy Markdown
Member

This pull request introduces enhancements to the accessibility checker by adding support for additional selector-related data (selector, ancestry, xpath) in various parts of the system, including database schema, backend logic, and frontend processing. The changes improve the granularity of accessibility rule data and streamline the processing of violations in the frontend.

Backend Enhancements:

  • Updated the Insert_Rule_Data class to include new parameters (selectors) and handle additional fields (selector, ancestry, xpath) in database operations. This includes changes to the insert method signature, database updates, and sanitization logic. [1] [2] [3] [4]
  • Modified the database schema in edac_update_database to add new columns (selector, ancestry, xpath) for storing detailed selector data.
  • Updated the set_post_scan_results method in the REST API to pass the new selector data structure when inserting rule data.

Frontend Enhancements:

  • Refactored the scan function in src/pageScanner/index.js to use a new helper function, processViolation, for processing violations. This helper encapsulates logic for extracting and formatting selector-related data (selector, ancestry, xpath). [1] [2]

Version Update:

  • Incremented the database version from 1.0.4 to 1.0.5 in accessibility-checker.php to reflect schema changes.
  • PR is linked to the main issue in the repo
  • Tests are added that cover changes

Summary by CodeRabbit

  • New Features
    • Added support for storing and managing additional selector information (selector, ancestry, xpath) for accessibility rule records.
  • Bug Fixes
    • Improved handling of rule violation data to include new selector-related fields.
  • Refactor
    • Streamlined violation object construction to reduce code duplication and centralize formatting logic.
  • Tests
    • Updated test setup to use the centralized database update utility for schema creation.

This update introduces new fields in the database schema to support enhanced accessibility features.

[PRO-191]
This function extracts relevant details from a violation object, including selector, ancestry, xpath, and landmark information.

[PRO-192]
This change introduces additional selectors (selector, ancestry, xpath) to the Insert_Rule_Data method, improving the flexibility and functionality of rule data insertion.

[PRO-193]
Enhanced the insert method to accept additional parameters for selectors and ancestry, improving the flexibility of rule insertion.

[PRO-193]
Copilot AI review requested due to automatic review settings July 3, 2025 22:51
@coderabbitai

coderabbitai Bot commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes add support for three new selector-related fields—selector, ancestry, and xpath—to rule violation data handling. This includes updating the database schema, extending the insert method and its usage, refactoring violation processing in the scanner, and adjusting the test setup to use the updated schema logic.

Changes

File(s) Change Summary
admin/class-insert-rule-data.php Extended Insert_Rule_Data::insert() to accept and handle selector, ancestry, and xpath fields.
admin/class-update-database.php Modified database schema to add nullable selector, ancestry, and xpath columns to the violations table.
includes/classes/class-rest-api.php Updated set_post_scan_results() to pass selector-related data to the insert method.
src/pageScanner/index.js Refactored violation processing logic into a new helper function processViolation for code reuse.
tests/phpunit/Admin/InsertRuleDataTest.php Updated test setup to use the centralized database update utility for schema creation.

Sequence Diagram(s)

sequenceDiagram
    participant Scanner (JS)
    participant REST API (PHP)
    participant Insert_Rule_Data
    participant Database

    Scanner (JS)->>REST API (PHP): POST scan results (includes selector, ancestry, xpath)
    REST API (PHP)->>Insert_Rule_Data: insert(post, rule, ..., selectors)
    Insert_Rule_Data->>Database: INSERT/UPDATE with selector, ancestry, xpath fields
    Database-->>Insert_Rule_Data: Success/Failure
    Insert_Rule_Data-->>REST API (PHP): Result
    REST API (PHP)-->>Scanner (JS): Response
Loading

Possibly related PRs

  • equalizedigital/accessibility-checker#1028: Also extends Insert_Rule_Data::insert() and database schema, but for landmark-related fields instead of selector-related fields; both PRs enhance the same core methods and tables.

Suggested reviewers

  • SteveJonesDev

Poem

In the warren of code, selectors now hop,
With ancestry and xpath, they leap to the top.
The database burrow grows three columns wide,
While scanner and tests keep bugs outside.
A carrot for helpers, a thump for the rest—
This rabbit declares: “Selectors are best!” 🥕

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-08T16_29_43_567Z-debug-0.log


📜 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 1bb8760 and da57e09.

📒 Files selected for processing (5)
  • admin/class-insert-rule-data.php (4 hunks)
  • admin/class-update-database.php (1 hunks)
  • includes/classes/class-rest-api.php (1 hunks)
  • src/pageScanner/index.js (2 hunks)
  • tests/phpunit/Admin/InsertRuleDataTest.php (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: SteveJonesDev
PR: equalizedigital/accessibility-checker#880
File: src/pageScanner/rules/video-present.js:3-3
Timestamp: 2025-04-08T21:36:48.803Z
Learning: In the accessibility-checker, the broad selector pattern in video-present.js (`'video, iframe, object, source, [src], [class], [role]'`) is intentional, as it allows the JavaScript evaluation function in video-detected.js to perform case-insensitive matching and sophisticated pattern detection that CSS selectors cannot replicate.
Learnt from: SteveJonesDev
PR: equalizedigital/accessibility-checker#921
File: src/pageScanner/checks/linked-image-alt-present.js:43-50
Timestamp: 2025-04-15T02:30:38.897Z
Learning: In the Accessibility Checker plugin, accessibility rules are separated by specific concerns. For example, linked images have separate rules for checking: (1) missing alt attributes and (2) empty alt attributes. The rule `linked_image_alt_present` specifically checks for the presence of alt attributes on linked images, while a separate rule `img_linked_alt_empty` handles validation of empty alt attributes. Suggestions should respect this separation of concerns.
src/pageScanner/index.js (1)
Learnt from: SteveJonesDev
PR: equalizedigital/accessibility-checker#880
File: src/pageScanner/rules/video-present.js:3-3
Timestamp: 2025-04-08T21:36:48.803Z
Learning: In the accessibility-checker, the broad selector pattern in video-present.js (`'video, iframe, object, source, [src], [class], [role]'`) is intentional, as it allows the JavaScript evaluation function in video-detected.js to perform case-insensitive matching and sophisticated pattern detection that CSS selectors cannot replicate.
🧬 Code Graph Analysis (1)
includes/classes/class-rest-api.php (1)
admin/class-insert-rule-data.php (2)
  • Insert_Rule_Data (17-168)
  • insert (35-167)
🔇 Additional comments (8)
admin/class-update-database.php (1)

53-55: LGTM! Database schema correctly updated for selector fields.

The addition of the three new nullable text columns (selector, ancestry, xpath) properly supports the new selector-related data fields being introduced throughout the system.

tests/phpunit/Admin/InsertRuleDataTest.php (1)

24-27: Excellent refactoring for test consistency.

Using the centralized edac_update_database() method ensures the test database schema automatically includes the new selector columns and stays synchronized with production schema changes.

src/pageScanner/index.js (2)

213-213: Good refactoring to eliminate code duplication.

The extraction of violation processing logic into the processViolation helper function improves code maintainability and reduces duplication between the violations and incomplete items processing.

Also applies to: 220-220


332-351: Helper function improves code organization.

The processViolation helper function effectively centralizes the violation formatting logic. Note that the selector array handling approach was previously reviewed and the developer chose to maintain the current implementation with awareness of potential debugging complexity.

admin/class-insert-rule-data.php (4)

24-35: Method signature and documentation properly updated.

The addition of the $selectors parameter with appropriate type hints and PHPDoc documentation correctly extends the method to handle the new selector-related data fields.


55-57: Selector data extraction implemented as designed.

The extraction of selector data using [0] indexing follows the intended design pattern. Past review comments regarding type safety were addressed by the developer's decision to ensure arrays are passed from the calling code.


103-118: SQL UPDATE statement correctly includes new columns.

The UPDATE statement properly handles the new selector-related columns alongside the existing fields, maintaining consistency with the database schema changes.


146-148: Data sanitization properly implemented for new fields.

The sanitization of the new selector fields using sanitize_text_field is appropriate for the text data type and follows the established pattern for other similar fields.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary of Changes

Hello @pattonwebz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the accessibility checker's ability to provide detailed feedback by enabling the storage and processing of comprehensive element selector information. By capturing CSS selectors, ancestry, and XPath, the system can now offer more precise highlighting and identification of accessibility violations in the frontend, improving the overall user experience for debugging and remediation.

Highlights

  • Backend Data Storage Enhancement: I've updated the database schema and backend logic to store more granular selector-related data (selector, ancestry, xpath) for accessibility violations. This includes modifications to the Insert_Rule_Data class to accept and persist this new information.
  • REST API Integration: The set_post_scan_results method in the REST API has been updated to extract and pass the newly available selector, ancestry, and xpath data from frontend scan results to the backend database insertion process.
  • Frontend Data Collection and Refactoring: On the frontend, the scan function in src/pageScanner/index.js has been refactored. I've introduced a new processViolation helper function that encapsulates the logic for extracting and formatting violation data, now including ancestry and xpath alongside the existing selector information.
  • Database Version Update: To reflect the schema changes, I've incremented the database version from 1.0.4 to 1.0.5 in accessibility-checker.php.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the accessibility checker by capturing and persisting detailed selector metadata (selector, ancestry, xpath) through the full scan lifecycle for improved frontend highlighting.

  • Refactors frontend scanning in src/pageScanner/index.js to use a processViolation helper that includes new selector fields.
  • Updates REST API (class-rest-api.php) and insertion logic (class-insert-rule-data.php) to accept and store the selector metadata.
  • Adds new database columns (selector, ancestry, xpath) and bumps the DB version to 1.0.5.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/pageScanner/index.js Introduced processViolation helper to include selector, ancestry, and xpath.
includes/classes/class-rest-api.php Passed a $selectors array into Insert_Rule_Data::insert.
admin/class-update-database.php Added selector, ancestry, and xpath columns to the schema.
admin/class-insert-rule-data.php Extended insert signature and mapped new selector fields into inserts/updates.
accessibility-checker.php Incremented EDAC_DB_VERSION from 1.0.4 to 1.0.5.
Comments suppressed due to low confidence (1)

includes/classes/class-rest-api.php:386

  • No tests currently cover the new selector metadata flow. Add integration or unit tests for set_post_scan_results to verify that selector, ancestry, and xpath fields are correctly passed to Insert_Rule_Data.
						$selectors = [

Comment thread admin/class-insert-rule-data.php
Comment thread admin/class-insert-rule-data.php

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the accessibility checker by storing more detailed selector information in the database. The changes span the backend PHP code and the frontend JavaScript scanner. A critical issue was identified in the new JavaScript helper and a high-severity issue in the PHP REST API handler that could lead to runtime errors and incorrect data handling.

Comment thread src/pageScanner/index.js
Comment thread includes/classes/class-rest-api.php Outdated
@pattonwebz
pattonwebz changed the base branch from steve/try/landmark-location to develop July 8, 2025 16:21
@pattonwebz
pattonwebz requested a review from SteveJonesDev July 8, 2025 17:54

@SteveJonesDev SteveJonesDev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested locally and appears to function properly.

Screenshot 2025-07-08 at 2 34 27 PM

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.

3 participants