Skip to content

Commit e850dee

Browse files
committed
chore: bulk action component progress
1 parent 55429f2 commit e850dee

File tree

5 files changed

+69
-30
lines changed

5 files changed

+69
-30
lines changed

adminforth/spa/src/components/ThreeDotsMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</div>
3636
</a>
3737
</li>
38-
<li v-for="action in bulkActions.filter(a => a.showInThreeDotsDropdown)" :key="action.id">
38+
<li v-for="action in bulkActions?.filter(a => a.showInThreeDotsDropdown)" :key="action.id">
3939
<a href="#" @click.prevent="startBulkAction(action.id)"
4040
class="block px-4 py-2 hover:text-lightThreeDotsMenuBodyTextHover hover:bg-lightThreeDotsMenuBodyBackgroundHover dark:hover:bg-darkThreeDotsMenuBodyBackgroundHover dark:hover:text-darkThreeDotsMenuBodyTextHover"
4141
:class="{

adminforth/spa/src/views/ShowView.vue

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,44 @@
1010
:adminUser="coreStore.adminUser"
1111
/>
1212
<BreadcrumbsWithButtons>
13-
<template v-if="coreStore.resource?.options?.bulkActions">
14-
<button
15-
v-for="action in coreStore.resource.options.bulkActions.filter(a => a.showIn?.showButton)"
16-
:key="action.id"
17-
@click="startCustomAction(action.id)"
18-
:disabled="actionLoadingStates[action.id]"
19-
class="flex items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-default border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700"
20-
>
21-
<component
22-
v-if="action.icon"
23-
:is="getIcon(action.icon)"
24-
class="w-4 h-4 me-2 text-lightPrimary dark:text-darkPrimary"
25-
/>
26-
{{ action.name }}
27-
</button>
13+
<template v-if="coreStore.resource?.options?.actions">
14+
15+
<template v-for="action in coreStore.resource.options.actions.filter(a => a.showIn?.showButton)" >
16+
<component
17+
v-if="action.customComponent"
18+
:is="getCustomComponent(action.customComponent)"
19+
:meta="action.customComponent.meta"
20+
@callAction="startCustomAction(action.id)"
21+
:disabled="actionLoadingStates[action.id]"
22+
>
23+
<button
24+
:key="action.id"
25+
class="flex items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-default border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700"
26+
>
27+
<component
28+
v-if="action.icon"
29+
:is="getIcon(action.icon)"
30+
class="w-4 h-4 me-2 text-lightPrimary dark:text-darkPrimary"
31+
/>
32+
{{ action.name }}
33+
</button>
34+
</component>
35+
36+
<button
37+
v-else
38+
:key="action.id"
39+
@click="startCustomAction(action.id)"
40+
:disabled="actionLoadingStates[action.id]"
41+
class="flex items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-default border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700"
42+
>
43+
<component
44+
v-if="action.icon"
45+
:is="getIcon(action.icon)"
46+
class="w-4 h-4 me-2 text-lightPrimary dark:text-darkPrimary"
47+
/>
48+
{{ action.name }}
49+
</button>
50+
</template>
2851
</template>
2952
<RouterLink v-if="coreStore.resource?.options?.allowedActions?.create"
3053
:to="{ name: 'resource-create', params: { resourceId: $route.params.resourceId } }"

adminforth/types/Back.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ export interface AdminForthActionInput {
819819
}>;
820820
icon?: string;
821821
id?: string;
822+
customComponent?: AdminForthComponentDeclaration;
822823
}
823824

824825
export interface AdminForthResourceInput extends Omit<NonNullable<AdminForthResourceInputCommon>, 'columns' | 'hooks' | 'options'> {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<span> TEST CUSTOM COMPONENT </span>

dev-demo/resources/users.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default {
5050
dataSource: "maindb",
5151
table: "users",
5252
resourceId: "users",
53-
label: "Users",
53+
label: "Users1",
5454

5555
recordLabel: (r: any) => `👤 ${r.email}`,
5656
plugins: [
@@ -153,19 +153,33 @@ export default {
153153
}),
154154
],
155155
options: {
156-
allowedActions: {
157-
create: async ({
158-
adminUser,
159-
meta,
160-
}: {
161-
adminUser: AdminUser;
162-
meta: any;
163-
}) => {
164-
// console.log('create', adminUser, meta);
165-
return true;
166-
},
167-
delete: true,
168-
},
156+
actions: [
157+
{
158+
name: 'Auto submit', // Display name of the action
159+
icon: 'flowbite:play-solid', // Icon to display (using Flowbite icons)
160+
161+
// Control who can see/use this action
162+
allowed: ({ adminUser, standardAllowedActions }) => {
163+
return true; // Allow everyone
164+
},
165+
166+
// Handler function when action is triggered
167+
action: async ({ recordId, adminUser }) => {
168+
console.log("auto submit", recordId, adminUser);
169+
return {
170+
ok: true,
171+
successMessage: "Auto submitted"
172+
};
173+
},
174+
175+
// Configure where the action appears
176+
showIn: {
177+
showButton: true, // Show as a button
178+
// showThreeDotsMenu: true, // Show in the three dots menu
179+
list: true, // Show in the list view
180+
}
181+
}
182+
],
169183
},
170184
columns: [
171185
{

0 commit comments

Comments
 (0)