Skip to content

Commit

Permalink
MBS-12622: Show if URL has pending edits in links editor
Browse files Browse the repository at this point in the history
If a URL is being edited, we should indicate it in the links editor.
This way it is possible to find out that, say, the URL you are adding
or changing the relationship for is actually going to change soon,
otherwise making your changes have unexpected consequences.
  • Loading branch information
reosarevok committed Mar 15, 2023
1 parent 8be0a2e commit 0a8d644
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 26 deletions.
51 changes: 51 additions & 0 deletions root/static/scripts/edit/components/EntityPendingEditsWarning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* @flow strict-local
* Copyright (C) 2023 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 * as React from 'react';

import openEditsForEntityIconUrl
from '../../../images/icons/open_edits_for_entity.svg';
import entityHref from '../../common/utility/entityHref.js';

import Tooltip from './Tooltip.js';


type PropsT = {
+entity: CoreEntityT,
};

const EntityPendingEditsWarning = ({
entity,
}: PropsT): React$Element<typeof React.Fragment> | null => {
const hasPendingEdits = Boolean(entity.editsPending);
const openEditsLink = entityHref(entity, '/open_edits');

return hasPendingEdits && nonEmpty(openEditsLink) ? (
<>
{' '}
<Tooltip
content={exp.l(
'This entity has {edits_link|pending edits}.',
{edits_link: openEditsLink},
)}
target={
<img
alt={l('This entity has pending edits.')}
className="info"
height={16}
src={openEditsForEntityIconUrl}
style={{verticalAlign: 'middle'}}
/>
}
/>
</>
) : null;
};

export default EntityPendingEditsWarning;
9 changes: 8 additions & 1 deletion root/static/scripts/edit/externalLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import {isMalware} from '../url/utility/isGreyedOut.js';
import ExternalLinkAttributeDialog
from './components/ExternalLinkAttributeDialog.js';
import HelpIcon from './components/HelpIcon.js';
import EntityPendingEditsWarning
from './components/EntityPendingEditsWarning.js';
import RelationshipPendingEditsWarning
from './components/RelationshipPendingEditsWarning.js';
import RemoveButton from './components/RemoveButton.js';
Expand Down Expand Up @@ -928,7 +930,7 @@ export class _ExternalLinksEditor
* The first element of tuple `item` is not the URL
* when the URL is not submitted therefore isn't grouped.
*/
const {url, rawUrl} = relationships[0];
const {url, rawUrl, entity1} = relationships[0];
const isLastLink = index === linksByUrl.length - 1;
const links = [...relationships];
const linkIndexes = [];
Expand Down Expand Up @@ -1063,6 +1065,7 @@ export class _ExternalLinksEditor
relationships={links}
typeOptions={typeOptions}
url={url}
urlEntity={entity1}
urlMatchesType={urlMatchesType}
validateLink={(link) => this.validateLink(link)}
/>
Expand Down Expand Up @@ -1306,6 +1309,7 @@ type LinkProps = {
+relationships: $ReadOnlyArray<LinkRelationshipT>,
+typeOptions: $ReadOnlyArray<LinkTypeOptionT>,
+url: string,
+urlEntity?: CoreEntityT,
+urlMatchesType: boolean,
+validateLink: (LinkRelationshipT | LinkStateT) => ErrorT | null,
};
Expand Down Expand Up @@ -1448,6 +1452,9 @@ export class ExternalLink extends React.Component<LinkProps> {
{props.url}
</a>
)}
{props.urlEntity ? (
<EntityPendingEditsWarning entity={props.urlEntity} />
) : null}
{props.url && props.duplicate !== null ? (
<div
className="error field-error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
import * as React from 'react';
import * as tree from 'weight-balanced-tree';

import openEditsForEntityIconUrl
from '../../../images/icons/open_edits_for_entity.svg';
import ButtonPopover from '../../common/components/ButtonPopover.js';
import DescriptiveLink from '../../common/components/DescriptiveLink.js';
import {bracketedText} from '../../common/utility/bracketed.js';
import {displayLinkAttributesText}
from '../../common/utility/displayLinkAttribute.js';
import entityHref from '../../common/utility/entityHref.js';
import {
performReactUpdateAndMaintainFocus,
} from '../../common/utility/focusManagement.js';
Expand All @@ -27,9 +24,10 @@ import {
} from '../../common/utility/isLinkTypeDirectionOrderable.js';
import relationshipDateText
from '../../common/utility/relationshipDateText.js';
import EntityPendingEditsWarning
from '../../edit/components/EntityPendingEditsWarning.js';
import RelationshipPendingEditsWarning
from '../../edit/components/RelationshipPendingEditsWarning.js';
import Tooltip from '../../edit/components/Tooltip.js';
import {
getPhraseAndExtraAttributesText,
} from '../../edit/utility/linkPhrase.js';
Expand Down Expand Up @@ -82,7 +80,6 @@ const RelationshipItem = (React.memo<PropsT>(({
const [sourceCredit, targetCredit] = backward
? [relationship.entity1_credit, relationship.entity0_credit]
: [relationship.entity0_credit, relationship.entity1_credit];
const targetHasPendingEdits = Boolean(target.editsPending);
const isRemoved = relationship._status === REL_STATUS_REMOVE;
const removeButtonId =
'remove-relationship-' + getRelationshipKey(relationship);
Expand Down Expand Up @@ -281,26 +278,7 @@ const RelationshipItem = (React.memo<PropsT>(({
})
)
: targetDisplay}
{targetHasPendingEdits ? (
<>
{' '}
<Tooltip
content={exp.l(
'This entity has {edits_link|pending edits}.',
{edits_link: entityHref(target, '/open_edits')},
)}
target={
<img
alt={l('This entity has pending edits.')}
className="info"
height={16}
src={openEditsForEntityIconUrl}
style={{verticalAlign: 'middle'}}
/>
}
/>
</>
) : null}
<EntityPendingEditsWarning entity={target} />
<RelationshipPendingEditsWarning relationship={relationship} />
{datesAndAttributes}
</span>
Expand Down

0 comments on commit 0a8d644

Please sign in to comment.