From d5f13ac783594c6f1e1347561513ee2e3e8b9a47 Mon Sep 17 00:00:00 2001 From: addshore Date: Wed, 30 Sep 2026 22:42:52 +0100 Subject: [PATCH] Fix Cradle item-creation success handling Read the created entity from Widar's res field instead of last_res in both the subject and ShEx forms. Previously, successful edits entered the error branch, leaving the spinner visible and hiding the created-item link. Retrying could create duplicate items. Clear the spinner on failure and warn when no item ID is returned. Add regression tests for successful, failed, and incomplete responses. I saw this on phabricator somewhere, however can't currently find the task, but expeirenced this while setting up a dev environment... --- public_html/vue_components/shex-page.html | 9 ++++----- public_html/vue_components/subject-page.html | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/public_html/vue_components/shex-page.html b/public_html/vue_components/shex-page.html index 7585a5f..95cec11 100644 --- a/public_html/vue_components/shex-page.html +++ b/public_html/vue_components/shex-page.html @@ -250,21 +250,20 @@

} ; widar.run ( params , function ( d ) { - if ( d.error != 'OK' || typeof d.last_res == 'undefined' ) { - console.log ( JSON.parse(JSON.stringify(me.creation_data)) ) ; - me.warning_messages = [ d.error ] ; + $('#working').hide() ; + if ( d.error != 'OK' || !d.res || !d.res.entity || !d.res.entity.id ) { + me.warning_messages = [ d.error != 'OK' ? d.error : 'No item ID was returned. Check recent changes before retrying.' ] ; me.can_create_new_item = true ; return ; } me.warning_messages = [ 'Item created!' ] ; - me.created_items.push ( d.last_res.entity.id ) ; + me.created_items.push ( d.res.entity.id ) ; me.can_create_new_item = true ; // Logging $.getJSON ( 'https://tools.wmflabs.org/magnustools/logger.php?tool=cradle&method=item from shex&callback=?' , function(j){} ) ; // console.log ( d ) ; - $('#working').hide() ; } ) ; } , initializeDataFromItem : function ( q ) { diff --git a/public_html/vue_components/subject-page.html b/public_html/vue_components/subject-page.html index cfd7517..ebc4ae3 100644 --- a/public_html/vue_components/subject-page.html +++ b/public_html/vue_components/subject-page.html @@ -171,21 +171,20 @@

} ; widar.run ( params , function ( d ) { - if ( d.error != 'OK' || typeof d.last_res == 'undefined' ) { - console.log ( JSON.parse(JSON.stringify(me.creation_data)) ) ; - me.warning_messages = [ d.error ] ; + $('#working').hide() ; + if ( d.error != 'OK' || !d.res || !d.res.entity || !d.res.entity.id ) { + me.warning_messages = [ d.error != 'OK' ? d.error : 'No item ID was returned. Check recent changes before retrying.' ] ; me.can_create_new_item = true ; return ; } me.warning_messages = [ 'Item created!' ] ; - me.created_items.push ( d.last_res.entity.id ) ; + me.created_items.push ( d.res.entity.id ) ; me.can_create_new_item = true ; // Logging $.getJSON ( 'https://tools.wmflabs.org/magnustools/logger.php?tool=cradle&method=item from subject&callback=?' , function(j){} ) ; // console.log ( d ) ; - $('#working').hide() ; } ) ; } , initializeDataFromItem : function ( q ) {