Skip to content

Commit b1beb76

Browse files
committed
feat: enhance tableRowReplace injection to support array input and validate element count
1 parent 6f0c30e commit b1beb76

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

adminforth/modules/configValidator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export default class ConfigValidator implements IConfigValidator {
4545
}
4646

4747
validateAndListifyInjection(obj, key, errors) {
48+
if (key.includes('tableRowReplace')) {
49+
if (obj[key].length > 1) {
50+
throw new Error(`tableRowReplace injection supports only one element, but received ${obj[key].length}.`);
51+
}
52+
}
4853
if (!Array.isArray(obj[key])) {
4954
// not array
5055
obj[key] = [obj[key]];

adminforth/spa/src/utils.ts

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

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-
70+
export function getCustomComponent({ file, meta }: { file: string, meta?: any }) {
8671
const name = file.replace(/@/g, '').replace(/\./g, '').replace(/\//g, '');
8772
return resolveComponent(name);
8873
}

adminforth/spa/src/views/ListView.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@
143143
? [coreStore.resourceOptions.pageInjections.list.tableBodyStart]
144144
: []
145145
"
146-
:tableRowReplaceInjection="coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace || undefined"
146+
:tableRowReplaceInjection="Array.isArray(coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace)
147+
? coreStore.resourceOptions.pageInjections.list.tableRowReplace[0]
148+
: coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace || undefined"
147149
:container-height="1100"
148150
:item-height="52.5"
149151
:buffer-size="listBufferSize"
@@ -174,7 +176,9 @@
174176
? [coreStore.resourceOptions.pageInjections.list.tableBodyStart]
175177
: []
176178
"
177-
:tableRowReplaceInjection="coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace || null"
179+
:tableRowReplaceInjection="Array.isArray(coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace)
180+
? coreStore.resourceOptions.pageInjections.list.tableRowReplace[0]
181+
: coreStore.resourceOptions?.pageInjections?.list?.tableRowReplace || undefined"
178182
/>
179183

180184
<component

adminforth/types/Common.ts

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

510510
/**

0 commit comments

Comments
 (0)