fix: respect hidden: true for virtual fields that have reference to a relationship field (#12219)
Previously, `hidden: true` on a virtual field that references a relationship field didn't work. Now, this field doesn't get calculated if there's `hidden: true` and no `showHiddenFields` was passed. Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
This commit is contained in:
@@ -1,9 +0,0 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
|
||||||
<configuration default="true" type="JavaScriptTestRunnerJest">
|
|
||||||
<node-interpreter value="project" />
|
|
||||||
<node-options value="--no-deprecation" />
|
|
||||||
<envs />
|
|
||||||
<scope-kind value="ALL" />
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
||||||
@@ -307,7 +307,11 @@ export const promise = async ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('virtual' in field && typeof field.virtual === 'string') {
|
if (
|
||||||
|
'virtual' in field &&
|
||||||
|
typeof field.virtual === 'string' &&
|
||||||
|
(!field.hidden || showHiddenFields)
|
||||||
|
) {
|
||||||
populationPromises.push(
|
populationPromises.push(
|
||||||
virtualFieldPopulationPromise({
|
virtualFieldPopulationPromise({
|
||||||
name: field.name,
|
name: field.name,
|
||||||
|
|||||||
@@ -466,6 +466,12 @@ export default buildConfigWithDefaults({
|
|||||||
type: 'text',
|
type: 'text',
|
||||||
virtual: 'post.title',
|
virtual: 'post.title',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'postTitleHidden',
|
||||||
|
type: 'text',
|
||||||
|
virtual: 'post.title',
|
||||||
|
hidden: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'postCategoryTitle',
|
name: 'postCategoryTitle',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
|
|||||||
@@ -2014,6 +2014,26 @@ describe('database', () => {
|
|||||||
expect(doc.postTitle).toBe('my-title-10')
|
expect(doc.postTitle).toBe('my-title-10')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should respect hidden: true for virtual fields with reference', async () => {
|
||||||
|
const post = await payload.create({ collection: 'posts', data: { title: 'my-title-3' } })
|
||||||
|
const { id } = await payload.create({
|
||||||
|
collection: 'virtual-relations',
|
||||||
|
depth: 0,
|
||||||
|
data: { post: post.id },
|
||||||
|
})
|
||||||
|
|
||||||
|
const doc = await payload.findByID({ collection: 'virtual-relations', depth: 0, id })
|
||||||
|
expect(doc.postTitleHidden).toBeUndefined()
|
||||||
|
|
||||||
|
const doc_show = await payload.findByID({
|
||||||
|
collection: 'virtual-relations',
|
||||||
|
depth: 0,
|
||||||
|
id,
|
||||||
|
showHiddenFields: true,
|
||||||
|
})
|
||||||
|
expect(doc_show.postTitleHidden).toBe('my-title-3')
|
||||||
|
})
|
||||||
|
|
||||||
it('should allow virtual field as reference to ID', async () => {
|
it('should allow virtual field as reference to ID', async () => {
|
||||||
const post = await payload.create({ collection: 'posts', data: { title: 'my-title' } })
|
const post = await payload.create({ collection: 'posts', data: { title: 'my-title' } })
|
||||||
const { id } = await payload.create({
|
const { id } = await payload.create({
|
||||||
|
|||||||
@@ -374,6 +374,7 @@ export interface Place {
|
|||||||
export interface VirtualRelation {
|
export interface VirtualRelation {
|
||||||
id: string;
|
id: string;
|
||||||
postTitle?: string | null;
|
postTitle?: string | null;
|
||||||
|
postTitleHidden?: string | null;
|
||||||
postCategoryTitle?: string | null;
|
postCategoryTitle?: string | null;
|
||||||
postCategoryID?:
|
postCategoryID?:
|
||||||
| {
|
| {
|
||||||
@@ -828,6 +829,7 @@ export interface PlacesSelect<T extends boolean = true> {
|
|||||||
*/
|
*/
|
||||||
export interface VirtualRelationsSelect<T extends boolean = true> {
|
export interface VirtualRelationsSelect<T extends boolean = true> {
|
||||||
postTitle?: T;
|
postTitle?: T;
|
||||||
|
postTitleHidden?: T;
|
||||||
postCategoryTitle?: T;
|
postCategoryTitle?: T;
|
||||||
postCategoryID?: T;
|
postCategoryID?: T;
|
||||||
postID?: T;
|
postID?: T;
|
||||||
|
|||||||
Reference in New Issue
Block a user