Skip to content

Commit

Permalink
add confirmation for reindex button (#2919)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmachughes authored Jan 21, 2025
1 parent 3bab59e commit 6327165
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
16 changes: 14 additions & 2 deletions sourcecode/hub/app/Http/Controllers/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
use App\Jobs\RebuildContentIndex;
use App\Models\LtiToolExtra;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\Response;

use function back;
use function response;
use function route;
use function trans;
use function view;

final class AdminController extends Controller
Expand All @@ -23,10 +27,18 @@ public function index(): View
]);
}

public function rebuildContentIndex(Dispatcher $dispatcher): RedirectResponse
public function rebuildContentIndex(Dispatcher $dispatcher, Request $request): Response
{
$dispatcher->dispatch(new RebuildContentIndex());

$request->session()
->flash('alert', trans('messages.alert-rebuilding-content-index'));

if ($request->header('HX-Request')) {
return response()->noContent()
->header('HX-Redirect', route('admin.index'));
}

return back()
->with('alert', trans('messages.alert-rebuilding-content-index'));
}
Expand Down
2 changes: 2 additions & 0 deletions sourcecode/hub/lang/en/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,6 @@
'attach-context-to-contents' => 'Attach context to contents',
'attach-context-to-contents-warning' => 'This adds a context to all contents',
'start-job' => 'Start job',
'danger-zone' => 'Danger zone',
'confirm-reindex' => 'Reindexing will make content listings unavailable until the process has completed. Are you sure you want to continue?',
];
19 changes: 13 additions & 6 deletions sourcecode/hub/resources/views/admin/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@
{{ trans('messages.attach-context-to-contents') }}
</a>
</li>

<li>
<x-form action="{{ route('admin.rebuild-content-index') }}">
<button class="btn btn-link p-0">{{ trans('messages.rebuild-content-index') }}</button>
</x-form>
</li>
</ul>

<h3>{{ trans('messages.danger-zone') }}</h3>

<x-form
action="{{ route('admin.rebuild-content-index') }}"
class="mb-3"
hx-post="{{ route('admin.rebuild-content-index') }}"
hx-confirm="{{ trans('messages.confirm-reindex') }}"
>
<button class="btn btn-danger">
{{ trans('messages.rebuild-content-index') }}
</button>
</x-form>

<h3>Admin tools</h3>

<ul>
Expand Down
8 changes: 8 additions & 0 deletions sourcecode/hub/tests/Browser/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public function testCanRebuildIndex(): void
->loginAs($user->email)
->visit('/admin')
->press('Rebuild content index')
->waitFor('#htmxConfirmModal')
->with(
'#htmxConfirmModal',
fn(Browser $modal) => $modal
->assertSee('Are you sure you want to continue?')
->press('OK'),
)
->waitForReload()
->assertPathIs('/admin')
->assertSee('Rebuilding content index…');
});
Expand Down

0 comments on commit 6327165

Please sign in to comment.