Skip to content

Commit a7693f4

Browse files
authored
Fix silent failure when attaching evidence to unsaved reviews (#1690)
1 parent c98d5ad commit a7693f4

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

client/src/js/SM/Attachments.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ SM.Attachments.Grid = Ext.extend(Ext.grid.GridPanel, {
248248
style: 'width: 95px;',
249249
buttonText: `Attach image...`,
250250
buttonCfg: {
251-
icon: "img/attachment.svg"
251+
icon: "img/attachment.svg",
252+
tooltip: ''
252253
},
253254
listeners: {
254255
fileselected: onFileSelected
@@ -257,6 +258,18 @@ SM.Attachments.Grid = Ext.extend(Ext.grid.GridPanel, {
257258
const config = {
258259
loadArtifacts: loadArtifacts,
259260
fileUploadField: fileUploadField,
261+
updateAttachmentButtonState: function(reviewExists, hasWriteAccess) {
262+
fileUploadField.setDisabled(!reviewExists || !hasWriteAccess)
263+
if (fileUploadField.button) {
264+
if (!reviewExists) {
265+
fileUploadField.button.setTooltip('Save the review before attaching evidence')
266+
} else if (!hasWriteAccess) {
267+
fileUploadField.button.setTooltip('No write access')
268+
} else {
269+
fileUploadField.button.setTooltip('Attach an image file as evidence for this review')
270+
}
271+
}
272+
},
260273
disableSelection: true,
261274
layout: 'fit',
262275
cls: 'custom-artifacts',

client/src/js/review.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,9 @@ async function addReview( params ) {
12191219
assetId: leaf.assetId
12201220
})
12211221

1222+
// Track whether a review exists in the database
1223+
attachmentsGrid.reviewExists = false
1224+
12221225
/******************************************************/
12231226
// END Attachments Panel
12241227
/******************************************************/
@@ -1388,11 +1391,6 @@ async function addReview( params ) {
13881391
projection: ['detail','ccis','check','fix']
13891392
}
13901393
}),
1391-
Ext.Ajax.requestPromise({
1392-
responseType: 'json',
1393-
url: `${STIGMAN.Env.apiBase}/collections/${collectionId}/reviews/${assetId}/${groupGridRecord.data.ruleId}`,
1394-
method: 'GET',
1395-
}),
13961394
Ext.Ajax.requestPromise({
13971395
responseType: 'json',
13981396
url: `${STIGMAN.Env.apiBase}/collections/${collectionId}/reviews/${assetId}/${groupGridRecord.data.ruleId}`,
@@ -1403,7 +1401,7 @@ async function addReview( params ) {
14031401
})
14041402
]
14051403

1406-
const [content, review, reviewProjected] = await Promise.all(requests)
1404+
const [content, reviewProjected] = await Promise.all(requests)
14071405

14081406
// CONTENT
14091407
reviewTab.contentPanel.update(content)
@@ -1418,8 +1416,13 @@ async function addReview( params ) {
14181416

14191417
// Display the review
14201418
reviewForm.groupGridRecord = groupGridRecord
1421-
reviewForm.loadValues(review)
1419+
reviewForm.loadValues(reviewProjected)
14221420
reviewForm.isLoaded = true
1421+
1422+
// Check if review exists in database and update attachment button accordingly
1423+
attachmentsGrid.reviewExists = !!reviewProjected
1424+
attachmentsGrid.updateAttachmentButtonState(attachmentsGrid.reviewExists, reviewForm.defaultAccess === 'rw')
1425+
14231426
reviewForm.setReviewFormItemStates()
14241427

14251428
if (! reviewProjected) {
@@ -1674,6 +1677,11 @@ async function addReview( params ) {
16741677
saveParams.sm.selectRow(saveParams.index);
16751678
return
16761679
}
1680+
1681+
// After successful save, review now exists in database
1682+
attachmentsGrid.reviewExists = true
1683+
attachmentsGrid.updateAttachmentButtonState(true, reviewForm.defaultAccess === 'rw')
1684+
16771685
reviewForm.setReviewFormItemStates(reviewForm)
16781686
}
16791687
catch (e) {

0 commit comments

Comments
 (0)