Skip to content

Commit ccb7a64

Browse files
committed
Make list of attribute types more usable
This splits the list in two, one for entity types and one for everything else. It also sorts them by the (translated) names of the attribute types, rather than by the static model name.
1 parent 17d45a4 commit ccb7a64

File tree

4 files changed

+108
-65
lines changed

4 files changed

+108
-65
lines changed

lib/MusicBrainz/Server/Controller/Attributes.pm

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,32 @@ use MusicBrainz::Server::Translation qw( l );
1010

1111
BEGIN { extends 'MusicBrainz::Server::Controller' }
1212

13-
my @models = qw(
13+
my @entity_type_models = qw(
1414
AreaType
1515
ArtistType
1616
CollectionType
17-
CoverArtType
1817
EventType
19-
Gender
2018
InstrumentType
2119
LabelType
22-
Language
23-
MediumFormat
2420
PlaceType
2521
ReleaseGroupType
2622
ReleaseGroupSecondaryType
23+
SeriesType
24+
WorkType
25+
);
26+
27+
my @other_models = qw(
28+
CoverArtType
29+
Gender
30+
Language
31+
MediumFormat
2732
ReleaseStatus
2833
ReleasePackaging
2934
Script
30-
SeriesType
31-
WorkType
3235
WorkAttributeType
3336
);
37+
38+
my @all_models = (@entity_type_models, @other_models);
3439
# Missing: Alias types, WorkAttributeTypeAllowedValue
3540

3641
sub index : Path('/attributes') Args(0) {
@@ -39,14 +44,17 @@ sub index : Path('/attributes') Args(0) {
3944
$c->stash(
4045
current_view => 'Node',
4146
component_path => 'attributes/Index',
42-
component_props => {models => \@models},
47+
component_props => {
48+
entityTypeModels => \@entity_type_models,
49+
otherModels => \@other_models,
50+
},
4351
);
4452
}
4553

4654
sub attribute_base : Chained('/') PathPart('attributes') CaptureArgs(1) {
4755
my ($self, $c, $model) = @_;
4856

49-
$c->detach('/error_404') unless contains_string(\@models, $model);
57+
$c->detach('/error_404') unless contains_string(\@all_models, $model);
5058

5159
$c->stash->{model} = $model;
5260
}

root/attributes/AttributeLayout.js

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,8 @@
88
*/
99

1010
import Layout from '../layout/index.js';
11-
12-
export function modelToTitle(model: string): string {
13-
switch (model) {
14-
case 'AreaType':
15-
return l('Area types');
16-
case 'ArtistType':
17-
return l('Artist types');
18-
case 'CollectionType':
19-
return l('Collection types');
20-
case 'CoverArtType':
21-
return l('Cover art types');
22-
case 'EventType':
23-
return l('Event types');
24-
case 'Gender':
25-
return l('Genders');
26-
case 'InstrumentType':
27-
return l('Instrument types');
28-
case 'LabelType':
29-
return l('Label types');
30-
case 'Language':
31-
return l('Languages');
32-
case 'MediumFormat':
33-
return l('Medium formats');
34-
case 'PlaceType':
35-
return l('Place types');
36-
case 'ReleaseGroupSecondaryType':
37-
return l('Release group secondary types');
38-
case 'ReleaseGroupType':
39-
return l('Release group primary types');
40-
case 'ReleasePackaging':
41-
return l('Release packagings');
42-
case 'ReleaseStatus':
43-
return l('Release statuses');
44-
case 'Script':
45-
return l('Scripts');
46-
case 'SeriesType':
47-
return l('Series types');
48-
case 'WorkAttributeType':
49-
return l('Work attribute types');
50-
case 'WorkType':
51-
return l('Work types');
52-
default:
53-
return model;
54-
}
55-
}
11+
import attributeModelName
12+
from '../static/scripts/common/utility/attributeModelName.js';
5613

5714
type Props = {
5815
+children: React$Node,
@@ -65,10 +22,10 @@ const AttributeLayout = ({
6522
model,
6623
showEditSections,
6724
}: Props): React$Element<typeof Layout> => (
68-
<Layout fullWidth title={modelToTitle(model)}>
25+
<Layout fullWidth title={attributeModelName(model)}>
6926
<h1>
7027
<a href="/attributes">{l('Attributes')}</a>
71-
{' / ' + modelToTitle(model)}
28+
{' / ' + attributeModelName(model)}
7229
</h1>
7330

7431
{children}

root/attributes/Index.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,44 @@
99
*/
1010

1111
import Layout from '../layout/index.js';
12+
import {sortByString} from '../static/scripts/common/utility/arrays.js';
13+
import attributeModelName
14+
from '../static/scripts/common/utility/attributeModelName.js';
1215

13-
type Props = {
14-
+models: Array<string>,
15-
};
16+
const AttributeList = ({modelList}: {modelList: Array<string>}) => {
17+
const sortedModels = sortByString(
18+
modelList,
19+
model => attributeModelName(model),
20+
);
1621

17-
const Attributes = ({models}: Props): React$Element<typeof Layout> => (
18-
<Layout fullWidth title={l('Attributes')}>
19-
<h1>{l('Attributes')}</h1>
22+
return (
2023
<ul>
21-
{models.sort().map((item) => (
22-
<li key={item}>
23-
<a href={'/attributes/' + item}>{item}</a>
24+
{sortedModels.map((model) => (
25+
<li key={model}>
26+
<a href={'/attributes/' + model}>{attributeModelName(model)}</a>
2427
</li>
2528
))}
2629
</ul>
30+
);
31+
};
32+
33+
type Props = {
34+
+entityTypeModels: Array<string>,
35+
+otherModels: Array<string>,
36+
};
37+
38+
const Attributes = ({
39+
entityTypeModels,
40+
otherModels,
41+
}: Props): React$Element<typeof Layout> => (
42+
<Layout fullWidth title={l('Attributes')}>
43+
<h1>{l('Attributes')}</h1>
44+
45+
<h2>{l('Entity types')}</h2>
46+
<AttributeList modelList={entityTypeModels} />
47+
48+
<h2>{l('Other attributes')}</h2>
49+
<AttributeList modelList={otherModels} />
2750
</Layout>
2851
);
2952

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* @flow strict
3+
* Copyright (C) 2022 MetaBrainz Foundation
4+
*
5+
* This file is part of MusicBrainz, the open internet music database,
6+
* and is licensed under the GPL version 2, or (at your option) any
7+
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
8+
*/
9+
10+
function attributeModelName(model: string): string {
11+
switch (model) {
12+
case 'AreaType':
13+
return l('Area types');
14+
case 'ArtistType':
15+
return l('Artist types');
16+
case 'CollectionType':
17+
return l('Collection types');
18+
case 'CoverArtType':
19+
return l('Cover art types');
20+
case 'EventType':
21+
return l('Event types');
22+
case 'Gender':
23+
return l('Genders');
24+
case 'InstrumentType':
25+
return l('Instrument types');
26+
case 'LabelType':
27+
return l('Label types');
28+
case 'Language':
29+
return l('Languages');
30+
case 'MediumFormat':
31+
return l('Medium formats');
32+
case 'PlaceType':
33+
return l('Place types');
34+
case 'ReleaseGroupSecondaryType':
35+
return l('Release group secondary types');
36+
case 'ReleaseGroupType':
37+
return l('Release group primary types');
38+
case 'ReleasePackaging':
39+
return l('Release packagings');
40+
case 'ReleaseStatus':
41+
return l('Release statuses');
42+
case 'Script':
43+
return l('Scripts');
44+
case 'SeriesType':
45+
return l('Series types');
46+
case 'WorkAttributeType':
47+
return l('Work attribute types');
48+
case 'WorkType':
49+
return l('Work types');
50+
default:
51+
return model;
52+
}
53+
}
54+
55+
export default attributeModelName;

0 commit comments

Comments
 (0)