Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConditionalField plugin doesn't work with dato migration #58

Closed
joanpadolina opened this issue May 18, 2022 · 11 comments
Closed

ConditionalField plugin doesn't work with dato migration #58

joanpadolina opened this issue May 18, 2022 · 11 comments

Comments

@joanpadolina
Copy link

I'm trying to run a migration with your plugin, the addon is being installed perfectly but somehow it won't implement the plugin to the specific targetFieldsApiKey.

  await client.fields.create(pageLinkBlock.id, {
    label: 'Render as button',
    apiKey: 'ti_render_as_button',
    fieldType: 'boolean',
    defaultValue: false,
    appearance: {
      editor: 'boolean',
      parameters: {},
      addons: [
        {
          id: conditionalFieldsPlugin.id,
          parameters: {
            invert: false,
            targetFieldsApiKey: ['ti_button_style'],
          },
          fieldExtension: 'conditionalFields',
        },
      ],
    },
  })

I've also tried manually adding it to dato and the addons was exactly the same as the code above.
Thanks in advanced!
ConditionalFields

@stefanoverna
Copy link
Member

Could it be that the API client automatically transforms targetFieldsApiKey into target_fields_api_key (which won't work)?

@arakoczy
Copy link

arakoczy commented Sep 22, 2022

We've faced the same issue today and I can confirm that eventually, it works with both targetFieldsApiKey and target_fields_api_key.

The returned object I got back for hideNavigationField.appeareance.addons[0].parameters looks like this:

{ invert: false, targetFieldsApiKey: [ 'banner_text' ] }

What happens after is really weird, going back to the UI and either refreshing the page or going to check (manually) in the settings if the plugin setup worked, I see the ctx.notice message "Plugin upgraded successfully!" and the targetFieldsApiKey will be suddenly erased:

{ invert: false, targetFieldsApiKey: [] }

@souljuse
Copy link
Contributor

Hi @arakoczy,

it works with both targetFieldsApiKey and target_fields_api_key.

This is not possible with our node client. The creation of the plugin works only with the camelized key targetFieldsApiKey, and all the others keys in snake case.

Try using this code:

await client.fields.create(pageLinkBlock.id, {
	label: "Render as button",
	api_key: "ti_render_as_button",
	field_type: "boolean",
	default_value: false,
	appearance: {
		editor: "boolean",
		parameters: {},
		addons: [
			{
				id: conditionalFieldsPlugin.id,
				parameters: {
					invert: false,
					targetFieldsApiKey: ["ti_button_style"],
				},
				field_extension: "conditionalFields",
			},
		],
	},
});

Let me know :) I will close this issue for now, and re-open if not solved.

@Faxxiz
Copy link

Faxxiz commented Jun 27, 2023

Hello @souljuse,

Couldn't find any other answer where this problem is discussed/solved.
I got myself into the same kind of issue, I am scripting this in 50+ projects so I can't update everything manually.

This is what I did to make things work, pay attention to the "targetFieldsApiKey" written in camelCase.

appearance: {
      editor: "boolean",
      parameters: {},
      addons: [
        {
          id: conditionalBooleanPlugin.id,
          parameters: {
            invert: false,
            targetFieldsApiKey: ["internal_link"],
          },
          fieldExtension: "conditionalFields",
        },
        {
          id: conditionalBooleanPlugin.id,
          parameters: {
            invert: true,
            targetFieldsApiKey: ["external_link"],
          },
          fieldExtension: "conditionalFields",
        },
      ],
    },

and the surprise is on DatoCMS directly where I can't see nothing, except in the request that there is the field "target_fields_api_key" written in snake case.

image

Obviously, I'd like to point out that it works through the interface the field is transformed into "targetFieldsApiKey" and the behaviour is perfect after that,
And to avoid wasting anymore time too, I tried changing my script with what you said about having all other fields in snake case too, tried all fields in camelCase, and all possible combinations of formatting

@stefanoverna
Copy link
Member

@Faxxiz we need more info to be able to reproduce.

  • Which version of the DatoCMS client are you using in your scripts?

@Faxxiz
Copy link

Faxxiz commented Jun 27, 2023

@Faxxiz we need more info to be able to reproduce.

  • Which version of the DatoCMS client are you using in your scripts?

v3.5.21, I think it's the latest one

@stefanoverna
Copy link
Member

The latest version of @datocms/cma-client-node is 2.0.0, are you using the deprecated datocms-client client?

@Faxxiz
Copy link

Faxxiz commented Jun 27, 2023

Oh okay the legacy client is still written in all documentation pages, I wasn't aware we needed to stop using it.

@stefanoverna
Copy link
Member

stefanoverna commented Jun 27, 2023

Where did you find those links exactly? We should correct them.. thanks!

@Faxxiz
Copy link

Faxxiz commented Jun 27, 2023

I took it from the people talking about the plugin here : https://community.datocms.com/t/conditional-fields-plugin-does-not-work-with-migrations/3570. If I'm not mistaking there is no documentation in the plugin so this is all I've got, and the request when I do it manually from the interface.

And as they were using in the first line await client.plugins.all();,
I assumed it was done with the legacy client like everywhere in this documentation https://www.datocms.com/docs/content-management-api/resources/plugin/instances (especially here it's a .all() and not a .list() like in the @datocms/cma-client-node)

And as the legacy JS client is part of every page of the documentation, I didn't think it could fail.

@stefanoverna
Copy link
Member

stefanoverna commented Jun 27, 2023

Updated the discussion on the forum, thanks! And the Docs offers the new client by default, but we'll add a deprecation notice for the legacy one!

video1.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants