@@ -51,7 +51,12 @@ export default class RepoNew extends React.Component {
5151 fetch ( pp + "api/repos" )
5252 . then ( utils . jsonHandler )
5353 . then ( repos => {
54- this . updateState ( { initGroups : repos . find ( r => r . owner === st . org && r . name === st . repo ) . groups . map ( g => g . w3cid ) } ) ;
54+ const repo = repos . find ( r => r . owner === st . org && r . name === st . repo ) ;
55+ if ( ! repo ) {
56+ MessageActions . error ( "Repository not found" ) ;
57+ return this . updateState ( { status : "ready" } ) ;
58+ }
59+ this . updateState ( { initGroups : repo . groups . map ( g => g . w3cid ) } ) ;
5560 } ) ;
5661 }
5762 fetch ( pp + "api/my/last-added-repo" , { credentials : "include" } )
@@ -98,16 +103,17 @@ export default class RepoNew extends React.Component {
98103 if ( ! Object . keys ( this . state . orgRepos ) . length ) return ;
99104 let org = utils . val ( this . refs . org ) ;
100105 switch ( this . state . mode ) {
101- case "new" :
102- if ( this . state . orgRepos [ org ] . indexOf ( ev . target . value ) !== - 1 ) {
103- return ev . target . setCustomValidity ( "Can't create a repo with that name - already exists" ) ;
104- }
105- break ;
106- case "import" :
107- if ( this . state . orgRepos [ org ] . indexOf ( ev . target . value ) === - 1 ) {
108- return ev . target . setCustomValidity ( "Can't import a repo with that name - does not exist" ) ;
109- }
110- break ;
106+ case "new" :
107+ if ( this . state . orgRepos [ org ] . indexOf ( ev . target . value ) !== - 1 ) {
108+ return ev . target . setCustomValidity ( "Can't create a repo with that name - already exists" ) ;
109+ }
110+ break ;
111+ case "import" :
112+ case "edit" :
113+ if ( this . state . orgRepos [ org ] . indexOf ( ev . target . value ) === - 1 ) {
114+ return ev . target . setCustomValidity ( `Can't ${ this . state . mode } a repo with that name - does not exist` ) ;
115+ }
116+ break ;
111117 }
112118 ev . target . setCustomValidity ( "" ) ;
113119 }
@@ -149,7 +155,7 @@ export default class RepoNew extends React.Component {
149155 apiPath = "api/create-repo" ;
150156 break ;
151157 case "edit" :
152- apiPath = "api/repos/" + org + "/" + repo + "/edit" ;
158+ apiPath = "api/repos/" + this . props . params . owner + "/" + this . props . params . shortname + "/edit" ;
153159 break ;
154160 case "import" :
155161 apiPath = "api/import-repo" ;
@@ -220,8 +226,7 @@ export default class RepoNew extends React.Component {
220226
221227 render ( ) {
222228 let st = this . state
223- , results = ""
224- , readonly = st . mode === "edit" ;
229+ , results = "" ;
225230 let org = st . org || ( st . orgs ? st . orgs [ 0 ] : null ) ;
226231 let repos = org && Object . keys ( st . orgRepos ) . length ? st . orgRepos [ org ] : [ ] ;
227232 let selectedGroupType = st . repoGroups . length ? st . groups . filter ( g => g . w3cid == st . repoGroups [ 0 ] ) [ 0 ] . groupType : null ;
@@ -261,12 +266,12 @@ export default class RepoNew extends React.Component {
261266 < form onSubmit = { this . onSubmit . bind ( this ) } ref = "form" >
262267 < div className = "formline" >
263268 < label htmlFor = "repo" > pick organisation or account, and repository name</ label >
264- < select disabled = { readonly } ref = "org" defaultValue = { st . org ? st . org : st . lastAddedRepo . org } required onChange = { this . updateOrg . bind ( this ) } >
269+ < select ref = "org" defaultValue = { st . org ? st . org : st . lastAddedRepo . org } required onChange = { this . updateOrg . bind ( this ) } >
265270 { st . orgs . map ( ( org ) => { return < option value = { org } key = { org } > { org } </ option > ; } ) }
266271 </ select >
267272 { " / " }
268- < input readOnly = { readonly } type = "text" ref = "repo" id = "repo" defaultValue = { st . repo } required list = "repos" onChange = { this . onRepoNameChange . bind ( this ) } />
269- { ( st . mode === "import" ) ?
273+ < input type = "text" ref = "repo" id = "repo" defaultValue = { st . repo } required list = "repos" onChange = { this . onRepoNameChange . bind ( this ) } />
274+ { ( st . mode === "import" || st . mode === "edit" ) ?
270275 < datalist id = "repos" >
271276 { repos . map ( repo => {
272277 return < option key = { org + "/" + repo } > { repo } </ option > ;
@@ -336,7 +341,7 @@ export default class RepoNew extends React.Component {
336341 return < div className = "primary-app" >
337342 < h2 > Update Repository Data</ h2 >
338343 < p >
339- Use the form below to update the group(s) to which an existing managed repository is associated.
344+ Use the form below to update the owner/name of the repository and/or the group(s) to which this repository is associated with .
340345 </ p >
341346 { content }
342347 { results }
0 commit comments