Skip to content

Commit bf0ab80

Browse files
[O2B-1106] Preliminary cleaning of log creation component (#1378)
* [O2B-1106] Preliminary cleaning of log creation component * Fix tests * Remove useless docblock * Remove useless editor reference * Remove useless editor reference * Put back tests * Revert wrong files * Fix linter
1 parent e2d5a77 commit bf0ab80

16 files changed

Lines changed: 157 additions & 219 deletions

File tree

lib/public/components/Log/logDetailsButton.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

lib/public/components/Log/log.js renamed to lib/public/components/Log/logDisplayComponent.js

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@ import { h } from '/js/src/index.js';
1616
import { formatTimestamp } from '../../utilities/formatting/formatTimestamp.js';
1717
import { detailsFrontLinks } from '../common/navigation/frontLinks.js';
1818

19-
import { logDetails } from './logDetails.js';
2019
import { logLinkButton } from './logLinkButton.js';
21-
import { logReplyButton } from './logReplyButton.js';
22-
import { logText } from './logText.js';
23-
import { primaryButton } from '../common/primaryButton.js';
24-
import { logDetailsButton } from './logDetailsButton.js';
2520
import { attachmentPreviewComponent } from '../../views/Logs/FilePreview/attachmentPreviewComponent.js';
2621
import { tagBadge } from '../tag/tagBadge.js';
22+
import { markdownDisplay } from '../common/markdown/markdown.js';
2723

2824
/**
29-
* Provides formatting for each log field to display that field on the webpage
25+
* Map between log properties and the way to display it
26+
*
3027
* @return {Object} an object determining how each log field wil lbe displayed on the page
3128
*/
3229
const logFields = () => ({
@@ -76,40 +73,74 @@ const logFields = () => ({
7673
},
7774
});
7875

76+
/**
77+
* Format a given log's metadata
78+
*
79+
* @param {Log} log the log
80+
* @param {string[]} fields the names of the fields to display
81+
* @param {Object} fieldFormats an object containing a format function for each field
82+
* @return {Component} the log field displayed
83+
*/
84+
const displayLogMetadata = (log, fields, fieldFormats) => fields.map((key) => h(`div#log-${log.id}-${key}.flex-row`, [
85+
h('div.mr2', `${fieldFormats[key].name}:`),
86+
fieldFormats[key].format(log[key]),
87+
]));
88+
89+
/**
90+
* Returns a component displaying the text of a log
91+
*
92+
* @param {Log} log the log to display
93+
* @param {object} [options] display options
94+
* @param {boolean} [options.isCollapsed] true if the log is collapsed
95+
* @param {Partial<MarkdownBoxSize>} [options.boxSize] the text's markdown box size
96+
* @return {Component} the log's text display
97+
*/
98+
const displayLogText = (log, options) => {
99+
const { isCollapsed, boxSize } = options || {};
100+
101+
return h(
102+
`div#log-id-${log.id}`,
103+
isCollapsed
104+
? h(`.text-ellipsis.w-100#log-text-${log.id}`, log.text)
105+
: markdownDisplay(
106+
log.text,
107+
{
108+
classes: 'w-100',
109+
id: `log-text-${log.id}`,
110+
},
111+
boxSize,
112+
),
113+
);
114+
};
115+
79116
const expandedLogFields = ['runs', 'environments', 'lhcFills', 'attachments'];
80117

81118
/**
82119
* Returns a card for the given log
83120
*
84121
* @param {Log} log all data related to the log
85-
* @param {boolean} highlight indicator if this log should be highlighted
86-
* @param {boolean} showLogTitle indicator if the title of this log should be visible
87122
* @param {boolean} isCollapsed indicator if the title of this log is collapsed
88-
* @param {function} onCollapse function called when the log should be collapsed
89-
* @param {function} onExpand function called when the log should be expanded
90-
* @param {Object} options other options
91-
* @param {boolean} [options.replyButton] if true, reply button will be displayed
92-
* @param {boolean} [options.goToDetailsButton] if true, button to go to details will be displayed
93-
* @param {Object} [options.logMarkdownDisplayOpts] markdown display opts @see logText opts argument
94-
* @param {Partial<MarkdownBoxSize>} [options.logMarkdownDisplayOpts.boxSize] size of markdown display
123+
* @param {function} setCollapsed function called when the log should be collapsed or expanded
124+
* @param {Object} [options] other options
125+
* @param {boolean} [options.highlight] indicator if this log should be highlighted
126+
* @param {boolean} [options.hideTitle] indicator if the title of this log should be visible
127+
* @param {Component} [options.customActionButtons] optional custom buttons to display between copy link and collapse
128+
* @param {Partial<MarkdownBoxSize>} [options.textBoxSize] size of the log's content markdown display
95129
* @return {Component} the log's display component
96130
*/
97-
export const logComponent = (
131+
export const logDisplayComponent = (
98132
log,
99-
highlight,
100-
showLogTitle,
101133
isCollapsed,
102-
onCollapse,
103-
onExpand,
104-
options = {},
134+
setCollapsed,
135+
options,
105136
) => {
106137
const { title = '', id = '' } = log;
138+
const { highlight, hideTitle, customActionButtons, textBoxSize } = options || {};
139+
107140
const fieldFormatting = logFields();
108-
const logTitle = showLogTitle ? h(`h4#log-${id}-title`, title) : '';
141+
const logTitle = !hideTitle && h(`h4#log-${id}-title`, title);
109142
const displayedLogFields = isCollapsed ? [] : expandedLogFields;
110-
const logViewButton = isCollapsed
111-
? primaryButton('Show', onExpand, `show-collapse-${id}`)
112-
: primaryButton('Collapse', onCollapse, `collapse-${id}`);
143+
const logViewButton = h('button.btn.btn-primary', { onclick: () => setCollapsed(!isCollapsed) }, isCollapsed ? 'Show' : 'Collapse');
113144

114145
return h(
115146
`#log-${id}.br2.m1.p3.shadow-level1.flex-column.g1${highlight ? '.b1.b-primary' : ''}`,
@@ -122,15 +153,14 @@ export const logComponent = (
122153
),
123154
fieldFormatting.tags.format(log.tags),
124155
]),
125-
h('div.flex-row.flex-shrink-0.flex-wrap.items-start.g1', [
156+
h('div.log-display-action-buttons.flex-row.flex-shrink-0.flex-wrap.items-start.g1', [
126157
logLinkButton(log),
127-
options.replyButton && logReplyButton(log),
128-
options.goToDetailsButton && logDetailsButton(log),
158+
customActionButtons,
129159
logViewButton,
130160
]),
131161
]),
132-
logDetails(log, displayedLogFields, fieldFormatting),
133-
h('.bt1.b-gray-light.pv2/'),
134-
logText(log, isCollapsed, options?.logMarkdownDisplayOpts),
162+
displayLogMetadata(log, displayedLogFields, fieldFormatting),
163+
h('.bt1.b-gray-light.pv2'),
164+
displayLogText(log, { isCollapsed, boxSize: textBoxSize }),
135165
);
136166
};

lib/public/components/Log/logText.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

lib/public/components/common/errorAlert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { h } from '/js/src/index.js';
1616
/**
1717
* @typedef ApiError
1818
* @property {string} title the error's title
19-
* @property {Component} detail the error's details
19+
* @property {Component} [detail] the error's details
2020
*/
2121

2222
/**

lib/public/components/common/markdown/markdown.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ const DEFAULT_SIZE = 'auto';
2727
*
2828
* @param {string} content the initial content of the input
2929
* @param {Object} attributes the additional attributes to pass to the component, such as id and classes
30-
* @param {function} [onEditorChange] callback called any time the editor handler changes
3130
* @param {Partial<MarkdownBoxSize>} [size] the size of the markdown box
3231
* @return {vnode} the component
3332
*/
34-
export const markdownInput = (content, attributes, onEditorChange, size) => {
35-
onEditorChange = onEditorChange || (() => {
36-
});
37-
33+
export const markdownInput = (content, attributes, size) => {
3834
const onInput = attributes.oninput || attributes.onchange || (() => {
3935
});
4036

@@ -47,17 +43,16 @@ export const markdownInput = (content, attributes, onEditorChange, size) => {
4743
// eslint-disable-next-line require-jsdoc
4844
oncreate: function (node) {
4945
cleanCodeMirror(this.textarea);
50-
onEditorChange(markdownInputFromTextarea(
46+
markdownInputFromTextarea(
5147
node.dom,
5248
(value) => onInput({ target: { value } }),
5349
size,
54-
));
50+
);
5551
this.textarea = node.dom;
5652
},
5753
// eslint-disable-next-line require-jsdoc
5854
onremove: function () {
5955
cleanCodeMirror(this.textarea);
60-
onEditorChange(null);
6156
this.textarea = null;
6257
},
6358
},

lib/public/components/common/selection/infoLoggerButtonGroup/CopyToClipboardComponent.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14-
import { h } from '/js/src/index.js';
15-
import { iconLinkIntact, iconCheck } from '/js/src/icons.js';
14+
import { h, iconLinkIntact, iconCheck } from '/js/src/index.js';
1615
import { StatefulComponent } from '../../StatefulComponent.js';
1716

1817
/**

lib/public/views/EosReport/create/eosReportCreationComponent.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ const eosReportCreationForm = (reportType, formData, shiftData) => [
7777
// eslint-disable-next-line no-return-assign
7878
oninput: (e) => formData.lhcTransitions = e.target.value,
7979
},
80-
null,
8180
{ height: '20rem' },
8281
),
8382
]),
@@ -89,7 +88,6 @@ const eosReportCreationForm = (reportType, formData, shiftData) => [
8988
// eslint-disable-next-line no-return-assign
9089
oninput: (e) => formData.shiftFlow = e.target.value,
9190
},
92-
null,
9391
{ height: '20rem' },
9492
),
9593
]),
@@ -111,7 +109,6 @@ const eosReportCreationForm = (reportType, formData, shiftData) => [
111109
// eslint-disable-next-line no-return-assign
112110
oninput: (e) => formData.infoFromPreviousShifter = e.target.value,
113111
},
114-
null,
115112
{ height: '10rem' },
116113
),
117114
]),
@@ -125,7 +122,6 @@ const eosReportCreationForm = (reportType, formData, shiftData) => [
125122
// eslint-disable-next-line no-return-assign
126123
oninput: (e) => formData.infoForNextShifter = e.target.value,
127124
},
128-
null,
129125
{ height: '10rem' },
130126
),
131127
]),
@@ -140,7 +136,6 @@ const eosReportCreationForm = (reportType, formData, shiftData) => [
140136
// eslint-disable-next-line no-return-assign
141137
oninput: (e) => formData.infoForRmRc = e.target.value,
142138
},
143-
null,
144139
{ height: '10rem' },
145140
),
146141
]),

lib/public/views/EosReport/create/typeSpecific/eosFormDcsSpecificPart.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export const eosFormDcsSpecificPart = (formData) => h('#type-specific', h('.pane
2828
// eslint-disable-next-line no-return-assign
2929
oninput: (e) => formData.typeSpecific.alerts = e.target.value,
3030
},
31-
null,
3231
{ height: '20rem' },
3332
),
3433
]));

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

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ export class LogCreationModel extends Observable {
2626
* Constructor
2727
*
2828
* @param {function} [onCreation] function called when log is created, with the id of the created log
29-
* @param {number|null} parentLogId optionally the id of log that will be the parent of the created one
30-
* @param {Object} preFilledRelations the pre-filled relations of the log to create
31-
* @param {string[]} preFilledRelations.runNumbers the run numbers to link to the log being created
32-
* @param {string[]} preFilledRelations.lhcFillNumbers the fill numbers to link to the log being created
33-
* @param {string[]} preFilledRelations.environmentIds the environment ids to link to the log being created
3429
*/
3530
constructor(onCreation) {
3631
super();
@@ -51,12 +46,10 @@ export class LogCreationModel extends Observable {
5146

5247
this._createdLog = RemoteData.notAsked();
5348
this._isRunNumbersReadonly = false;
54-
55-
this._textEditor = null;
5649
}
5750

5851
/**
59-
* Provide initial data fro creation
52+
* Provide initial data for creation
6053
* @param {Object} [data] data
6154
* @param {number} [data.parentLogId] id of parent log
6255
* @param {number[]} [data.runNumbers] run numbers associated with log being created
@@ -86,24 +79,6 @@ export class LogCreationModel extends Observable {
8679
}
8780
}
8881

89-
/**
90-
* Show parent log entry collapsed
91-
* @returns {void}
92-
*/
93-
collapseParentLog() {
94-
this._isParentLogCollapsed = true;
95-
this.notify();
96-
}
97-
98-
/**
99-
* Show full parent log entry
100-
* @returns {void}
101-
*/
102-
showFullParentLog() {
103-
this._isParentLogCollapsed = false;
104-
this.notify();
105-
}
106-
10782
/**
10883
* Returns whether parent log is collapsed
10984
*
@@ -113,6 +88,15 @@ export class LogCreationModel extends Observable {
11388
return this._isParentLogCollapsed;
11489
}
11590

91+
/**
92+
* Defines if the parent log is collapsed
93+
* @param {boolean} collapsed true if the parent log is collapsed
94+
*/
95+
set isParentLogCollapsed(collapsed) {
96+
this._isParentLogCollapsed = collapsed;
97+
this.notify();
98+
}
99+
116100
/**
117101
* Create the log with the variables set in the model, handling errors appropriately
118102
* Adds the title of the parent log to a log reply if the title is empty.
@@ -385,22 +369,4 @@ export class LogCreationModel extends Observable {
385369
get isRunNumbersReadonly() {
386370
return this._isRunNumbersReadonly;
387371
}
388-
389-
/**
390-
* Return the markdown editor used to edit log's text
391-
*
392-
* @return {Object} the editor
393-
*/
394-
get textEditor() {
395-
return this._textEditor;
396-
}
397-
398-
/**
399-
* Set the markdown editor used to edit log's text
400-
*
401-
* @param {Object} value the new editor
402-
*/
403-
set textEditor(value) {
404-
this._textEditor = value;
405-
}
406372
}

0 commit comments

Comments
 (0)