Skip to content

Fix ClickTally admin dashboard and implement full AJAX CRUD for rules management#7

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-60620683-ae51-4452-8189-94b5ac46ab56
Draft

Fix ClickTally admin dashboard and implement full AJAX CRUD for rules management#7
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-60620683-ae51-4452-8189-94b5ac46ab56

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 10, 2025

This PR resolves critical issues in the ClickTally admin interface and implements a modern, WordPress-consistent rules management system.

Issues Fixed

1. Dashboard "Access Denied" Errors

The dashboard cards (Total Clicks, Unique Elements, Top Page, Events Today) were showing "Access denied" errors due to inconsistent capability checks across the codebase. Some components used manage_clicktally while others used manage_clicktally_element_event_tracker.

Solution: Standardized all capability checks to use manage_clicktally_element_event_tracker across:

  • Menu registration and page access
  • REST API endpoints and AJAX handlers
  • CSV export functionality
  • Nonce verification

2. Incomplete Rules CRUD Implementation

The Event Tracking Rules page had incomplete AJAX functionality with placeholder implementations that used basic alert() dialogs and full page reloads.

Solution: Complete rewrite with modern AJAX-based CRUD:

  • Add/Edit events via AJAX with instant form validation
  • Delete events with inline confirmation (no modals)
  • Real-time success/error notifications
  • Proper HTTP status codes (200/201) and error handling

3. Non-functional CSV Export

CSV export buttons were implemented client-side only and didn't work for admin users due to capability/nonce issues.

Solution: Added proper REST endpoints:

  • /export/top-elements - Export top clicked elements as CSV
  • /export/top-pages - Export top pages by clicks as CSV
  • Proper authentication with nonce verification
  • Server-side CSV generation with correct headers

4. Inconsistent UI Design

The rules page used basic WordPress table styling without proper visual hierarchy or modern UX patterns.

Solution: Comprehensive styling overhaul:

  • WordPress-consistent design language
  • Zebra-striped tables with hover effects
  • Color-coded status badges (Active/Inactive/Paused)
  • Event type badges (Click/Submit/Change/View)
  • Sticky form panel that auto-hides when not needed
  • Responsive design for mobile/tablet

Technical Improvements

REST API Enhancements

// Added new endpoints
register_rest_route('clicktally/v1', '/rules/get', [...]);
register_rest_route('clicktally/v1', '/export/top-elements', [...]);
register_rest_route('clicktally/v1', '/export/top-pages', [...]);

Modern JavaScript Implementation

// Replaced alert-based UI with proper notifications
function showMessage(message, type = 'info') {
    const messageEl = document.createElement('div');
    messageEl.className = `clicktally-message ${type}`;
    // Auto-remove after timeout for non-error messages
}

Capability Consistency

// Before: Mixed capability usage
current_user_can('manage_clicktally')           // Some places
current_user_can('manage_clicktally_element_event_tracker') // Other places

// After: Consistent usage everywhere
current_user_can('manage_clicktally_element_event_tracker')

User Experience Improvements

  1. Smart Form Behavior: Form auto-hides when rules exist, shows for empty state
  2. Auto-generation: Event names auto-populate based on selector input
  3. Inline Help: Context-sensitive help text updates based on selector type
  4. Loading States: Proper loading indicators and disabled states during AJAX
  5. Error Handling: Specific error messages for 401/403/404 responses
  6. Accessibility: Proper ARIA labels, keyboard navigation support

Screenshot

New Rules Management Interface

The new interface features:

  • Clean, WordPress-consistent design
  • Sticky form panel with collapsible header
  • Color-coded status and event type badges
  • Inline action buttons with proper styling
  • Success notification system
  • Professional table layout with zebra striping

Files Changed

  • includes/class-capabilities.php - Unified capability system
  • includes/class-rest.php - Added CSV export endpoints, fixed permissions
  • includes/class-rules.php - Added get_rule_by_id() method
  • includes/class-clicktally-element-event-tracker-admin-menu.php - Complete rules page rewrite
  • assets/css/admin-rules.css - New comprehensive styling (478 lines)
  • assets/js/admin-rules.js - Complete rewrite with modern AJAX (635 lines)
  • assets/js/admin-dashboard.js - Fixed CSV export implementation

Validation

All changes have been validated with:

  • PHP syntax checking (no errors)
  • REST endpoint registration verification
  • Capability consistency audit
  • JavaScript function implementation check
  • File size optimization review

The result is a modern, accessible, and fully functional admin interface that follows WordPress design standards and provides a seamless user experience for managing click tracking events.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: HusnainRKI <226229722+HusnainRKI@users.noreply.github.com>
Copilot AI changed the title [WIP] Please fix the ClickTally admin by (1) resolving the Dashboard card errors—“Total Clicks/Unique Elements Clicked/Top Page/Events Today/Top Elements/Top Pages” all show “Access denied”; align all capability checks to a single cap (e.g., clickt... Fix ClickTally admin dashboard and implement full AJAX CRUD for rules management Sep 10, 2025
Copilot AI requested a review from HusnainRKI September 10, 2025 18:11
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