Added selectable field on languages

This commit is contained in:
DrMint 2024-06-30 13:21:57 +02:00
parent 3f478580d3
commit 3ca42c5705
2 changed files with 23 additions and 7 deletions

View File

@ -2,6 +2,7 @@ import { text } from "payload/dist/fields/validations";
import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin"; import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin";
import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin"; import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin";
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { rowField } from "../../fields/rowField/rowField";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildCollectionConfig } from "../../utils/collectionConfig";
import { getAllEndpoint } from "./endpoints/getAllEndpoint"; import { getAllEndpoint } from "./endpoints/getAllEndpoint";
import { importFromStrapi } from "./endpoints/importFromStrapi"; import { importFromStrapi } from "./endpoints/importFromStrapi";
@ -9,6 +10,7 @@ import { importFromStrapi } from "./endpoints/importFromStrapi";
const fields = { const fields = {
id: "id", id: "id",
name: "name", name: "name",
selectable: "selectable",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const Languages = buildCollectionConfig({ export const Languages = buildCollectionConfig({
@ -20,7 +22,7 @@ export const Languages = buildCollectionConfig({
defaultSort: fields.name, defaultSort: fields.name,
admin: { admin: {
useAsTitle: fields.name, useAsTitle: fields.name,
defaultColumns: [fields.name, fields.id], defaultColumns: [fields.name, fields.id, fields.selectable],
disableDuplicate: true, disableDuplicate: true,
group: CollectionGroups.Meta, group: CollectionGroups.Meta,
pagination: { defaultLimit: 100 }, pagination: { defaultLimit: 100 },
@ -43,11 +45,24 @@ export const Languages = buildCollectionConfig({
return text(value, options); return text(value, options);
}, },
}, },
rowField([
{ {
name: fields.name, name: fields.name,
type: "text", type: "text",
unique: true, unique: true,
required: true, required: true,
}, },
{
name: fields.selectable,
type: "checkbox",
defaultValue: false,
required: true,
admin: {
description:
"Check this box to make the language available to visitors on the website.\
Make sure wordings have been translated in that language before making it selectable.",
},
},
]),
], ],
}); });

View File

@ -227,6 +227,7 @@ export interface Image {
export interface Language { export interface Language {
id: string; id: string;
name: string; name: string;
selectable: boolean;
} }
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema