Show existing publications when creating a new one.

master
Pacman Ghost 4 years ago
parent c3cc81f552
commit 71667f0ee2
  1. 37
      asl_articles/tests/test_publications.py
  2. 6
      web/src/ArticleSearchResult2.js
  3. 34
      web/src/PublicationSearchResult2.js

@ -6,6 +6,7 @@ import urllib.error
import json
import base64
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import StaleElementReferenceException
from asl_articles.search import SEARCH_ALL
@ -41,28 +42,13 @@ def test_edit_publication( webdriver, flask_app, dbconn ):
[ "ASL Journal (updated)", "2a", "Updated ASLJ description.", ["abc","xyz"], "http://aslj-updated.com/" ]
)
# try to remove all fields from "ASL Journal #2" (should fail)
edit_publication( result,
{ "name": "", "edition": "", "description": "", "tags":["-abc","-xyz"], "url": "" },
expected_error = "Please specify the publication's name."
)
# enter something for the name
dlg = find_child( "#modal-form" )
set_elem_text( find_child( ".name input", dlg ), "Updated ASL Journal" )
find_child( "button.ok", dlg ).click()
# check that the search result was updated in the UI
results = find_children( "#search-results .search-result" )
result = results[1]
assert find_child( ".name a", result ) is None
assert find_child( ".name", result ).text == "Updated ASL Journal"
assert find_child( ".description", result ).text == ""
assert find_children( ".tag", result ) == []
# NOTE: We used to try to remove all fields from "ASL Journal #2" (which should fail, since we can't
# have an empty name), but we can no longer remove an existing publication name (which is OK, since we
# don't want to allow that, only change it).
# check that the search result was updated in the database
results = do_search( '"ASL Journal"' )
assert get_result_names( results ) == [ "ASL Journal (1)", "Updated ASL Journal" ]
assert get_result_names( results ) == [ "ASL Journal (1)", "ASL Journal (updated) (2a)" ]
# ---------------------------------------------------------------------
@ -78,7 +64,8 @@ def test_create_publication( webdriver, flask_app, dbconn ):
# enter a name and other details
dlg = find_child( "#modal-form" ) # nb: the form is still on-screen
set_elem_text( find_child( ".name input", dlg ), "New publication" )
elem = find_child( ".name .react-select input", dlg )
elem.send_keys( "New publication", Keys.RETURN )
set_elem_text( find_child( ".edition input", dlg ), "#1" )
set_elem_text( find_child( ".description textarea", dlg ), "New publication description." )
select = ReactSelect( find_child( ".tags .react-select", dlg ) )
@ -406,7 +393,11 @@ def create_publication( vals, toast_type="info" ):
find_child( "#menu .new-publication" ).click()
dlg = wait_for_elem( 2, "#modal-form" )
for key,val in vals.items():
if key == "tags":
if key == "name":
elem = find_child( ".name .react-select input" )
set_elem_text( elem, val )
elem.send_keys( Keys.RETURN )
elif key == "tags":
select = ReactSelect( find_child( ".tags .react-select", dlg ) )
select.update_multiselect_values( *val )
else:
@ -434,6 +425,10 @@ def edit_publication( result, vals, toast_type="info", expected_error=None ):
)
else:
find_child( ".remove-image", dlg ).click()
elif key == "name":
elem = find_child( ".name .react-select input" )
set_elem_text( elem, val )
elem.send_keys( Keys.RETURN )
elif key == "publisher":
select = ReactSelect( find_child( ".publisher .react-select", dlg ) )
select.select_by_name( val )

@ -55,10 +55,10 @@ export class ArticleSearchResult2
publications.sort( (lhs,rhs) => {
return ReactDOMServer.renderToStaticMarkup( lhs.label ).localeCompare( ReactDOMServer.renderToStaticMarkup( rhs.label ) ) ;
} ) ;
let currPub = 0 ;
let currPub = publications[0] ;
for ( let i=1; i < publications.length ; ++i ) {
if ( publications[i].value === vals.pub_id ) {
currPub = i ;
currPub = publications[i] ;
break ;
}
}
@ -112,7 +112,7 @@ export class ArticleSearchResult2
</div>
<div className="row publication"> <label> Publication: </label>
<Select className="react-select" classNamePrefix="react-select" options={publications} isSearchable={true}
defaultValue = { publications[ currPub ] }
defaultValue = {currPub}
ref = { (r) => refs.pub_id=r }
/>
</div>

@ -57,6 +57,28 @@ export class PublicationSearchResult2
return ReactDOMServer.renderToStaticMarkup( lhs.label ).localeCompare( ReactDOMServer.renderToStaticMarkup( rhs.label ) ) ;
} ) ;
// initialize the publications
// NOTE: As a convenience, we provide a droplist of known publication names (without edition #'s),
// to make it easier to add a new edition of an existing publication.
let publications = {} ;
for ( let p of Object.entries(gAppRef.caches.publications) )
publications[ p[1].pub_name ] = p[1] ;
let publications2 = [] ;
for ( let pub_name in publications ) {
const pub = publications[ pub_name ] ;
publications2.push( { value: pub.pub_id, label: pub.pub_name } ) ;
}
publications2.sort( (lhs,rhs) => {
return ReactDOMServer.renderToStaticMarkup( lhs.label ).localeCompare( ReactDOMServer.renderToStaticMarkup( rhs.label ) ) ;
} ) ;
let currPub = null ;
for ( let pub of publications2 ) {
if ( pub.label === vals.pub_name ) {
currPub = pub ;
break ;
}
}
// initialize the tags
const tags = gAppRef.makeTagLists( vals.pub_tags ) ;
@ -69,7 +91,10 @@ export class PublicationSearchResult2
<input type="file" accept="image/*" onChange={onUploadImage} style={{display:"none"}} ref={r => uploadImageRef=r} />
</div>
<div className="row name"> <label> Name: </label>
<input type="text" defaultValue={vals.pub_name} ref={(r) => refs.pub_name=r} />
<CreatableSelect className="react-select" classNamePrefix="react-select" options={publications2}
defaultValue = {currPub}
ref = { (r) => refs.pub_name=r }
/>
</div>
<div className="row edition"> <label> Edition: </label>
<input type="text" defaultValue={vals.pub_edition} ref={(r) => refs.pub_edition=r} />
@ -102,7 +127,10 @@ export class PublicationSearchResult2
for ( let r in refs ) {
if ( r === "publ_id" )
newVals[ r ] = refs[r].state.value && refs[r].state.value.value ;
else if ( r === "pub_tags" ) {
else if ( r === "pub_name" ) {
if ( refs[r].state.value )
newVals[ r ] = refs[r].state.value.label.trim() ;
} else if ( r === "pub_tags" ) {
let vals = unloadCreatableSelect( refs[r] ) ;
newVals[ r ] = vals.map( v => v.label ) ;
} else
@ -112,7 +140,7 @@ export class PublicationSearchResult2
newVals.imageData = imageData ;
newVals.imageFilename = imageFilename ;
}
if ( newVals.pub_name === "" ) {
if ( newVals.pub_name === undefined || newVals.pub_name === "" ) {
gAppRef.showErrorMsg( <div> Please specify the publication's name. </div>) ;
return ;
}

Loading…
Cancel
Save