Skip to content

Commit 6a97e60

Browse files
authored
Merge pull request #111 from devforth/foreign-resource-unset-label
feat: add unsetLabel field to foreign resources
2 parents fbcc903 + c961191 commit 6a97e60

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

adminforth/modules/configValidator.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,15 @@ export default class ConfigValidator implements IConfigValidator {
471471
errors.push(`Resource "${res.resourceId}" column "${col.name}" has foreignResource resourceId which is not in resources: "${col.foreignResource.resourceId}".
472472
${similar ? `Did you mean "${similar}" instead of "${col.foreignResource.resourceId}"?` : ''}`);
473473
}
474+
475+
if (col.foreignResource.unsetLabel) {
476+
if (typeof col.foreignResource.unsetLabel !== 'string') {
477+
errors.push(`Resource "${res.resourceId}" column "${col.name}" has foreignResource unsetLabel which is not a string`);
478+
}
479+
} else {
480+
// set default unset label
481+
col.foreignResource.unsetLabel = 'Unset';
482+
}
474483
const befHook = col.foreignResource.hooks?.dropdownList?.beforeDatasourceRequest;
475484
if (befHook) {
476485
if (!Array.isArray(befHook)) {

adminforth/modules/restApi.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
515515
if (col.editingNote?.edit) {
516516
col.editingNote.edit = await tr(col.editingNote.edit, `resource.${resource.resourceId}.editingNote.edit`);
517517
}
518+
if (col.foreignResource?.unsetLabel) {
519+
col.foreignResource.unsetLabel = await tr(col.foreignResource.unsetLabel, `resource.${resource.resourceId}.foreignResource.unsetLabel`);
520+
}
518521

519522
return {
520523
...col,

adminforth/spa/src/components/ResourceForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ const columnOptions = computedAsync(async () => {
263263
},
264264
});
265265
266-
if (!column.required[props.source]) list.items.push({ value: null, label: t('Unset') });
266+
if (!column.required[props.source]) list.items.push({ value: null, label: column.foreignResource.unsetLabel });
267267
268268
return { [column.name]: list.items };
269269
}

adminforth/types/Common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ export type ShowInResolved = {
543543

544544
export interface AdminForthForeignResourceCommon {
545545
resourceId: string,
546+
unsetLabel?: string,
546547
}
547548

548549
/**

0 commit comments

Comments
 (0)