From 24db07e624c10a5528f0c6d62c8f58971e0d17d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Tamargo?= Date: Fri, 8 Apr 2022 13:26:51 +0300 Subject: [PATCH 1/9] Clarify function names The attributes are rendered in Attribute, these are only a few extra headers/columns for some types. --- root/admin/attributes/Attribute.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/root/admin/attributes/Attribute.js b/root/admin/attributes/Attribute.js index dbe392d1e2f..a1e4d78b31b 100644 --- a/root/admin/attributes/Attribute.js +++ b/root/admin/attributes/Attribute.js @@ -20,7 +20,7 @@ type Props = { +model: string, }; -const renderAttributesHeaderAccordingToModel = (model: string) => { +const extraHeaders = (model: string) => { switch (model) { case 'MediumFormat': { return ( @@ -41,7 +41,7 @@ const renderAttributesHeaderAccordingToModel = (model: string) => { } }; -const renderAttributes = (attribute: AttributeT) => { +const extraColumns = (attribute: AttributeT) => { switch (attribute.entityType) { case 'medium_format': { return ( @@ -80,7 +80,7 @@ const Attribute = ({ {'MBID'} {'Child order'} {'Parent ID'} - {renderAttributesHeaderAccordingToModel(model)} + {extraHeaders(model)} {'Actions'} @@ -95,7 +95,7 @@ const Attribute = ({ {attribute.gid} {attribute.child_order} {attribute.parent_id} - {renderAttributes(attribute)} + {extraColumns(attribute)} {'Edit'} From 648fb54827e8dc57d74b13e316ba553832a4f960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Tamargo?= Date: Fri, 8 Apr 2022 14:25:15 +0300 Subject: [PATCH 2/9] MBS-11178: Make attribute lists visible to all users This removes the info that is mostly useless for people without editing rights (such as edit links) but displays everything else. Row ids are not removed since documenting these on the site is apparently helpful for people putting together SQL queries (this has been requested). Since this is visible to users, translations are brought back. --- .../Server/Controller/Admin/Attributes.pm | 6 +- root/admin/attributes/Attribute.js | 147 +++++++++++------- root/admin/attributes/Index.js | 2 +- root/admin/attributes/Language.js | 78 ++++++---- root/admin/attributes/Script.js | 120 +++++++------- root/layout/components/BottomMenu.js | 3 + 6 files changed, 212 insertions(+), 144 deletions(-) diff --git a/lib/MusicBrainz/Server/Controller/Admin/Attributes.pm b/lib/MusicBrainz/Server/Controller/Admin/Attributes.pm index 66a522a4946..203caca099b 100644 --- a/lib/MusicBrainz/Server/Controller/Admin/Attributes.pm +++ b/lib/MusicBrainz/Server/Controller/Admin/Attributes.pm @@ -31,7 +31,7 @@ my @models = qw( ); # Missing: Alias types, WorkAttributeTypeAllowedValue -sub index : Path('/admin/attributes') Args(0) RequireAuth(account_admin) { +sub index : Path('/admin/attributes') Args(0) { my ($self, $c) = @_; $c->stash( @@ -41,7 +41,7 @@ sub index : Path('/admin/attributes') Args(0) RequireAuth(account_admin) { ); } -sub attribute_base : Chained('/') PathPart('admin/attributes') CaptureArgs(1) RequireAuth(account_admin) { +sub attribute_base : Chained('/') PathPart('admin/attributes') CaptureArgs(1) { my ($self, $c, $model) = @_; $c->detach('/error_404') unless contains_string(\@models, $model); @@ -49,7 +49,7 @@ sub attribute_base : Chained('/') PathPart('admin/attributes') CaptureArgs(1) Re $c->stash->{model} = $model; } -sub attribute_index : Chained('attribute_base') PathPart('') RequireAuth(account_admin) { +sub attribute_index : Chained('attribute_base') PathPart('') { my ($self, $c) = @_; my $model = $c->stash->{model}; my @attr = $c->model($model)->get_all(); diff --git a/root/admin/attributes/Attribute.js b/root/admin/attributes/Attribute.js index a1e4d78b31b..3d2f48d1be1 100644 --- a/root/admin/attributes/Attribute.js +++ b/root/admin/attributes/Attribute.js @@ -8,8 +8,14 @@ * later version: http://www.gnu.org/licenses/gpl-2.0.txt */ +import * as React from 'react'; + +import {CatalystContext} from '../../context.mjs'; import Layout from '../../layout/index.js'; import {compare} from '../../static/scripts/common/i18n.js'; +import expand2react from '../../static/scripts/common/i18n/expand2react.js'; +import {isRelationshipEditor} + from '../../static/scripts/common/utility/privileges.js'; import yesNo from '../../static/scripts/common/utility/yesNo.js'; import loopParity from '../../utility/loopParity.js'; @@ -25,17 +31,17 @@ const extraHeaders = (model: string) => { case 'MediumFormat': { return ( <> - {'Year'} - {'Disc IDs allowed'} + {l('Year')} + {l('Disc IDs allowed')} ); } case 'SeriesType': case 'CollectionType': { - return {'Entity type'}; + return {l('Entity type')}; } case 'WorkAttributeType': { - return {'Free text'}; + return {l('Free text')}; } default: return null; } @@ -65,58 +71,85 @@ const extraColumns = (attribute: AttributeT) => { const Attribute = ({ attributes, model, -}: Props): React$Element => ( - -

- {'Attributes'} - {' / ' + model} -

- - - - - - - - - - {extraHeaders(model)} - - - - - {attributes ? attributes - .sort((a, b) => compare(a.name, b.name)) - .map((attribute, index) => ( - - - - - - - - {extraColumns(attribute)} - - - )) : null} - -
{'ID'}{'Name'}{'Description'}{'MBID'}{'Child order'}{'Parent ID'}{'Actions'}
{attribute.id}{attribute.name}{exp.l_admin(attribute.description)}{attribute.gid}{attribute.child_order}{attribute.parent_id} - - {'Edit'} - - {' | '} - - {'Remove'} - -
-

- - - {'Add new attribute'} - - -

- -); +}: Props): React$Element => { + const $c = React.useContext(CatalystContext); + const showEditSections = isRelationshipEditor($c.user); + + return ( + +

+ {l('Attributes')} + {' / ' + model} +

+ + + + + + + + + {showEditSections ? ( + <> + + + + ) : null} + {extraHeaders(model)} + {showEditSections ? ( + + ) : null} + + + + {attributes ? attributes + .sort((a, b) => compare(a.name, b.name)) + .map((attribute, index) => ( + + + + + + {showEditSections ? ( + <> + + + + ) : null} + {extraColumns(attribute)} + {showEditSections ? ( + + ) : null} + + )) : null} + +
{l('ID')}{l('Name')}{l('Description')}{l('MBID')}{l('Child order')}{l('Parent ID')}{l('Actions')}
{attribute.id}{attribute.name}{expand2react(attribute.description)}{attribute.gid}{attribute.child_order}{attribute.parent_id} + + {l('Edit')} + + {' | '} + + {l('Remove')} + +
+ + {showEditSections ? ( +

+ + + {l('Add new attribute')} + + +

+ ) : null} +
+ ); +}; export default Attribute; diff --git a/root/admin/attributes/Index.js b/root/admin/attributes/Index.js index 1790175fa29..d367372d432 100644 --- a/root/admin/attributes/Index.js +++ b/root/admin/attributes/Index.js @@ -16,7 +16,7 @@ type Props = { const Attributes = ({models}: Props): React$Element => ( -

{'Attributes'}

+

{l('Attributes')}