diff --git a/lib/public/views/Logs/Create/TemplatedLogCreationModel.js b/lib/public/views/Logs/Create/TemplatedLogCreationModel.js index 2a4460d394..f5ce560976 100644 --- a/lib/public/views/Logs/Create/TemplatedLogCreationModel.js +++ b/lib/public/views/Logs/Create/TemplatedLogCreationModel.js @@ -27,15 +27,16 @@ import { RcDailyMeetingTemplate } from './templates/RcDailyMeetingTemplate.js'; * 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) => { const templateClass = { ['on-call']: OnCallLogTemplate, ['rc-daily-meeting']: RcDailyMeetingTemplate, }[key] ?? null; if (templateClass) { - return new templateClass(); + return new templateClass(templateData); } return null; }; @@ -49,8 +50,10 @@ export class TemplatedLogCreationModel extends LogCreationModel { * * @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) { super(onCreation, relations); /** @@ -59,21 +62,20 @@ export class TemplatedLogCreationModel extends LogCreationModel { */ this._templateKey = null; - /** - * @type {LogTemplate|null} - * @private - */ - this._templateModel = null; + if (templateKey) { + this.useTemplate(templateKey, templateData); + } } /** * 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 = {}) { + const templateModel = logTemplatesFactory(key, templateData); if (templateModel) { templateModel.bubbleTo(this); } diff --git a/lib/public/views/Logs/Create/templates/OnCallLogTemplate.js b/lib/public/views/Logs/Create/templates/OnCallLogTemplate.js index 11741d732c..e0d8494f70 100644 --- a/lib/public/views/Logs/Create/templates/OnCallLogTemplate.js +++ b/lib/public/views/Logs/Create/templates/OnCallLogTemplate.js @@ -49,8 +49,10 @@ const SHIFTER_TAGS = { export class OnCallLogTemplate extends Observable { /** * Constructor + * + * @param {object} templateData the template data */ - constructor() { + constructor(templateData) { super(); /** @@ -73,6 +75,13 @@ export class OnCallLogTemplate extends Observable { reason: '', alreadyTakenActions: '', }; + + if (templateData.detectorOrSubsystem) { + this.formData.detectorOrSubsystem = templateData.detectorOrSubsystem; + } + if (templateData.issueDescription) { + this.formData.issueDescription = templateData.issueDescription; + } } /** diff --git a/lib/public/views/Logs/Create/templates/onCallLogCreationConfiguration.js b/lib/public/views/Logs/Create/templates/onCallLogCreationConfiguration.js index 5d6945c36d..565873a56d 100644 --- a/lib/public/views/Logs/Create/templates/onCallLogCreationConfiguration.js +++ b/lib/public/views/Logs/Create/templates/onCallLogCreationConfiguration.js @@ -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, )), ], diff --git a/lib/public/views/Logs/LogsModel.js b/lib/public/views/Logs/LogsModel.js index 866d0dfac0..b4f9342d42 100644 --- a/lib/public/views/Logs/LogsModel.js +++ b/lib/public/views/Logs/LogsModel.js @@ -111,10 +111,14 @@ export class LogsModel extends Observable { * @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 }) { const relations = {}; + const templateData = {}; if (runNumbers) { relations.runNumbers = this._parseCommaSeparatedNumbers(runNumbers); @@ -125,8 +129,14 @@ export class LogsModel extends Observable { if (environmentIds) { relations.environmentIds = environmentIds.split(',').map((environmentId) => environmentId.trim()); } + if (issueDescription) { + templateData.issueDescription = issueDescription; + } + if (detectorOrSubsystem) { + templateData.detectorOrSubsystem = detectorOrSubsystem; + } - this._creationModel = new TemplatedLogCreationModel(this.handleLogCreation.bind(this), relations); + this._creationModel = new TemplatedLogCreationModel(this.handleLogCreation.bind(this), relations, templateKey, templateData); this._creationModel.bubbleTo(this); } diff --git a/test/public/logs/create.test.js b/test/public/logs/create.test.js index 3147896907..9ec56da9cc 100644 --- a/test/public/logs/create.test.js +++ b/test/public/logs/create.test.js @@ -185,6 +185,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'));