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

Add RFC 067 Prismic API ID casing #117

Merged
merged 9 commits into from
Jan 13, 2025
Merged

Conversation

davidpmccormick
Copy link
Contributor

☝️

@davidpmccormick davidpmccormick requested review from a team as code owners January 8, 2025 15:06
Copy link
Contributor

@rcantin-w rcantin-w left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(np? unsure)
Can we put it in a folder so the order doesn't get messed up when other RFCs are created 🙏

Whereas this isn’t a problem:

```
const { someProperty } = data; // <-- ✨
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@rcantin-w rcantin-w left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this, much needed conversations on there. Feels like details but really it amount to some level of frustration every time we try to do the right thing when creating new fields/modifying them, so I think it's very valuable in the long-term.

@rcantin-w rcantin-w changed the title Add RFC 066 Prismic API ID casing Add RFC 067 Prismic API ID casing Jan 8, 2025
@kenoir
Copy link
Contributor

kenoir commented Jan 9, 2025

SliceMachine makes these snake_case by default but allows this to be overridden easily in the GUI - we've done this fairly consistently although a couple of reusable content types have been given singular API IDs – `card` and `collection-venue`. I don't think there's any mileage in updating everything to snake_case since *none* of them are in that format currently. I'm not sure if we should try to update to `cards` and `collection-venues` or just live with those as they are?
SliceMachine makes these snake_case by default but allows this to be overridden easily in the Graphical User Interface (GUI) and to-date we have made *all* of them kebab-case, so there probably isn't a good case for changing these to snake_case now.

A couple of reusable content types have been given singular API IDs – `card` and `collection-venue` – should we consider changing these two to `cards` and `collection-venues`?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the effort level is low, I think it would be nice, so might be a question of weighing time/effort? With the migration script, is this something we can consider doing easily?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating the new (pluralised) types and migrating the content should be straightforward. I think the riskier part would be finding where the old (singular types) are linked from and updating those too. e.g. where a card is used on a page, we'd need to link it to the new version of the card

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migration doesn't allow for overwriting, right? We always have to re-create a new document?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what I was thumbs-up-ing there, but when we migrate we can modify existing documents rather than creating new ones

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that'd be great if it worked for IDs


SliceMachine makes these snake_case by default but allows this to be overridden easily in the GUI - we've done this fairly consistently although a couple of reusable content types have been given singular API IDs – `card` and `collection-venue`. I don't think there's any mileage in updating everything to snake_case since *none* of them are in that format currently. I'm not sure if we should try to update to `cards` and `collection-venues` or just live with those as they are?
SliceMachine makes these snake_case by default but allows this to be overridden easily in the Graphical User Interface (GUI) and to-date we have made *all* of them kebab-case, so there probably isn't a good case for changing these to snake_case now.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
Let's consider this a documented decision and keep an eye should new content be created to ensure it's kebab-cased!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, quick thought, what about changing the decision to camelCase to reduce the amount of different casings we use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…or snake_case so that they're aligned with what we're going to (have to) go for with the Slice API IDs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these IDs used in our code/will cause TS pain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't used as TS variables, no (they are currently kebab-case and that would already have been a problem for use in JS). They can only be used in quotes when querying Prismic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! So snake_case works too 👍

## Slice IDs
Prior to our use of SliceMachine, we gave our Slices camelCased IDs. However, SliceMachine requires that Slices have snake_cased IDs (it doesn’t let you override it in the GUI). When we migrated to SliceMachine we updated the Slice IDs in the [code](https://github.com/wellcomecollection/wellcomecollection.org/blob/main/common/views/slices/index.ts) and [type](https://github.com/wellcomecollection/wellcomecollection.org/blob/main/common/prismicio-types.d.ts) files that it generates to be camelCased in order to be able to use our existing code consistently. But each subsequent change to the Slice through SliceMachine will revert the IDs to snake_case and we have to remember to override it back to camelCase in several places across these two files. For newer Slices we have kept the default (snake_case) ids rather than override them to camelCase.

I don’t think we deal directly with the Slice IDs. Instead, we send all of them (in [a `components` object](https://github.com/wellcomecollection/wellcomecollection.org/blob/main/common/views/slices/index.ts#L5-L29)) along to SliceMachine, so the linting problems mentioned above don’t arise. As such, I propose that we move to using snake_case for all Slice IDs.
Copy link
Contributor

@rcantin-w rcantin-w Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Since it gets overwritten every time, we don't need to revert camelcasing anywhere do we?

@davidpmccormick davidpmccormick self-assigned this Jan 13, 2025
@davidpmccormick davidpmccormick merged commit 5602518 into main Jan 13, 2025
7 of 9 checks passed
@davidpmccormick davidpmccormick deleted the rfc-066-prismic-api-ids branch January 13, 2025 14:48
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

Successfully merging this pull request may close these issues.

4 participants