Default the availability admin page to the week view too
CI / Tests (PHP 8.2) (pull_request) Successful in 38s
CI / Tests (PHP 8.1) (pull_request) Successful in 48s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 2m49s
CI / PHPStan (pull_request) Successful in 2m53s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m38s
CI / Build Plugin Zip (pull_request) Skipped

Follow-up demo feedback: the My Availability page now opens in its weekly
calendar (usc_view=list opts back into the table, which keeps the bulk-delete
form), matching the new lessons defaults.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
2026-07-22 11:09:23 -03:00
co-authored by Claude Fable 5
parent 5808defd1a
commit 266f572884
4 changed files with 22 additions and 6 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ Instructors access **My Availability** in wp-admin (`?page=us-availability`).
- Add a weekly series: tick weekly repeat and choose the number of weeks - Add a weekly series: tick weekly repeat and choose the number of weeks
- Delete a slot: only allowed if `is_booked = 0` - Delete a slot: only allowed if `is_booked = 0`
- Bulk delete: the list view has a checkbox per unbooked slot (with a select-all header checkbox) and a **Delete selected** button (`usc_action=bulk_delete`, `slot_ids[]`); each id is ownership-checked, and booked slots are refused at the repository level - Bulk delete: the list view has a checkbox per unbooked slot (with a select-all header checkbox) and a **Delete selected** button (`usc_action=bulk_delete`, `slot_ids[]`); each id is ownership-checked, and booked slots are refused at the repository level
- Current slots can be shown as a **list** or a **weekly calendar** (`usc_view=week`, navigated with `usc_week=Y-m-d`); the grid honours the site's `start_of_week` option via `Availability\WeekCalendar` - Current slots can be shown as a **weekly calendar** (the default, navigated with `usc_week=Y-m-d`) or a **list** (`usc_view=list`); the grid honours the site's `start_of_week` option via `Availability\WeekCalendar`
## Public Calendar ## Public Calendar
The front-end booking shortcode renders open slots from `GET /availability` The front-end booking shortcode renders open slots from `GET /availability`
+1 -1
View File
@@ -32,7 +32,7 @@ class AvailabilityController {
// View-state query params only (which view, which week) — nothing is // View-state query params only (which view, which week) — nothing is
// mutated from them, so no nonce applies. // mutated from them, so no nonce applies.
// phpcs:disable WordPress.Security.NonceVerification.Recommended // phpcs:disable WordPress.Security.NonceVerification.Recommended
$view = 'week' === sanitize_key( Val::string( wp_unslash( $_GET['usc_view'] ?? '' ) ) ) ? 'week' : 'list'; $view = 'list' === sanitize_key( Val::string( wp_unslash( $_GET['usc_view'] ?? '' ) ) ) ? 'list' : 'week';
$requestedWeek = sanitize_text_field( Val::string( wp_unslash( $_GET['usc_week'] ?? '' ) ) ); $requestedWeek = sanitize_text_field( Val::string( wp_unslash( $_GET['usc_week'] ?? '' ) ) );
// phpcs:enable WordPress.Security.NonceVerification.Recommended // phpcs:enable WordPress.Security.NonceVerification.Recommended
+4 -4
View File
@@ -84,24 +84,24 @@ $deleteForm = static function (\Unsupervised\Schedular\Availability\Availability
<ul class="subsubsub" style="margin-bottom:12px;"> <ul class="subsubsub" style="margin-bottom:12px;">
<li> <li>
<a href="<?php echo esc_url($baseUrl); ?>" <?php echo 'list' === $view ? 'class="current"' : ''; ?>><?php esc_html_e('List', 'unsupervised-schedular'); ?></a> | <a href="<?php echo esc_url($baseUrl); ?>" <?php echo 'week' === $view ? 'class="current"' : ''; ?>><?php esc_html_e('Week', 'unsupervised-schedular'); ?></a> |
</li> </li>
<li> <li>
<a href="<?php echo esc_url(add_query_arg('usc_view', 'week', $baseUrl)); ?>" <?php echo 'week' === $view ? 'class="current"' : ''; ?>><?php esc_html_e('Week', 'unsupervised-schedular'); ?></a> <a href="<?php echo esc_url(add_query_arg('usc_view', 'list', $baseUrl)); ?>" <?php echo 'list' === $view ? 'class="current"' : ''; ?>><?php esc_html_e('List', 'unsupervised-schedular'); ?></a>
</li> </li>
</ul> </ul>
<div class="clear"></div> <div class="clear"></div>
<?php if ('week' === $view) : ?> <?php if ('week' === $view) : ?>
<p> <p>
<a class="button" href="<?php echo esc_url(add_query_arg(['usc_view' => 'week', 'usc_week' => $prevWeek], $baseUrl)); ?>">&lsaquo; <?php esc_html_e('Previous week', 'unsupervised-schedular'); ?></a> <a class="button" href="<?php echo esc_url(add_query_arg('usc_week', $prevWeek, $baseUrl)); ?>">&lsaquo; <?php esc_html_e('Previous week', 'unsupervised-schedular'); ?></a>
<strong style="margin:0 12px;"> <strong style="margin:0 12px;">
<?php <?php
/* translators: %s: date of the first day of the displayed week */ /* translators: %s: date of the first day of the displayed week */
echo esc_html(sprintf(__('Week of %s', 'unsupervised-schedular'), (string) mysql2date('M j, Y', $weekStart))); echo esc_html(sprintf(__('Week of %s', 'unsupervised-schedular'), (string) mysql2date('M j, Y', $weekStart)));
?> ?>
</strong> </strong>
<a class="button" href="<?php echo esc_url(add_query_arg(['usc_view' => 'week', 'usc_week' => $nextWeek], $baseUrl)); ?>"><?php esc_html_e('Next week', 'unsupervised-schedular'); ?> &rsaquo;</a> <a class="button" href="<?php echo esc_url(add_query_arg('usc_week', $nextWeek, $baseUrl)); ?>"><?php esc_html_e('Next week', 'unsupervised-schedular'); ?> &rsaquo;</a>
</p> </p>
<table class="wp-list-table widefat fixed"> <table class="wp-list-table widefat fixed">
<thead> <thead>
@@ -99,8 +99,24 @@ class AvailabilityControllerTest extends TestCase
$this->render(); $this->render();
} }
public function testDefaultsToWeekView(): void
{
$slot = new AvailabilitySlot(instructorId: 3, startDt: '2026-07-08 09:00:00', endDt: '2026-07-08 10:00:00', id: 5);
$this->repository->shouldReceive('findByInstructor')->once()->with(3)->andReturn([$slot]);
$html = $this->render();
// Week of Monday 2026-07-06 (start_of_week = 1, today = 2026-07-06).
self::assertStringContainsString('Week of', $html);
// The list table (with its bulk-delete form) is not rendered by default.
self::assertStringNotContainsString('id="usc-bulk-delete-form"', $html);
}
public function testListViewRendersBulkCheckboxesOnlyForUnbookedSlots(): void public function testListViewRendersBulkCheckboxesOnlyForUnbookedSlots(): void
{ {
$_GET['usc_view'] = 'list';
$unbooked = new AvailabilitySlot(instructorId: 3, startDt: '2026-07-08 09:00:00', endDt: '2026-07-08 10:00:00', id: 5); $unbooked = new AvailabilitySlot(instructorId: 3, startDt: '2026-07-08 09:00:00', endDt: '2026-07-08 10:00:00', id: 5);
$booked = new AvailabilitySlot(instructorId: 3, startDt: '2026-07-08 10:00:00', endDt: '2026-07-08 11:00:00', isBooked: true, id: 6); $booked = new AvailabilitySlot(instructorId: 3, startDt: '2026-07-08 10:00:00', endDt: '2026-07-08 11:00:00', isBooked: true, id: 6);