1
- import { empty } from '#sugar' ;
1
+ import { compareArrays , empty } from '#sugar' ;
2
2
3
3
export default {
4
4
contentDependencies : [
@@ -8,75 +8,155 @@ export default {
8
8
9
9
extraDependencies : [ 'html' , 'language' ] ,
10
10
11
- query : ( contributions ) => ( {
12
- normalContributions :
13
- contributions
14
- . filter ( contrib => ! contrib . annotation ?. startsWith ( `edits for wiki` ) ) ,
11
+ query : ( creditContributions , contextContributions ) => {
12
+ const query = { } ;
15
13
16
- wikiEditContributions :
17
- contributions
18
- . filter ( contrib => contrib . annotation ?. startsWith ( `edits for wiki` ) ) ,
19
- } ) ,
14
+ const featuringFilter = contribution =>
15
+ contribution . annotation === 'featuring' ;
16
+
17
+ const wikiEditFilter = contribution =>
18
+ contribution . annotation ?. startsWith ( 'edits for wiki' ) ;
19
+
20
+ const normalFilter = contribution =>
21
+ ! featuringFilter ( contribution ) &&
22
+ ! wikiEditFilter ( contribution ) ;
23
+
24
+ query . normalContributions =
25
+ creditContributions . filter ( normalFilter ) ;
26
+
27
+ query . featuringContributions =
28
+ creditContributions . filter ( featuringFilter ) ;
20
29
21
- relations : ( relation , query , _contributions ) => ( {
22
- contributionLinks :
30
+ query . wikiEditContributions =
31
+ creditContributions . filter ( wikiEditFilter ) ;
32
+
33
+ const contextNormalContributions =
34
+ contextContributions . filter ( normalFilter ) ;
35
+
36
+ query . normalContributionsAreDifferent =
37
+ ! compareArrays (
38
+ query . normalContributions . map ( ( { artist} ) => artist ) ,
39
+ contextNormalContributions . map ( ( { artist} ) => artist ) ,
40
+ { checkOrder : false } ) ;
41
+
42
+ return query ;
43
+ } ,
44
+
45
+ relations : ( relation , query , _creditContributions , _contextContributions ) => ( {
46
+ normalContributionLinks :
23
47
query . normalContributions
24
48
. map ( contrib => relation ( 'linkContribution' , contrib ) ) ,
25
49
50
+ featuringContributionLinks :
51
+ query . featuringContributions
52
+ . map ( contrib => relation ( 'linkContribution' , contrib ) ) ,
53
+
26
54
wikiEditsPart :
27
55
relation ( 'generateArtistCreditWikiEditsPart' ,
28
56
query . wikiEditContributions ) ,
29
57
} ) ,
30
58
31
- data : ( query , _contributions ) => ( {
59
+ data : ( query , _creditContributions , _contextContributions ) => ( {
60
+ normalContributionsAreDifferent :
61
+ query . normalContributionsAreDifferent ,
62
+
32
63
hasWikiEdits :
33
64
! empty ( query . wikiEditContributions ) ,
34
65
} ) ,
35
66
36
67
slots : {
37
- showAnnotation : { type : 'boolean' , default : true } ,
38
- showExternalLinks : { type : 'boolean' , default : true } ,
39
- showChronology : { type : 'boolean' , default : true } ,
68
+ // This string is mandatory.
69
+ normalStringKey : { type : 'string' } ,
70
+
71
+ // This string is optional.
72
+ // Without it, there's no special behavior for "featuring" credits.
73
+ normalFeaturingStringKey : { type : 'string' } ,
74
+
75
+ // This string is optional.
76
+ // Without it, "featuring" credits will always be alongside main credits.
77
+ // It won't be used if contextContributions isn't provided.
78
+ featuringStringKey : { type : 'string' } ,
79
+
80
+ showAnnotation : { type : 'boolean' , default : false } ,
81
+ showExternalLinks : { type : 'boolean' , default : false } ,
82
+ showChronology : { type : 'boolean' , default : false } ,
83
+ showWikiEdits : { type : 'boolean' , default : false } ,
40
84
41
85
trimAnnotation : { type : 'boolean' , default : false } ,
42
86
43
87
chronologyKind : { type : 'string' } ,
44
-
45
- stringKey : { type : 'string' } ,
46
88
} ,
47
89
48
- generate ( data , relations , slots , { language} ) {
49
- const contributionsList =
50
- language . formatConjunctionList (
51
- relations . contributionLinks . map ( link =>
52
- link . slots ( {
53
- showAnnotation : slots . showAnnotation ,
54
- showExternalLinks : slots . showExternalLinks ,
55
- showChronology : slots . showChronology ,
56
-
57
- trimAnnotation : slots . trimAnnotation ,
58
-
59
- chronologyKind : slots . chronologyKind ,
60
- } ) ) ) ;
61
-
62
- return language . $ ( slots . stringKey , {
63
- [ language . onlyIfOptions ] : [ 'artists' ] ,
64
-
65
- artists :
66
- ( data . hasWikiEdits
67
- ? language . encapsulate ( 'misc.artistLink.withEditsForWiki' , capsule =>
68
- language . $ ( capsule , {
69
- // It's nonsense to display "+ edits" without
70
- // having any regular contributions, also.
71
- [ language . onlyIfOptions ] : [ 'artists' ] ,
72
-
73
- artists : contributionsList ,
74
- edits :
75
- relations . wikiEditsPart . slots ( {
76
- showAnnotation : slots . showAnnotation ,
77
- } ) ,
78
- } ) )
79
- : contributionsList ) ,
80
- } ) ;
90
+ generate ( data , relations , slots , { html, language} ) {
91
+ if ( ! slots . normalStringKey ) return html . blank ( ) ;
92
+
93
+ for ( const link of [
94
+ ...relations . normalContributionLinks ,
95
+ ...relations . featuringContributionLinks ,
96
+ ] ) {
97
+ link . setSlots ( {
98
+ showExternalLinks : slots . showExternalLinks ,
99
+ showChronology : slots . showChronology ,
100
+ trimAnnotation : slots . trimAnnotation ,
101
+ chronologyKind : slots . chronologyKind ,
102
+ } ) ;
103
+ }
104
+
105
+ for ( const link of relations . normalContributionLinks ) {
106
+ link . setSlots ( {
107
+ showAnnotation : slots . showAnnotation ,
108
+ } ) ;
109
+ }
110
+
111
+ for ( const link of relations . featuringContributionLinks ) {
112
+ link . setSlots ( {
113
+ showAnnotation : false ,
114
+ } ) ;
115
+ }
116
+
117
+ if ( empty ( relations . normalContributionLinks ) ) {
118
+ return html . blank ( ) ;
119
+ }
120
+
121
+ const artistsList =
122
+ ( data . hasWikiEdits && slots . showWikiEdits
123
+ ? language . $ ( 'misc.artistLink.withEditsForWiki' , {
124
+ artists :
125
+ language . formatConjunctionList ( relations . normalContributionLinks ) ,
126
+
127
+ edits :
128
+ relations . wikiEditsPart . slots ( {
129
+ showAnnotation : slots . showAnnotation ,
130
+ } ) ,
131
+ } )
132
+ : language . formatConjunctionList ( relations . normalContributionLinks ) ) ;
133
+
134
+ const featuringList =
135
+ language . formatConjunctionList ( relations . featuringContributionLinks ) ;
136
+
137
+ const everyoneList =
138
+ language . formatConjunctionList ( [
139
+ ...relations . normalContributionLinks ,
140
+ ...relations . featuringContributionLinks ,
141
+ ] ) ;
142
+
143
+ if ( empty ( relations . featuringContributionLinks ) ) {
144
+ if ( data . normalContributionsAreDifferent ) {
145
+ return language . $ ( slots . normalStringKey , { artists : artistsList } ) ;
146
+ } else {
147
+ return html . blank ( ) ;
148
+ }
149
+ }
150
+
151
+ if ( data . normalContributionsAreDifferent && slots . normalFeaturingStringKey ) {
152
+ return language . $ ( slots . normalFeaturingStringKey , {
153
+ artists : artistsList ,
154
+ featuring : featuringList ,
155
+ } ) ;
156
+ } else if ( slots . featuringStringKey ) {
157
+ return language . $ ( slots . featuringStringKey , { artists : featuringList } ) ;
158
+ } else {
159
+ return language . $ ( slots . normalStringKey , { artists : everyoneList } ) ;
160
+ }
81
161
} ,
82
162
} ;
0 commit comments