Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[O2B-1405] Additional query parameters for creating a log #1809

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/public/views/Logs/Create/TemplatedLogCreationModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
* Return a new instance of log template for the given key
*
* @param {logTemplateKey} key the template key
* @param {object} templateData the template data
* @return {LogTemplate|null} the new log template
*/
const logTemplatesFactory = (key) => {
const logTemplatesFactory = (key, templateData) => {

Check warning on line 33 in lib/public/views/Logs/Create/TemplatedLogCreationModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Create/TemplatedLogCreationModel.js#L33

Added line #L33 was not covered by tests
const templateClass = {
['on-call']: OnCallLogTemplate,
['rc-daily-meeting']: RcDailyMeetingTemplate,
}[key] ?? null;
if (templateClass) {
return new templateClass();
return new templateClass(templateData);

Check warning on line 39 in lib/public/views/Logs/Create/TemplatedLogCreationModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Create/TemplatedLogCreationModel.js#L39

Added line #L39 was not covered by tests
}
return null;
};
Expand All @@ -49,8 +50,10 @@
*
* @param {function} [onCreation] function called when log is created, with the id of the created log
* @param {LogCreationRelations} relations the relations of the log
* @param {logTemplateKey|null} templateKey the key of the template to use
* @param {object} templateData the template data of the log
*/
constructor(onCreation, relations) {
constructor(onCreation, relations, templateKey, templateData) {

Check warning on line 56 in lib/public/views/Logs/Create/TemplatedLogCreationModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Create/TemplatedLogCreationModel.js#L56

Added line #L56 was not covered by tests
super(onCreation, relations);

/**
Expand All @@ -59,21 +62,20 @@
*/
this._templateKey = null;

/**
* @type {LogTemplate|null}
* @private
*/
this._templateModel = null;
if (templateKey) {
this.useTemplate(templateKey, templateData);

Check warning on line 66 in lib/public/views/Logs/Create/TemplatedLogCreationModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Create/TemplatedLogCreationModel.js#L65-L66

Added lines #L65 - L66 were not covered by tests
}
}

/**
* Defines the template to use, defined by its key
*
* @param {logTemplateKey|null} key the key of the template to use (there may be no model for the given key)
* @param {object} [templateData={}] the optional template data
* @return {void}
*/
useTemplate(key) {
const templateModel = logTemplatesFactory(key);
useTemplate(key, templateData={}) {

Check failure on line 77 in lib/public/views/Logs/Create/TemplatedLogCreationModel.js

View workflow job for this annotation

GitHub Actions / linter

Operator '=' must be spaced
const templateModel = logTemplatesFactory(key, templateData);

Check warning on line 78 in lib/public/views/Logs/Create/TemplatedLogCreationModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Create/TemplatedLogCreationModel.js#L77-L78

Added lines #L77 - L78 were not covered by tests
if (templateModel) {
templateModel.bubbleTo(this);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/public/views/Logs/Create/logCreationComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export const logCreationComponent = (creationModel) => {
'select.f5.form-control',
{ onchange: (e) => creationModel.useTemplate(e.target.value) },
[
h('option', { value: null, selected: creationModel.templateKey === null }, '- No template -'),
h('option', { value: 'null', selected: creationModel.templateKey === null }, '- No template -'),
...Object.entries(templates)
.map(([template, configuration]) => h(
'option',
Expand Down
12 changes: 11 additions & 1 deletion lib/public/views/Logs/Create/templates/OnCallLogTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
export class OnCallLogTemplate extends Observable {
/**
* Constructor
*
* @param {object} templateData the template data

Check failure on line 53 in lib/public/views/Logs/Create/templates/OnCallLogTemplate.js

View workflow job for this annotation

GitHub Actions / linter

Expected this line to be aligned with the start of the comment
*/
constructor() {
constructor(templateData) {

Check warning on line 55 in lib/public/views/Logs/Create/templates/OnCallLogTemplate.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Create/templates/OnCallLogTemplate.js#L55

Added line #L55 was not covered by tests
super();

/**
Expand All @@ -73,6 +75,13 @@
reason: '',
alreadyTakenActions: '',
};

if (templateData.detectorOrSubsystem) {
this.formData.detectorOrSubsystem = templateData.detectorOrSubsystem;

Check warning on line 80 in lib/public/views/Logs/Create/templates/OnCallLogTemplate.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Create/templates/OnCallLogTemplate.js#L79-L80

Added lines #L79 - L80 were not covered by tests
}
if (templateData.issueDescription) {
this.formData.issueDescription = templateData.issueDescription;

Check warning on line 83 in lib/public/views/Logs/Create/templates/OnCallLogTemplate.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Create/templates/OnCallLogTemplate.js#L82-L83

Added lines #L82 - L83 were not covered by tests
}
}

/**
Expand Down Expand Up @@ -119,6 +128,7 @@
* @return {boolean} true if the form is valid
*/
get isValid() {
console.log(this.formData)

Check failure on line 131 in lib/public/views/Logs/Create/templates/OnCallLogTemplate.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected console statement

Check failure on line 131 in lib/public/views/Logs/Create/templates/OnCallLogTemplate.js

View workflow job for this annotation

GitHub Actions / linter

Missing semicolon

Check warning on line 131 in lib/public/views/Logs/Create/templates/OnCallLogTemplate.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/Create/templates/OnCallLogTemplate.js#L131

Added line #L131 was not covered by tests
return Boolean(this.formData.shortDescription.length >= 4 && this.formData.shortDescription.length <= 100
&& this.formData.detectorOrSubsystem
&& this.formData.severity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const onCallLogCreationConfiguration = (creationModel, template) => {
h('option', { disabled: null, selected: true }, '- None -'),
...systems.map((detectorOrSubsystem) => h(
'option',
{ value: detectorOrSubsystem },
{ value: detectorOrSubsystem, selected: template.formData.detectorOrSubsystem === detectorOrSubsystem },
detectorOrSubsystem,
)),
],
Expand Down
17 changes: 15 additions & 2 deletions lib/public/views/Logs/LogsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,14 @@
* @param {string} [queryParams.runNumbers] the run numbers to link to the log being created
* @param {string} [queryParams.lhcFillNumbers] the lhc fill numbers to link to the log being created
* @param {string} [queryParams.environmentIds] the environment ids to link to the log being created
* @param {string} [queryParams.templateKey] the key of the template to use
* @param {string} [queryParams.issueDescription] the description of the issue
* @param {string} [queryParams.detectorOrSubsystem] the detector or subsystem to link to the log being created
* @return {void}
*/
loadCreation({ runNumbers, lhcFillNumbers, environmentIds }) {
loadCreation({ runNumbers, lhcFillNumbers, environmentIds, templateKey, issueDescription, detectorOrSubsystem }) {

Check warning on line 119 in lib/public/views/Logs/LogsModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/LogsModel.js#L119

Added line #L119 was not covered by tests
martinboulais marked this conversation as resolved.
Show resolved Hide resolved
const relations = {};
const templateData = {};

Check warning on line 121 in lib/public/views/Logs/LogsModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/LogsModel.js#L121

Added line #L121 was not covered by tests

if (runNumbers) {
relations.runNumbers = this._parseCommaSeparatedNumbers(runNumbers);
Expand All @@ -125,8 +129,17 @@
if (environmentIds) {
relations.environmentIds = environmentIds.split(',').map((environmentId) => environmentId.trim());
}
if (templateKey) {
templateData.templateKey = templateKey;

Check warning on line 133 in lib/public/views/Logs/LogsModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/LogsModel.js#L132-L133

Added lines #L132 - L133 were not covered by tests
}
if (issueDescription) {
templateData.issueDescription = issueDescription;

Check warning on line 136 in lib/public/views/Logs/LogsModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/LogsModel.js#L135-L136

Added lines #L135 - L136 were not covered by tests
}
if (detectorOrSubsystem) {
templateData.detectorOrSubsystem = detectorOrSubsystem;

Check warning on line 139 in lib/public/views/Logs/LogsModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/LogsModel.js#L138-L139

Added lines #L138 - L139 were not covered by tests
}

this._creationModel = new TemplatedLogCreationModel(this.handleLogCreation.bind(this), relations);
this._creationModel = new TemplatedLogCreationModel(this.handleLogCreation.bind(this), relations, templateKey, templateData);

Check warning on line 142 in lib/public/views/Logs/LogsModel.js

View check run for this annotation

Codecov / codecov/patch

lib/public/views/Logs/LogsModel.js#L142

Added line #L142 was not covered by tests
this._creationModel.bubbleTo(this);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/server/services/log/LogService.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,16 @@
* @param {Attachment[]} attachments the list of attachments to link to the log
* @return {Promise<Log>} resolve with the created log instance
*/
async create(newLog, runNumbers = [], tagsTexts = [], environments = [], lhcFills = [], attachments = []) {
async create(

Check failure on line 204 in lib/server/services/log/LogService.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected newline after '('
newLog, runNumbers = [], tagsTexts = [], environments = [], lhcFills = []

Check failure on line 205 in lib/server/services/log/LogService.js

View workflow job for this annotation

GitHub Actions / linter

Missing trailing comma
) {

Check failure on line 206 in lib/server/services/log/LogService.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected newline before ')'

Check warning on line 206 in lib/server/services/log/LogService.js

View check run for this annotation

Codecov / codecov/patch

lib/server/services/log/LogService.js#L205-L206

Added lines #L205 - L206 were not covered by tests
const logId = await createLog(
logAdapter.toDatabase(newLog),
runNumbers,
tagsTexts,
environments,
lhcFills,
attachments.map((attachment) => attachmentAdapter.toDatabase(attachment)),

Check failure on line 213 in lib/server/services/log/LogService.js

View workflow job for this annotation

GitHub Actions / linter

'attachments' is not defined
);
// No transaction, log is ready here and can not be null
return this.get(logId);
Expand Down
40 changes: 40 additions & 0 deletions test/public/logs/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,46 @@ module.exports = () => {
await expectInputValue(page, 'input#lhc-fills', '1,2,3');
});

it('Should set the correct template when templateKey is specified.', async () => {
const templateKey = 'on-call';
await goToPage(page, `log-create&templateKey=${templateKey}`);

await page.waitForSelector('select');
const selectedOption = await page.evaluate(() => document.querySelector('select').value);
expect(selectedOption).to.equal('on-call');
});

it('Should autofill detectorOrSubsystem and issueDescription if templateKey is "on-call".', async () => {
const templateKey = 'on-call';
const detectorOrSubsystem = 'ALL';
const issueDescription = 'This is a sample issue description';
await goToPage(
page,
`log-create&templateKey=${templateKey}&detectorOrSubsystem=${detectorOrSubsystem}&` +
`issueDescription=${issueDescription}`,
);

await expectInputValue(page, 'input#run-numbers', '');
await expectInputValue(page, 'input#environments', '');
await expectInputValue(page, 'input#lhc-fills', '');
expect(await page.evaluate(() => document.querySelector('select#detectorOrSubsystem').value)).to.equal('ALL');
await expectInputValue(page, 'textarea#issue-description', issueDescription);
});

it('Should autofill all inputs with provided full parameters.', async () => {
await goToPage(
page,
'log-create&runNumbers=1,2,3&lhcFillNumbers=1,2,3&environmentIds=1,2,3&templateKey=on-call&detectorOrSubsystem=ALL&' +
'issueDescription=This is a sample issue description',
);

await expectInputValue(page, 'input#run-numbers', '1,2,3');
await expectInputValue(page, 'input#environments', '1,2,3');
await expectInputValue(page, 'input#lhc-fills', '1,2,3');
expect(await page.evaluate(() => document.querySelector('select#detectorOrSubsystem').value)).to.equal('ALL');
await expectInputValue(page, 'textarea#issue-description', 'This is a sample issue description');
});

it('should successfully provide a tag picker with search input', async () => {
await waitForNavigation(page, () => pressElement(page, '#create-log-button'));

Expand Down
Loading