feat: hasMany property for text fields (#4605)
* fix for supporting hasMany property in text field * Updated docs * handle text case types for schema and graphql schema * fix unit test for required failing * add unit test for has many text field * add end to end test for has many on text field creation * support has many feature for text field on postgres --------- Co-authored-by: Chris Heinz <chrisi.heinz@web.de>
This commit is contained in:
@@ -111,6 +111,35 @@ const TextFields: CollectionConfig = {
|
||||
},
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'hasMany',
|
||||
type: 'text',
|
||||
hasMany: true,
|
||||
},
|
||||
{
|
||||
name: 'validatesHasMany',
|
||||
type: 'text',
|
||||
hasMany: true,
|
||||
minLength: 3,
|
||||
},
|
||||
{
|
||||
name: 'localizedHasMany',
|
||||
type: 'text',
|
||||
hasMany: true,
|
||||
localized: true,
|
||||
},
|
||||
{
|
||||
name: 'withMinRows',
|
||||
type: 'text',
|
||||
hasMany: true,
|
||||
minRows: 2,
|
||||
},
|
||||
{
|
||||
name: 'withMaxRows',
|
||||
type: 'text',
|
||||
hasMany: true,
|
||||
maxRows: 4,
|
||||
},
|
||||
],
|
||||
slug: textFieldsSlug,
|
||||
}
|
||||
|
||||
@@ -119,6 +119,25 @@ describe('fields', () => {
|
||||
const nextSiblingText = await page.evaluate((el) => el.textContent, nextSibling)
|
||||
expect(nextSiblingText).toEqual('#after-input')
|
||||
})
|
||||
|
||||
test('should create hasMany with multiple texts', async () => {
|
||||
const input = 'five'
|
||||
const furtherInput = 'six'
|
||||
|
||||
await page.goto(url.create)
|
||||
const requiredField = page.locator('#field-text')
|
||||
const field = page.locator('.field-hasMany')
|
||||
|
||||
await requiredField.fill(String(input))
|
||||
await field.click()
|
||||
await page.keyboard.type(input)
|
||||
await page.keyboard.press('Enter')
|
||||
await page.keyboard.type(furtherInput)
|
||||
await page.keyboard.press('Enter')
|
||||
await saveDocAndAssert(page)
|
||||
await expect(field.locator('.rs__value-container')).toContainText(input)
|
||||
await expect(field.locator('.rs__value-container')).toContainText(furtherInput)
|
||||
})
|
||||
})
|
||||
|
||||
describe('number', () => {
|
||||
|
||||
@@ -95,6 +95,27 @@ describe('Fields', () => {
|
||||
|
||||
await expect(fieldWithDefaultValue).toEqual(dependentOnFieldWithDefaultValue)
|
||||
})
|
||||
|
||||
it('should localize an array of strings using hasMany', async () => {
|
||||
const localizedHasMany = ['hello', 'world']
|
||||
const { id } = await payload.create({
|
||||
collection: 'text-fields',
|
||||
data: {
|
||||
text,
|
||||
localizedHasMany,
|
||||
},
|
||||
locale: 'en',
|
||||
})
|
||||
const localizedDoc = await payload.findByID({
|
||||
id,
|
||||
collection: 'text-fields',
|
||||
locale: 'all',
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
expect(localizedDoc.localizedHasMany.en).toEqual(localizedHasMany)
|
||||
})
|
||||
})
|
||||
|
||||
describe('relationship', () => {
|
||||
|
||||
@@ -94,6 +94,21 @@ export interface LexicalMigrateField {
|
||||
}
|
||||
[k: string]: unknown
|
||||
} | null
|
||||
lexicalWithSlateData?: {
|
||||
root: {
|
||||
children: {
|
||||
type: string
|
||||
version: number
|
||||
[k: string]: unknown
|
||||
}[]
|
||||
direction: ('ltr' | 'rtl') | null
|
||||
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''
|
||||
indent: number
|
||||
type: string
|
||||
version: number
|
||||
}
|
||||
[k: string]: unknown
|
||||
} | null
|
||||
lexicalSimple?: {
|
||||
root: {
|
||||
children: {
|
||||
@@ -426,6 +441,35 @@ export interface BlockField {
|
||||
}
|
||||
)[]
|
||||
| null
|
||||
relationshipBlocks?:
|
||||
| {
|
||||
relationship?: (string | null) | TextField
|
||||
id?: string | null
|
||||
blockName?: string | null
|
||||
blockType: 'relationships'
|
||||
}[]
|
||||
| null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
export interface TextField {
|
||||
id: string
|
||||
text: string
|
||||
localizedText?: string | null
|
||||
i18nText?: string | null
|
||||
defaultFunction?: string | null
|
||||
defaultAsync?: string | null
|
||||
overrideLength?: string | null
|
||||
fieldWithDefaultValue?: string | null
|
||||
dependentOnFieldWithDefaultValue?: string | null
|
||||
customLabel?: string | null
|
||||
customError?: string | null
|
||||
beforeAndAfterInput?: string | null
|
||||
hasMany?: string[] | null
|
||||
validatesHasMany?: string[] | null
|
||||
localizedHasMany?: string[] | null
|
||||
withMinRows?: string[] | null
|
||||
withMaxRows?: string[] | null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
@@ -692,22 +736,6 @@ export interface RelationshipField {
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
export interface TextField {
|
||||
id: string
|
||||
text: string
|
||||
localizedText?: string | null
|
||||
i18nText?: string | null
|
||||
defaultFunction?: string | null
|
||||
defaultAsync?: string | null
|
||||
overrideLength?: string | null
|
||||
fieldWithDefaultValue?: string | null
|
||||
dependentOnFieldWithDefaultValue?: string | null
|
||||
customLabel?: string | null
|
||||
customError?: string | null
|
||||
beforeAndAfterInput?: string | null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
export interface RichTextField {
|
||||
id: string
|
||||
title: string
|
||||
|
||||
Reference in New Issue
Block a user