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 overrides for the Chef card #1589

Merged
merged 23 commits into from
Jun 20, 2024
Merged

Add overrides for the Chef card #1589

merged 23 commits into from
Jun 20, 2024

Conversation

jonathonherbert
Copy link
Contributor

@jonathonherbert jonathonherbert commented Jun 3, 2024

What's changed?

Adds the missing overrides for the Chef card – image and palette overrides. The palette data is copied from mis-en-place, the tool that Fronts will eventually replace, here.

chef-overrides

Implementation notes

  • I've added the collection data in this PR, as it was a similar shape and it seemed to make sense to do the lot at once.
  • It'd be much nicer to have ADTs that reflected the fact that cards with different cardType values have different types of metadata. I've left that for now, as this PR was already large, but it'd be good to do this in another PR on both client and server.

Checklist

General

  • 🤖 Relevant tests added
  • ✅ CI checks / tests run locally
  • 🔍 Checked on CODE

Client

  • 🚫 No obvious console errors on the client (i.e. React dev mode errors)
  • 🎛️ No regressions with existing user interactions (i.e. all existing buttons, inputs etc. work)
  • 📷 Screenshots / GIFs of relevant UI changes included

@jonathonherbert jonathonherbert requested a review from a team as a code owner June 3, 2024 16:01
lightBackgroundHex: '#F9F9F5',
darkForegroundHex: '#F0C5B4',
darkBackgroundHex: '#363632',
imageURL: 'https://uploads.guim.co.uk/2024/03/21/Potatos.png',
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick #1: Potatoes :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ikr? not my images 😅

lightBackgroundHex: '#F9F9F5',
darkForegroundHex: '#ACD8E5',
darkBackgroundHex: '#363632',
imageURL: 'https://uploads.guim.co.uk/2024/03/21/TVsbacks.png',
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick #2: TVsnacks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as above, but we could always rename 'em, it's somewhat irritating

Copy link
Contributor

@fredex42 fredex42 left a comment

Choose a reason for hiding this comment

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

Like it! I made some comments which I hope are helpful, though feel free to disregard as I don't know the frontend code on this project well

@jonathonherbert jonathonherbert force-pushed the jsh/chef-overrides branch 4 times, most recently from 0238025 to 53b15b5 Compare June 6, 2024 16:21
Copy link
Contributor

@emdash-ie emdash-ie left a comment

Choose a reason for hiding this comment

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

I haven’t yet run this locally, but it looks good to me! I have some questions below, but I’m happy to merge as-is as well :)


return (
<ConnectedChefForm
chef={chef}
chefWithoutOverrides={chefWithoutOverrides}
card={card}
initialValues={initialValues}
initialValues={card.meta as ChefCardMeta}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, a comment here explaining why this cast is ok might be helpful

Copy link
Contributor Author

@jonathonherbert jonathonherbert Jun 13, 2024

Choose a reason for hiding this comment

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

👍 this should go away with a larger refactor: comment added in 8cb223e.

return undefined;
}

return formValues[fieldName] as Palette;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this as Palette needed, given the type for formValues above? I wouldn’t have expected it to be, but I have not checked!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Frustratingly, I think Object.entries will not give a union type for the object keys, even if they're known type – we just get string, requiring a cast further downstream.

In reminding myself why Typescript behaves this way, I stumbled across the first answer in this post on stackoverflow, which was very informative, and gave a few examples of a better-typed implementation! I've added that in 10213da. Thanks for the prompt, this is nicer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, good! Nice to have some clearer types. I don’t quite see how Object.entries is relevant here though: since the code declares the type of formValues to be {[T: string]: Palette;}, I’m quite surprised that the compiler can’t tell the type of formValues[fieldName] must be Palette. But also: why is the check if (!formValues) needed? (Maybe the type given for formValues should include undefined, and this is what’s confusing the compiler?)

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you can remove as Palette without getting any complaints from the compiler. But I guess there’s no real need: it doesn’t provide any benefits, especially as I think the type of getFormValues(formName) is any => any.

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 think I read your comment as relating to as PaletteId! The improvements above are fine, but spot on, this is not needed. Possibly artefact from previous model where keys were a union. 564fab7

darkBackgroundHex: '#363632',
imageURL: 'https://uploads.guim.co.uk/2024/03/21/Celebration.png',
},
'Celebration\nCakes': {
Copy link
Contributor

Choose a reason for hiding this comment

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

A newline in a key?? I assume this is outside our control, but it sure is strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're stuck for now, but I will point this out to Feast. It's weird.

@jonathonherbert jonathonherbert force-pushed the jsh/chef-overrides branch 2 times, most recently from 7ac4285 to 4a2a80b Compare June 13, 2024 20:20
jonathonherbert and others added 9 commits June 20, 2024 10:12
Co-authored-by: Jonathon Herbert <jonathon.herbert@guardian.co.uk>
…on drop (#1591)

* use hard coded constant so all trails are required to be portrait

* allow grid to select either image type, add state for the dimension of the selected replacement image, use to style the ImageContainer

* bug fix? aspect ratio test should use absolute difference

* use the criteria to set the gird url, not a separate prop

* export the default trail image criteria from constants

* remove unused imports

* shorted var name, comments about use of constant criteria

* add selectCollectionType selector

* provide the collection type to the InputImage

* add feature switch for whether to allow portrait crops

* if the feature switch is enabled, set criteria based on collection type

* dont change the FeatureSwitch class - just hide the new one client-side

* provide criteria to slideshow

* dont need state for imageDims - can get from props.input.value

* remove collection type from render

* use horrendous css funcions to style the image containers for small portraits in slideshows

* wrangle the css for ImageContainer

* move the image container to own file

* validate image error distinguishes between 'no crops' and 'no matching crops'

* dont use the default criteria

* move constants to constants/image

* Card components check the collection type to set criteria for image drops

* add TO DO about dragging images from card to card

* cards check replacement image dimensions and style thumbnails to display portraits right

* validate dimensions of incoming dragged images from other cards

* undo switch change

* more coherent comments

* update tests to account for more specific error messaging

* message correctly when crops fail validation of a criteria without aspect ratio

* refactor validation to reduce duplication of dimension criteria checks

* add a crop icon next to the Collection title if it uses 5:4 crops

* remove import

* don't show the crop icon with feature switch off

* remove test value from COLLECTIONS_USING_PORTRAIT_TRAILS

* define type for empty string array
@jonathonherbert jonathonherbert merged commit 7764593 into main Jun 20, 2024
9 checks passed
@jonathonherbert jonathonherbert deleted the jsh/chef-overrides branch June 20, 2024 09:38
@prout-bot
Copy link

Seen on PROD (merged by @jonathonherbert 9 minutes and 32 seconds ago) Please check your changes!

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

Successfully merging this pull request may close these issues.

7 participants