Skip to content

Commit 6f0c30e

Browse files
committed
feat: enhance tableRowReplaceInjection type and simplify its usage in ResourceListTable components
1 parent f02359e commit 6f0c30e

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

adminforth/spa/src/components/ResourceListTable.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ import {
335335
} from '@iconify-prerendered/vue-flowbite';
336336
import router from '@/router';
337337
import { Tooltip } from '@/afcl';
338-
import type { AdminForthResourceCommon, AdminForthResourceColumnInputCommon, AdminForthResourceColumnCommon } from '@/types/Common';
338+
import type { AdminForthResourceCommon, AdminForthResourceColumnInputCommon, AdminForthResourceColumnCommon, AdminForthComponentDeclaration } from '@/types/Common';
339339
import adminforth from '@/adminforth';
340340
import Checkbox from '@/afcl/Checkbox.vue';
341341
@@ -352,7 +352,7 @@ const props = defineProps<{
352352
noRoundings?: boolean,
353353
customActionsInjection?: any[],
354354
tableBodyStartInjection?: any[],
355-
tableRowReplaceInjection?: any,
355+
tableRowReplaceInjection?: AdminForthComponentDeclaration,
356356
}>();
357357
358358
// emits, update page

adminforth/spa/src/components/ResourceListTableVirtual.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ import {
357357
} from '@iconify-prerendered/vue-flowbite';
358358
import router from '@/router';
359359
import { Tooltip } from '@/afcl';
360-
import type { AdminForthResourceCommon, AdminForthResourceColumnCommon } from '@/types/Common';
360+
import type { AdminForthResourceCommon, AdminForthResourceColumnCommon, AdminForthComponentDeclaration } from '@/types/Common';
361361
import adminforth from '@/adminforth';
362362
import Checkbox from '@/afcl/Checkbox.vue';
363363
@@ -377,7 +377,7 @@ const props = defineProps<{
377377
containerHeight?: number,
378378
itemHeight?: number,
379379
bufferSize?: number,
380-
tableRowReplaceInjection?: any
380+
tableRowReplaceInjection?: AdminForthComponentDeclaration
381381
}>();
382382
383383
// emits, update page

adminforth/spa/src/utils.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,22 @@ export async function callAdminForthApi({ path, method, body=undefined, headers=
6767
}
6868
}
6969

70-
export function getCustomComponent({ file, meta }: { file: string, meta?: any }) {
70+
export function getCustomComponent(input: any) {
71+
let file: string | undefined;
72+
if (Array.isArray(input)) {
73+
input = input?.[0];
74+
}
75+
if (typeof input === 'string') {
76+
file = input;
77+
} else if (input && typeof input === 'object') {
78+
file = (input as { file?: string }).file;
79+
}
80+
81+
if (!file || typeof file !== 'string') {
82+
// Fallback to a neutral element to avoid runtime errors
83+
return 'div';
84+
}
85+
7186
const name = file.replace(/@/g, '').replace(/\./g, '').replace(/\//g, '');
7287
return resolveComponent(name);
7388
}

adminforth/spa/src/views/ListView.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@
143143
? [coreStore.resourceOptions.pageInjections.list.tableBodyStart]
144144
: []
145145
"
146-
:tableRowReplaceInjection="Array.isArray(coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace)
147-
? coreStore.resourceOptions.pageInjections.list.tableRowReplace[0]
148-
: coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace || null"
146+
:tableRowReplaceInjection="coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace || undefined"
149147
:container-height="1100"
150148
:item-height="52.5"
151149
:buffer-size="listBufferSize"
@@ -176,9 +174,7 @@
176174
? [coreStore.resourceOptions.pageInjections.list.tableBodyStart]
177175
: []
178176
"
179-
:tableRowReplaceInjection="Array.isArray(coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace)
180-
? coreStore.resourceOptions.pageInjections.list.tableRowReplace[0]
181-
: coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace || null"
177+
:tableRowReplaceInjection="coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace || null"
182178
/>
183179

184180
<component

adminforth/types/Common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ export interface AdminForthResourceInputCommon {
504504
threeDotsDropdownItems?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
505505
customActionIcons?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
506506
tableBodyStart?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
507+
tableRowReplace?: AdminForthComponentDeclaration
507508
},
508509

509510
/**

0 commit comments

Comments
 (0)