Skip to content

Commit 0afb0e0

Browse files
committed
[O2B-1536] Pass EOR lastEditedName through RunPatch
Stop keeping a separate `eorReasonLastEditedNames` list on RunDetailsModel and instead include `lastEditedName` on each eorReason within RunPatch. RunPatch `toPojo` then strips that field when building the outbound patch. This removes duplicate state and ensures only allowed fields are sent to the server.
1 parent cfb984b commit 0afb0e0

4 files changed

Lines changed: 9 additions & 19 deletions

File tree

lib/public/views/Runs/Details/RunDetailsModel.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ export class RunDetailsModel extends Observable {
5353
this.editionTagPickerModel = new TagSelectionDropdownModel();
5454
this._runPatch = new RunPatch();
5555
this._runPatch.bubbleTo(this);
56-
this._eorReasonLastEditedNames = [];
57-
5856
this._tabbedPanelModel = new RunDetailsTabbedPanelModel();
5957
this._tabbedPanelModel.bubbleTo(this);
6058

@@ -279,14 +277,6 @@ export class RunDetailsModel extends Observable {
279277
return this._runPatch;
280278
}
281279

282-
/**
283-
* Returns the list of last edited names for EOR reasons, to be displayed in the edit form so as not to get added to patch
284-
* @return {string[]} the list of last edited names for EOR reasons
285-
*/
286-
get eorReasonLastEditedNames() {
287-
return this._eorReasonLastEditedNames;
288-
}
289-
290280
/**
291281
* Returns the model for bottom-page tabs
292282
*
@@ -310,8 +300,6 @@ export class RunDetailsModel extends Observable {
310300
this._runPatch = new RunPatch(run);
311301
this._runPatch.bubbleTo(this);
312302

313-
this._eorReasonLastEditedNames = (run.eorReasons || []).map((eorReason) => eorReason.lastEditedName ?? null);
314-
315303
this.editionTagPickerModel = new TagSelectionDropdownModel({ defaultSelection: run.tags.map(tagToOption) });
316304
this._tabbedPanelModel.runNumber = run.runNumber;
317305
this._runNumber = run.runNumber;

lib/public/views/Runs/Details/RunPatch.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { RunQualities } from '../../../domain/enums/RunQualities.js';
99
* @property {string} category
1010
* @property {string} title
1111
* @property {string} description
12+
* @property {string|null} [lastEditedName]
1213
*/
1314

1415
/**
@@ -75,7 +76,8 @@ export class RunPatch extends Observable {
7576
}
7677

7778
if (this._eorReasons.length !== this._run.eorReasons.length || this._eorReasons.some(({ id }) => id === undefined)) {
78-
ret.eorReasons = this._eorReasons;
79+
// Strip lastEditedName — the server's EorReasonDto only accepts id, reasonTypeId, and description
80+
ret.eorReasons = this._eorReasons.map(({ id, reasonTypeId, description }) => ({ id, reasonTypeId, description }));
7981
}
8082

8183
if (this._hasRunQualityChange()) {
@@ -126,10 +128,11 @@ export class RunPatch extends Observable {
126128
} = this._run || {};
127129

128130
this._runQuality = runQuality;
129-
this._eorReasons = eorReasons.map(({ id, description, reasonTypeId }) => ({
131+
this._eorReasons = eorReasons.map(({ id, description, reasonTypeId, lastEditedName }) => ({
130132
id,
131133
description,
132134
reasonTypeId,
135+
lastEditedName,
133136
}));
134137
this._tags = tags.map(({ text }) => text);
135138

lib/public/views/Runs/format/editRunEorReasons.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ export const editRunEorReasons = (runDetailsModel) => {
9393
* added EOR reason is still displayed
9494
*/
9595
runDetailsModel.runPatch.eorReasons.length > 0
96-
? runDetailsModel.runPatch.eorReasons.map((eorReason, index) => {
97-
const { reasonTypeId, description } = eorReason;
98-
const lastEditedName = runDetailsModel.eorReasonLastEditedNames[index];
96+
? runDetailsModel.runPatch.eorReasons.map((eorReason) => {
97+
const { reasonTypeId, description, lastEditedName } = eorReason;
9998
const { category = '-', title } = eorReasonTypes.find((eorReasonType) => eorReasonType.id === reasonTypeId) || {};
10099
const titleString = title ? ` - ${title}` : '';
101100
const descriptionString = description ? ` - ${description}` : '';
@@ -111,7 +110,7 @@ export const editRunEorReasons = (runDetailsModel) => {
111110
}, iconTrash()),
112111
h('.w-wrapped', `${category} ${titleString} ${descriptionString}`),
113112
]),
114-
h('.w-wrapped', `${lastEditedName ? `${lastEditedName}` : ''}`),
113+
h('.w-wrapped', lastEditedName || ''),
115114
],
116115
);
117116
})

lib/public/views/Runs/format/eorReasonComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ export const eorReasonComponent = (eorReason) => {
3131
const reasonText = formatEorReason(eorReason);
3232
return h('.w-100.flex-row.justify-between', [
3333
h('', reasonText),
34-
tooltip(h('.w-wrapped', `${lastEditedName}`), 'Last edited by'),
34+
lastEditedName ? tooltip(h('.w-wrapped', lastEditedName), 'Last edited by') : '',
3535
]);
3636
};

0 commit comments

Comments
 (0)