init
This commit is contained in:
21 files changed
+12224
No files matched your search
@@ -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)
|
||||
})
|
||||
Reference in new issue
Block a user