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 editable maxItems field in Config tool #1763

Merged
merged 7 commits into from
Feb 28, 2025
Merged

Conversation

Fweddi
Copy link
Contributor

@Fweddi Fweddi commented Feb 21, 2025

What's changed?

Add an editable maxItems field per 'group' (e.g. splash, standard) in a given container.

This allows the new flexible/general container to have different card groups with variable card limits.

Intended to replace the use of the maxItemsToDisplay field. Note this PR does not enforce any card limits in the Fronts Tool, this will be carried out in a future PR.

Note you will need to 'reset' the container to see the groupsConfig defaults pull through. So if you are looking at a flexible/general container in the config, you will need to change the container type to something else and then back to flexible/general.

Before After

build.sbt Outdated
@@ -83,7 +83,7 @@ libraryDependencies ++= Seq(
"com.gu" %% "content-api-client-aws" % "0.7.6",
"com.gu" %% "content-api-client-default" % capiClientVersion,
"com.gu" %% "editorial-permissions-client" % "3.0.0",
"com.gu" %% "fapi-client-play30" % "15.0.0",
"com.gu" %% "fapi-client-play30" % "16.0.0-PREVIEW.fpadd-groups-config-field.2025-02-21T1227.15f48131",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will need to swap out for 16.0.0 once guardian/facia-scala-client#345 is released.

@Fweddi Fweddi force-pushed the fp/max-items-per-group branch from 564bf14 to 9f359da Compare February 21, 2025 14:18
@Fweddi Fweddi force-pushed the fp/max-items-per-group branch 2 times, most recently from 740e2ca to 76f9439 Compare February 26, 2025 09:33
@Fweddi Fweddi force-pushed the fp/max-items-per-group branch from e7750a2 to c3c96ff Compare February 27, 2025 09:02
@Fweddi Fweddi changed the title Allow each group to have different maxItems Add editable maxItems field in Config tool Feb 27, 2025
@Fweddi Fweddi force-pushed the fp/max-items-per-group branch 4 times, most recently from b7605a8 to 13fc4ef Compare February 27, 2025 15:09
@Fweddi Fweddi marked this pull request as ready for review February 27, 2025 15:10
@Fweddi Fweddi requested a review from a team as a code owner February 27, 2025 15:10
@Fweddi Fweddi self-assigned this Feb 27, 2025
@Fweddi Fweddi force-pushed the fp/max-items-per-group branch 2 times, most recently from 6cb9177 to f50a18c Compare February 27, 2025 16:28
@@ -65,7 +68,8 @@ function flattenModel (model) {
return _.reduce(model, function (accumulator, value, key) {
var x = flattenValue(value);

if (x) {
// We want to drop falsy values, but not 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cf. #682

This pr also cleans all falsy values and empty arrays from the meta object to correspond with what is saved in the meta by v1 and avoid any obscure future bugs.

There are a couple of places in the tests where we are explicitly testing falsy values are filtered out, so this seemed the minimum change to allow us to support 0 as a value.

0 as a value is useful as it lets config editors know that a group (e.g. Very Big) has explicitly been set to 0 rather than it is unset and waiting to be filled in.

display: inline-block;
}

.capitalize-first-letter:first-letter {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This means we can write 'very big' as 'Very big' (and not 'Very Big' which text-transform: capitalize would do if left to its own devices).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Stakeholder request)

@Fweddi
Copy link
Contributor Author

Fweddi commented Feb 27, 2025

It would be good to have future PRs to:

  1. remove all references to groups in place of groupsConfig
  2. allow some groupConfig maxItems to not be editable - specifically, splash, which should only ever be one card*.
  3. fix suppressImages (a boolean) being instantiated with observableNumeric - it works, because observableNumeric is slightly odd, but it shouldn't be instantiated this way

*At least, at this current moment...

Copy link
Member

@davidfurey davidfurey left a comment

Choose a reason for hiding this comment

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

👏
I've made a few non-blocking suggestions

@@ -65,7 +68,8 @@ function flattenModel (model) {
return _.reduce(model, function (accumulator, value, key) {
var x = flattenValue(value);

if (x) {
// We want to drop falsy values, but not 0
if (x || x === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

@@ -8,7 +8,7 @@ export default function(initialValue) {
},
write(newValue) {
var parsedValue = parseFloat(newValue);
actual(isNaN(parsedValue) ? newValue : parsedValue);
actual(isNaN(parsedValue) ? newValue : Math.abs(parsedValue));
Copy link
Member

Choose a reason for hiding this comment

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

Is the Math.abs required? This is slightly unexpected behaviour for something called "observable-numeric"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It prevents us from modelling negative numbers. This code is invoked in the few cases we expect numbers, and we have already checked at this stage that the variable definitely is a number. Happy to jettison it or move it elsewhere though.

Copy link
Member

Choose a reason for hiding this comment

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

We plan to EOL this app so it is not really a problem for this API to be confusing, let's leave as is.
(with apologies to me or other future developer who gets bitten by this in 5 years time when we are still using this code)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps we can address this when we fix the suppressImages being treated as an observableNumeric.

<!-- ko if: meta.type() === "flexible/general"-->
<div data-bind="foreach: meta.groupsConfig">
<label for="flexGenSplashStoryLimit"><span data-bind="text: name" class="capitalize-first-letter"></span> stories</label>
<input id="flexGenSplashStoryLimit" type="number" data-bind="value: maxItems" attr: { max: 20, min: 0 } max="20" min="0">
Copy link
Member

Choose a reason for hiding this comment

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

id should be unique, and "SplashStory" in the id is no longer accurate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actioned

@davidfurey
Copy link
Member

It would be good to have future PRs to:

  1. remove all references to groups in place of groupsConfig
  2. allow some groupConfig maxItems to not be editable - specifically, splash, which should only ever be one card*.
  3. fix suppressImages (a boolean) being instantiated with observableNumeric - it works, because observableNumeric is slightly odd, but it shouldn't be instantiated this way

*At least, at this current moment...

When we do 1. we need to make sure that groupsConfig is populated without someone having to go through each container and changing the type backwards/forwards.

For 2., if rendering platforms can handle multi splash cards, JH has no concerns about the tool allowing it. Even if the platforms cannot handle it, he is still fairly relaxed about this.

@Fweddi
Copy link
Contributor Author

Fweddi commented Feb 27, 2025

It would be good to have future PRs to:

  1. remove all references to groups in place of groupsConfig
  2. allow some groupConfig maxItems to not be editable - specifically, splash, which should only ever be one card*.
  3. fix suppressImages (a boolean) being instantiated with observableNumeric - it works, because observableNumeric is slightly odd, but it shouldn't be instantiated this way

*At least, at this current moment...

When we do 1. we need to make sure that groupsConfig is populated without someone having to go through each container and changing the type backwards/forwards.

For 2., if rendering platforms can handle multi splash cards, JH has no concerns about the tool allowing it. Even if the platforms cannot handle it, he is still fairly relaxed about this.

Thank you for clarifying 2 as I'd expected us to want to keep the hard limit introduced in #1753.

@davidfurey
Copy link
Member

Thank you for clarifying 2 as I'd expected us to want to keep the hard limit introduced in #1753.

It is fine for the hard-limit to be controlled by configuration, rather than hardcoded.

Comment on lines 264 to 265
<label data-bind="attr: { for: name }"><span data-bind="text: name" class="capitalize-first-letter"></span> stories</label>
<input type="number" data-bind="value: maxItems, attr: { id: name, max: 20, min: 0 }" max="20" min="0">
Copy link
Member

Choose a reason for hiding this comment

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

I don't think ids can have whitespace. Perhaps this will work (untested):
attr: { for: 'maxItems-' + $index }

@Fweddi Fweddi force-pushed the fp/max-items-per-group branch from 8380b3d to 1e2dad6 Compare February 28, 2025 10:18
@Fweddi Fweddi force-pushed the fp/max-items-per-group branch from 1e2dad6 to 3d0888b Compare February 28, 2025 10:21
@Fweddi Fweddi merged commit af340ac into main Feb 28, 2025
13 checks passed
@Fweddi Fweddi deleted the fp/max-items-per-group branch February 28, 2025 10:33
@prout-bot
Copy link

Seen on PROD (merged by @Fweddi 6 minutes and 22 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.

4 participants