Skip to content

Commit

Permalink
Change updated_at attribute when the action/flow model is updated v…
Browse files Browse the repository at this point in the history
…ia socket notification
  • Loading branch information
nmajor25 committed Nov 19, 2024
1 parent 3579198 commit 5e52dfc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/js/base/model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { extend, isEmpty, isFunction, pick, reduce, result } from 'underscore';
import Backbone from 'backbone';
import dayjs from 'dayjs';
import JsonApiMixin from './jsonapi-mixin';

export default Backbone.Model.extend(extend({
Expand Down Expand Up @@ -84,6 +85,8 @@ export default Backbone.Model.extend(extend({
return isFunction(messages[category]) ? messages[category] : this[messages[category]];
},
handleMessage({ category, payload }) {
payload.attributes = extend(payload.attributes || {}, { updated_at: dayjs.utc().format() });

const handler = this._getMessageHandler(category);
if (handler) handler.call(this, payload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ const TimestampsView = View.extend({
createdAt: this.getOption('createdEvent').get('date'),
};
},
modelEvents: {
'change:updated_at': 'render',
},
});

export {
Expand Down
1 change: 1 addition & 0 deletions src/js/views/patients/sidebar/flow/flow-sidebar_views.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const LayoutView = View.extend({
modelEvents: {
'change:_state': 'showOwner',
'change:_owner': 'showFlow',
'change:updated_at': 'showTimestamps',
},
onAttach() {
animSidebar(this.el);
Expand Down
33 changes: 33 additions & 0 deletions test/integration/patients/patient/patient-flow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'underscore';
import dayjs from 'dayjs';

import { testTs, testTsSubtract } from 'helpers/test-timestamp';
import { testDate, testDateAdd, testDateSubtract } from 'helpers/test-date';
Expand Down Expand Up @@ -121,6 +122,7 @@ context('patient flow page', function() {
duration: 10,
outreach: 'disabled',
sharing: 'disabled',
updated_at: testTsSubtract(1),
},
relationships: {
flow: getRelationship(testFlow),
Expand Down Expand Up @@ -190,6 +192,13 @@ context('patient flow page', function() {
.find('[data-action-region] .action-sidebar__name')
.should('contain', 'New Websocket Name');

cy
.get('.sidebar')
.find('.sidebar__footer')
.contains('Updated')
.next()
.should('contain', formatDate(dayjs.utc().format(), 'AT_TIME'));

cy
.get('.sidebar')
.find('[data-details-region] .js-input')
Expand Down Expand Up @@ -2344,6 +2353,7 @@ context('patient flow page', function() {
const testSocketFlow = getFlow({
attributes: {
name: 'Flow Test',
updated_at: testTsSubtract(1),
},
relationships: {
state: getRelationship(stateInProgress),
Expand All @@ -2358,6 +2368,7 @@ context('patient flow page', function() {
due_time: '06:00:00',
outreach: 'disabled',
sharing: 'disabled',
updated_at: testTsSubtract(1),
},
relationships: {
flow: getRelationship(testSocketFlow),
Expand All @@ -2383,6 +2394,7 @@ context('patient flow page', function() {
return fx;
})
.routeActionActivity()
.routeFlowActivity()
.visit(`/flow/${ testSocketFlow.id }`)
.wait('@routeFlow')
.wait('@routePatientByFlow')
Expand All @@ -2394,6 +2406,10 @@ context('patient flow page', function() {
getRelationship(testSocketAction).data,
]);

cy
.get('[data-header-region]')
.click('top');

cy.sendWs({
category: 'NameChanged',
resource: {
Expand All @@ -2412,6 +2428,18 @@ context('patient flow page', function() {
.find('.patient-flow__name')
.contains('New Flow Name');

cy
.get('.app-frame__sidebar')
.find('.sidebar__footer')
.contains('Updated')
.next()
.should('contain', formatDate(dayjs.utc().format(), 'AT_TIME'));

cy
.get('.app-frame__sidebar')
.find('.js-close')
.click();

cy.sendWs({
category: 'DetailsChanged',
resource: {
Expand Down Expand Up @@ -2448,6 +2476,11 @@ context('patient flow page', function() {
.find('.table-list__item .patient__action-name')
.contains('New Action Name');

cy
.get('.patient-flow__list')
.find('.table-list__item .patient__action-ts')
.should('contain', formatDate(dayjs.utc().format(), 'TIME_OR_DAY'));

cy.sendWs({
category: 'ActionDueChanged',
resource: {
Expand Down

0 comments on commit 5e52dfc

Please sign in to comment.