Skip to content

Commit c167d42

Browse files
authored
OpenConceptLab/ocl_issues#2644 | fix Remove Resources by Reference dialog feedback and radio grouping (#40)
Fixes two bugs in the "Remove Resources by Reference" dialog reported by MSF: 1. onExecute hardcoded deleteReferences(referenceIds, false), so choosing only "Remove reference(s)" (the recommended action for the common single-reference case) suppressed all success/error feedback and never closed the dialog or reloaded, even though the DELETE request succeeded server-side. Replaced with a combined completion handler that always surfaces success/error/queued-task status regardless of which action(s) ran, and also fixes excludeReferences silently claiming success on a 202 (queued Celery task) response instead of surfacing it like ReferenceForm.jsx already does for Add References. 2. Each resource row's RadioGroup used the literal name="reference-action", shared across every row rendered in the same dialog. Native HTML radio grouping is scoped by name across the whole page, not per React component instance, so selecting more than one resource collapsed all rows into a single mutually-exclusive group -- only one radio in the entire dialog could end up checked, regardless of each row's own recommendation. Scoped the name per row via resource.uuid.
1 parent 3f48ae6 commit c167d42

1 file changed

Lines changed: 31 additions & 22 deletions

File tree

src/components/collections/CollectionHomeChildrenList.jsx

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import alertifyjs from 'alertifyjs';
33
import {
4-
includes, compact, isEmpty, get, merge, forEach, flatten, uniq, map, max, keys, filter
4+
includes, compact, isEmpty, get, merge, forEach, flatten, uniq, map, max, keys, filter, some
55
} from 'lodash';
66
import {
77
Dialog, DialogContent, DialogTitle, Divider, CircularProgress,
@@ -67,34 +67,43 @@ class CollectionHomeChildrenList extends React.Component {
6767
const conceptURLs = getURLs('Concept')
6868
const mappingURLs = getURLs('Mapping')
6969

70-
this.deleteReferences(referenceIds, false)
70+
const requests = []
71+
if(!isEmpty(referenceIds))
72+
requests.push(this.deleteReferences(referenceIds, false))
7173
if(!isEmpty(conceptURLs) || !isEmpty(mappingURLs))
72-
this.excludeReferences({concepts: conceptURLs, mappings: mappingURLs, exclude: true})
74+
requests.push(this.excludeReferences({concepts: conceptURLs, mappings: mappingURLs, exclude: true}))
75+
76+
Promise.all(requests).then(this.onExecuteComplete)
7377
}
7478

75-
excludeReferences = data => {
76-
APIService
77-
.new()
78-
.overrideURL(this.props.versionedObjectURL)
79-
.appendToUrl('references/').put({data: data}).then(() => {
80-
this.setState(
81-
{describeDelete: false},
82-
() => alertifyjs.success(`Successfully executed`, 1, () => window.location.reload())
83-
)
84-
})
79+
onExecuteComplete = responses => {
80+
const statuses = map(responses, response => get(response, 'status'))
81+
this.setState({describeDelete: false}, () => {
82+
if(some(statuses, status => !includes([200, 202, 204], status)))
83+
alertifyjs.error('Failed!')
84+
else if(includes(statuses, 202))
85+
alertifyjs.success('The request is in the queue and will be processed soon.', 10, () => window.location.reload())
86+
else
87+
alertifyjs.success(`Successfully executed`, 1, () => window.location.reload())
88+
})
8589
}
8690

91+
excludeReferences = data => APIService
92+
.new()
93+
.overrideURL(this.props.versionedObjectURL)
94+
.appendToUrl('references/').put({data: data})
95+
8796
deleteReferences = (referenceIds, alert = true) => {
88-
if(!isEmpty(referenceIds)) {
89-
APIService.new().overrideURL(this.props.versionedObjectURL).appendToUrl('references/').delete({ids: referenceIds}).then(response => {
90-
if(alert) {
91-
if(get(response, 'status') === 204)
92-
alertifyjs.success(`Successfully delete references`, 1, () => window.location.reload())
93-
else if(alert)
94-
alertifyjs.error('Failed!')
95-
}
97+
const request = APIService.new().overrideURL(this.props.versionedObjectURL).appendToUrl('references/').delete({ids: referenceIds})
98+
if(alert) {
99+
request.then(response => {
100+
if(get(response, 'status') === 204)
101+
alertifyjs.success(`Successfully delete references`, 1, () => window.location.reload())
102+
else
103+
alertifyjs.error('Failed!')
96104
})
97105
}
106+
return request
98107
}
99108

100109
onReferencesDelete = items => {
@@ -256,7 +265,7 @@ class CollectionHomeChildrenList extends React.Component {
256265
<FormControl style={{width: '100%'}}>
257266
<RadioGroup
258267
aria-labelledby="demo-radio-buttons-group-label"
259-
name="reference-action"
268+
name={`reference-action-${resource.uuid}`}
260269
onChange={(event, value) => this.onActionChange(event, resource, value)}
261270
defaultValue={recommendedOption}
262271
>

0 commit comments

Comments
 (0)