Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/dev-dependencies-c8a…
Browse files Browse the repository at this point in the history
…baed068
  • Loading branch information
martinboulais authored Jan 7, 2025
2 parents 286186d + 639e634 commit d00cbdd
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN apk add --no-cache \
freetype=2.13.0-r5 \
freetype-dev=2.13.0-r5 \
harfbuzz=7.3.0-r0 \
ca-certificates=20240226-r0
ca-certificates=20241121-r0

# Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
Expand Down
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 @@ 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;
};
Expand All @@ -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);

/**
Expand All @@ -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);
}
Expand Down
11 changes: 10 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 @@ const SHIFTER_TAGS = {
export class OnCallLogTemplate extends Observable {
/**
* Constructor
*
* @param {object} templateData the template data
*/
constructor() {
constructor(templateData) {
super();

/**
Expand All @@ -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;
}
}

/**
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
14 changes: 12 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 @@ 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);
Expand All @@ -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);
}

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 @@ -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'));

Expand Down

0 comments on commit d00cbdd

Please sign in to comment.