Merge branch 'master' of https://github.com/payloadcms/payload into feat/1695-nullable-localized-array-and-blocks
This commit is contained in:
@@ -5,7 +5,7 @@ import payload from '../src';
|
||||
|
||||
const expressApp = express();
|
||||
const init = async () => {
|
||||
await payload.initAsync({
|
||||
await payload.init({
|
||||
secret: uuid(),
|
||||
mongoURL: process.env.MONGO_URL || 'mongodb://localhost/payload',
|
||||
express: expressApp,
|
||||
|
||||
@@ -67,6 +67,49 @@ const GroupFields: CollectionConfig = {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'row',
|
||||
fields: [
|
||||
{
|
||||
name: 'groupInRow',
|
||||
type: 'group',
|
||||
fields: [
|
||||
{
|
||||
name: 'field',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'secondField',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'thirdField',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'secondGroupInRow',
|
||||
type: 'group',
|
||||
fields: [
|
||||
{
|
||||
name: 'field',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'nestedGroup',
|
||||
type: 'group',
|
||||
fields: [
|
||||
{
|
||||
name: 'nestedField',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -282,6 +282,17 @@ export interface GroupField {
|
||||
potentiallyEmptyGroup: {
|
||||
text?: string;
|
||||
};
|
||||
groupInRow: {
|
||||
field?: string;
|
||||
secondField?: string;
|
||||
thirdField?: string;
|
||||
};
|
||||
secondGroupInRow: {
|
||||
field?: string;
|
||||
nestedGroup: {
|
||||
nestedField?: string;
|
||||
};
|
||||
};
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ export async function initPayloadTest(options: Options): Promise<{ serverURL: st
|
||||
initOptions.express = express();
|
||||
}
|
||||
|
||||
await payload.initAsync(initOptions);
|
||||
await payload.init(initOptions);
|
||||
|
||||
if (initOptions.express) {
|
||||
initOptions.express.listen(port);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { buildConfig } from '../buildConfig';
|
||||
import { devUser } from '../credentials';
|
||||
import { GlobalArray } from './Array';
|
||||
import { LocalizedPost, RelationshipLocalized } from './payload-types';
|
||||
import {
|
||||
defaultLocale,
|
||||
@@ -196,6 +197,24 @@ export default buildConfig({
|
||||
],
|
||||
},
|
||||
],
|
||||
globals: [
|
||||
{
|
||||
slug: 'global-array',
|
||||
fields: [
|
||||
{
|
||||
name: 'array',
|
||||
type: 'array',
|
||||
fields: [
|
||||
{
|
||||
name: 'text',
|
||||
type: 'text',
|
||||
localized: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
onInit: async (payload) => {
|
||||
const collection = slug;
|
||||
|
||||
@@ -287,5 +306,30 @@ export default buildConfig({
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const globalArray = await payload.updateGlobal({
|
||||
slug: 'global-array',
|
||||
data: {
|
||||
array: [
|
||||
{
|
||||
text: 'test en 1',
|
||||
},
|
||||
{
|
||||
text: 'test en 2',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
await payload.updateGlobal({
|
||||
slug: 'global-array',
|
||||
locale: 'es',
|
||||
data: {
|
||||
array: globalArray.array.map((row, i) => ({
|
||||
...row,
|
||||
text: `test es ${i + 1}`,
|
||||
})),
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
WithLocalizedRelationship,
|
||||
LocalizedRequired,
|
||||
RelationshipLocalized,
|
||||
GlobalArray,
|
||||
} from './payload-types';
|
||||
import type { LocalizedPostAllLocale } from './config';
|
||||
import config, { relationshipLocalizedSlug, slug, withLocalizedRelSlug, withRequiredLocalizedFields } from './config';
|
||||
@@ -477,6 +478,27 @@ describe('Localization', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Localized - arrays with nested localized fields', () => {
|
||||
it('should allow moving rows and retain existing row locale data', async () => {
|
||||
const globalArray = await payload.findGlobal<GlobalArray>({
|
||||
slug: 'global-array',
|
||||
});
|
||||
|
||||
const reversedArrayRows = [...globalArray.array].reverse();
|
||||
|
||||
const updatedGlobal = await payload.updateGlobal({
|
||||
slug: 'global-array',
|
||||
locale: 'all',
|
||||
data: {
|
||||
array: reversedArrayRows,
|
||||
},
|
||||
});
|
||||
|
||||
expect(updatedGlobal.array[0].text.en).toStrictEqual('test en 2');
|
||||
expect(updatedGlobal.array[0].text.es).toStrictEqual('test es 2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Localized - required', () => {
|
||||
it('should update without passing all required fields', async () => {
|
||||
const newDoc = await payload.create({
|
||||
|
||||
@@ -6,6 +6,17 @@
|
||||
*/
|
||||
|
||||
export interface Config {}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "global-array".
|
||||
*/
|
||||
export interface GlobalArray {
|
||||
id: string;
|
||||
array: {
|
||||
text?: string;
|
||||
id?: string;
|
||||
}[];
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "users".
|
||||
|
||||
Reference in New Issue
Block a user