Make job page task cards and change history collapsible

Task cards on the job page start collapsed and show the title, assignee,
due date and status; each opens on its own, so several can be open at
once, and "Expand all" / "Collapse all" open or close them together with
a status message. A card opens when focus moves into it. The change
history is a disclosure panel with the number of changes, closed by
default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-25 06:12:15 +02:00
co-authored by Claude Opus 5.5
parent 6936d0950b
commit 9a9935098c
3 changed files with 239 additions and 106 deletions
@@ -335,95 +335,161 @@ new class extends Component
@php($canChangeStatus = Gate::allows('jobs.update-task-status', $job->id)) @php($canChangeStatus = Gate::allows('jobs.update-task-status', $job->id))
@php($canManageTasks = Gate::allows('jobs.manage-tasks', $job->id)) @php($canManageTasks = Gate::allows('jobs.manage-tasks', $job->id))
{{--
Task cards are disclosures: collapsed by default, each opened on its own, so several can be open at once.
"Expand all" and "Collapse all" send a tasks-expand window event that every card follows. A card also opens
when focus moves into it (e.g. the status select keeps focus after a re-render).
--}}
<div
class="flex flex-wrap items-center gap-2"
x-data="{ message: '', expandedText: @js(__('jobs.tasks.all_expanded')), collapsedText: @js(__('jobs.tasks.all_collapsed')) }"
>
<x-button
x-on:click="$dispatch('tasks-expand', true); message = expandedText"
subtle
color="black"
sm
icon="chevron-double-down"
:text="__('jobs.tasks.expand_all')"
data-tasks-expand-all
/>
<x-button
x-on:click="$dispatch('tasks-expand', false); message = collapsedText"
subtle
color="black"
sm
icon="chevron-double-up"
:text="__('jobs.tasks.collapse_all')"
data-tasks-collapse-all
/>
<p role="status" aria-live="polite" class="text-sm" x-text="message"></p>
</div>
<ul class="space-y-3"> <ul class="space-y-3">
@foreach ($this->tasks as $task) @foreach ($this->tasks as $task)
<li wire:key="task-{{ $task->id }}"> <li
<article aria-labelledby="task-{{ $task->id }}-title" class="space-y-3 rounded-lg border border-zinc-200 p-4 text-sm dark:border-zinc-700"> wire:key="task-{{ $task->id }}"
<div class="flex flex-wrap items-start justify-between gap-3"> x-data="{ open: false }"
<h3 id="task-{{ $task->id }}-title" class="text-base font-medium break-words">{{ $task->title }}</h3> x-on:tasks-expand.window="open = $event.detail"
<span>{{ __('jobs.tasks.statuses.'.$task->status->value) }}</span> x-on:focusin="if ($event.target.closest('[data-task-details]')) open = true"
>
<article aria-labelledby="task-{{ $task->id }}-title" class="rounded-lg border border-zinc-200 bg-white text-sm dark:border-zinc-700 dark:bg-zinc-900">
<div class="flex flex-col gap-2 p-3 sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-6">
<h3 id="task-{{ $task->id }}-title" class="min-w-0 text-base font-medium sm:flex-1">
<button
type="button"
id="task-toggle-{{ $task->id }}"
x-on:click="open = ! open"
x-bind:aria-expanded="open.toString()"
aria-expanded="false"
aria-controls="task-{{ $task->id }}-details"
class="flex min-h-6 w-full items-start gap-2 rounded-md text-left focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-400"
>
<x-icon name="chevron-right" class="mt-0.5 size-5 shrink-0 transition-transform" x-bind:class="{ 'rotate-90': open }" aria-hidden="true" />
<span class="min-w-0 break-words">{{ $task->title }}</span>
</button>
</h3>
<dl class="flex flex-col gap-1 ps-7 sm:flex-row sm:flex-wrap sm:gap-x-6 sm:ps-0">
<div class="flex flex-wrap gap-x-1">
<dt class="font-medium">{{ __('jobs.tasks.fields.assignee') }}:</dt>
<dd>{{ $task->assignee?->name ?? __('jobs.calendar.no_assignee') }}</dd>
</div>
<div class="flex flex-wrap gap-x-1">
<dt class="font-medium">{{ __('jobs.tasks.fields.due_on') }}:</dt>
<dd><x-jobs.due-date :date="$task->dueOn" :status="$task->status" /></dd>
</div>
<div class="flex flex-wrap gap-x-1">
<dt class="font-medium">{{ __('jobs.tasks.fields.status') }}:</dt>
<dd>{{ __('jobs.tasks.statuses.'.$task->status->value) }}</dd>
</div>
</dl>
</div> </div>
<dl class="grid gap-x-6 gap-y-1 sm:grid-cols-[max-content_1fr]"> <div
<dt class="font-medium">{{ __('jobs.tasks.fields.work_type') }}</dt> id="task-{{ $task->id }}-details"
<dd>{{ $task->workType->name }}</dd> data-task-details
<dt class="font-medium">{{ __('jobs.tasks.fields.assignee') }}</dt> x-show="open"
<dd>{{ $task->assignee?->name ?? __('jobs.calendar.no_assignee') }}</dd> x-cloak
@if ($task->members !== []) class="space-y-3 border-t border-zinc-200 p-4 dark:border-zinc-700"
<dt class="font-medium">{{ __('jobs.tasks.fields.members') }}</dt> >
<dd>{{ collect($task->members)->pluck('name')->join(', ') }}</dd> <dl class="grid gap-x-6 gap-y-1 sm:grid-cols-[max-content_1fr]">
@endif <dt class="font-medium">{{ __('jobs.tasks.fields.work_type') }}</dt>
<dt class="font-medium">{{ __('jobs.tasks.fields.due_on') }}</dt> <dd>{{ $task->workType->name }}</dd>
<dd><x-jobs.due-date :date="$task->dueOn" :status="$task->status" /></dd> @if ($task->members !== [])
<dt class="font-medium">{{ __('jobs.tasks.schedule') }}</dt> <dt class="font-medium">{{ __('jobs.tasks.fields.members') }}</dt>
<dd> <dd>{{ collect($task->members)->pluck('name')->join(', ') }}</dd>
@if ($task->plannedFrom === null)
{{ __('jobs.not_set') }}
@else
{{ __('jobs.tasks.schedule_range', ['from' => $this->formatDate($task->plannedFrom), 'to' => $this->formatDate($task->plannedTo)]) }}
@endif @endif
</dd> <dt class="font-medium">{{ __('jobs.tasks.schedule') }}</dt>
<dt class="font-medium">{{ __('jobs.tasks.fields.estimated_hours') }}</dt> <dd>
<dd>{{ $task->estimatedHours === null ? __('jobs.not_set') : str_replace('.', ',', $task->estimatedHours).' h' }}</dd> @if ($task->plannedFrom === null)
</dl> {{ __('jobs.not_set') }}
@else
{{ __('jobs.tasks.schedule_range', ['from' => $this->formatDate($task->plannedFrom), 'to' => $this->formatDate($task->plannedTo)]) }}
@endif
</dd>
<dt class="font-medium">{{ __('jobs.tasks.fields.estimated_hours') }}</dt>
<dd>{{ $task->estimatedHours === null ? __('jobs.not_set') : str_replace('.', ',', $task->estimatedHours).' h' }}</dd>
</dl>
@if ($task->description !== null) @if ($task->description !== null)
<p class="whitespace-pre-line">{{ $task->description }}</p> <p class="whitespace-pre-line">{{ $task->description }}</p>
@endif
<livewire:jobs::task-checklist :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'checklist-'.$task->id" />
<div class="flex flex-wrap items-end gap-3">
@if ($canChangeStatus)
<div class="w-full sm:w-56">
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
<x-select.native
id="task-status-{{ $task->id }}"
wire:change="changeTaskStatus({{ $task->id }}, $event.target.value)"
:label="__('jobs.tasks.fields.status')"
:aria-label="__('jobs.tasks.status_of', ['title' => $task->title])"
>
@foreach (TaskStatus::cases() as $status)
<option value="{{ $status->value }}" @selected($status === $task->status)>{{ __('jobs.tasks.statuses.'.$status->value) }}</option>
@endforeach
</x-select.native>
</div>
@endif @endif
@if (! $job->status->locksTime() && Gate::allows('time.book', $job->id)) <livewire:jobs::task-checklist :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'checklist-'.$task->id" />
<x-button
:href="route('time.task', $task->id)"
wire:navigate
subtle
color="black"
sm
icon="clock"
:text="__('jobs.tasks.book_time')"
:aria-label="__('jobs.tasks.book_time_named', ['title' => $task->title])"
/>
@endif
@if ($canManageTasks) <div class="flex flex-wrap items-end gap-3">
<x-button @if ($canChangeStatus)
:href="route('jobs.tasks.edit', [$job->id, $task->id])" <div class="w-full sm:w-56">
wire:navigate {{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
subtle <x-select.native
color="black" id="task-status-{{ $task->id }}"
sm wire:change="changeTaskStatus({{ $task->id }}, $event.target.value)"
icon="pencil" :label="__('jobs.tasks.fields.status')"
:text="__('jobs.edit')" :aria-label="__('jobs.tasks.status_of', ['title' => $task->title])"
:aria-label="__('jobs.tasks.edit_named', ['title' => $task->title])" >
/> @foreach (TaskStatus::cases() as $status)
<x-button <option value="{{ $status->value }}" @selected($status === $task->status)>{{ __('jobs.tasks.statuses.'.$status->value) }}</option>
wire:click="confirmTaskRemoval({{ $task->id }})" @endforeach
subtle </x-select.native>
color="black" </div>
sm @endif
icon="trash"
:text="__('customers.remove')" @if (! $job->status->locksTime() && Gate::allows('time.book', $job->id))
:aria-label="__('jobs.tasks.remove_named', ['title' => $task->title])" <x-button
/> :href="route('time.task', $task->id)"
@endif wire:navigate
subtle
color="black"
sm
icon="clock"
:text="__('jobs.tasks.book_time')"
:aria-label="__('jobs.tasks.book_time_named', ['title' => $task->title])"
/>
@endif
@if ($canManageTasks)
<x-button
:href="route('jobs.tasks.edit', [$job->id, $task->id])"
wire:navigate
subtle
color="black"
sm
icon="pencil"
:text="__('jobs.edit')"
:aria-label="__('jobs.tasks.edit_named', ['title' => $task->title])"
/>
<x-button
wire:click="confirmTaskRemoval({{ $task->id }})"
subtle
color="black"
sm
icon="trash"
:text="__('customers.remove')"
:aria-label="__('jobs.tasks.remove_named', ['title' => $task->title])"
/>
@endif
</div>
</div> </div>
</article> </article>
</li> </li>
@@ -474,33 +540,49 @@ new class extends Component
<p class="whitespace-pre-line text-sm">{{ $job->instructions ?? __('jobs.not_set') }}</p> <p class="whitespace-pre-line text-sm">{{ $job->instructions ?? __('jobs.not_set') }}</p>
</section> </section>
<section aria-labelledby="history-heading" class="space-y-3"> <section aria-labelledby="history-heading" class="space-y-3" x-data="{ open: false }">
<h2 id="history-heading" class="text-xl font-semibold">{{ __('jobs.sections.history') }}</h2> <h2 id="history-heading" class="text-xl font-semibold">
<button
type="button"
id="history-toggle"
x-on:click="open = ! open"
x-bind:aria-expanded="open.toString()"
aria-expanded="false"
aria-controls="history-panel"
class="flex min-h-6 items-center gap-2 rounded-md text-left focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-400"
>
<x-icon name="chevron-right" class="size-5 shrink-0 transition-transform" x-bind:class="{ 'rotate-90': open }" aria-hidden="true" />
{{ __('jobs.sections.history') }}
<span class="text-base font-normal">{{ trans_choice('jobs.history.count', count($this->changes), ['count' => count($this->changes)]) }}</span>
</button>
</h2>
@if ($this->changes === []) <div id="history-panel" x-show="open" x-cloak>
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.history.empty') }}</p> @if ($this->changes === [])
@else <p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.history.empty') }}</p>
<ol class="space-y-2 text-sm"> @else
@foreach ($this->changes as $change) <ol class="space-y-2 text-sm">
<li class="border-b border-zinc-200 pb-2 dark:border-zinc-700"> @foreach ($this->changes as $change)
@if ($change->field === 'created') <li class="border-b border-zinc-200 pb-2 dark:border-zinc-700">
{{ __('jobs.history.created', ['user' => $change->userName, 'number' => $change->newValue]) }} @if ($change->field === 'created')
@else {{ __('jobs.history.created', ['user' => $change->userName, 'number' => $change->newValue]) }}
<span class="break-words">{{ __('jobs.history.changed', [ @else
'field' => __('jobs.fields.'.$change->field), <span class="break-words">{{ __('jobs.history.changed', [
'old' => $this->historyValue($change->field, $change->oldValue), 'field' => __('jobs.fields.'.$change->field),
'new' => $this->historyValue($change->field, $change->newValue), 'old' => $this->historyValue($change->field, $change->oldValue),
]) }}</span> 'new' => $this->historyValue($change->field, $change->newValue),
@if ($change->field === 'status' && \App\Modules\Jobs\Domain\Enums\JobStatus::tryFrom((string) $change->oldValue)?->unlocksTo(\App\Modules\Jobs\Domain\Enums\JobStatus::from((string) $change->newValue))) ]) }}</span>
<span class="font-medium">{{ __('jobs.history.unlocked') }}</span> @if ($change->field === 'status' && \App\Modules\Jobs\Domain\Enums\JobStatus::tryFrom((string) $change->oldValue)?->unlocksTo(\App\Modules\Jobs\Domain\Enums\JobStatus::from((string) $change->newValue)))
<span class="font-medium">{{ __('jobs.history.unlocked') }}</span>
@endif
@endif @endif
@endif <span class="block text-zinc-600 dark:text-zinc-300">
<span class="block text-zinc-600 dark:text-zinc-300"> {{ __('jobs.history.by', ['user' => $change->userName, 'time' => CarbonImmutable::parse($change->changedAt)->format('j.n.Y H.i')]) }}
{{ __('jobs.history.by', ['user' => $change->userName, 'time' => CarbonImmutable::parse($change->changedAt)->format('j.n.Y H.i')]) }} </span>
</span> </li>
</li> @endforeach
@endforeach </ol>
</ol> @endif
@endif </div>
</section> </section>
</div> </div>
+5
View File
@@ -22,6 +22,10 @@ return [
'edit_title' => 'Muokkaa tehtävää', 'edit_title' => 'Muokkaa tehtävää',
'job_label' => 'Asiakastyö', 'job_label' => 'Asiakastyö',
'empty' => 'Ei tehtäviä.', 'empty' => 'Ei tehtäviä.',
'expand_all' => 'Laajenna kaikki',
'collapse_all' => 'Supista kaikki',
'all_expanded' => 'Kaikki tehtävät laajennettu.',
'all_collapsed' => 'Kaikki tehtävät supistettu.',
'not_allowed_yet' => 'Tehtäviä voi lisätä, kun työ on tarjouspyyntö-tilassa tai myöhemmässä tilassa.', 'not_allowed_yet' => 'Tehtäviä voi lisätä, kun työ on tarjouspyyntö-tilassa tai myöhemmässä tilassa.',
'created' => 'Tehtävä :title lisätty.', 'created' => 'Tehtävä :title lisätty.',
'updated' => 'Tehtävä :title tallennettu.', 'updated' => 'Tehtävä :title tallennettu.',
@@ -313,6 +317,7 @@ return [
'history' => [ 'history' => [
'empty' => 'Ei muutoksia.', 'empty' => 'Ei muutoksia.',
'count' => '{0} (ei muutoksia)|{1} (1 muutos)|[2,*] (:count muutosta)',
'unlocked' => '(lukitus avattu)', 'unlocked' => '(lukitus avattu)',
'created' => ':user loi työn :number.', 'created' => ':user loi työn :number.',
'changed' => ':field: :old → :new', 'changed' => ':field: :old → :new',
+46
View File
@@ -172,6 +172,12 @@ it('has no accessibility issues on a job with tasks and on the task form', funct
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop(); $visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode(); $visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
if ($page === 'job page') {
$visit->click('[data-tasks-expand-all]')
->click('#history-toggle')
->assertVisible('#task-status-'.$task->id);
}
$visit->assertNoJavaScriptErrors() $visit->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2); ->assertNoAccessibilityIssues(level: 2);
})->with(['job page', 'new task', 'edit task'])->with([ })->with(['job page', 'new task', 'edit task'])->with([
@@ -188,9 +194,11 @@ it('changes a task status and removes a task with the keyboard', function () {
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä']); ->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä']);
visit(route('jobs.show', $this->job->id)) visit(route('jobs.show', $this->job->id))
->keys('#task-toggle-'.$task->id, 'Enter')
->select('#task-status-'.$task->id, 'in_progress') ->select('#task-status-'.$task->id, 'in_progress')
->assertSee('Tehtävän Kuvauspäivä tila on nyt Työn alla.') ->assertSee('Tehtävän Kuvauspäivä tila on nyt Työn alla.')
->assertScript('document.activeElement.id', 'task-status-'.$task->id) ->assertScript('document.activeElement.id', 'task-status-'.$task->id)
->assertAttribute('#task-toggle-'.$task->id, 'aria-expanded', 'true')
->keys('[aria-label="Poista tehtävä Kuvauspäivä"]', 'Enter') ->keys('[aria-label="Poista tehtävä Kuvauspäivä"]', 'Enter')
->assertScript('document.getElementById("remove-task-dialog").open', true) ->assertScript('document.getElementById("remove-task-dialog").open', true)
->assertScript('document.getElementById("remove-task-dialog").contains(document.activeElement)', true) ->assertScript('document.getElementById("remove-task-dialog").contains(document.activeElement)', true)
@@ -199,6 +207,43 @@ it('changes a task status and removes a task with the keyboard', function () {
->assertScript('document.activeElement.id', 'tasks-heading'); ->assertScript('document.activeElement.id', 'tasks-heading');
}); });
it('shows task cards collapsed, opens several at once and expands or collapses them all', function () {
$this->job->update(['status' => 'order']);
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
$shoot = TaskModel::factory()
->assignedTo([$this->user->id])
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä', 'due_on' => '2026-12-04']);
$edit = TaskModel::factory()
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Editointi']);
$page = visit(route('jobs.show', $this->job->id))
->assertSee('Johanna Johto')
->assertSee('4.12.2026')
->assertAttribute('#task-toggle-'.$shoot->id, 'aria-expanded', 'false')
->assertMissing('#task-status-'.$shoot->id)
->keys('#task-toggle-'.$shoot->id, 'Enter')
->assertAttribute('#task-toggle-'.$shoot->id, 'aria-expanded', 'true')
->assertVisible('#task-status-'.$shoot->id)
->keys('#task-toggle-'.$edit->id, 'Enter')
->assertVisible('#task-status-'.$shoot->id)
->assertVisible('#task-status-'.$edit->id)
->click('[data-tasks-collapse-all]')
->assertSee('Kaikki tehtävät supistettu.')
->assertMissing('#task-status-'.$shoot->id)
->assertMissing('#task-status-'.$edit->id)
->click('[data-tasks-expand-all]')
->assertSee('Kaikki tehtävät laajennettu.')
->assertAttribute('#task-toggle-'.$shoot->id, 'aria-expanded', 'true')
->assertAttribute('#task-toggle-'.$edit->id, 'aria-expanded', 'true');
$page->assertAttribute('#history-toggle', 'aria-expanded', 'false')
->assertMissing('#history-panel')
->keys('#history-toggle', 'Enter')
->assertAttribute('#history-toggle', 'aria-expanded', 'true')
->assertVisible('#history-panel')
->assertNoAccessibilityIssues(level: 2);
});
it('adds, checks, renames, moves and removes checklist items with the keyboard', function () { it('adds, checks, renames, moves and removes checklist items with the keyboard', function () {
$this->job->update(['status' => 'order']); $this->job->update(['status' => 'order']);
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole(); $workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
@@ -206,6 +251,7 @@ it('adds, checks, renames, moves and removes checklist items with the keyboard',
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä']); ->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä']);
$page = visit(route('jobs.show', $this->job->id)) $page = visit(route('jobs.show', $this->job->id))
->click('#task-toggle-'.$task->id)
->type('#checklist-new-'.$task->id, 'Valot') ->type('#checklist-new-'.$task->id, 'Valot')
->keys('#checklist-new-'.$task->id, 'Enter') ->keys('#checklist-new-'.$task->id, 'Enter')
->assertSee('Kohta Valot lisätty.') ->assertSee('Kohta Valot lisätty.')