payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
25.49k stars 1.62k forks source link

Admin Condition seems to be broken #8072

Closed gujral1997 closed 1 month ago

gujral1997 commented 2 months ago

Link to reproduction

No response

Environment Info

Payload: 3.0.0-beta.78
Next.js: ^15.0.0-rc.0
Node.js: v20.9.0

Describe the Bug

I use admin.condition to render UI for questions and answers. But the condition sometimes, works and sometimes doesn't (on dev). On prod, it's not working at all. It's happening for both questions and options. Below is the collection:

   {
          label: 'Questions',
          fields: [
            {
              name: 'questions',
              type: 'array',
              minRows: 6,
              fields: [
                {
                  name: 'question',
                  type: 'group',
                  fields: [
                    {
                      name: 'contentType',
                      type: 'radio',
                      options: [
                        {
                          label: 'Text',
                          value: 'text',
                        },
                        {
                          label: 'Media',
                          value: 'media',
                        },
                        {
                          label: 'Text & Media',
                          value: 'text-media',
                        },
                      ],
                      required: true,
                    },
                    {
                      name: 'text',
                      type: 'richText',
                      required: false,
                      admin: {
                        condition: (_, data) =>
                          data?.contentType === 'text' || data?.contentType === 'text-media',
                      },
                    },
                    {
                      name: 'media',
                      type: 'upload',
                      relationTo: 'media',
                      required: false,
                      admin: {
                        condition: (_, data) =>
                          data?.contentType === 'media' || data?.contentType === 'text-media',
                      },
                    },
                    {
                      name: 'fontSize',
                      type: 'select',
                      options: fontSize,
                    },
                    colorField('fontColor'),
                    colorField('bgColor'),
                  ],
                },
                {
                  name: 'options',
                  type: 'array',
                  fields: [
                    {
                      name: 'contentType',
                      type: 'radio',
                      options: [
                        {
                          label: 'Text',
                          value: 'text',
                        },
                        {
                          label: 'Media',
                          value: 'media',
                        },
                        {
                          label: 'Text & Media',
                          value: 'text-media',
                        },
                      ],
                      required: true,
                    },
                    {
                      name: 'text',
                      type: 'richText',
                      required: false,
                      admin: {
                        condition: (_, data) => {
                          console.log(data)
                          return data?.contentType === 'text' || data?.contentType === 'text-media'
                        },
                      },
                    },
                    {
                      name: 'media',
                      type: 'upload',
                      relationTo: 'media',
                      required: false,
                      admin: {
                        condition: (_, data) => {
                          console.log(data)
                          return data?.contentType === 'media' || data?.contentType === 'text-media'
                        },
                      },
                    },
                    {
                      name: 'result',
                      type: 'text',
                      label: 'Result',
                      admin: {
                        components: {
                          Field: CustomSelectComponent,
                        },
                      },
                    },
                    {
                      name: 'points',
                      type: 'number',
                      defaultValue: 1,
                    },
                  ],
                },
              ],
            },
          ],
        },

Current Behaviour:

Screenshot 2024-09-05 at 6 19 13 PM

Expected Behaviour:

Screenshot 2024-09-05 at 6 19 23 PM

Reproduction Steps

  1. Create a new collection
  2. Add the above collection

Adapters and Plugins

No response

gujral1997 commented 2 months ago

I am able to find the reason

  versions: {
    drafts: {
      autosave: {
        interval: 100, // Happening if the autosave interval is very short
      },
    },
    maxPerDoc: 50,
  },
irhtml commented 1 month ago

Having the same issue on 3.0.0-beta.104

paulpopus commented 1 month ago

Fixed in https://github.com/payloadcms/payload/issues/8072

github-actions[bot] commented 1 month ago

🚀 This is included in version v3.0.0-beta.109

github-actions[bot] commented 1 month ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.