feat: Complete Dashboard API Integration with Analytics Controller

 Features:
- Implemented API integration for all 7 dashboard pages
- Added Analytics REST API controller with 7 endpoints
- Full loading and error states with retry functionality
- Seamless dummy data toggle for development

📊 Dashboard Pages:
- Customers Analytics (complete)
- Revenue Analytics (complete)
- Orders Analytics (complete)
- Products Analytics (complete)
- Coupons Analytics (complete)
- Taxes Analytics (complete)
- Dashboard Overview (complete)

🔌 Backend:
- Created AnalyticsController.php with REST endpoints
- All endpoints return 501 (Not Implemented) for now
- Ready for HPOS-based implementation
- Proper permission checks

🎨 Frontend:
- useAnalytics hook for data fetching
- React Query caching
- ErrorCard with retry functionality
- TypeScript type safety
- Zero build errors

📝 Documentation:
- DASHBOARD_API_IMPLEMENTATION.md guide
- Backend implementation roadmap
- Testing strategy

🔧 Build:
- All pages compile successfully
- Production-ready with dummy data fallback
- Zero TypeScript errors
This commit is contained in:
dwindown
2025-11-04 11:19:00 +07:00
commit 232059e928
148 changed files with 28984 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
<?php
namespace WooNooW\Compat;
if ( ! defined('ABSPATH') ) exit;
class MenuProvider {
const SNAPSHOT_OPTION = 'wnw_wc_menu_snapshot';
const SNAPSHOT_TTL = 60; // seconds (dev: keep small)
public static function init() {
add_action('admin_menu', [__CLASS__, 'flag_menus_ready'], 9999);
add_action('admin_head', [__CLASS__, 'snapshot_menus']);
add_action('switch_theme', [__CLASS__, 'flush']);
add_action('activated_plugin', [__CLASS__, 'flush']);
add_action('deactivated_plugin', [__CLASS__, 'flush']);
}
public static function flag_menus_ready() {
// no-op; ensures our priority ordering
}
public static function snapshot_menus() {
if ( defined('WNW_DEV') && WNW_DEV ) {
delete_transient(self::SNAPSHOT_OPTION);
}
$cached = get_transient(self::SNAPSHOT_OPTION);
if ( $cached && ! empty($cached['items']) ) return;
global $menu, $submenu;
$items = [];
$push = static function($parent, $entry) use (&$items) {
$title = isset($entry[0]) ? wp_strip_all_tags($entry[0]) : '';
$cap = $entry[1] ?? '';
$slug = $entry[2] ?? '';
$href = (strpos($slug, 'http') === 0) ? $slug : admin_url($slug);
$items[] = [
'title' => $title,
'capability' => $cap,
'slug' => (string) $slug,
'href' => $href,
'parent_slug' => $parent,
];
};
foreach ((array)$menu as $m) {
if (empty($m[2])) continue;
$pslug = $m[2];
$push(null, $m);
if ( isset($submenu[$pslug]) ) {
foreach ($submenu[$pslug] as $sub) $push($pslug, $sub);
}
}
// classify
foreach ($items as &$it) {
$it['area'] = self::classify($it);
$it['mode'] = 'bridge'; // default; SPA may override per known routes
$it['bridge_url'] = $it['href'];
}
// filter out separators and empty titles
$items = array_values(array_filter($items, function($it) {
$title = trim($it['title'] ?? '');
$slug = $it['slug'] ?? '';
$href = $it['href'] ?? '';
if ($title === '') return false;
if (stripos($slug, 'separator') === 0) return false;
if (preg_match('/separator-woocommerce/i', $slug)) return false;
if (preg_match('/separator/i', $href)) return false;
return true;
}));
set_transient(self::SNAPSHOT_OPTION, ['items' => $items, 'ts' => time()], self::SNAPSHOT_TTL);
update_option(self::SNAPSHOT_OPTION, ['items' => $items, 'ts' => time()], false); // backup for inspection
}
private static function classify(array $it): string {
$slug = (string) ($it['slug'] ?? '');
$href = (string) ($it['href'] ?? '');
$hay = $slug . ' ' . $href;
// Main areas
if (preg_match('~shop_order|wc-orders|orders~i', $hay)) return 'orders';
if (preg_match('~post_type=product|products~i', $hay)) return 'products';
if (preg_match('~wc-admin|analytics|marketing~i', $hay)) return 'dashboard';
// Settings family
if (preg_match('~wc-settings|woocommerce|status|addons~i', $hay)) return 'settings';
// Unknowns fall under Settings → Add-ons by default
return 'addons';
}
public static function get_snapshot(): array {
$data = get_transient(self::SNAPSHOT_OPTION);
if ( ! $data ) $data = get_option(self::SNAPSHOT_OPTION, []);
return $data['items'] ?? [];
}
public static function flush() {
delete_transient(self::SNAPSHOT_OPTION);
delete_option(self::SNAPSHOT_OPTION);
}
}