diff --git a/asl_articles/tests/test_articles.py b/asl_articles/tests/test_articles.py index 0c69e0e..3b0b57f 100644 --- a/asl_articles/tests/test_articles.py +++ b/asl_articles/tests/test_articles.py @@ -236,7 +236,7 @@ def test_parent_publisher( webdriver, flask_app, dbconn ): nonlocal article_sr elem = find_child( ".title .publication", article_sr ) if expected_parent: - assert elem.text == "({})".format( expected_parent[1] ) + assert elem.text == "[{}]".format( expected_parent[1] ) else: assert elem is None @@ -255,7 +255,7 @@ def test_parent_publisher( webdriver, flask_app, dbconn ): article_sr = results[0] elem = find_child( ".title .publication", article_sr ) if expected_parent: - assert elem.text == "({})".format( expected_parent[1] ) + assert elem.text == "[{}]".format( expected_parent[1] ) else: assert elem is None diff --git a/web/src/ArticleSearchResult.js b/web/src/ArticleSearchResult.js index 0302de5..71a2832 100644 --- a/web/src/ArticleSearchResult.js +++ b/web/src/ArticleSearchResult.js @@ -1,5 +1,6 @@ import React from "react" ; import { ArticleSearchResult2 } from "./ArticleSearchResult2.js" ; +import { PublicationSearchResult } from "./PublicationSearchResult.js" ; import { gAppRef } from "./index.js" ; import { makeScenarioDisplayName, applyUpdatedVals, removeSpecialFields, makeOptionalLink, makeCommaList } from "./utils.js" ; @@ -60,13 +61,14 @@ export class ArticleSearchResult extends React.Component } // NOTE: The "title" field is also given the CSS class "name" so that the normal CSS will apply to it. // Some tests also look for a generic ".name" class name when checking search results. + const pub_display_name = pub ? PublicationSearchResult.makeDisplayName( pub ) : null ; return (
gAppRef.setTestAttribute( r, "article_id", this.props.data.article_id ) } >
{ image_url && Article. } { makeOptionalLink( display_title, this.props.data.article_url ) } - { pub && ({pub.pub_name}) } + { pub_display_name && [{pub_display_name}] } Edit this article. Delete this article. { display_subtitle &&
} diff --git a/web/src/ArticleSearchResult2.js b/web/src/ArticleSearchResult2.js index 0ab2761..ebdb985 100644 --- a/web/src/ArticleSearchResult2.js +++ b/web/src/ArticleSearchResult2.js @@ -2,6 +2,7 @@ import React from "react" ; import ReactDOMServer from "react-dom/server" ; import Select from "react-select" ; import CreatableSelect from "react-select/creatable" ; +import { PublicationSearchResult } from "./PublicationSearchResult.js" ; import { gAppRef } from "./index.js" ; import { ImageFileUploader } from "./FileUploader.js" ; import { makeScenarioDisplayName, parseScenarioDisplayName, unloadCreatableSelect } from "./utils.js" ; @@ -44,18 +45,23 @@ export class ArticleSearchResult2 // initialize the publications let publications = [ { value: null, label: (none) } ] ; - let currPub = 0 ; for ( let p of Object.entries(gAppRef.caches.publications) ) { + const pub_display_name = PublicationSearchResult.makeDisplayName( p[1] ) ; publications.push( { value: p[1].pub_id, - label: + label: } ) ; - if ( p[1].pub_id === vals.pub_id ) - currPub = publications.length - 1 ; } publications.sort( (lhs,rhs) => { return ReactDOMServer.renderToStaticMarkup( lhs.label ).localeCompare( ReactDOMServer.renderToStaticMarkup( rhs.label ) ) ; } ) ; + let currPub = 0 ; + for ( let i=1; i < publications.length ; ++i ) { + if ( publications[i].value === vals.pub_id ) { + currPub = i ; + break ; + } + } // initialize the authors let allAuthors = [] ; diff --git a/web/src/PublicationSearchResult.js b/web/src/PublicationSearchResult.js index dfbf2d2..2668303 100644 --- a/web/src/PublicationSearchResult.js +++ b/web/src/PublicationSearchResult.js @@ -148,16 +148,17 @@ export class PublicationSearchResult extends React.Component } ) ; } - _makeDisplayName( allowAlternateContent ) { + static makeDisplayName( vals, allowAlternateContent ) { let pub_name = null ; - if ( allowAlternateContent && this.props.data["pub_name!"] ) - pub_name = this.props.data[ "pub_name!" ] ; + if ( allowAlternateContent && vals["pub_name!"] ) + pub_name = vals[ "pub_name!" ] ; if ( ! pub_name ) - pub_name = this.props.data.pub_name ; - if ( this.props.data.pub_edition ) - return pub_name + " (" + this.props.data.pub_edition + ")" ; + pub_name = vals.pub_name ; + if ( vals.pub_edition ) + return pub_name + " (" + vals.pub_edition + ")" ; else return pub_name ; } + _makeDisplayName( allowAlternateContent ) { return PublicationSearchResult.makeDisplayName( this.props.data, allowAlternateContent ) ; } }