Skip to content

Commit

Permalink
Reinstate groups (WIP)
Browse files Browse the repository at this point in the history
We will need them until all clients are on latest model
  • Loading branch information
Fweddi committed Feb 26, 2025
1 parent 2201248 commit 740e2ca
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 16 deletions.
1 change: 1 addition & 0 deletions fronts-client/src/fixtures/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ const collectionConfig: CollectionConfig = {
id: 'exampleCollection',
displayName: 'Example Collection',
type: 'any',
groups: ['large', 'medium', 'small'],
groupsConfig: [{
name: 'large',
maxItems: 10,
Expand Down
2 changes: 1 addition & 1 deletion fronts-client/src/types/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface Group {

interface GroupConfig {
name: string;
maxItems: number | null;
maxItems?: number;
}

/** CardSets represent all of the lists of cards available in a collection. */
Expand Down
2 changes: 2 additions & 0 deletions fronts-client/src/types/FaciaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface CollectionConfigResponse {
type?: string;
backfill?: unknown;
href?: string;
groups?: string[];
groupsConfig?: GroupConfig[];
metadata?: unknown[];
uneditable?: boolean;
Expand Down Expand Up @@ -116,6 +117,7 @@ export interface EditionCollectionFromResponse {
platform?: string;
displayName: string;
groups?: string[];
groupsConfig?: GroupConfig[];
metadata?: Array<{ type: string }>;
uneditable?: boolean;
isHidden?: boolean;
Expand Down
8 changes: 4 additions & 4 deletions fronts-client/src/util/__tests__/shared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('Shared utilities', () => {
expect(result.cards[prevGroup3.cards[0]].id).toBe('article/live/3');
});
it('should insert a default group for empty collections', () => {
const { groupsConfig, ...collectionConfigWithoutGroups } = collectionConfig;
const { groups, ...collectionConfigWithoutGroups } = collectionConfig;
const result = normaliseCollectionWithNestedArticles(
{
...collection,
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('Shared utilities', () => {
collectionWithoutGroups,
{
...collectionConfig,
groupsConfig: undefined,
groups: undefined,
},
);
const groupId = result.normalisedCollection.live![0];
Expand All @@ -154,7 +154,7 @@ describe('Shared utilities', () => {
it('should create different groups for cards belonging to different groups even if they are not specified in the config', () => {
const result = normaliseCollectionWithNestedArticles(collection, {
...collectionConfig,
groupsConfig: undefined,
groups: undefined,
});
const groupId1 = result.normalisedCollection.live![0];
expect(result.groups[groupId1].cards).toHaveLength(1);
Expand All @@ -168,7 +168,7 @@ describe('Shared utilities', () => {
};
const result = normaliseCollectionWithNestedArticles(collection, {
...configWithExtraGroup,
groupsConfig: undefined,
groups: undefined,
});
expect(Object.keys(result.groups)).toHaveLength(4);
});
Expand Down
1 change: 1 addition & 0 deletions fronts-client/src/util/frontsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const combineCollectionWithConfig = (
displayName: useCollectionDisplayName
? collection.displayName
: collectionConfig.displayName,
groups: collectionConfig.groups,
groupsConfig: collectionConfig.groupsConfig,
type: collectionConfig.type,
frontsToolSettings: collectionConfig.frontsToolSettings,
Expand Down
12 changes: 6 additions & 6 deletions fronts-client/src/util/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ const addGroupsForStage = (
let name: string | null = null;
const groupNumberAsInt = getGroupIndex(group.id);
if (
collectionConfig.groupsConfig &&
groupNumberAsInt < collectionConfig.groupsConfig.length
collectionConfig.groups &&
groupNumberAsInt < collectionConfig.groups.length
) {
name = collectionConfig.groupsConfig[groupNumberAsInt].name;
name = collectionConfig.groups[groupNumberAsInt];
}
return { ...group, name };
});

// We may have empty groups in the config which would not show up in the normalised
// groups result. We need to add these into the groups array.
if (collectionConfig.groupsConfig) {
collectionConfig.groupsConfig.forEach((groupConfig, groupConfigIndex) => {
if (collectionConfig.groups) {
collectionConfig.groups.forEach((group, groupConfigIndex) => {
if (!configGroupIndexExistsInGroups(groupsWithNames, groupConfigIndex)) {
groupsWithNames.push(createGroup(`${groupConfigIndex}`, groupConfig.name));
groupsWithNames.push(createGroup(`${groupConfigIndex}`, group));
}
});
}
Expand Down
33 changes: 33 additions & 0 deletions public/src/js/constants/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export default {
{ 'name': 'fixed/small/slow-V-half' },
{
'name': 'dynamic/fast',
'groups': [
'standard',
'big',
'very big',
'huge'
],
'groupsConfig': [
{
name: 'standard'
Expand All @@ -43,6 +49,12 @@ export default {
},
{
'name': 'dynamic/slow',
'groups': [
'standard',
'big',
'very big',
'huge'
],
'groupsConfig': [
{
name: 'standard'
Expand All @@ -60,6 +72,10 @@ export default {
},
{
'name': 'dynamic/package',
'groups': [
'standard',
'snap',

Check warning on line 77 in public/src/js/constants/defaults.js

View workflow job for this annotation

GitHub Actions / test_client_v1

Unexpected trailing comma
],
'groupsConfig': [
{
name: 'standard'
Expand All @@ -71,6 +87,10 @@ export default {
},
{
'name': 'dynamic/slow-mpu',
'groups': [
'standard',
'big',

Check warning on line 92 in public/src/js/constants/defaults.js

View workflow job for this annotation

GitHub Actions / test_client_v1

Unexpected trailing comma
],
'groupsConfig': [
{
name: 'standard'
Expand All @@ -85,6 +105,10 @@ export default {
{ 'name': 'news/most-popular' },
{
'name': 'breaking-news/not-for-other-fronts',
groups: [
'minor',
'major'
],
groupsConfig: [
{
name: 'minor'
Expand All @@ -98,6 +122,11 @@ export default {
{ 'name': 'scrollable/highlights' },
{
'name': 'flexible/general',
'groups': [
'small',
'large',
'splash'
],
'groupsConfig': [
{
name: 'small',
Expand All @@ -115,6 +144,10 @@ export default {
},
{
'name': 'flexible/special',
'groups': [
'standard',
'snap',

Check warning on line 149 in public/src/js/constants/defaults.js

View workflow job for this annotation

GitHub Actions / test_client_v1

Unexpected trailing comma
],
'groupsConfig': [
{
name: 'standard'
Expand Down
6 changes: 2 additions & 4 deletions public/src/js/widgets/columns/fronts-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,9 @@
</div>

<config-collection-tags params="tags: meta.metadata" class="tags"></config-collection-tags>
<!-- ko if: meta.groupsConfig -->
<!-- ko if: meta.groups -->
<label>Groups</label>
<div data-bind="foreach: meta.groupsConfig">
<span class="cnf-form__value" data-bind="text: name"></span>
</div>
<span class="cnf-form__value" data-bind="text: meta.groups"></span>
<!-- /ko -->

<!-- ko if: meta.type() === "flexible/general"-->
Expand Down
1 change: 1 addition & 0 deletions test/config/TransformationsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TransformationsSpec extends FlatSpec with Matchers {
displayName = Some("New collection"),
`type` = Some("???"),
href = Some("newfront"),
groups = Some(List("1", "2")),
groupsConfig = Some(List(GroupsConfigJson(name = "1", maxItems = Some(10)), GroupsConfigJson(name = "2", maxItems = Some(10)))),
uneditable = Some(false),
showTags = Some(true),
Expand Down
2 changes: 1 addition & 1 deletion test/services/CollectionServiceTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CollectionServiceTest extends FreeSpec with Matchers {
`type` = Some("dynamic/slow"),
href = None,
description = None,
groups = None,
groups = Some(List("Group 1", "Group 2")),
groupsConfig = Some(List(
GroupsConfigJson(name = "Group 1", maxItems = Some(10)),
GroupsConfigJson(name = "Group 2", maxItems = Some(10))
Expand Down

0 comments on commit 740e2ca

Please sign in to comment.