wip merge master

This commit is contained in:
Dan Ribbens
2023-06-29 13:27:33 -04:00
parent b4c049c745
commit 682f8ecae4
173 changed files with 9894 additions and 2930 deletions

View File

@@ -32,6 +32,67 @@ const ConditionalLogic: CollectionConfig = {
},
},
},
{
name: 'parentGroup',
type: 'group',
fields: [
{
name: 'enableParentGroupFields',
type: 'checkbox',
defaultValue: false,
},
{
name: 'siblingField',
type: 'text',
admin: {
description: 'Ensures we can rely on nested fields within `data`.',
condition: ({ parentGroup }) => Boolean(parentGroup?.enableParentGroupFields),
},
},
],
},
{
name: 'reliesOnParentGroup',
type: 'text',
admin: {
description: 'Ensures we can rely on nested fields within `siblingsData`.',
condition: (_, { parentGroup }) => Boolean(parentGroup?.enableParentGroupFields),
},
},
{
name: 'groupSelection',
type: 'select',
options: [
'group1',
'group2',
],
},
{
name: 'group1',
type: 'group',
fields: [
{
name: 'group1Field',
type: 'text',
},
],
admin: {
condition: ({ groupSelection }) => groupSelection === 'group1',
},
},
{
name: 'group2',
type: 'group',
fields: [
{
name: 'group2Field',
type: 'text',
},
],
admin: {
condition: ({ groupSelection }) => groupSelection === 'group2',
},
},
],
};

View File

@@ -47,6 +47,30 @@ const NumberFields: CollectionConfig = {
type: 'number',
defaultValue: defaultNumber,
},
{
name: 'hasMany',
type: 'number',
hasMany: true,
min: 5,
max: 100,
},
{
name: 'validatesHasMany',
type: 'number',
hasMany: true,
validate: (value: number[]) => {
if (value && !Array.isArray(value)) {
return 'value should be an array';
}
return true;
},
},
{
name: 'localizedHasMany',
type: 'number',
hasMany: true,
localized: true,
},
],
};
@@ -58,6 +82,9 @@ export const numberDoc = {
negativeNumber: -5,
decimalMin: 1.25,
decimalMax: 0.25,
hasMany: [5, 10, 15],
validatesHasMany: [5],
localizedHasMany: [10],
};
export default NumberFields;

View File

@@ -44,14 +44,20 @@ const RelationshipFields: CollectionConfig = {
type: 'relationship',
relationTo: 'text-fields',
hasMany: true,
min: 2,
minRows: 2,
},
{
name: 'relationshipWithMax',
type: 'relationship',
relationTo: 'text-fields',
hasMany: true,
max: 2,
maxRows: 2,
},
{
name: 'relationshipHasMany',
type: 'relationship',
relationTo: 'text-fields',
hasMany: true,
},
],
};

View File

