init
This commit is contained in:
21 files changed
+12224
No files matched your search
+10
@@ -0,0 +1,10 @@
|
|||||||
|
/.idea
|
||||||
|
/vendor
|
||||||
|
/node_modules
|
||||||
|
/auth.json
|
||||||
|
composer.phar
|
||||||
|
composer.lock
|
||||||
|
phpunit.xml
|
||||||
|
.phpunit.result.cache
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Meghdad Fadaee
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
# Nova Row Actions
|
||||||
|
|
||||||
|
displays ordinary Laravel Nova actions as
|
||||||
|
visible, accessible buttons in resource index rows. It uses Nova's standard
|
||||||
|
action endpoint, authorization, confirmation forms, response handling, and
|
||||||
|
table refresh flow.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- PHP 8.1+
|
||||||
|
- Laravel 10.48+, 11.44+, 12.1+, or 13
|
||||||
|
- Laravel Nova 5.8.3+
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Install the package with Composer. Laravel package discovery registers its
|
||||||
|
service provider and compiled Nova assets automatically.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
composer require meghdadfadaee/nova-row-actions
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Add the field to a Nova resource and keep each represented action registered
|
||||||
|
in the resource's `actions()` method. The latter is required because Nova's
|
||||||
|
standard action endpoint only executes actions registered by the resource.
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use MeghdadFadaee\NovaRowActions\RowActions;
|
||||||
|
|
||||||
|
public function fields(NovaRequest $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
RowActions::make('Actions')
|
||||||
|
->add(
|
||||||
|
Approve::make(),
|
||||||
|
icon: 'check',
|
||||||
|
color: 'success',
|
||||||
|
activeWhen: fn (Model $model) => $model->approved,
|
||||||
|
disabledWhen: fn (Model $model) => $model->approved,
|
||||||
|
confirm: false,
|
||||||
|
)
|
||||||
|
->add(
|
||||||
|
Reject::make(),
|
||||||
|
icon: 'x-mark',
|
||||||
|
color: 'danger',
|
||||||
|
tooltip: 'Reject this record',
|
||||||
|
visibleWhen: fn (Model $model) => ! $model->archived,
|
||||||
|
order: 20,
|
||||||
|
confirm: true,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actions(NovaRequest $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Approve::make()->exceptInline(),
|
||||||
|
Reject::make()->exceptInline(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`exceptInline()` leaves actions available in Nova's bulk selector and detail
|
||||||
|
view while removing them from the row ellipsis.
|
||||||
|
|
||||||
|
## Button options
|
||||||
|
|
||||||
|
`add()` accepts the following named arguments:
|
||||||
|
|
||||||
|
- `icon`: a Nova icon name, such as `check` or `x-mark`.
|
||||||
|
- `color`: `default`, `primary`, `success`, `danger`, `warning`, or `info`.
|
||||||
|
- `variant`: `outline`, `solid`, or `ghost`.
|
||||||
|
- `label`: button/accessibility label; defaults to the action name.
|
||||||
|
- `tooltip`: tooltip text; defaults to the resolved label.
|
||||||
|
- `activeWhen`: boolean or row callback controlling the pressed/active state.
|
||||||
|
- `disabledWhen`: boolean or row callback controlling disabled state.
|
||||||
|
- `visibleWhen`: boolean or row callback controlling server-side visibility.
|
||||||
|
- `order`: numeric order; insertion order is used by default.
|
||||||
|
- `confirm`: `true` to force confirmation, `false` to skip it, or `null` to
|
||||||
|
preserve the Nova action's own confirmation strategy.
|
||||||
|
- `showLabel`: display text beside the icon; labels remain available to screen
|
||||||
|
readers when this is false.
|
||||||
|
|
||||||
|
Callbacks receive `(Model $model, NovaRequest $request, Action $action)` and may
|
||||||
|
declare only the leading arguments they need.
|
||||||
|
|
||||||
|
## Notes and limitations
|
||||||
|
|
||||||
|
- Actions must be normal resource actions registered by `actions()`. Pivot-only
|
||||||
|
actions and lens-specific endpoints are not supported by the field.
|
||||||
|
- Relationship indexes are supported through Nova's `viaResource`,
|
||||||
|
`viaResourceId`, and `viaRelationship` action parameters.
|
||||||
|
- Nova action fields, validation errors, downloads, events, response modals,
|
||||||
|
redirects, visits, danger messages, notifications, and progress state are
|
||||||
|
delegated to Nova 5.8.3's native action composable.
|
||||||
|
- The package ships compiled production assets; Node is only needed when
|
||||||
|
modifying the Vue or CSS sources.
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm ci
|
||||||
|
npm test
|
||||||
|
npm run production
|
||||||
|
composer validate --strict
|
||||||
|
```
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"name": "meghdadfadaee/nova-row-actions",
|
||||||
|
"description": "Display arbitrary Laravel Nova actions as accessible index-row buttons.",
|
||||||
|
"keywords": [
|
||||||
|
"laravel",
|
||||||
|
"nova"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Meghdad Fadaee"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": "^8.1",
|
||||||
|
"illuminate/support": "^10.48|^11.44|^12.1|^13.0",
|
||||||
|
"laravel/nova": "^5.8.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"laravel/nova-devtool": "^1.9",
|
||||||
|
"orchestra/testbench-core": "^8.35|^9.12|^10.1|^11.0",
|
||||||
|
"phpunit/phpunit": "^10.0|^11.0|^12.0|^13.0"
|
||||||
|
},
|
||||||
|
"repositories": [
|
||||||
|
{ "type": "composer", "url": "https://nova.laravel.com" }
|
||||||
|
],
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"MeghdadFadaee\\NovaRowActions\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"MeghdadFadaee\\NovaRowActions\\Tests\\": "tests/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"MeghdadFadaee\\NovaRowActions\\FieldServiceProvider"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"sort-packages": true
|
||||||
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"prefer-stable": true
|
||||||
|
}
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
.nova-row-actions{direction:inherit;gap:.4rem}.nova-row-actions,.nova-row-actions__button{align-items:center;display:inline-flex;justify-content:center}.nova-row-actions__button{--row-action-color:#6b7280;--row-action-soft:#f3f4f6;background:transparent;border:1px solid #d1d5db;border-radius:.5rem;color:var(--row-action-color);gap:.35rem;height:2.25rem;line-height:1;min-width:2.25rem;padding-inline:.5rem;position:relative;transition:background-color .15s,border-color .15s,color .15s,transform .15s}.nova-row-actions__button--primary{--row-action-color:#0ea5e9;--row-action-soft:#f0f9ff}.nova-row-actions__button--success{--row-action-color:#16a34a;--row-action-soft:#f0fdf4}.nova-row-actions__button--danger{--row-action-color:#dc2626;--row-action-soft:#fef2f2}.nova-row-actions__button--warning{--row-action-color:#d97706;--row-action-soft:#fffbeb}.nova-row-actions__button--info{--row-action-color:#0891b2;--row-action-soft:#ecfeff}.nova-row-actions__button--outline.nova-row-actions__button--active,.nova-row-actions__button--outline:not(:disabled):hover{background:var(--row-action-soft);border-color:var(--row-action-color)}.nova-row-actions__button--solid{background:var(--row-action-color);border-color:var(--row-action-color);color:#fff}.nova-row-actions__button--ghost{border-color:transparent}.nova-row-actions__button--ghost.nova-row-actions__button--active,.nova-row-actions__button--ghost:not(:disabled):hover{background:var(--row-action-soft)}.nova-row-actions__button:not(:disabled):hover{transform:scale(1.04)}.nova-row-actions__button:focus-visible{outline:2px solid var(--row-action-color);outline-offset:2px}.nova-row-actions__button:disabled{cursor:not-allowed;opacity:.55}.nova-row-actions__button--working:disabled{cursor:wait}.dark .nova-row-actions__button{--row-action-soft:rgba(55,65,81,.55);border-color:#4b5563}.dark .nova-row-actions__button--solid{border-color:var(--row-action-color)}.nova-row-actions__icon{flex:none;height:1.2rem;width:1.2rem}.nova-row-actions__label{font-size:.75rem;font-weight:600;white-space:nowrap}.nova-row-actions__button--working>:not(.nova-row-actions__spinner){opacity:0}.nova-row-actions__spinner{animation:nova-row-actions-spin .65s linear infinite;border:2px solid;border-inline-end-color:transparent;border-radius:9999px;height:1rem;position:absolute;width:1rem}.nova-row-actions__sr-only{clip:rect(0,0,0,0);border:0;height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;white-space:nowrap;width:1px}@media (prefers-reduced-motion:reduce){.nova-row-actions__button{transition:none}.nova-row-actions__spinner{animation-duration:1.5s}}@keyframes nova-row-actions-spin{to{transform:rotate(1turn)}}
|
||||||
Vendored
+2
@@ -0,0 +1,2 @@
|
|||||||
|
/*! For license information please see field.js.LICENSE.txt */
|
||||||
|
(()=>{var e,t={673(e,t,r){"use strict";var n={};r.r(n),r.d(n,{hasBrowserEnv:()=>jt,hasStandardBrowserEnv:()=>Tt,hasStandardBrowserWebWorkerEnv:()=>Ct,navigator:()=>Pt,origin:()=>Nt});const o=Vue;var i=r(4383),s=r.n(i),a={nested:{type:Boolean,default:!1},preventInitialLoading:{type:Boolean,default:!1},showHelpText:{type:Boolean,default:!1},shownViaNewRelationModal:{type:Boolean,default:!1},resourceId:{type:[Number,String]},resourceName:{type:String},relatedResourceId:{type:[Number,String]},relatedResourceName:{type:String},field:{type:Object,required:!0},viaResource:{type:String,required:!1},viaResourceId:{type:[String,Number],required:!1},viaRelationship:{type:String,required:!1},relationshipType:{type:String,default:""},shouldOverrideMeta:{type:Boolean,default:!1},disablePagination:{type:Boolean,default:!1},clickAction:{type:String,default:"view",validator:function(e){return["edit","select","ignore","detail"].includes(e)}},mode:{type:String,default:"form",validator:function(e){return["form","modal","action-modal","action-fullscreen"].includes(e)}}};function u(e){return s()(a,e)}function c(e){return Boolean(null!=e&&null!=e&&""!==e)}function l(){return"undefined"!=typeof navigator&&"undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:{}}const f="function"==typeof Proxy;let p,d;function h(){return void 0!==p||("undefined"!=typeof window&&window.performance?(p=!0,d=window.performance):"undefined"!=typeof globalThis&&(null===(e=globalThis.perf_hooks)||void 0===e?void 0:e.performance)?(p=!0,d=globalThis.perf_hooks.performance):p=!1),p?d.now():Date.now();var e}class y{constructor(e,t){this.target=null,this.targetQueue=[],this.onQueue=[],this.plugin=e,this.hook=t;const r={};if(e.settings)for(const t in e.settings){const n=e.settings[t];r[t]=n.defaultValue}const n=`__vue-devtools-plugin-settings__${e.id}`;let o=Object.assign({},r);try{const e=localStorage.getItem(n),t=JSON.parse(e);Object.assign(o,t)}catch(e){}this.fallbacks={getSettings:()=>o,setSettings(e){try{localStorage.setItem(n,JSON.stringify(e))}catch(e){}o=e},now:()=>h()},t&&t.on("plugin:settings:set",(e,t)=>{e===this.plugin.id&&this.fallbacks.setSettings(t)}),this.proxiedOn=new Proxy({},{get:(e,t)=>this.target?this.target.on[t]:(...e)=>{this.onQueue.push({method:t,args:e})}}),this.proxiedTarget=new Proxy({},{get:(e,t)=>this.target?this.target[t]:"on"===t?this.proxiedOn:Object.keys(this.fallbacks).includes(t)?(...e)=>(this.targetQueue.push({method:t,args:e,resolve:()=>{}}),this.fallbacks[t](...e)):(...e)=>new Promise(r=>{this.targetQueue.push({method:t,args:e,resolve:r})})})}async setRealTarget(e){this.target=e;for(const e of this.onQueue)this.target.on[e.method](...e.args);for(const e of this.targetQueue)e.resolve(await this.target[e.method](...e.args))}}function g(e,t){const r=e,n=l(),o=l().__VUE_DEVTOOLS_GLOBAL_HOOK__,i=f&&r.enableEarlyProxy;if(!o||!n.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__&&i){const e=i?new y(r,o):null;(n.__VUE_DEVTOOLS_PLUGINS__=n.__VUE_DEVTOOLS_PLUGINS__||[]).push({pluginDescriptor:r,setupFn:t,proxy:e}),e&&t(e.proxiedTarget)}else o.emit("devtools-plugin:setup",e,t)}var v="store";function b(e,t){Object.keys(e).forEach(function(r){return t(e[r],r)})}function m(e){return null!==e&&"object"==typeof e}function w(e,t,r){return t.indexOf(e)<0&&(r&&r.prepend?t.unshift(e):t.push(e)),function(){var r=t.indexOf(e);r>-1&&t.splice(r,1)}}function O(e,t){e._actions=Object.create(null),e._mutations=Object.create(null),e._wrappedGetters=Object.create(null),e._modulesNamespaceMap=Object.create(null);var r=e.state;E(e,r,[],e._modules.root,!0),_(e,r,t)}function _(e,t,r){var n=e._state,i=e._scope;e.getters={},e._makeLocalGettersCache=Object.create(null);var s=e._wrappedGetters,a={},u={},c=(0,o.effectScope)(!0);c.run(function(){b(s,function(t,r){a[r]=function(e,t){return function(){return e(t)}}(t,e),u[r]=(0,o.computed)(function(){return a[r]()}),Object.defineProperty(e.getters,r,{get:function(){return u[r].value},enumerable:!0})})}),e._state=(0,o.reactive)({data:t}),e._scope=c,e.strict&&function(e){(0,o.watch)(function(){return e._state.data},function(){0},{deep:!0,flush:"sync"})}(e),n&&r&&e._withCommit(function(){n.data=null}),i&&i.stop()}function E(e,t,r,n,o){var i=!r.length,s=e._modules.getNamespace(r);if(n.namespaced&&(e._modulesNamespaceMap[s],e._modulesNamespaceMap[s]=n),!i&&!o){var a=S(t,r.slice(0,-1)),u=r[r.length-1];e._withCommit(function(){a[u]=n.state})}var c=n.context=function(e,t,r){var n=""===t,o={dispatch:n?e.dispatch:function(r,n,o){var i=x(r,n,o),s=i.payload,a=i.options,u=i.type;return a&&a.root||(u=t+u),e.dispatch(u,s)},commit:n?e.commit:function(r,n,o){var i=x(r,n,o),s=i.payload,a=i.options,u=i.type;a&&a.root||(u=t+u),e.commit(u,s,a)}};return Object.defineProperties(o,{getters:{get:n?function(){return e.getters}:function(){return R(e,t)}},state:{get:function(){return S(e.state,r)}}}),o}(e,s,r);n.forEachMutation(function(t,r){!function(e,t,r,n){var o=e._mutations[t]||(e._mutations[t]=[]);o.push(function(t){r.call(Line truncated
|
||||||
Vendored
+18
@@ -0,0 +1,18 @@
|
|||||||
|
/*!
|
||||||
|
* The buffer module from node.js, for the browser.
|
||||||
|
*
|
||||||
|
* @author Feross Aboukhadijeh <http://feross.org>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* vuex v4.1.0
|
||||||
|
* (c) 2022 Evan You
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! Axios v1.18.1 Copyright (c) 2026 Matt Zabriskie and contributors */
|
||||||
|
|
||||||
|
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||||
|
|
||||||
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"/js/field.js": "/js/field.js?id=56e41090bedfddb3143c04e6a31b515a",
|
||||||
|
"/css/field.css": "/css/field.css?id=fa4c2caaf5807af420c6944bb9a2969c"
|
||||||
|
}
|
||||||
Generated
+11156
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "nova-row-actions",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"test": "node --test tests-js/*.test.mjs",
|
||||||
|
"dev": "npm run development",
|
||||||
|
"development": "mix",
|
||||||
|
"watch": "mix watch",
|
||||||
|
"watch-poll": "mix watch -- --watch-options-poll=1000",
|
||||||
|
"prod": "npm run production",
|
||||||
|
"production": "mix --production"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"laravel-nova-devtool": "file:vendor/laravel/nova-devtool",
|
||||||
|
"lodash": "^4.17.21"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
module.exports = {}
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
.nova-row-actions {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
direction: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button {
|
||||||
|
--row-action-color: rgb(107 114 128);
|
||||||
|
--row-action-soft: rgb(243 244 246);
|
||||||
|
position: relative;
|
||||||
|
display: inline-flex;
|
||||||
|
min-width: 2.25rem;
|
||||||
|
height: 2.25rem;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.35rem;
|
||||||
|
padding-inline: 0.5rem;
|
||||||
|
border: 1px solid rgb(209 213 219);
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--row-action-color);
|
||||||
|
line-height: 1;
|
||||||
|
transition: background-color 150ms, border-color 150ms, color 150ms,
|
||||||
|
transform 150ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--primary {
|
||||||
|
--row-action-color: rgb(14 165 233);
|
||||||
|
--row-action-soft: rgb(240 249 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--success {
|
||||||
|
--row-action-color: rgb(22 163 74);
|
||||||
|
--row-action-soft: rgb(240 253 244);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--danger {
|
||||||
|
--row-action-color: rgb(220 38 38);
|
||||||
|
--row-action-soft: rgb(254 242 242);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--warning {
|
||||||
|
--row-action-color: rgb(217 119 6);
|
||||||
|
--row-action-soft: rgb(255 251 235);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--info {
|
||||||
|
--row-action-color: rgb(8 145 178);
|
||||||
|
--row-action-soft: rgb(236 254 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--outline:not(:disabled):hover,
|
||||||
|
.nova-row-actions__button--outline.nova-row-actions__button--active {
|
||||||
|
border-color: var(--row-action-color);
|
||||||
|
background: var(--row-action-soft);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--solid {
|
||||||
|
border-color: var(--row-action-color);
|
||||||
|
background: var(--row-action-color);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--ghost {
|
||||||
|
border-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--ghost:not(:disabled):hover,
|
||||||
|
.nova-row-actions__button--ghost.nova-row-actions__button--active {
|
||||||
|
background: var(--row-action-soft);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button:not(:disabled):hover {
|
||||||
|
transform: scale(1.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button:focus-visible {
|
||||||
|
outline: 2px solid var(--row-action-color);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--working:disabled {
|
||||||
|
cursor: wait;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark .nova-row-actions__button {
|
||||||
|
--row-action-soft: rgb(55 65 81 / 0.55);
|
||||||
|
border-color: rgb(75 85 99);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark .nova-row-actions__button--solid {
|
||||||
|
border-color: var(--row-action-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__icon {
|
||||||
|
width: 1.2rem;
|
||||||
|
height: 1.2rem;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__label {
|
||||||
|
white-space: nowrap;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__button--working > :not(.nova-row-actions__spinner) {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__spinner {
|
||||||
|
position: absolute;
|
||||||
|
width: 1rem;
|
||||||
|
height: 1rem;
|
||||||
|
border: 2px solid currentColor;
|
||||||
|
border-inline-end-color: transparent;
|
||||||
|
border-radius: 9999px;
|
||||||
|
animation: nova-row-actions-spin 650ms linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__sr-only {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
padding: 0;
|
||||||
|
margin: -1px;
|
||||||
|
overflow: hidden;
|
||||||
|
clip: rect(0, 0, 0, 0);
|
||||||
|
white-space: nowrap;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.nova-row-actions__button {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nova-row-actions__spinner {
|
||||||
|
animation-duration: 1.5s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes nova-row-actions-spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export function resolveActionContext(props, search = '') {
|
||||||
|
const query = new URLSearchParams(search)
|
||||||
|
|
||||||
|
return {
|
||||||
|
viaResource:
|
||||||
|
props.viaResource || query.get('viaResource') || undefined,
|
||||||
|
viaResourceId:
|
||||||
|
props.viaResourceId ?? query.get('viaResourceId') ?? undefined,
|
||||||
|
viaRelationship: query.get('viaRelationship') || undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="nova-row-actions"
|
||||||
|
role="group"
|
||||||
|
:aria-label="field.name"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
v-for="button in buttons"
|
||||||
|
:key="button.key"
|
||||||
|
type="button"
|
||||||
|
class="nova-row-actions__button"
|
||||||
|
:class="buttonClasses(button)"
|
||||||
|
:disabled="working || button.disabled"
|
||||||
|
:aria-label="button.label"
|
||||||
|
:aria-pressed="button.active"
|
||||||
|
:aria-busy="isWorking(button)"
|
||||||
|
:title="button.tooltip"
|
||||||
|
v-tooltip="button.tooltip"
|
||||||
|
@click.stop="run(button)"
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
:name="button.icon"
|
||||||
|
class="nova-row-actions__icon"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span v-if="button.showLabel" class="nova-row-actions__label">
|
||||||
|
{{ button.label }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span v-else class="nova-row-actions__sr-only">
|
||||||
|
{{ button.label }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span
|
||||||
|
v-if="isWorking(button)"
|
||||||
|
class="nova-row-actions__spinner"
|
||||||
|
role="status"
|
||||||
|
:aria-label="__('Running Action')"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<component
|
||||||
|
v-if="actionModalVisible"
|
||||||
|
:is="selectedAction?.component"
|
||||||
|
class="text-left"
|
||||||
|
:show="actionModalVisible"
|
||||||
|
:working="working"
|
||||||
|
:selected-resources="selectedResources"
|
||||||
|
:resource-name="resourceName"
|
||||||
|
:action="selectedAction"
|
||||||
|
:errors="errors"
|
||||||
|
@confirm="executeAction"
|
||||||
|
@close="closeConfirmationModal"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<component
|
||||||
|
v-if="responseModalVisible"
|
||||||
|
:is="actionModalReponseData?.component"
|
||||||
|
:show="responseModalVisible"
|
||||||
|
:data="actionModalReponseData?.payload ?? {}"
|
||||||
|
@confirm="closeResponseModalAndRefresh"
|
||||||
|
@close="closeResponseModalAndRefresh"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, getCurrentInstance } from 'vue'
|
||||||
|
import { useActions } from '@/composables/useActions'
|
||||||
|
import { resolveActionContext } from '../actionContext.mjs'
|
||||||
|
|
||||||
|
const emit = defineEmits(['actionExecuted'])
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
resource: { type: Object, required: true },
|
||||||
|
resourceName: { type: String, required: true },
|
||||||
|
field: { type: Object, required: true },
|
||||||
|
viaResource: { type: String, default: null },
|
||||||
|
viaResourceId: { type: [String, Number], default: null },
|
||||||
|
})
|
||||||
|
|
||||||
|
const instance = getCurrentInstance()
|
||||||
|
const actionContext = resolveActionContext(props, window.location.search)
|
||||||
|
|
||||||
|
const buttons = computed(() => props.field.actions || [])
|
||||||
|
const actions = computed(() => buttons.value.map(button => button.action))
|
||||||
|
const selectedResources = computed(() => [props.resource.id.value])
|
||||||
|
|
||||||
|
const runnerProps = {
|
||||||
|
get actions() {
|
||||||
|
return actions.value
|
||||||
|
},
|
||||||
|
get selectedResources() {
|
||||||
|
return selectedResources.value
|
||||||
|
},
|
||||||
|
get resourceName() {
|
||||||
|
return props.resourceName
|
||||||
|
},
|
||||||
|
get viaResource() {
|
||||||
|
return actionContext.viaResource
|
||||||
|
},
|
||||||
|
get viaResourceId() {
|
||||||
|
return actionContext.viaResourceId
|
||||||
|
},
|
||||||
|
get viaRelationship() {
|
||||||
|
return actionContext.viaRelationship
|
||||||
|
},
|
||||||
|
pivotActions: { actions: [] },
|
||||||
|
endpoint: null,
|
||||||
|
}
|
||||||
|
|
||||||
|
const relayActionExecuted = event => {
|
||||||
|
emit(event)
|
||||||
|
|
||||||
|
// Nova does not forward custom field events from the field cell. Relay the
|
||||||
|
// native event through ResourceTableRow, whose listener refreshes the table.
|
||||||
|
if (event === 'actionExecuted') {
|
||||||
|
instance?.proxy?.$parent?.$emit('actionExecuted')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
errors,
|
||||||
|
working,
|
||||||
|
actionModalVisible,
|
||||||
|
responseModalVisible,
|
||||||
|
selectedActionKey,
|
||||||
|
selectedAction,
|
||||||
|
closeConfirmationModal,
|
||||||
|
closeResponseModal,
|
||||||
|
handleActionClick,
|
||||||
|
executeAction,
|
||||||
|
actionModalReponseData,
|
||||||
|
} = useActions(runnerProps, relayActionExecuted, instance.proxy.$store)
|
||||||
|
|
||||||
|
const run = button => {
|
||||||
|
if (!working.value && !button.disabled) {
|
||||||
|
handleActionClick(button.action.uriKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isWorking = button =>
|
||||||
|
working.value && selectedActionKey.value === button.action.uriKey
|
||||||
|
|
||||||
|
const buttonClasses = button => [
|
||||||
|
`nova-row-actions__button--${button.color}`,
|
||||||
|
`nova-row-actions__button--${button.variant}`,
|
||||||
|
{
|
||||||
|
'nova-row-actions__button--active': button.active,
|
||||||
|
'nova-row-actions__button--working': isWorking(button),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const closeResponseModalAndRefresh = () => {
|
||||||
|
closeResponseModal()
|
||||||
|
relayActionExecuted('actionExecuted')
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import IndexField from './components/IndexField'
|
||||||
|
|
||||||
|
Nova.booting((app, store) => {
|
||||||
|
app.component('index-row-actions', IndexField)
|
||||||
|
})
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MeghdadFadaee\NovaRowActions;
|
||||||
|
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Laravel\Nova\Events\ServingNova;
|
||||||
|
use Laravel\Nova\Nova;
|
||||||
|
|
||||||
|
class FieldServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap any application services.
|
||||||
|
*/
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
Nova::serving(function (ServingNova $event) {
|
||||||
|
Nova::mix('nova-row-actions', __DIR__.'/../dist/mix-manifest.json');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register any application services.
|
||||||
|
*/
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MeghdadFadaee\NovaRowActions;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Laravel\Nova\Actions\Action;
|
||||||
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||||
|
use Stringable;
|
||||||
|
|
||||||
|
final class RowAction
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Closure(Model, NovaRequest, Action): bool|bool $activeWhen
|
||||||
|
* @param Closure(Model, NovaRequest, Action): bool|bool $disabledWhen
|
||||||
|
* @param Closure(Model, NovaRequest, Action): bool|bool $visibleWhen
|
||||||
|
* @param Closure(Model, NovaRequest, Action): (Stringable|string|null)|Stringable|string|null $label
|
||||||
|
* @param Closure(Model, NovaRequest, Action): (Stringable|string|null)|Stringable|string|null $tooltip
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public readonly Action $action,
|
||||||
|
public readonly string $icon,
|
||||||
|
public readonly string $color,
|
||||||
|
public readonly string $variant,
|
||||||
|
public readonly Closure|Stringable|string|null $label,
|
||||||
|
public readonly Closure|Stringable|string|null $tooltip,
|
||||||
|
public readonly Closure|bool $activeWhen,
|
||||||
|
public readonly Closure|bool $disabledWhen,
|
||||||
|
public readonly Closure|bool $visibleWhen,
|
||||||
|
public readonly int $order,
|
||||||
|
public readonly ?bool $confirm,
|
||||||
|
public readonly bool $showLabel,
|
||||||
|
public readonly int $sequence,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MeghdadFadaee\NovaRowActions;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Laravel\Nova\Actions\Action;
|
||||||
|
use Laravel\Nova\Fields\Field;
|
||||||
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||||
|
use Stringable;
|
||||||
|
|
||||||
|
class RowActions extends Field
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The field's Vue component.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $component = 'row-actions';
|
||||||
|
|
||||||
|
/** @var array<int, RowAction> */
|
||||||
|
private array $rowActions = [];
|
||||||
|
|
||||||
|
public function __construct($name = null, $attribute = null, ?callable $resolveCallback = null)
|
||||||
|
{
|
||||||
|
parent::__construct($name ?? trans('Actions'), $attribute ?? 'row_actions', $resolveCallback);
|
||||||
|
|
||||||
|
$this->onlyOnIndex()->textAlign('center');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Nova action as a visible index-row button.
|
||||||
|
*
|
||||||
|
* Callbacks receive the row model, current Nova request, and action instance.
|
||||||
|
* A null confirmation value preserves the action's native confirmation setting.
|
||||||
|
*
|
||||||
|
* @param Closure(Model, NovaRequest, Action): (Stringable|string|null)|Stringable|string|null $label
|
||||||
|
* @param Closure(Model, NovaRequest, Action): (Stringable|string|null)|Stringable|string|null $tooltip
|
||||||
|
* @param Closure(Model, NovaRequest, Action): bool|bool $activeWhen
|
||||||
|
* @param Closure(Model, NovaRequest, Action): bool|bool $disabledWhen
|
||||||
|
* @param Closure(Model, NovaRequest, Action): bool|bool $visibleWhen
|
||||||
|
*/
|
||||||
|
public function add(
|
||||||
|
Action $action,
|
||||||
|
string $icon = 'play',
|
||||||
|
string $color = 'default',
|
||||||
|
string $variant = 'outline',
|
||||||
|
Closure|Stringable|string|null $label = null,
|
||||||
|
Closure|Stringable|string|null $tooltip = null,
|
||||||
|
Closure|bool $activeWhen = false,
|
||||||
|
Closure|bool $disabledWhen = false,
|
||||||
|
Closure|bool $visibleWhen = true,
|
||||||
|
?int $order = null,
|
||||||
|
?bool $confirm = null,
|
||||||
|
bool $showLabel = false,
|
||||||
|
): static {
|
||||||
|
$sequence = count($this->rowActions);
|
||||||
|
|
||||||
|
$this->rowActions[] = new RowAction(
|
||||||
|
action: $action,
|
||||||
|
icon: $icon,
|
||||||
|
color: $color,
|
||||||
|
variant: $variant,
|
||||||
|
label: $label,
|
||||||
|
tooltip: $tooltip,
|
||||||
|
activeWhen: $activeWhen,
|
||||||
|
disabledWhen: $disabledWhen,
|
||||||
|
visibleWhen: $visibleWhen,
|
||||||
|
order: $order ?? $sequence,
|
||||||
|
confirm: $confirm,
|
||||||
|
showLabel: $showLabel,
|
||||||
|
sequence: $sequence,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the row-specific state and the native Nova action payload.
|
||||||
|
*/
|
||||||
|
#[\Override]
|
||||||
|
public function resolveForDisplay($resource, ?string $attribute = null): void
|
||||||
|
{
|
||||||
|
parent::resolveForDisplay($resource, $attribute);
|
||||||
|
|
||||||
|
if (! $resource instanceof Model) {
|
||||||
|
$this->withMeta(['actions' => []]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var NovaRequest $request */
|
||||||
|
$request = app(NovaRequest::class);
|
||||||
|
|
||||||
|
$this->withMeta([
|
||||||
|
'actions' => $this->serializedActions($request, $resource),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, array<string, mixed>>
|
||||||
|
*/
|
||||||
|
private function serializedActions(NovaRequest $request, Model $model): array
|
||||||
|
{
|
||||||
|
return Collection::make($this->rowActions)
|
||||||
|
->sortBy([
|
||||||
|
['order', 'asc'],
|
||||||
|
['sequence', 'asc'],
|
||||||
|
])
|
||||||
|
->filter(fn (RowAction $button) => $this->evaluate($button->visibleWhen, $model, $request, $button->action))
|
||||||
|
->filter(fn (RowAction $button) => $this->authorized($button->action, $request, $model))
|
||||||
|
->values()
|
||||||
|
->map(function (RowAction $button, int $index) use ($request, $model): array {
|
||||||
|
$action = $button->action;
|
||||||
|
$action->resource = $model;
|
||||||
|
$nativeAction = $action->jsonSerialize();
|
||||||
|
|
||||||
|
if ($button->confirm !== null) {
|
||||||
|
$nativeAction['withoutConfirmation'] = ! $button->confirm;
|
||||||
|
}
|
||||||
|
|
||||||
|
$label = $this->text($button->label, $model, $request, $action) ?? (string) $action->name();
|
||||||
|
$tooltip = $this->text($button->tooltip, $model, $request, $action) ?? $label;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'key' => $action->uriKey().'-'.$button->sequence.'-'.$index,
|
||||||
|
'action' => $nativeAction,
|
||||||
|
'icon' => $button->icon,
|
||||||
|
'color' => $button->color,
|
||||||
|
'variant' => $button->variant,
|
||||||
|
'label' => $label,
|
||||||
|
'tooltip' => $tooltip,
|
||||||
|
'active' => $this->evaluate($button->activeWhen, $model, $request, $action),
|
||||||
|
'disabled' => $this->evaluate($button->disabledWhen, $model, $request, $action),
|
||||||
|
'showLabel' => $button->showLabel,
|
||||||
|
'order' => $button->order,
|
||||||
|
];
|
||||||
|
})
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function authorized(Action $action, NovaRequest $request, Model $model): bool
|
||||||
|
{
|
||||||
|
if (! $action->authorizedToSee($request) || ! $action->authorizedToRun($request, $model)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nova treats an explicit canRun callback as the complete execution policy.
|
||||||
|
if ($action->runCallback !== null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $request->newResourceWith($model)->authorizedToRunAction($request, $action);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function evaluate(Closure|bool $value, Model $model, NovaRequest $request, Action $action): bool
|
||||||
|
{
|
||||||
|
return (bool) ($value instanceof Closure ? $value($model, $request, $action) : $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function text(
|
||||||
|
Closure|Stringable|string|null $value,
|
||||||
|
Model $model,
|
||||||
|
NovaRequest $request,
|
||||||
|
Action $action,
|
||||||
|
): ?string {
|
||||||
|
$resolved = $value instanceof Closure ? $value($model, $request, $action) : $value;
|
||||||
|
|
||||||
|
return $resolved === null ? null : (string) $resolved;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import test from 'node:test'
|
||||||
|
|
||||||
|
import { resolveActionContext } from '../resources/js/actionContext.mjs'
|
||||||
|
|
||||||
|
test('uses explicit relationship parent props and the URL relationship name', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
resolveActionContext(
|
||||||
|
{ viaResource: 'courses', viaResourceId: 42 },
|
||||||
|
'?viaResource=ignored&viaResourceId=99&viaRelationship=answers'
|
||||||
|
),
|
||||||
|
{
|
||||||
|
viaResource: 'courses',
|
||||||
|
viaResourceId: 42,
|
||||||
|
viaRelationship: 'answers',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('falls back to URL context and leaves normal indexes undefined', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
resolveActionContext({}, '?viaResource=users&viaResourceId=7'),
|
||||||
|
{
|
||||||
|
viaResource: 'users',
|
||||||
|
viaResourceId: '7',
|
||||||
|
viaRelationship: undefined,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert.deepEqual(resolveActionContext({}, ''), {
|
||||||
|
viaResource: undefined,
|
||||||
|
viaResourceId: undefined,
|
||||||
|
viaRelationship: undefined,
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MeghdadFadaee\NovaRowActions\Tests;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Laravel\Nova\Actions\Action;
|
||||||
|
use Laravel\Nova\Fields\ActionFields;
|
||||||
|
use Laravel\Nova\Fields\Text;
|
||||||
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||||
|
use Laravel\Nova\Nova;
|
||||||
|
use Laravel\Nova\Resource;
|
||||||
|
use MeghdadFadaee\NovaRowActions\FieldServiceProvider;
|
||||||
|
use MeghdadFadaee\NovaRowActions\RowActions;
|
||||||
|
use Orchestra\Testbench\TestCase;
|
||||||
|
|
||||||
|
class RowActionsTest extends TestCase
|
||||||
|
{
|
||||||
|
protected function getPackageProviders($app): array
|
||||||
|
{
|
||||||
|
return [FieldServiceProvider::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Nova::resources([RowActionResource::class]);
|
||||||
|
RowActionResource::$allowsActions = true;
|
||||||
|
$this->app->instance(NovaRequest::class, $this->novaRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_serializes_native_action_metadata_and_arbitrary_configuration(): void
|
||||||
|
{
|
||||||
|
$field = RowActions::make('Operations')
|
||||||
|
->add(
|
||||||
|
ConfigurableAction::make()->withoutConfirmation(),
|
||||||
|
icon: 'bolt',
|
||||||
|
color: 'warning',
|
||||||
|
variant: 'solid',
|
||||||
|
label: fn (Model $model) => 'Run '.$model->getKey(),
|
||||||
|
tooltip: 'Custom tooltip',
|
||||||
|
order: 42,
|
||||||
|
confirm: true,
|
||||||
|
showLabel: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
$action = $this->serialize($field, $this->model(id: 17))['actions'][0];
|
||||||
|
|
||||||
|
$this->assertSame('configurable-action', $action['action']['uriKey']);
|
||||||
|
$this->assertSame('Configurable Action', $action['action']['name']);
|
||||||
|
$this->assertSame('confirm-action-modal', $action['action']['component']);
|
||||||
|
$this->assertSame('reason', $action['action']['fields'][0]['attribute']);
|
||||||
|
$this->assertFalse($action['action']['withoutConfirmation']);
|
||||||
|
$this->assertSame('bolt', $action['icon']);
|
||||||
|
$this->assertSame('warning', $action['color']);
|
||||||
|
$this->assertSame('solid', $action['variant']);
|
||||||
|
$this->assertSame('Run 17', $action['label']);
|
||||||
|
$this->assertSame('Custom tooltip', $action['tooltip']);
|
||||||
|
$this->assertSame(42, $action['order']);
|
||||||
|
$this->assertTrue($action['showLabel']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_hides_actions_that_fail_nova_authorization(): void
|
||||||
|
{
|
||||||
|
$field = RowActions::make()
|
||||||
|
->add(ConfigurableAction::make()->canSee(fn () => false))
|
||||||
|
->add(ConfigurableAction::make()->canRun(fn () => false));
|
||||||
|
|
||||||
|
$this->assertSame([], $this->serialize($field, $this->model())['actions']);
|
||||||
|
|
||||||
|
RowActionResource::$allowsActions = false;
|
||||||
|
|
||||||
|
$policyField = RowActions::make()->add(ConfigurableAction::make());
|
||||||
|
|
||||||
|
$this->assertSame([], $this->serialize($policyField, $this->model())['actions']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_explicit_can_run_authorization_matches_novas_policy_precedence(): void
|
||||||
|
{
|
||||||
|
RowActionResource::$allowsActions = false;
|
||||||
|
|
||||||
|
$field = RowActions::make()->add(
|
||||||
|
ConfigurableAction::make()->canRun(fn () => true)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertCount(1, $this->serialize($field, $this->model())['actions']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_applies_visibility_active_and_disabled_callbacks_per_model(): void
|
||||||
|
{
|
||||||
|
$field = RowActions::make()
|
||||||
|
->add(
|
||||||
|
ConfigurableAction::make(),
|
||||||
|
activeWhen: fn (Model $model) => $model->state === 'active',
|
||||||
|
disabledWhen: fn (Model $model) => $model->locked,
|
||||||
|
visibleWhen: fn (Model $model) => $model->visible,
|
||||||
|
);
|
||||||
|
|
||||||
|
$visible = $this->serialize($field, $this->model(
|
||||||
|
state: 'active',
|
||||||
|
locked: true,
|
||||||
|
visible: true,
|
||||||
|
))['actions'][0];
|
||||||
|
|
||||||
|
$this->assertTrue($visible['active']);
|
||||||
|
$this->assertTrue($visible['disabled']);
|
||||||
|
|
||||||
|
$hidden = $this->serialize($field, $this->model(visible: false));
|
||||||
|
|
||||||
|
$this->assertSame([], $hidden['actions']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_orders_buttons_stably_and_preserves_action_confirmation_by_default(): void
|
||||||
|
{
|
||||||
|
$field = RowActions::make()
|
||||||
|
->add(ConfigurableAction::make()->withName('Last'), order: 20)
|
||||||
|
->add(ConfigurableAction::make()->withName('First A'), order: 10)
|
||||||
|
->add(ConfigurableAction::make()->withName('First B'), order: 10);
|
||||||
|
|
||||||
|
$actions = $this->serialize($field, $this->model())['actions'];
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
['First A', 'First B', 'Last'],
|
||||||
|
array_column(array_column($actions, 'action'), 'name'),
|
||||||
|
);
|
||||||
|
$this->assertFalse($actions[0]['action']['withoutConfirmation']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
private function serialize(RowActions $field, RowActionModel $model): array
|
||||||
|
{
|
||||||
|
$field->resolveForDisplay($model);
|
||||||
|
|
||||||
|
return json_decode(json_encode($field, JSON_THROW_ON_ERROR), true, flags: JSON_THROW_ON_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function model(
|
||||||
|
int $id = 1,
|
||||||
|
string $state = 'idle',
|
||||||
|
bool $locked = false,
|
||||||
|
bool $visible = true,
|
||||||
|
): RowActionModel {
|
||||||
|
return (new RowActionModel)->forceFill(compact('id', 'state', 'locked', 'visible'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function novaRequest(): NovaRequest
|
||||||
|
{
|
||||||
|
$baseRequest = Request::create('/nova-api/row-action-models', 'GET');
|
||||||
|
$route = new Route('GET', '/nova-api/{resource}', fn () => null);
|
||||||
|
$route->bind($baseRequest);
|
||||||
|
|
||||||
|
return tap(NovaRequest::createFrom($baseRequest), function (NovaRequest $request) use ($route): void {
|
||||||
|
$request->setRouteResolver(fn () => $route);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RowActionModel extends Model
|
||||||
|
{
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class RowActionResource extends Resource
|
||||||
|
{
|
||||||
|
public static $model = RowActionModel::class;
|
||||||
|
|
||||||
|
public static bool $allowsActions = true;
|
||||||
|
|
||||||
|
public static function uriKey(): string
|
||||||
|
{
|
||||||
|
return 'row-action-models';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fields(NovaRequest $request): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function authorizedToRunAction(NovaRequest $request, Action $action): bool
|
||||||
|
{
|
||||||
|
return static::$allowsActions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConfigurableAction extends Action
|
||||||
|
{
|
||||||
|
public function name(): string
|
||||||
|
{
|
||||||
|
return $this->name ?? 'Configurable Action';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function uriKey(): string
|
||||||
|
{
|
||||||
|
return 'configurable-action';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fields(NovaRequest $request): array
|
||||||
|
{
|
||||||
|
return [Text::make('Reason', 'reason')];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(ActionFields $fields, Collection $models): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
let mix = require('laravel-mix')
|
||||||
|
let NovaExtension = require('laravel-nova-devtool')
|
||||||
|
let path = require('path')
|
||||||
|
|
||||||
|
mix.extend('nova', new NovaExtension())
|
||||||
|
|
||||||
|
mix
|
||||||
|
.setPublicPath('dist')
|
||||||
|
.js('resources/js/field.js', 'js')
|
||||||
|
.vue({ version: 3 })
|
||||||
|
.css('resources/css/field.css', 'css')
|
||||||
|
.alias({
|
||||||
|
'@': path.resolve(__dirname, 'vendor/laravel/nova/resources/js'),
|
||||||
|
'@/mixins$': path.resolve(
|
||||||
|
__dirname,
|
||||||
|
'vendor/laravel/nova/resources/js/util/FormValidation.js'
|
||||||
|
),
|
||||||
|
})
|
||||||
|
.webpackConfig({
|
||||||
|
resolve: {
|
||||||
|
modules: [path.resolve(__dirname, 'node_modules'), 'node_modules'],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.nova('meghdadfadaee/nova-row-actions')
|
||||||
|
.version()
|
||||||
Reference in new issue
Block a user