Skip to content

Commit

Permalink
Update fronts config tool with new container level tags (#1712)
Browse files Browse the repository at this point in the history
* bump fapi client to v12.1

* Hide primary tag from the options in the tag selector dropdown

* Add check to ensure beta containers have the appropriate primary/secondary tag

* Account for edge case where both primary and secondary are in the list of tags

* Add comments and make code easier to read
  • Loading branch information
Georges-GNM authored Nov 4, 2024
1 parent 51dac62 commit 16dc41b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ libraryDependencies ++= Seq(
"com.gu" %% "content-api-client-aws" % "0.6",
"com.gu" %% "content-api-client-default" % capiClientVersion,
"com.gu" %% "editorial-permissions-client" % "3.0.0",
"com.gu" %% "fapi-client-play30" % "12.0.0",
"com.gu" %% "fapi-client-play30" % "12.1.0",
"com.gu" %% "mobile-notifications-api-models" % "3.0.0",
"com.gu" %% "pan-domain-auth-play_3-0" % "4.0.0",

Expand Down
5 changes: 4 additions & 1 deletion public/src/js/models/common-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ ko.bindingHandlers.tagSelector = {
});
return parsed;
}, []);
return parsedData;
// The primary tag is the default for specific containers (e.g. scrollable/small).
// Because of this, we don't want it as an option in the dropdown menu.
const parsedDataWithoutPrimaryTag = parsedData.filter(item => item.text !== 'Primary');
return parsedDataWithoutPrimaryTag;
}
});
}
Expand Down
19 changes: 19 additions & 0 deletions public/src/js/models/config/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ export default class ConfigCollection extends DropTarget {
return;
}

// The BetaCollection containers need a Primary or Secondary tag indicating its level.
if (this.thisIsBetaCollection()) {
const hasPrimaryTag = this.meta.metadata().some(tag => tag.type === 'Primary');
const hasSecondaryTag = this.meta.metadata().some(tag => tag.type === 'Secondary');

// If no tags are set, or if neither Primary nor Secondary tags are set, we default the container to Primary.
if (this.meta.metadata() === undefined) {
this.meta.metadata([{ type: 'Primary' }]);
}
if (!hasPrimaryTag && !hasSecondaryTag) {
this.meta.metadata().push({ type: 'Primary' });}
if (hasPrimaryTag && hasSecondaryTag) {
// If both tags are present, we assume the intention was to set the container to Secondary
// So we remove the primary tag from the metadata.
const updatedTags = this.meta.metadata().filter(tag => tag.type !== 'Primary');
this.meta.metadata(updatedTags);
}
}

this.meta.href(urlAbsPath(this.meta.href()));

this.state.isOpen(false);
Expand Down

0 comments on commit 16dc41b

Please sign in to comment.