Skip to content

Commit 4369994

Browse files
authored
Merge pull request #318 from devforth/AdminForth/770
feat: add possibility to add bulk actions to the three dots dropdown
2 parents 6586d43 + 59eccdd commit 4369994

File tree

3 files changed

+67
-35
lines changed

3 files changed

+67
-35
lines changed

adminforth/spa/src/components/ThreeDotsMenu.vue

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
</div>
3636
</a>
3737
</li>
38+
<li v-if="checkboxes.length" v-for="action in bulkActions.filter(a => a.showInThreeDotsDropdown)" :key="action.id">
39+
<a href="#" @click.prevent="startBulkAction(action.id)" class="block px-4 py-2 hover:text-lightThreeDotsMenuBodyTextHover hover:bg-lightThreeDotsMenuBodyBackgroundHover dark:hover:bg-darkThreeDotsMenuBodyBackgroundHover dark:hover:text-darkThreeDotsMenuBodyTextHover">
40+
<div class="flex items-center gap-2">
41+
<component
42+
v-if="action.icon"
43+
:is="getIcon(action.icon)"
44+
class="w-4 h-4 text-lightPrimary dark:text-darkPrimary"
45+
/>
46+
{{ action.label }}
47+
</div>
48+
</a>
49+
</li>
3850
</ul>
3951
</div>
4052
</template>
@@ -54,9 +66,13 @@ const router = useRouter();
5466
5567
const props = defineProps({
5668
threeDotsDropdownItems: Array,
57-
customActions: Array
69+
customActions: Array,
70+
bulkActions: Array,
71+
checkboxes: Array
5872
});
5973
74+
const emit = defineEmits(['startBulkAction']);
75+
6076
async function handleActionClick(action) {
6177
adminforth.list.closeThreeDotsDropdown();
6278
@@ -108,4 +124,9 @@ async function handleActionClick(action) {
108124
});
109125
}
110126
}
127+
128+
function startBulkAction(actionId) {
129+
adminforth.list.closeThreeDotsDropdown();
130+
emit('startBulkAction', actionId);
131+
}
111132
</script>

adminforth/spa/src/views/ListView.vue

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,45 @@
3131
</Tooltip>
3232
</button>
3333

