tinacms / tina-graphql-gateway

Makes it easier to build TinaCMS websites with a GraphQL Layer.
https://tina.io/cloud
Apache License 2.0
6 stars 2 forks source link

273 - Revisits useDocumentCreatorPlugin to improve UX #326

Closed Enigmatical closed 3 years ago

Enigmatical commented 3 years ago

The initial version of useDocumentCreatorPlugin() cheated a bit with Tina Standards, leveraging the constant calling of validate() to make it behave like an onChange() event with controlled fields. This meant adding a bunch of non-validation logic into the functions for collection and collectionTemplate as well as embedding the value for collection inside collectionTemplate.

Ideally, we'd want collection and template to be deterministic, but separate.

This change leverages the recent changes to ContentCreator Plugin that lets us use onChange() and initialValues, removing much of the validate() logic and utilizing useState() to watch for changes to collection and determining the options for template from that.

It is not completely void of "questionable" code - particularly saving the plugin in useState() as well and having a separate useEffect() for .add() and .remove().

But it cleans up the UX for the useDocumentCreatorPlugin() and, hopefully, more closely adheres to the Tina Way™.

Closes #273

changeset-bot[bot] commented 3 years ago

🦋 Changeset detected

Latest commit: 24e3b10662cce427bd9a0103b6f233d526eecb21

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages | Name | Type | | -------------------------- | ----- | | tina-graphql-gateway | Minor | | next-tinacms-cloudinary | Major | | demo | Patch | | test | Patch | | tina-cloud-starter | Patch | | tina-tailwind-sidebar-demo | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR