Skip to content

Commit 11c5865

Browse files
Matus Kasakclaude
andcommitted
ZCU-PUB/feat(community): also apply "Články" 3rd order in the community browse tree (#953)
The initial fix only reordered the community *detail* page (the themed sub-collection list). The "Communities & Collections" browse tree (/community-list) renders collections through CommunityListService and was still showing the default alphabetical order (Články last). Extract the ordering rule into a shared pure helper (shared/zcu-collection-order.ts) and apply it in both places: - the custom-theme sub-collection-list override (delegates to the helper), - CommunityListService (reorders each fetched collection page in the tree). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 9314ef7 commit 11c5865

4 files changed

Lines changed: 115 additions & 25 deletions

File tree

src/app/community-list-page/community-list-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ShowMoreFlatNode } from './show-more-flat-node.model';
2525
import { FindListOptions } from '../core/data/find-list-options.model';
2626
import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface';
2727
import { v4 as uuidv4 } from 'uuid';
28+
import { reorderZcuPublicationCollections } from '../shared/zcu-collection-order';
2829

2930
// Helper method to combine and flatten an array of observables of flatNode arrays
3031
export const combineAndFlatten = (obsList: Observable<FlatNode[]>[]): Observable<FlatNode[]> =>
@@ -255,7 +256,8 @@ export class CommunityListService {
255256
getFirstCompletedRemoteData(),
256257
map((rd: RemoteData<PaginatedList<Collection>>) => {
257258
if (hasValue(rd) && hasValue(rd.payload)) {
258-
let nodes = rd.payload.page
259+
// issue #953: apply the ZCU collection display order in the community browse tree
260+
let nodes = reorderZcuPublicationCollections(rd.payload.page)
259261
.map((collection: Collection) => toFlatNode(collection, observableOf(false), level + 1, false, communityFlatNode));
260262
if (currentCollectionPage < rd.payload.totalPages && currentCollectionPage === rd.payload.currentPage) {
261263
nodes = [...nodes, showMoreFlatNode(`collection-${uuidv4()}`, level + 1, communityFlatNode)];
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Collection } from '../core/shared/collection.model';
2+
import {
3+
reorderZcuPublicationCollections,
4+
ZCU_SECOND_COLLECTION_NAME,
5+
ZCU_THIRD_COLLECTION_NAME,
6+
} from './zcu-collection-order';
7+
8+
/**
9+
* Builds a minimal Collection-like stub that only exposes the `name` getter used by the ordering.
10+
*
11+
* @param name the collection name (dc.title) to expose
12+
* @returns an object typed as Collection for the purposes of these tests
13+
*/
14+
function fakeCollection(name: string): Collection {
15+
return { get name(): string { return name; } } as Collection;
16+
}
17+
18+
/**
19+
* Maps a list of collections to their names for concise assertions.
20+
*
21+
* @param collections the collections to map
22+
* @returns the ordered list of collection names
23+
*/
24+
function names(collections: Collection[]): string[] {
25+
return collections.map((collection: Collection) => collection.name);
26+
}
27+
28+
describe('reorderZcuPublicationCollections', () => {
29+
it('uses the exact diacritic pinned names', () => {
30+
expect(ZCU_SECOND_COLLECTION_NAME).toBe('Kapitoly v knihách');
31+
expect(ZCU_THIRD_COLLECTION_NAME).toBe('Články');
32+
});
33+
34+
it('pins "Články" to the 3rd position, directly after "Kapitoly v knihách"', () => {
35+
const input = [
36+
fakeCollection('Knihy'),
37+
fakeCollection(ZCU_SECOND_COLLECTION_NAME),
38+
fakeCollection('Zprávy'),
39+
fakeCollection(ZCU_THIRD_COLLECTION_NAME),
40+
];
41+
42+
const result = reorderZcuPublicationCollections(input);
43+
44+
expect(result[2].name).toBe(ZCU_THIRD_COLLECTION_NAME);
45+
expect(names(result).indexOf(ZCU_THIRD_COLLECTION_NAME))
46+
.toBe(names(result).indexOf(ZCU_SECOND_COLLECTION_NAME) + 1);
47+
expect(names(result)).toEqual(['Knihy', ZCU_SECOND_COLLECTION_NAME, ZCU_THIRD_COLLECTION_NAME, 'Zprávy']);
48+
});
49+
50+
it('leaves the list unchanged when a pinned collection is missing', () => {
51+
expect(names(reorderZcuPublicationCollections([
52+
fakeCollection('Knihy'), fakeCollection(ZCU_THIRD_COLLECTION_NAME),
53+
]))).toEqual(['Knihy', ZCU_THIRD_COLLECTION_NAME]);
54+
55+
expect(names(reorderZcuPublicationCollections([
56+
fakeCollection('Knihy'), fakeCollection(ZCU_SECOND_COLLECTION_NAME),
57+
]))).toEqual(['Knihy', ZCU_SECOND_COLLECTION_NAME]);
58+
});
59+
60+
it('leaves the list unchanged when there are no other collections', () => {
61+
expect(names(reorderZcuPublicationCollections([
62+
fakeCollection(ZCU_SECOND_COLLECTION_NAME), fakeCollection(ZCU_THIRD_COLLECTION_NAME),
63+
]))).toEqual([ZCU_SECOND_COLLECTION_NAME, ZCU_THIRD_COLLECTION_NAME]);
64+
});
65+
66+
it('handles empty and single-element input without error', () => {
67+
expect(reorderZcuPublicationCollections([])).toEqual([]);
68+
expect(names(reorderZcuPublicationCollections([fakeCollection('Knihy')]))).toEqual(['Knihy']);
69+
});
70+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Collection } from '../core/shared/collection.model';
2+
3+
/**
4+
* Name of the collection pinned to the 2nd position for the ZCU publications community (issue #953).
5+
*/
6+
export const ZCU_SECOND_COLLECTION_NAME = 'Kapitoly v knihách';
7+
8+
/**
9+
* Name of the collection pinned to the 3rd position for the ZCU publications community (issue #953).
10+
*/
11+
export const ZCU_THIRD_COLLECTION_NAME = 'Články';
12+
13+
/**
14+
* Reorders a list of collections so that "Kapitoly v knihách" is shown 2nd and "Články" 3rd, while
15+
* every other collection keeps its original (alphabetical) order. This is the ZCU-specific hardcode
16+
* for issue #953, shared by every place that lists a community's collections (the community page and
17+
* the community browse tree).
18+
*
19+
* The rule only applies when both pinned collections are present and there is at least one other
20+
* collection; otherwise the list is returned unchanged. The result is
21+
* `[others[0], second, third, ...others.slice(1)]`.
22+
*
23+
* @param collections the collections to reorder (as fetched, alphabetical by dc.title)
24+
* @returns a new, reordered array, or the original array when the rule does not apply
25+
*/
26+
export function reorderZcuPublicationCollections(collections: Collection[]): Collection[] {
27+
if (!Array.isArray(collections) || collections.length === 0) {
28+
return collections;
29+
}
30+
const second = collections.find((collection: Collection) => collection.name === ZCU_SECOND_COLLECTION_NAME);
31+
const third = collections.find((collection: Collection) => collection.name === ZCU_THIRD_COLLECTION_NAME);
32+
const others = collections.filter((collection: Collection) => collection !== second && collection !== third);
33+
34+
if (second && third && others.length >= 1) {
35+
return [others[0], second, third, ...others.slice(1)];
36+
}
37+
return collections;
38+
}

src/themes/custom/app/community-page/sub-collection-list/community-page-sub-collection-list.component.ts

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@ import { CommunityPageSubCollectionListComponent as BaseComponent }
44
import { RemoteData } from '../../../../../app/core/data/remote-data';
55
import { PaginatedList } from '../../../../../app/core/data/paginated-list.model';
66
import { Collection } from '../../../../../app/core/shared/collection.model';
7-
8-
/**
9-
* Name of the collection pinned to the 2nd position for the ZCU publications community.
10-
*/
11-
const SECOND_COLLECTION_NAME = 'Kapitoly v knihách';
12-
13-
/**
14-
* Name of the collection pinned to the 3rd position for the ZCU publications community.
15-
*/
16-
const THIRD_COLLECTION_NAME = 'Články';
7+
import { reorderZcuPublicationCollections } from '../../../../../app/shared/zcu-collection-order';
178

189
@Component({
1910
selector: 'ds-community-page-sub-collection-list',
@@ -40,25 +31,14 @@ export class CommunityPageSubCollectionListComponent extends BaseComponent {
4031
}
4132

4233
/**
43-
* Pure helper that reorders a list of collections to pin "Kapitoly v knihách" to the 2nd
44-
* position and "Články" to the 3rd, keeping every other collection in its original order.
45-
*
46-
* The rule only applies when both pinned collections are present and there is at least one
47-
* other collection; otherwise the list is returned unchanged. The result is
48-
* `[others[0], second, third, ...others.slice(1)]`.
34+
* Reorders the current page of collections using the shared ZCU ordering rule (issue #953),
35+
* pinning "Kapitoly v knihách" to the 2nd position and "Články" to the 3rd.
4936
*
5037
* @param collections the collections of the current page (alphabetical by dc.title)
5138
* @returns a new, reordered array, or the original array when the rule does not apply
5239
*/
5340
protected reorderCollections(collections: Collection[]): Collection[] {
54-
const second = collections.find((collection: Collection) => collection.name === SECOND_COLLECTION_NAME);
55-
const third = collections.find((collection: Collection) => collection.name === THIRD_COLLECTION_NAME);
56-
const others = collections.filter((collection: Collection) => collection !== second && collection !== third);
57-
58-
if (second && third && others.length >= 1) {
59-
return [others[0], second, third, ...others.slice(1)];
60-
}
61-
return collections;
41+
return reorderZcuPublicationCollections(collections);
6242
}
6343

6444
}

0 commit comments

Comments
 (0)