Files
payloadcms/test/fields/config.ts
Dan Ribbens bab34d82f5 feat: add i18n to admin panel (#1326)
Co-authored-by: shikhantmaungs <shinkhantmaungs@gmail.com>
Co-authored-by: Thomas Ghysels <info@thomasg.be>
Co-authored-by: Kokutse Djoguenou <kokutse@Kokutses-MacBook-Pro.local>
Co-authored-by: Christian Gil <47041342+ChrisGV04@users.noreply.github.com>
Co-authored-by: Łukasz Rabiec <lukaszrabiec@gmail.com>
Co-authored-by: Jenny <jennifer.eberlei@gmail.com>
Co-authored-by: Hung Vu <hunghvu2017@gmail.com>
Co-authored-by: Shin Khant Maung <101539335+shinkhantmaungs@users.noreply.github.com>
Co-authored-by: Carlo Brualdi <carlo.brualdi@gmail.com>
Co-authored-by: Ariel Tonglet <ariel.tonglet@gmail.com>
Co-authored-by: Roman Ryzhikov <general+github@ya.ru>
Co-authored-by: maekoya <maekoya@stromatolite.jp>
Co-authored-by: Emilia Trollros <3m1l1a@emiliatrollros.se>
Co-authored-by: Kokutse J Djoguenou <90865585+Julesdj@users.noreply.github.com>
Co-authored-by: Mitch Dries <mitch.dries@gmail.com>

BREAKING CHANGE: If you assigned labels to collections, globals or block names, you need to update your config! Your GraphQL schema and generated Typescript interfaces may have changed. Payload no longer uses labels for code based naming. To prevent breaking changes to your GraphQL API and typescript types in your project, you can assign the below properties to match what Payload previously generated for you from labels.

On Collections
Use `graphQL.singularName`, `graphQL.pluralName` for GraphQL schema names.
Use `typescript.interface` for typescript generation name.

On Globals
Use `graphQL.name` for GraphQL Schema name.
Use `typescript.interface` for typescript generation name.

On Blocks (within Block fields)
Use `graphQL.singularName` for graphQL schema names.
2022-11-18 07:36:30 -05:00

116 lines
4.7 KiB
TypeScript

/* eslint-disable @typescript-eslint/ban-ts-comment */
import path from 'path';
import fs from 'fs';
import { buildConfig } from '../buildConfig';
import { devUser } from '../credentials';
import ArrayFields, { arrayDoc } from './collections/Array';
import BlockFields, { blocksDoc } from './collections/Blocks';
import CollapsibleFields, { collapsibleDoc } from './collections/Collapsible';
import ConditionalLogic, { conditionalLogicDoc } from './collections/ConditionalLogic';
import DateFields, { dateDoc } from './collections/Date';
import RichTextFields, { richTextDoc } from './collections/RichText';
import SelectFields, { selectsDoc } from './collections/Select';
import TabsFields, { tabsDoc } from './collections/Tabs';
import TextFields, { textDoc } from './collections/Text';
import PointFields, { pointDoc } from './collections/Point';
import GroupFields, { groupDoc } from './collections/Group';
import getFileByPath from '../../src/uploads/getFileByPath';
import Uploads, { uploadsDoc } from './collections/Upload';
import IndexedFields from './collections/Indexed';
import NumberFields, { numberDoc } from './collections/Number';
import CodeFields, { codeDoc } from './collections/Code';
import RelationshipFields from './collections/Relationship';
import RadioFields, { radiosDoc } from './collections/Radio';
export default buildConfig({
admin: {
webpack: (config) => ({
...config,
resolve: {
...config.resolve,
alias: {
...config?.resolve?.alias,
fs: path.resolve(__dirname, './mocks/emptyModule.js'),
},
},
}),
},
collections: [
ArrayFields,
BlockFields,
CodeFields,
CollapsibleFields,
ConditionalLogic,
DateFields,
RadioFields,
GroupFields,
IndexedFields,
NumberFields,
PointFields,
RelationshipFields,
RichTextFields,
SelectFields,
TabsFields,
TextFields,
Uploads,
],
localization: {
defaultLocale: 'en',
locales: ['en', 'es'],
},
onInit: async (payload) => {
await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
});
const createdArrayDoc = await payload.create({ collection: 'array-fields', data: arrayDoc });
await payload.create({ collection: 'collapsible-fields', data: collapsibleDoc });
await payload.create({ collection: 'conditional-logic', data: conditionalLogicDoc });
await payload.create({ collection: 'group-fields', data: groupDoc });
await payload.create({ collection: 'select-fields', data: selectsDoc });
await payload.create({ collection: 'radio-fields', data: radiosDoc });
await payload.create({ collection: 'tabs-fields', data: tabsDoc });
await payload.create({ collection: 'point-fields', data: pointDoc });
await payload.create({ collection: 'date-fields', data: dateDoc });
await payload.create({ collection: 'code-fields', data: codeDoc });
const createdTextDoc = await payload.create({ collection: 'text-fields', data: textDoc });
const uploadsDir = path.resolve(__dirname, './collections/Upload/uploads');
if (fs.existsSync(uploadsDir)) fs.readdirSync(uploadsDir).forEach((f) => fs.rmSync(`${uploadsDir}/${f}`));
const filePath = path.resolve(__dirname, './collections/Upload/payload.jpg');
const file = await getFileByPath(filePath);
const createdUploadDoc = await payload.create({ collection: 'uploads', data: uploadsDoc, file });
const richTextDocWithRelId = JSON.parse(JSON.stringify(richTextDoc).replace('{{ARRAY_DOC_ID}}', createdArrayDoc.id));
const richTextDocWithRelationship = { ...richTextDocWithRelId };
const richTextRelationshipIndex = richTextDocWithRelationship.richText.findIndex(({ type }) => type === 'relationship');
richTextDocWithRelationship.richText[richTextRelationshipIndex].value = { id: createdTextDoc.id };
const richTextUploadIndex = richTextDocWithRelationship.richText.findIndex(({ type }) => type === 'upload');
richTextDocWithRelationship.richText[richTextUploadIndex].value = { id: createdUploadDoc.id };
richTextDocWithRelationship.richTextReadOnly[richTextUploadIndex].value = { id: createdUploadDoc.id };
await payload.create({ collection: 'rich-text-fields', data: richTextDocWithRelationship });
await payload.create({ collection: 'number-fields', data: numberDoc });
const blocksDocWithRichText = { ...blocksDoc };
// @ts-ignore
blocksDocWithRichText.blocks[0].richText = richTextDocWithRelationship.richText;
// @ts-ignore
blocksDocWithRichText.localizedBlocks[0].richText = richTextDocWithRelationship.richText;
await payload.create({ collection: 'block-fields', data: blocksDocWithRichText });
},
});