Skip to content

Commit

Permalink
Merge pull request #1086 from reosarevok/MBS-9915-pt-2
Browse files Browse the repository at this point in the history
MBS-10201 / MBS-10202: Convert artist works and rels tabs to React
  • Loading branch information
reosarevok committed Jul 19, 2019
2 parents 87ff892 + 397c92f commit 3329730
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 30 deletions.
29 changes: 24 additions & 5 deletions lib/MusicBrainz/Server/Controller/Artist.pm
Expand Up @@ -280,7 +280,15 @@ sub show : PathPart('') Chained('load')
identities => \@identities);
}

sub relationships : Chained('load') PathPart('relationships') {}
sub relationships : Chained('load') PathPart('relationships') {
my ($self, $c) = @_;

$c->stash(
component_path => 'artist/ArtistRelationships',
component_props => { artist => $c->stash->{artist} },
current_view => 'Node',
);
}

=head2 works
Expand All @@ -296,7 +304,18 @@ sub works : Chained('load')
});
$c->model('Work')->load_related_info(@$works);
$c->model('Work')->rating->load_user_ratings($c->user->id, @$works) if $c->user_exists;
$c->stash( works => $works );

my %props = (
artist => $c->stash->{artist},
pager => serialize_pager($c->stash->{pager}),
works => $works,
);

$c->stash(
component_path => 'artist/ArtistWorks',
component_props => \%props,
current_view => 'Node',
);
}

=head2 recordings
Expand Down Expand Up @@ -377,7 +396,7 @@ sub events : Chained('load')
);

$c->stash(
component_path => 'artist/ArtistEvents.js',
component_path => 'artist/ArtistEvents',
component_props => \%props,
current_view => 'Node',
);
Expand Down Expand Up @@ -589,7 +608,7 @@ around $_ => sub {
artist => $artist,
);
$c->stash(
component_path => 'artist/SpecialPurpose.js',
component_path => 'artist/SpecialPurpose',
component_props => \%props,
current_view => 'Node',
);
Expand Down Expand Up @@ -636,7 +655,7 @@ sub split : Chained('load') Edit {
artist => $artist,
);
$c->stash(
component_path => 'artist/CannotSplit.js',
component_path => 'artist/CannotSplit',
component_props => \%props,
current_view => 'Node',
);
Expand Down
32 changes: 32 additions & 0 deletions root/artist/ArtistRelationships.js
@@ -0,0 +1,32 @@
/*
* @flow
* Copyright (C) 2019 MetaBrainz Foundation
*
* This file is part of MusicBrainz, the open internet music database,
* and is licensed under the GPL version 2, or (at your option) any
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
*/

import React from 'react';

import Relationships from '../components/Relationships';
import RelationshipsTable from '../components/RelationshipsTable';
import EntityLink from '../static/scripts/common/components/EntityLink';

import ArtistLayout from './ArtistLayout';

const ArtistRelationships = ({artist}: {artist: ArtistT}) => (
<ArtistLayout entity={artist} page="relationships" title={l('Relationships')}>
{artist.relationships && artist.relationships.length > 0 ? (
<Relationships source={artist} />
) : (
<>
<h2 className="relationships">{l('Relationships')}</h2>
<p>{exp.l('{link} has no relationships.', {link: <EntityLink entity={artist} />})}</p>
</>
)}
<RelationshipsTable entity={artist} heading={l('Appearances')} showCredits />
</ArtistLayout>
);

export default ArtistRelationships;
61 changes: 61 additions & 0 deletions root/artist/ArtistWorks.js
@@ -0,0 +1,61 @@
/*
* @flow
* Copyright (C) 2019 MetaBrainz Foundation
*
* This file is part of MusicBrainz, the open internet music database,
* and is licensed under the GPL version 2, or (at your option) any
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
*/

import React from 'react';

import {withCatalystContext} from '../context';
import WorkList from '../components/list/WorkList';
import PaginatedResults from '../components/PaginatedResults';

import ArtistLayout from './ArtistLayout';

type Props = {|
+$c: CatalystContextT,
+artist: ArtistT,
+pager: PagerT,
+works: $ReadOnlyArray<WorkT>,
|};

const ArtistWorks = ({
$c,
artist,
pager,
works,
}: Props) => (
<ArtistLayout entity={artist} page="works" title={l('Works')}>
<h2>{l('Works')}</h2>

{works && works.length > 0 ? (
<form action="/work/merge_queue" method="post">
<PaginatedResults pager={pager}>
<WorkList
checkboxes="add-to-merge"
showRatings
works={works}
/>
</PaginatedResults>
{$c.user_exists ? (
<div className="row">
<span className="buttons">
<button type="submit">
{l('Add selected works for merging')}
</button>
</span>
</div>
) : null}
</form>
) : (
<p>
{l('This artist is not currently associated with any works.')}
</p>
)}
</ArtistLayout>
);

export default withCatalystContext(ArtistWorks);
12 changes: 0 additions & 12 deletions root/artist/relationships.tt

This file was deleted.

13 changes: 0 additions & 13 deletions root/artist/works.tt

This file was deleted.

2 changes: 2 additions & 0 deletions root/server/components.js
Expand Up @@ -44,6 +44,8 @@ module.exports = {
'area/NotFound': require('../area/NotFound'),
'artist/ArtistEvents': require('../artist/ArtistEvents'),
'artist/ArtistMerge': require('../artist/ArtistMerge'),
'artist/ArtistRelationships': require('../artist/ArtistRelationships'),
'artist/ArtistWorks': require('../artist/ArtistWorks'),
'artist/CannotSplit': require('../artist/CannotSplit'),
'artist/NotFound': require('../artist/NotFound'),
'artist/SpecialPurpose': require('../artist/SpecialPurpose'),
Expand Down

0 comments on commit 3329730

Please sign in to comment.