From 81445487f5b2576f61d284f78ed3e48b2e487f37 Mon Sep 17 00:00:00 2001 From: Taka Date: Sun, 21 Nov 2021 16:00:29 +1100 Subject: [PATCH] Fixed a problem updating the UI after deleting something. --- web/src/PublicationSearchResult.js | 2 +- web/src/PublisherSearchResult.js | 4 ++-- web/src/SearchResults.js | 20 +++++++++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/web/src/PublicationSearchResult.js b/web/src/PublicationSearchResult.js index 772d201..ac7f46b 100644 --- a/web/src/PublicationSearchResult.js +++ b/web/src/PublicationSearchResult.js @@ -223,7 +223,7 @@ export class PublicationSearchResult extends React.Component // update the UI this.props.onDelete( "pub_id", this.props.data.pub_id ) ; resp.data.deletedArticles.forEach( article_id => { - this.props.onDelete( "article_id", article_id ) ; + this.props.onDelete( "article_id", article_id, true ) ; } ) ; if ( this.props.data._parent_publ ) gAppRef.updatePublisher( this.props.data._parent_publ.publ_id ) ; diff --git a/web/src/PublisherSearchResult.js b/web/src/PublisherSearchResult.js index 0639314..a3220d1 100644 --- a/web/src/PublisherSearchResult.js +++ b/web/src/PublisherSearchResult.js @@ -191,10 +191,10 @@ export class PublisherSearchResult extends React.Component // update the UI this.props.onDelete( "publ_id", this.props.data.publ_id ) ; resp.data.deletedPublications.forEach( pub_id => { - this.props.onDelete( "pub_id", pub_id ) ; + this.props.onDelete( "pub_id", pub_id, true ) ; } ) ; resp.data.deletedArticles.forEach( article_id => { - this.props.onDelete( "article_id", article_id ) ; + this.props.onDelete( "article_id", article_id, true ) ; } ) ; // update the UI if ( resp.data.warnings ) diff --git a/web/src/SearchResults.js b/web/src/SearchResults.js index 3e0e27d..6e7f167 100644 --- a/web/src/SearchResults.js +++ b/web/src/SearchResults.js @@ -45,16 +45,16 @@ export class SearchResults extends React.Component this.props.searchResults.forEach( sr => { if ( sr._type === "publisher" ) { results.push( this.onDeleteSearchResult( n, v ) } + onDelete = { (n,v,i) => this.onDeleteSearchResult( n, v, i ) } /> ) ; } else if ( sr._type === "publication" ) { results.push( this.onDeleteSearchResult( n, v ) } + onDelete = { (n,v,i) => this.onDeleteSearchResult( n, v, i ) } onArticleClick = { (a) => scrollToArticle(a) } /> ) ; } else if ( sr._type === "article" ) { results.push( this.onDeleteSearchResult( n, v ) } + onDelete = { (n,v,i) => this.onDeleteSearchResult( n, v, i ) } ref = { r => articleRefs[sr.article_id] = r } /> ) ; } else { @@ -65,16 +65,26 @@ export class SearchResults extends React.Component return
{results}
; } - onDeleteSearchResult( idName, idVal ) { + onDeleteSearchResult( idName, idVal, ignoreNotFound ) { + // look for the specified search result for ( let i=0 ; i < this.props.searchResults.length ; ++i ) { const sr = this.props.searchResults[ i ] ; if ( sr[idName] === idVal ) { + // found it - remove it the UI this.props.searchResults.splice( i, 1 ) ; this.forceUpdate() ; return ; } } - gAppRef.logInternalError( "Tried to delete an unknown search result.", idName+" = "+idVal ) ; + // the search result wasn't found + // NOTE: This would normally indicate an internal coding error, but there is one case where + // it can happen: when a publisher or publication is deleted, we want to also delete all + // their child objects, but they may not necessarily be on-screen. + if ( ! ignoreNotFound ) { + gAppRef.logInternalError( + "Tried to delete an unknown search result.", idName+" = "+idVal + ) ; + } } }