Created
November 2, 2022 01:02
-
-
Save dmason30/421c0a36b01789447a6f8819db5a5694 to your computer and use it in GitHub Desktop.
Hide table row actions when all rows are disabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/Http/Resources/IndexViewResource.php | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/src/Http/Resources/IndexViewResource.php b/src/Http/Resources/IndexViewResource.php | |
--- a/src/Http/Resources/IndexViewResource.php (revision 791a5f1d0544e11036f41c64a64128c774072212) | |
+++ b/src/Http/Resources/IndexViewResource.php (date 1667350406116) | |
@@ -3,6 +3,7 @@ | |
namespace Laravel\Nova\Http\Resources; | |
use Laravel\Nova\Http\Requests\ResourceIndexRequest; | |
+use Laravel\Nova\ResourceCollection; | |
class IndexViewResource extends Resource | |
{ | |
@@ -18,9 +19,21 @@ | |
[$paginator, $total, $sortable] = $request->searchIndex(); | |
+ /** @var ResourceCollection $resources */ | |
+ $resources = $paginator->getCollection()->mapInto($resource)->map->serializeForIndex($request); | |
+ | |
+ $authorized = [ | |
+ 'authorizedToViewSome' => $resources->some('authorizedToView', true), | |
+ 'authorizedToUpdateSome' => $resources->some('authorizedToUpdate', true), | |
+ 'authorizedToDeleteSome' => $resources->some('authorizedToDelete', true), | |
+ 'authorizedToRestoreSome' => $resources->some('authorizedToRestore', true), | |
+ ]; | |
+ | |
return [ | |
'label' => $resource::label(), | |
- 'resources' => $paginator->getCollection()->mapInto($resource)->map->serializeForIndex($request), | |
+ 'resources' => $resources->map(function (array $resource) use ($authorized) { | |
+ return array_merge($resource, $authorized); | |
+ }), | |
'prev_page_url' => $paginator->previousPageUrl(), | |
'next_page_url' => $paginator->nextPageUrl(), | |
'per_page' => $paginator->perPage(), | |
Index: resources/js/components/ResourceTableRow.vue | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/resources/js/components/ResourceTableRow.vue b/resources/js/components/ResourceTableRow.vue | |
--- a/resources/js/components/ResourceTableRow.vue (revision 791a5f1d0544e11036f41c64a64128c774072212) | |
+++ b/resources/js/components/ResourceTableRow.vue (date 1667350732324) | |
@@ -77,6 +77,7 @@ | |
<!-- View Resource Link --> | |
<Link | |
+ v-if="resource.authorizedToViewSome" | |
as="button" | |
v-tooltip.click="__('View')" | |
:aria-label="__('View')" | |
@@ -89,6 +90,7 @@ | |
<Icon type="eye" /> | |
</Link> | |
+ <template v-if="resource.authorizedToUpdateSome"> | |
<!-- Edit Pivot Button --> | |
<Link | |
as="button" | |
@@ -135,10 +137,11 @@ | |
> | |
<Icon type="pencil-alt" /> | |
</Link> | |
+ </template> | |
<!-- Delete Resource Link --> | |
<button | |
- v-if="!resource.softDeleted || viaManyToMany" | |
+ v-if="resource.authorizedToDeleteSome && (!resource.softDeleted || viaManyToMany)" | |
v-tooltip.click="__(viaManyToMany ? 'Detach' : 'Delete')" | |
:aria-label="__(viaManyToMany ? 'Detach' : 'Delete')" | |
:data-testid="`${testId}-delete-button`" | |
@@ -152,7 +155,7 @@ | |
<!-- Restore Resource Link --> | |
<button | |
- v-if="resource.softDeleted && !viaManyToMany" | |
+ v-if="resource.authorizedToRestoreSome && !resource.authorizedToDelete && resource.softDeleted && !viaManyToMany" | |
v-tooltip.click="__('Restore')" | |
:aria-label="__('Restore')" | |
:disabled="!resource.authorizedToRestore" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment