Skip to content

Commit a32133d

Browse files
committed
fix: allow required and editingNote types to have scalar (non-object) value
1 parent bdf3867 commit a32133d

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

adminforth/modules/configValidator.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ export default class ConfigValidator implements IConfigValidator {
437437
res.columns = [];
438438
}
439439
res.columns = resInput.columns.map((inCol: AdminForthResourceColumnInput, inColIndex) => {
440-
const col: Partial<AdminForthResourceColumn> = { ...inCol, showIn: undefined, editingNote: undefined };
440+
const col: Partial<AdminForthResourceColumn> = {
441+
...inCol, showIn: undefined, editingNote: undefined, required: undefined,
442+
};
443+
444+
col.required = typeof inCol.required === 'boolean' ? { create: inCol.required, edit: inCol.required } : inCol.required;
441445

442446
// check for duplicate column names
443447
if (resInput.columns.findIndex((c) => c.name === col.name) !== inColIndex) {
@@ -705,6 +709,14 @@ export default class ConfigValidator implements IConfigValidator {
705709
col.components[key] = this.validateComponent(comp, errors);
706710
}
707711
}
712+
713+
// fixes issues after discover when result of this validation applied to discovered column
714+
Object.keys(col).forEach((key) => {
715+
if (col[key] === undefined) {
716+
delete col[key];
717+
}
718+
});
719+
708720
return col as AdminForthResourceColumn;
709721
})
710722

adminforth/types/Back.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ActionCheckSource, AdminForthFilterOperators, AdminForthSortDirections,
1313
AdminForthConfigMenuItem,
1414
AnnouncementBadgeResponse,
1515
AdminForthResourcePages,
16+
AdminForthResourceColumnInputCommon,
1617
} from './Common.js';
1718
import { AnyCnameRecord } from 'dns';
1819

@@ -1420,12 +1421,12 @@ export type ShowIn = {
14201421
[key in AdminForthResourcePages]: AllowedActionValue
14211422
}
14221423

1423-
export interface AdminForthResourceColumnInput extends Omit<AdminForthResourceColumnCommon, 'showIn'> {
1424+
export interface AdminForthResourceColumnInput extends Omit<AdminForthResourceColumnInputCommon, 'showIn'> {
14241425
showIn?: ShowInInput,
14251426
foreignResource?: AdminForthForeignResource,
14261427
}
14271428

1428-
export interface AdminForthResourceColumn extends Omit<AdminForthResourceColumnInput, 'showIn'> {
1429+
export interface AdminForthResourceColumn extends Omit<AdminForthResourceColumnCommon, 'showIn'> {
14291430
showIn?: ShowIn,
14301431
foreignResource?: AdminForthForeignResource,
14311432
}

dev-demo/resources/translation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import AdminForth, {
44
} from "../../adminforth";
55
import CompletionAdapterOpenAIChatGPT from "../../adapters/adminforth-completion-adapter-open-ai-chat-gpt";
66
import I18nPlugin from "../../plugins/adminforth-i18n";
7-
import { v1 as uuid } from "uuid";
7+
import { randomUUID } from "crypto";
88

99

1010
export default {
@@ -75,14 +75,16 @@ export default {
7575
columns: [
7676
{
7777
name: "id",
78-
fillOnCreate: ({ initialRecord, adminUser }: any) => uuid(),
78+
fillOnCreate: ({ initialRecord, adminUser }: any) => randomUUID(),
7979
primaryKey: true,
8080
showIn: [],
8181
},
8282
{
8383
name: "en_string",
8484
type: AdminForthDataTypes.STRING,
8585
label: "English",
86+
required: true,
87+
editingNote: "This is the original string in English. It will be used as a reference for translation.",
8688
},
8789
{
8890
name: "created_at",

0 commit comments

Comments
 (0)