feat(admin): replace ticket dialogs with in-page views
Ticket handling on users.php?page=aksrt_tickets no longer uses dialogs. The list, the workspace (?id=N) and the assisted create form (?view=new) are server-rendered page views that carry the list filters and page for going back. Writes still go through the ticket REST routes; on success the page reloads with a native notice, and unsent drafts in other forms survive the reload via sessionStorage. Uncertain or conflicting writes lock every form and only offer a reload. Remove dead code: UsersMenusTicketsDialogs, the aksrt_ticket_view AJAX read and its nonce, dialog CSS/JS (backdrop, scroll lock, focus return, read races) and the dialog runtime test. Fix the create link carrying an unclamped page number on out-of-range list pages. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
48e54dc115
commit
d86a85e6a6
13 files changed
+720
-1264
No files matched your search
@@ -10,39 +10,39 @@ const read = file => fs.readFileSync(path.join(root, file), 'utf8');
|
||||
const center = read('src/Admin/Native/UsersMenusTicketsCenter.php');
|
||||
const list = read('src/Admin/Native/UsersMenusTicketsList.php');
|
||||
const detail = read('src/Admin/Native/UsersMenusTicketsDetail.php');
|
||||
const dialogs = read('src/Admin/Native/UsersMenusTicketsDialogs.php');
|
||||
const create = read('src/Admin/Native/UsersMenusTicketsCreate.php');
|
||||
const menus = read('src/Admin/Native/UsersMenus.php');
|
||||
const js = read('assets/js/admin-tickets.js');
|
||||
const css = read('assets/css/admin/tickets.css');
|
||||
|
||||
test('ticket native page registers only a protected read action; writes reuse REST', () => {
|
||||
test('ticket native page registers no AJAX read; writes reuse REST', () => {
|
||||
assert.match(menus, /use UsersMenusTicketsCenter;/);
|
||||
assert.match(menus, /'users.php',[\s\S]*?'aksrt_tickets'/);
|
||||
assert.match(menus, /add_action\('wp_ajax_aksrt_ticket_view', \[\$this, 'ajax_ticket_view'\]\)/);
|
||||
assert.match(center, /current_user_can\(self::CAPABILITY\)/);
|
||||
assert.match(center, /check_ajax_referer\('aksrt_ticket_view', 'nonce', false\)/);
|
||||
assert.doesNotMatch(menus + center, /wp_ajax_aksrt_ticket_view|ajax_ticket_view|aksrt_ticket_view/);
|
||||
assert.match(center, /wp_create_nonce\('wp_rest'\)/);
|
||||
assert.match(center, /rest_url\('aksrt\/v1\/admin\/tickets' \./);
|
||||
assert.match(js, /'X-WP-Nonce': config.restNonce/);
|
||||
assert.doesNotMatch(menus, /admin_post_aksrt_ticket_update/);
|
||||
assert.doesNotMatch(center, /function (handle_ticket_update|ticket_action_\w+|ticket_redirect|render_ticket_notices)/);
|
||||
assert.doesNotMatch(center, /function (handle_ticket_update|ticket_action_\w+|ticket_redirect)/);
|
||||
assert.match(menus, /count_pending_tickets\(\)/);
|
||||
assert.match(menus, /TicketSettings::enabled\(\)/);
|
||||
});
|
||||
|
||||
test('create is a primary header dialog action, not an inline or collapsed form', () => {
|
||||
assert.match(center, /'label' => __\('代客提交工单', 'aksrt'\),\s*'dialog' => 'aksrt-ticket-create-dialog',\s*'primary' => true/);
|
||||
assert.match(center, /use UsersMenusTicketsDialogs;/);
|
||||
assert.match(dialogs, /<dialog id="aksrt-ticket-create-dialog"/);
|
||||
assert.match(dialogs, /<dialog id="aksrt-ticket-detail-dialog"/);
|
||||
assert.doesNotMatch(list, /ticket_form_open\('create'|<details|render_ticket_detail_panel/);
|
||||
assert.doesNotMatch(detail, /admin-post\.php|wp_nonce_field/);
|
||||
assert.match(dialogs, /aria-labelledby="aksrt-ticket-create-title"/);
|
||||
assert.match(js, /typeof detailDialog.showModal/);
|
||||
test('list, workspace and create are page views, never dialogs', () => {
|
||||
assert.match(center, /use UsersMenusTicketsCreate;/);
|
||||
assert.doesNotMatch(center, /UsersMenusTicketsDialogs/);
|
||||
assert.ok(!fs.existsSync(path.join(root, 'src/Admin/Native/UsersMenusTicketsDialogs.php')));
|
||||
assert.match(center, /render_ticket_detail_page\(\$id,/);
|
||||
assert.match(center, /\$view === 'new'/);
|
||||
assert.match(list, /'url' => \$this->ticket_page_url\(\['view' => 'new'\]/);
|
||||
assert.match(list, /ticket_page_url\(\['id' => \$id\] \+ \$context\)/);
|
||||
assert.match(create, /ticket_form_open\('create', 0,/);
|
||||
assert.doesNotMatch(center + list + detail + create + js + css, /<dialog|showModal|data-aksrt-dialog|aksrt-ticket-dialog|aksrt-ticket-modal-open/);
|
||||
});
|
||||
|
||||
test('detail lookup is independent of the filtered list; paging clamps and preserves filters', () => {
|
||||
assert.match(center, /TicketRepository::get_instance\(\)->find\(\$id\)/);
|
||||
assert.match(center, /wp_send_json_error\(\['message' => __\('工单不存在或已被删除。', 'aksrt'\)\], 404\)/);
|
||||
assert.match(detail, /TicketRepository::get_instance\(\)->find\(\$id\)/);
|
||||
assert.match(detail, /工单不存在/);
|
||||
assert.match(list, /AdminListPagination::render\(/);
|
||||
assert.match(list, /'limit' => self::TICKET_PER_PAGE/);
|
||||
assert.match(center, /private const TICKET_PER_PAGE = 20;/);
|
||||
@@ -50,9 +50,7 @@ test('detail lookup is independent of the filtered list; paging clamps and prese
|
||||
assert.match(list, /array_merge\(\$filters, \['status' => \$key\]\)/);
|
||||
assert.match(list, /'keywords' => \$filters\['s'\]/);
|
||||
assert.match(list, /'status' => array_column\(\$statuses, 'status_key'\)/);
|
||||
assert.match(js, /\['status', 'ticket_type_id', 's', 'paged'\]/);
|
||||
assert.match(js, /searchParams.get\('id'\)/);
|
||||
assert.doesNotMatch(list + js, /aria-expanded|detail-row|scrollIntoView/);
|
||||
assert.match(center, /function ticket_context\(/);
|
||||
});
|
||||
|
||||
test('conversation, private notes and final-state confirmation remain distinct', () => {
|
||||
@@ -69,27 +67,22 @@ test('conversation, private notes and final-state confirmation remain distinct',
|
||||
assert.match(detail, /仅管理员可见,不会发送给用户/);
|
||||
});
|
||||
|
||||
test('dialog safety includes dirty guards, focus return, cancel race protection and retry without POST', () => {
|
||||
assert.match(js, /window.confirm\(strings.discard\)/);
|
||||
test('page safety: unsaved-change guard, drafts survive the post-save reload, uncertain writes lock forms', () => {
|
||||
assert.match(js, /window.addEventListener\('beforeunload'/);
|
||||
assert.match(js, /current !== generation/);
|
||||
assert.match(js, /readController.abort\(\)/);
|
||||
assert.match(js, /previous.focus\(\)/);
|
||||
assert.match(js, /if \(saving \|\| loading \|\| stale/);
|
||||
assert.match(js, /sessionStorage/);
|
||||
assert.match(js, /aksrt_ticket_msg/);
|
||||
assert.match(js, /next.length > field.maxLength/);
|
||||
assert.match(js, /savedDrafts = restore \|\| \{\}/);
|
||||
assert.match(js, /strings.refreshFailed/);
|
||||
assert.match(js, /strings.uncertain/);
|
||||
const css = read('assets/css/admin/tickets.css');
|
||||
assert.match(css, /\.aksrt-ticket-dialog:not\(\[open\]\)/);
|
||||
assert.match(js, /\[401, 403, 404, 409\]/);
|
||||
assert.match(js, /lockForms\(\)/);
|
||||
assert.match(css, /:focus-visible/);
|
||||
assert.match(css, /@media \(prefers-reduced-motion: reduce\)/);
|
||||
assert.match(css, /@media \(max-width: 600px\)/);
|
||||
assert.doesNotMatch(css, /detail-row|row\.is-open/);
|
||||
assert.doesNotMatch(css, /detail-row|row\.is-open|::backdrop/);
|
||||
});
|
||||
|
||||
test('configuration remains in the SPA; native ops has no old config tabs', () => {
|
||||
assert.match(center, /admin_url\('admin\.php\?page=aksrt-settings#\/users\/ticket'\)/);
|
||||
assert.match(list, /admin_url\('admin\.php\?page=aksrt-settings#\/users\/ticket'\)/);
|
||||
assert.doesNotMatch(center + list + detail, /nav-tab-wrapper|ticket_tab|UsersMenusTicketsConfig/);
|
||||
assert.ok(!fs.existsSync(path.join(root, 'src/Admin/Native/UsersMenusTicketsConfig.php')));
|
||||
assert.ok(read('assets/admin/src/router/index.js').includes("{ path: '/users/tickets', title: '工单管理', nativeAdminPath: 'users.php?page=aksrt_tickets' }"));
|
||||
@@ -109,6 +102,6 @@ test('frontend hooks remain aligned with their independent REST consumer', () =>
|
||||
}
|
||||
assert.match(frontend, /runCaptcha\('ticket_create'\)/);
|
||||
assert.match(frontend, /runCaptcha\('ticket_reply'\)/);
|
||||
const css = read('assets/css/routes/tickets.css');
|
||||
for (const hook of ['.aksrt-tickets-page', '.aksrt-ticket-badge', '.aksrt-ticket-detail', '--aksrt-ticket-color']) assert.ok(css.includes(hook));
|
||||
const routeCss = read('assets/css/routes/tickets.css');
|
||||
for (const hook of ['.aksrt-tickets-page', '.aksrt-ticket-badge', '.aksrt-ticket-detail', '--aksrt-ticket-color']) assert.ok(routeCss.includes(hook));
|
||||
});
|
||||
Reference in new issue
Block a user