Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/js/pages/taxonomies/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default {
<span class="text-2xs font-mono">{{ term.slug }}</span>
</template>
<template #prepended-row-actions="{ row: term }">
<DropdownItem :text="__('Visit URL')" :href="term.permalink" target="_blank" icon="eye" />
<DropdownItem v-if="term.has_template" :text="__('Visit URL')" :href="term.permalink" target="_blank" icon="eye" />
<DropdownItem :text="__('Edit')" :href="term.edit_url" icon="edit" />
</template>
</Listing>
Expand Down
1 change: 1 addition & 0 deletions src/Http/Resources/CP/Taxonomies/ListedTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function toArray($request)

'permalink' => $term->absoluteUrl(),
'edit_url' => $term->editUrl(),
'has_template' => view()->exists($term->template()),
'taxonomy' => $term->taxonomy()->toArray(),
'viewable' => User::current()->can('view', $term),
'editable' => User::current()->can('edit', $term),
Expand Down
36 changes: 35 additions & 1 deletion tests/Feature/Taxonomies/ViewTermsListingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
use Statamic\Facades\Taxonomy;
use Statamic\Facades\Term;
use Statamic\Facades\User;
use Tests\FakesViews;
use Tests\PreventSavingStacheItemsToDisk;
use Tests\TestCase;

class ViewTermsListingTest extends TestCase
{
use PreventSavingStacheItemsToDisk;
use FakesViews, PreventSavingStacheItemsToDisk;

#[Test]
public function it_does_not_eager_load_actions_in_listing()
Expand All @@ -28,4 +29,37 @@ public function it_does_not_eager_load_actions_in_listing()
->assertJsonCount(1, 'data')
->assertJsonMissingPath('data.0.actions');
}

#[Test]
public function it_returns_has_template_true_when_template_exists()
{
$this->withFakeViews();
$this->viewShouldReturnRaw('tags.show', '');

$user = tap(User::make()->makeSuper())->save();
$taxonomy = tap(Taxonomy::make('tags'))->save();
tap(Term::make()->taxonomy('tags')->inDefaultLocale()->slug('alfa')->data(['title' => 'alfa']))->save();

$this
->actingAs($user)
->getJson(cp_route('taxonomies.terms.index', $taxonomy->handle()))
->assertSuccessful()
->assertJsonPath('data.0.has_template', true);
}

#[Test]
public function it_returns_has_template_false_when_template_does_not_exist()
{
$this->withFakeViews();

$user = tap(User::make()->makeSuper())->save();
$taxonomy = tap(Taxonomy::make('tags'))->save();
tap(Term::make()->taxonomy('tags')->inDefaultLocale()->slug('alfa')->data(['title' => 'alfa']))->save();

$this
->actingAs($user)
->getJson(cp_route('taxonomies.terms.index', $taxonomy->handle()))
->assertSuccessful()
->assertJsonPath('data.0.has_template', false);
}
}
Loading