Possible to change behaviour of Resource index click? #4215
Replies: 8 comments 11 replies
-
+1 for this idea. |
Beta Was this translation helpful? Give feedback.
-
+1 having to override ResourceTableRow right now to disable this functionality. |
Beta Was this translation helpful? Give feedback.
-
I'm gonna have a go a this tomorrow. Goal: Set the action of the click of the row on resource index level. |
Beta Was this translation helpful? Give feedback.
-
So.. @ianrobertsFF & @piljac1, I just have an update and figured it out: Solution: To do this I did the following: /**
* The action used for the click on the table row. Available options are 'view', 'select' and 'update'.
*
* @var string
*/
public static $tableRowClickAction = 'view';
/**
* Get the action that should be fired for the click on the table row.
*
* @return string
*/
public static function tableRowClickAction()
{
return static::$tableRowClickAction;
} In public static function resourceInformation(Request $request)
{
return static::resourceCollection()->map(function ($resource) use ($request) {
return array_merge([
'uriKey' => $resource::uriKey(),
'label' => $resource::label(),
'singularLabel' => $resource::singularLabel(),
'createButtonLabel' => $resource::createButtonLabel(),
'updateButtonLabel' => $resource::updateButtonLabel(),
'authorizedToCreate' => $resource::authorizedToCreate($request),
'searchable' => $resource::searchable(),
'perPageOptions' => $resource::perPageOptions(),
'tableStyle' => $resource::tableStyle(),
'showColumnBorders' => $resource::showColumnBorders(),
'debounce' => $resource::$debounce * 1000,
'tableRowClickAction' => $resource::tableRowClickAction(), // <-- This one
], $resource::additionalInformation($request));
})->values()->all();
} On the 'tableRowClickAction', And the methods: resourceClickAction(e) {
if (this.tableRowClickAction === 'update') {
return this.navigateToUpdate(e)
} else if (this.tableRowClickAction === 'select') {
return this.toggleSelection()
} else {
return this.navigateToDetail(e)
}
},
navigateToUpdate(e) {
if (!this.resource.authorizedToUpdate) {
return
}
this.commandPressed
? window.open(this.updateURL, '_blank')
: Inertia.visit(this.updateURL)
}, And the computed properties: updateURL() {
return this.$url(
`/resources/${this.resourceName}/${this.resource.id.value}/edit`,
{
viaResource: this.viaResource,
viaResourceId: this.viaResourceId,
viaRelationship: this.viaRelationship,
}
)
},
On the /**
* Determine the action of the click on the resource table row.
*/
tableRowClickAction() {
return this.resourceInformation.tableRowClickAction
}, And this line to the ResourceTableRow component: :table-row-click-action="tableRowClickAction" |
Beta Was this translation helpful? Give feedback.
-
Since it's not implemented (yet). I created a package: https://github.com/marshmallow-packages/nova-resource-click You can set the default action for all resources or per resource. |
Beta Was this translation helpful? Give feedback.
-
Definitely +1 on being able to disable it entirely. Not very friendly if you want to copy some text from a table row |
Beta Was this translation helpful? Give feedback.
-
Great Package. This should be integrated into core. |
Beta Was this translation helpful? Give feedback.
-
Ok, I've added this feature to Nova. We've got to add some tests first but it should be landing in an upcoming release. Thanks for all the feedback! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is is possible to change the behaviour of the click on the resource row on the index page?
Now it defaults to 'navigateToDetail'. It would be awesome to either disable this or change the behaviour to Edit / Preview.
EDIT: Since it's not implemented (yet). I created a package: https://github.com/marshmallow-packages/nova-resource-click
Beta Was this translation helpful? Give feedback.
All reactions