34-
<button
35-
v-if="checkboxes.length"
34+
<div
35+
v-if="checkboxes.length"
3636
v-for="(action,i) in coreStore.resource?.options?.bulkActions"
37-
:key="action.id"
38-
@click="startBulkAction(action.id)"
39-
class="flex gap-1 items-center py-1 px-3 text-sm font-medium text-lightListViewButtonText focus:outline-none bg-lightListViewButtonBackground rounded-default border border-lightListViewButtonBorder hover:bg-lightListViewButtonBackgroundHover hover:text-lightListViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightListViewButtonFocusRing dark:focus:ring-darkListViewButtonFocusRing dark:bg-darkListViewButtonBackground dark:text-darkListViewButtonText dark:border-darkListViewButtonBorder dark:hover:text-darkListViewButtonTextHover dark:hover:bg-darkListViewButtonBackgroundHover"
40-
:class="action.buttonCustomCssClass || ''"
4137
>
42-
<component
43-
v-if="action.icon && !bulkActionLoadingStates[action.id]"
44-
:is="getIcon(action.icon)"
45-
class="w-5 h-5 transition duration-75 group-hover:text-gray-900 dark:group-hover:text-white"></component>
46-
<div v-if="bulkActionLoadingStates[action.id]">
47-
<svg
48-
aria-hidden="true"
49-
class="w-5 h-5 animate-spin"
50-
:class="{
51-
'text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300': action.state !== 'danger',
52-
'text-red-200 dark:text-red-800 fill-red-600 dark:fill-red-500': action.state === 'danger'
53-
}"
54-
viewBox="0 0 100 101"
55-
fill="none"
56-
xmlns="http://www.w3.org/2000/svg"
57-
>
58-
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
59-
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
60-
</svg>
61-
<span class="sr-only">Loading...</span>
62-
</div>
63-
{{ `${action.label} (${checkboxes.length})` }}
64-
<div v-if="action.badge" class="text-white bg-gradient-to-r from-purple-500 via-purple-600 to-purple-700 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-purple-300 dark:focus:ring-purple-800
65-
font-medium rounded-sm text-xs px-1 ml-1 text-center ">
66-
{{ action.badge }}
67-
</div>
68-
</button>
69-
38+
<button
39+
v-if="!action.showInThreeDotsDropdown || action.showInThreeDotsDropdown===false"
40+
:key="action.id"
41+
@click="startBulkAction(action.id)"
42+
class="flex gap-1 items-center py-1 px-3 text-sm font-medium text-lightListViewButtonText focus:outline-none bg-lightListViewButtonBackground rounded-default border border-lightListViewButtonBorder hover:bg-lightListViewButtonBackgroundHover hover:text-lightListViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightListViewButtonFocusRing dark:focus:ring-darkListViewButtonFocusRing dark:bg-darkListViewButtonBackground dark:text-darkListViewButtonText dark:border-darkListViewButtonBorder dark:hover:text-darkListViewButtonTextHover dark:hover:bg-darkListViewButtonBackgroundHover"
43+
:class="action.buttonCustomCssClass || ''"
44+
>
45+
<component
46+
v-if="action.icon && !bulkActionLoadingStates[action.id]"
47+
:is="getIcon(action.icon)"
48+
class="w-5 h-5 transition duration-75 group-hover:text-gray-900 dark:group-hover:text-white"></component>
49+
<div v-if="bulkActionLoadingStates[action.id]">
50+
<svg
51+
aria-hidden="true"
52+
class="w-5 h-5 animate-spin"
53+
:class="{
54+
'text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300': action.state !== 'danger',
55+
'text-red-200 dark:text-red-800 fill-red-600 dark:fill-red-500': action.state === 'danger'
56+
}"
57+
viewBox="0 0 100 101"
58+
fill="none"
59+
xmlns="http://www.w3.org/2000/svg"
60+
>
61+
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
62+
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
63+
</svg>
64+
<span class="sr-only">Loading...</span>
65+
</div>
66+
{{ `${action.label} (${checkboxes.length})` }}
67+
<div v-if="action.badge" class="text-white bg-gradient-to-r from-purple-500 via-purple-600 to-purple-700 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-purple-300 dark:focus:ring-purple-800
68+
font-medium rounded-sm text-xs px-1 ml-1 text-center ">
69+
{{ action.badge }}
70+
</div>
71+
</button>
72+
</div>
7073
<RouterLink v-if="coreStore.resource?.options?.allowedActions?.create"
7174
:to="{ name: 'resource-create', params: { resourceId: $route.params.resourceId } }"
7275
class="af-create-button flex items-center py-1 px-3 text-sm font-medium text-lightListViewButtonText focus:outline-none bg-lightListViewButtonBackground rounded border border-lightListViewButtonBorder hover:bg-lightListViewButtonBackgroundHover hover:text-lightListViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightListViewButtonFocusRing dark:focus:ring-darkListViewButtonFocusRing dark:bg-darkListViewButtonBackground dark:text-darkListViewButtonText dark:border-darkListViewButtonBorder dark:hover:text-darkListViewButtonTextHover dark:hover:bg-darkListViewButtonBackgroundHover rounded-default"
@@ -91,6 +94,9 @@
9194

9295
<ThreeDotsMenu
9396
:threeDotsDropdownItems="coreStore.resourceOptions?.pageInjections?.list?.threeDotsDropdownItems"
97+
:bulkActions="coreStore.resource?.options?.bulkActions"
98+
:checkboxes="checkboxes"
99+
@startBulkAction="startBulkAction"
94100
></ThreeDotsMenu>
95101
</BreadcrumbsWithButtons>
96102

@@ -120,6 +126,7 @@
120126
:item-height="52.5"
121127
:buffer-size="listBufferSize"
122128
/>
129+
123130
<ResourceListTable
124131
v-else
125132
:resource="coreStore.resource"

adminforth/types/Common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ export interface AdminForthBulkActionCommon {
119119
*/
120120
successMessage?: string,
121121

122+
/**
123+
* Show in three dots dropdown menu in list view.
124+
*/
125+
showInThreeDotsDropdown?: boolean,
122126
}
123127

124128
export interface AdminForthFieldComponents {

0 commit comments

Comments
 (0)