@@ -12,6 +12,7 @@ import { tabsSlug } from './collections/Tabs';
import { collapsibleFieldsSlug } from './collections/Collapsible';
import wait from '../../src/utilities/wait';
import { jsonDoc } from './collections/JSON';
import { numberDoc } from './collections/Number';
const { beforeAll, describe } = test;
@@ -67,6 +68,42 @@ describe('fields', () => {
});
});
describe('number', () => {
let url: AdminUrlUtil;
beforeAll(() => {
url = new AdminUrlUtil(serverURL, 'number-fields');
});
test('should display field in list view', async () => {
await page.goto(url.list);
const textCell = page.locator('.row-1 .cell-number');
await expect(textCell)
.toHaveText(String(numberDoc.number));
});
test('should create', async () => {
const input = 5;
await page.goto(url.create);
const field = page.locator('#field-number');
await field.fill(String(input));
await saveDocAndAssert(page);
await expect(await field.inputValue()).toEqual(String(input));
});
test('should create hasMany', async () => {
const input = 5;
await page.goto(url.create);
const field = page.locator('.field-hasMany');
await field.click();
await page.keyboard.type(String(input));
await page.keyboard.press('Enter');
await saveDocAndAssert(page);
await expect(field.locator('.rs__value-container')).toContainText(String(input));
});
});
describe('json', () => {
let url: AdminUrlUtil;
beforeAll(() => {
@@ -838,6 +875,36 @@ describe('fields', () => {
await page.locator('.rs__option:has-text("Seeded text document")').click();
await saveDocAndAssert(page);
});
// Related issue: https://github.com/payloadcms/payload/issues/2815
test('should modify fields in relationship drawer', async () => {
await page.goto(url.create);
// Create a new doc for the `relationshipHasMany` field
await page.locator('#field-relationshipHasMany button.relationship-add-new__add-button').click();
const textField2 = page.locator('[id^=doc-drawer_text-fields_1_] #field-text');
const value = 'Hello, world!';
await textField2.fill(value);
// Save and close the drawer
await page.locator('[id^=doc-drawer_text-fields_1_] #action-save').click();
await expect(page.locator('.Toastify')).toContainText('successfully');
await page.locator('[id^=close-drawer__doc-drawer_text-fields_1_]').click();
// Now open the drawer again to edit the `text` field _using the keyboard_
await page.locator('#field-relationshipHasMany button.relationship--multi-value-label__drawer-toggler').click();
const textField3 = page.locator('[id^=doc-drawer_text-fields_1_] #field-text');
await textField3.click();
await page.keyboard.down('1');
await page.keyboard.down('2');
await page.keyboard.down('3');
await page.locator('[id^=doc-drawer_text-fields_1_] #action-save').click();
await expect(page.locator('.Toastify')).toContainText('successfully');
// TODO: uncomment this when the drawer is fixed
// await page.locator('[id^=close-drawer__doc-drawer_text-fields_1_]').click();
// await expect(page.locator('#field-relationshipHasMany .relationship--multi-value-label__text')).toContainText(`${value}123`);
await expect(page.locator('#field-relationshipHasMany .relationship--multi-value-label__text')).toContainText(value);
});
});
describe('upload', () => {
@@ -972,10 +1039,34 @@ describe('fields', () => {
await expect(fieldToToggle).toBeVisible();
});
test('should show conditionl field based on user data', async () => {
test('should show conditional field based on user data', async () => {
await page.goto(url.create);
const userConditional = page.locator('input#field-userConditional');
await expect(userConditional).toBeVisible();
});
test('should show conditional field based on fields nested within data', async () => {
await page.goto(url.create);
const parentGroupFields = page.locator('div#field-parentGroup > .group-field__wrap > .render-fields');
await expect(parentGroupFields).toHaveCount(1);
const toggle = page.locator('label[for=field-parentGroup__enableParentGroupFields]');
await toggle.click();
const toggledField = page.locator('input#field-parentGroup__siblingField');
await expect(toggledField).toBeVisible();
});
test('should show conditional field based on fields nested within siblingData', async () => {
await page.goto(url.create);
const toggle = page.locator('label[for=field-parentGroup__enableParentGroupFields]');
await toggle.click();
const fieldRelyingOnSiblingData = page.locator('input#field-reliesOnParentGroup');
await expect(fieldRelyingOnSiblingData).toBeVisible();
});
});
});

View File

@@ -194,6 +194,25 @@ describe('Fields', () => {
},
})).rejects.toThrow('The following field is invalid: decimalMax');
});
it('should localize an array of numbers using hasMany', async () => {
const localizedHasMany = [5, 10];
const { id } = await payload.create({
collection: 'number-fields',
locale: 'en',
data: {
localizedHasMany,
},
});
const localizedDoc = await payload.findByID({
collection: 'number-fields',
locale: 'all',
id,
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(localizedDoc.localizedHasMany.en).toEqual(localizedHasMany);
});
});
describe('indexes', () => {

View File

@@ -1,6 +1,6 @@
/* tslint:disable */
/**
* This file was automatically generated by Payload CMS.
* This file was automatically generated by Payload.
* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,
* and re-run `payload generate:types` to regenerate this file.
*/
@@ -35,13 +35,15 @@ export interface Config {
export interface User {
id: string;
canViewConditionalField?: boolean;
email?: string;
updatedAt: string;
createdAt: string;
email: string;
resetPasswordToken?: string;
resetPasswordExpiration?: string;
salt?: string;
hash?: string;
loginAttempts?: number;
lockUntil?: string;
createdAt: string;
updatedAt: string;
password?: string;
}
export interface ArrayField {
@@ -50,7 +52,7 @@ export interface ArrayField {
text: string;
id?: string;
}[];
collapsedArray: {
collapsedArray?: {
text: string;
id?: string;
}[];
@@ -74,8 +76,8 @@ export interface ArrayField {
title?: string;
id?: string;
}[];
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface BlockField {
id: string;
@@ -214,8 +216,8 @@ export interface BlockField {
blockName?: string;
blockType: 'text';
}[];
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface CodeField {
id: string;
@@ -224,8 +226,8 @@ export interface CodeField {
json?: string;
html?: string;
css?: string;
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface CollapsibleField {
id: string;
@@ -244,8 +246,8 @@ export interface CollapsibleField {
innerCollapsible?: string;
id?: string;
}[];
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface ConditionalLogic {
id: string;
@@ -253,8 +255,8 @@ export interface ConditionalLogic {
toggleField?: boolean;
fieldToToggle: string;
userConditional?: string;
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface DateField {
id: string;
@@ -263,14 +265,14 @@ export interface DateField {
dayOnly?: string;
dayAndTime?: string;
monthOnly?: string;
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface RadioField {
id: string;
radio?: 'one' | 'two' | 'three';
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface GroupField {
id: string;
@@ -300,14 +302,27 @@ export interface GroupField {
nestedField?: string;
};
};
createdAt: string;
groups: {
groupInRow?: {
field?: string;
secondField?: string;
thirdField?: string;
};
secondGroupInRow?: {
field?: string;
nestedGroup?: {
nestedField?: string;
};
};
};
updatedAt: string;
createdAt: string;
}
export interface RowField {
id: string;
title: string;
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface IndexedField {
id: string;
@@ -330,8 +345,8 @@ export interface IndexedField {
collapsibleTextUnique?: string;
partOne?: string;
partTwo?: string;
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface JsonField {
id: string;
@@ -344,8 +359,8 @@ export interface JsonField {
| number
| boolean
| null;
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface NumberField {
id: string;
@@ -357,8 +372,11 @@ export interface NumberField {
decimalMin?: number;
decimalMax?: number;
defaultNumber?: number;
createdAt: string;
hasMany?: number[];
validatesHasMany?: number[];
localizedHasMany?: number[];
updatedAt: string;
createdAt: string;
}
export interface PointField {
id: string;
@@ -379,8 +397,8 @@ export interface PointField {
*/
point?: [number, number];
};
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface RelationshipField {
id: string;
@@ -402,8 +420,8 @@ export interface RelationshipField {
};
relationshipWithMin?: string[] | TextField[];
relationshipWithMax?: string[] | TextField[];
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface TextField {
id: string;
@@ -413,8 +431,8 @@ export interface TextField {
defaultFunction?: string;
defaultAsync?: string;
overrideLength?: string;
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface RichTextField {
id: string;
@@ -423,11 +441,14 @@ export interface RichTextField {
richText: {
[k: string]: unknown;
}[];
richTextCustomFields?: {
[k: string]: unknown;
}[];
richTextReadOnly?: {
[k: string]: unknown;
}[];
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface SelectField {
id: string;
@@ -437,8 +458,8 @@ export interface SelectField {
selectHasManyLocalized?: ('one' | 'two')[];
selectI18n?: 'one' | 'two' | 'three';
simple?: 'One' | 'Two' | 'Three';
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface TabsField {
id: string;
@@ -522,8 +543,8 @@ export interface TabsField {
nestedTab: {
text?: string;
};
createdAt: string;
updatedAt: string;
createdAt: string;
}
export interface Upload {
id: string;
@@ -532,27 +553,27 @@ export interface Upload {
richText?: {
[k: string]: unknown;
}[];
updatedAt: string;
createdAt: string;
url?: string;
filename?: string;
mimeType?: string;
filesize?: number;
width?: number;
height?: number;
createdAt: string;
updatedAt: string;
}
export interface Uploads2 {
id: string;
text?: string;
media?: string | Uploads2;
updatedAt: string;
createdAt: string;
url?: string;
filename?: string;
mimeType?: string;
filesize?: number;
width?: number;
height?: number;
createdAt: string;
updatedAt: string;
}
export interface Uploads3 {
id: string;
@@ -560,12 +581,12 @@ export interface Uploads3 {
richText?: {
[k: string]: unknown;
}[];
updatedAt: string;
createdAt: string;
url?: string;
filename?: string;
mimeType?: string;
filesize?: number;
width?: number;
height?: number;
createdAt: string;
updatedAt: string;
}