Skip to content

Commit 89ca6b4

Browse files
[O2B-1106] Separate log reply from log creation (#1388)
* [O2B-1106] Separate log reply from main log creation * Fix tests * Fix tests * Fix tests
1 parent a6d9a8a commit 89ca6b4

16 files changed

Lines changed: 469 additions & 320 deletions

lib/public/Model.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ export default class Model extends Observable {
186186
case 'log-create':
187187
this.logs.loadCreation(this.router.params);
188188
break;
189+
case 'log-reply':
190+
this.logs.loadReply(this.router.params);
191+
break;
189192
case 'run-overview':
190193
this.runs.loadOverview();
191194
break;

lib/public/components/Filters/common/filters/TextTokensFilterModel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { FilterModel } from '../FilterModel.js';
1616
const TOKENS_DELIMITER = ',';
1717

1818
/**
19-
* Model which accept string input and treats it as sequence of tokens,
20-
* which processed with regards of given configuration. @see TextTokensFilterModel#constructor
19+
* Model which accept string input and treats it as sequence of tokens, which processed in regard to given configuration. @see
20+
* TextTokensFilterModel#constructor
2121
*/
2222
export class TextTokensFilterModel extends FilterModel {
2323
/**
@@ -30,7 +30,7 @@ export class TextTokensFilterModel extends FilterModel {
3030
}
3131

3232
/**
33-
* Update value kept by a filter model and inform observers that some change occured
33+
* Update value kept by a filter model and inform observers that some change occurred
3434
* @param {string} value value to be stored
3535
* @return {void}
3636
*/

lib/public/components/Log/logReplyButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { frontLink } from '../common/navigation/frontLink.js';
2121
*/
2222
export const logReplyButton = (log) => frontLink(
2323
'Reply',
24-
'log-create',
24+
'log-reply',
2525
{ parentLogId: log.id },
2626
{
2727
id: `reply-to-${log.id}`,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
import { h } from '/js/src/index.js';
15+
16+
/**
17+
* Panel header component formed by a label
18+
*/
19+
export const LabelPanelHeaderComponent = {
20+
// eslint-disable-next-line require-jsdoc
21+
view: function ({ children, attrs }) {
22+
return h('label.label.form-check-label.panel-header', attrs, children);
23+
},
24+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
import { h } from '/js/src/index.js';
15+
16+
/**
17+
* Panel component
18+
*/
19+
export const PanelComponent = {
20+
// eslint-disable-next-line require-jsdoc
21+
view: function ({ children, attrs }) {
22+
return h('.panel', attrs, children);
23+
},
24+
};

lib/public/view.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { RunsPerLhcPeriodOverviewPage } from './views/Runs/RunPerPeriod/RunsPerL
3838
import { HomePage } from './views/Home/Overview/HomePage.js';
3939
import { DataPassesPerLhcPeriodOverviewPage } from './views/DataPasses/PerLhcPeriodOverview/DataPassesPerLhcPeriodOverviewView.js';
4040
import { RunsPerDataPassOverviewPage } from './views/Runs/RunPerDataPass/RunsPerDataPassOverviewPage.js';
41+
import { LogReplyPage } from './views/Logs/Create/LogReplyPage.js';
4142

4243
/**
4344
* Main view layout
@@ -55,6 +56,7 @@ export default (model) => {
5556
'log-overview': LogsOverview,
5657
'log-detail': LogTreeViewPage,
5758
'log-create': LogCreationPage,
59+
'log-reply': LogReplyPage,
5860

5961
'env-overview': EnvironmentOverviewPage,
6062
'env-details': EnvironmentDetailsPage,

lib/public/views/Logs/Create/LogCreationModel.js

Lines changed: 16 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
*/
1313
import { Observable, RemoteData } from '/js/src/index.js';
1414
import { jsonFetch } from '../../../utilities/fetch/jsonFetch.js';
15-
import { tagToOption } from '../../../components/tag/tagToOption.js';
16-
import { getRemoteData } from '../../../utilities/fetch/getRemoteData.js';
1715
import { TagPickerModel } from '../../../components/tag/TagPickerModel.js';
1816

1917
const DATA_DISPLAY_DELIMITER = ',';
2018

19+
/**
20+
* @typedef LogCreationRelations
21+
* @property {number[]} [runNumbers] run numbers associated with log being created
22+
* @property {number[]} [lhcFillNumbers] lhc fill numbers associated with log being created
23+
* @property {number[]} [environmentIds] environment ids associated with log being created
24+
*/
25+
2126
/**
2227
* Model to cary log creation state
2328
*/
@@ -26,8 +31,9 @@ export class LogCreationModel extends Observable {
2631
* Constructor
2732
*
2833
* @param {function} [onCreation] function called when log is created, with the id of the created log
34+
* @param {LogCreationRelations} relations the relations of the log
2935
*/
30-
constructor(onCreation) {
36+
constructor(onCreation, relations) {
3137
super();
3238

3339
this._onCreation = onCreation;
@@ -38,47 +44,20 @@ export class LogCreationModel extends Observable {
3844
this._creationTagsPickerModel.bubbleTo(this);
3945
this._creationTagsPickerModel.visualChange$.bubbleTo(this);
4046

41-
this._parentLogId = null;
47+
const { runNumbers = [], environmentIds = [], lhcFillNumbers = [] } = relations;
48+
this._runNumbers = runNumbers.join(DATA_DISPLAY_DELIMITER);
49+
this._lhcFills = lhcFillNumbers.join(DATA_DISPLAY_DELIMITER);
50+
this._environments = environmentIds.join(DATA_DISPLAY_DELIMITER);
51+
this._isRunNumbersReadonly = Boolean(this._runNumbers);
4252

43-
this._isParentLogCollapsed = true;
53+
this._parentLogId = null;
4454

4555
this._attachments = [];
4656

4757
this._createdLog = RemoteData.notAsked();
4858
this._isRunNumbersReadonly = false;
4959
}
5060

51-
/**
52-
* Provide initial data for creation
53-
* @param {Object} [data] data
54-
* @param {number} [data.parentLogId] id of parent log
55-
* @param {number[]} [data.runNumbers] run numbers associated with log being created
56-
* @param {number[]} [data.lhcFillNumbers] lhc fill numbers associated with log being created
57-
* @param {number[]} [data.environmentIds] environment ids associated with log being created
58-
* @return {void}
59-
*/
60-
setLogCreationInitialData({ parentLogId, runNumbers, lhcFillNumbers, environmentIds }) {
61-
this._runNumbers = runNumbers.join(DATA_DISPLAY_DELIMITER);
62-
this._lhcFills = lhcFillNumbers.join(DATA_DISPLAY_DELIMITER);
63-
this._environments = environmentIds.join(DATA_DISPLAY_DELIMITER);
64-
this._isRunNumbersReadonly = Boolean(this._runNumbers);
65-
66-
if (parentLogId) {
67-
this._parentLogId = Number(parentLogId);
68-
this._parentLog = RemoteData.loading();
69-
getRemoteData(`/api/logs/${this._parentLogId}`).then(
70-
({ data: parentLog }) => {
71-
this.parentLog = RemoteData.success(parentLog);
72-
},
73-
(errors) => {
74-
this.parentLog = RemoteData.failure(errors);
75-
},
76-
);
77-
} else {
78-
this._parentLog = RemoteData.success(null);
79-
}
80-
}
81-
8261
/**
8362
* Returns whether parent log is collapsed
8463
*
@@ -103,10 +82,6 @@ export class LogCreationModel extends Observable {
10382
* @returns {undefined}
10483
*/
10584
async submit() {
106-
if (!this.isReady) {
107-
throw new Error('Log creation is not ready, please wait');
108-
}
109-
11085
if (!this.isValid) {
11186
throw new Error('Created log is not valid');
11287
}
@@ -126,7 +101,7 @@ export class LogCreationModel extends Observable {
126101
const body = {
127102
title,
128103
text,
129-
...parentLogId > 0 && { parentLogId },
104+
...parentLogId !== null && { parentLogId },
130105
...runNumbers && { runNumbers },
131106
};
132107

@@ -283,38 +258,6 @@ export class LogCreationModel extends Observable {
283258
return this._parentLogId;
284259
}
285260

286-
/**
287-
* Returns the current parent log as a remote data
288-
* If the log do not have a parent log, the value will be success(null)
289-
*
290-
* @return {RemoteData} the parent log
291-
*/
292-
get parentLog() {
293-
return this._parentLog;
294-
}
295-
296-
/**
297-
* Set the parent log and use its values to define default values for the created log
298-
*
299-
* @param {RemoteData} parentLog the new parent log as a remote data
300-
*/
301-
set parentLog(parentLog) {
302-
this._parentLog = parentLog;
303-
if (parentLog.isSuccess()) {
304-
const { title, tags, runs } = parentLog.payload;
305-
306-
this.title = `${title}`;
307-
308-
if (this.tagsPickerModel.hasOnlyDefaultSelection()) {
309-
this.tagsPickerModel.selectedOptions = tags.map(tagToOption);
310-
}
311-
if (!this.runNumbers) {
312-
this.runNumbers = runs.map(({ runNumber }) => runNumber).join(', ');
313-
}
314-
}
315-
this.notify();
316-
}
317-
318261
/**
319262
* Returns the list of files attachments linked to the log being created
320263
*
@@ -343,15 +286,6 @@ export class LogCreationModel extends Observable {
343286
return this._createdLog;
344287
}
345288

346-
/**
347-
* States if the log creation model is ready
348-
*
349-
* @return {boolean} true if the model is ready
350-
*/
351-
get isReady() {
352-
return this._parentLog.isSuccess();
353-
}
354-
355289
/**
356290
* States if the currently created log is valid
357291
*
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
import { LogCreationModel } from './LogCreationModel.js';
14+
import { getRemoteData } from '../../../utilities/fetch/getRemoteData.js';
15+
import { tagToOption } from '../../../components/tag/tagToOption.js';
16+
import { RemoteData } from '/js/src/index.js';
17+
18+
/**
19+
* Model for log reply creation
20+
*/
21+
export class LogReplyModel extends LogCreationModel {
22+
/**
23+
* Constructor
24+
*
25+
* @param {function} onCreation function called when the log has been created with the id of the created log as a parameter
26+
* @param {number} parentLogId the id of the parent log
27+
*/
28+
constructor(onCreation, parentLogId) {
29+
super(onCreation, {});
30+
31+
this._parentLogId = parentLogId;
32+
33+
this._parentLog = RemoteData.loading();
34+
getRemoteData(`/api/logs/${this._parentLogId}`).then(
35+
({ data: parentLog }) => {
36+
this._parentLog = RemoteData.success(parentLog);
37+
this.inheritFromParentLog(parentLog);
38+
},
39+
(errors) => {
40+
this._parentLog = RemoteData.failure(errors);
41+
},
42+
).finally(() => this.notify());
43+
44+
this._isParentLogCollapsed = true;
45+
}
46+
47+
/**
48+
* Inherit the title, tags and runs from the parent log
49+
*
50+
* @param {Log} parentLog the parent log
51+
* @return {void}
52+
*/
53+
inheritFromParentLog(parentLog) {
54+
const { title, tags, runs } = parentLog;
55+
56+
this.title = `${title}`;
57+
58+
if (this.tagsPickerModel.hasOnlyDefaultSelection()) {
59+
this.tagsPickerModel.selectedOptions = tags.map(tagToOption);
60+
}
61+
62+
if (!this.runNumbers) {
63+
this.runNumbers = runs.map(({ runNumber }) => runNumber).join(', ');
64+
}
65+
}
66+
67+
/**
68+
* Returns the current parent log as a remote data
69+
* If the log do not have a parent log, the value will be success(null)
70+
*
71+
* @return {RemoteData} the parent log
72+
*/
73+
get parentLog() {
74+
return this._parentLog;
75+
}
76+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
import errorAlert from '../../../components/common/errorAlert.js';
14+
import { logReplyComponent } from './logReplyComponent.js';
15+
16+
/**
17+
* Page displaying log reply form
18+
*
19+
* @param {Model} model the global model
20+
* @return {Component} the resulting component
21+
*/
22+
export const LogReplyPage = ({ logs: { replyModel } }) => {
23+
if (!replyModel) {
24+
return errorAlert({
25+
title: 'Incoherent state',
26+
detail: 'The page internal state is broken, please try to refresh the page',
27+
});
28+
}
29+
30+
return logReplyComponent(replyModel);
31+
};

0 commit comments

Comments
 (0)