Skip to content

Commit

Permalink
Merge pull request #1368 from RoundingWell/comments-ws-subscribe
Browse files Browse the repository at this point in the history
Subscribe/unsubscribe to each comment in action sidebar
  • Loading branch information
paulfalgout authored Dec 19, 2024
2 parents 79be4aa + f7e3d03 commit 922395f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/js/apps/patients/sidebar/action-sidebar_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export default App.extend(extend({
if (flow) this.stopListening(flow);
this.stopListening(this.action);
this.action.trigger('editing', false);

this.removeSubscriptions();
},
beforeStart() {
return [
Expand All @@ -76,14 +78,20 @@ export default App.extend(extend({
},
onCommentAdded(model) {
this.activityCollection.add(model);
this.comments.add(model);

Radio.request('ws', 'add', model);
},
onStart(options, activity, comments, attachments) {
this.activityCollection = new Backbone.Collection([...activity.models, ...comments.models]);
this.comments = comments;
this.attachments = attachments;

this.showActivity();
this.showNewCommentForm();
this.showAttachments();

this.addSubscriptions();
},
showContent() {
const sidebarView = new SidebarView({ model: this.action });
Expand Down Expand Up @@ -185,7 +193,12 @@ export default App.extend(extend({
},
onPostNewComment({ model }) {
model.set({ created_at: dayjs.utc().format() }).save();

this.activityCollection.add(model);
this.comments.add(model);

Radio.request('ws', 'add', model);

this.showNewCommentForm();
},
onCancelNewComment() {
Expand Down Expand Up @@ -224,5 +237,13 @@ export default App.extend(extend({
onRemoveAttachment(model) {
model.destroy();
},
addSubscriptions() {
Radio.request('ws', 'add', this.comments);
},
removeSubscriptions() {
// for when sidebar is closed before comments api request is finished
if (!this.comments) return;

Radio.request('ws', 'unsubscribe', this.comments);
},
}, SidebarMixin));
2 changes: 1 addition & 1 deletion test/integration/patients/patient/patient-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ context('patient flow page', function() {
.find('.comment__item')
.last()
.as('socketComment')
.should('contain', formatDate(testTs(), 'AT_TIME'))
.should('contain', formatDate(dayjs.utc().format(), 'AT_TIME'))
.should('contain', 'Clinician McTester')
.should('contain', 'New websocket comment.');

Expand Down
6 changes: 3 additions & 3 deletions test/integration/patients/worklist/reduced-schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ context('reduced schedule page', function() {
.find('.js-patient-sidebar-button')
.click()
.wait('@routePatient');

cy
.get('.worklist-patient-sidebar')
.should('contain', 'First Last');

cy
.get('.worklist-patient-sidebar .js-close')
.click();

cy
.get('.worklist-patient-sidebar')
.should('not.exist');
Expand Down

0 comments on commit 922395f

Please sign in to comment.