Skip to content

Commit 08efcc0

Browse files
authored
Merge pull request #1048 from opencb/TASK-7708
TASK-7708 - Job Logs in tail mode is never updated
2 parents 7e3753f + 50f7de1 commit 08efcc0

File tree

3 files changed

+55
-18
lines changed

3 files changed

+55
-18
lines changed

src/webcomponents/commons/grid-commons.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,21 @@ export default class GridCommons {
336336
}
337337
}
338338

339+
// get the configuration for the provided modal
340+
getModalConfig(name) {
341+
let modalConfig = this.modals[name || this.activeModal];
342+
// sometimes the modalConfig is a function that returns a modalConfig
343+
// for example when the configuration dependes on the selected row in the grid
344+
if (modalConfig && typeof modalConfig === "function") {
345+
modalConfig = modalConfig(this.context);
346+
}
347+
return modalConfig;
348+
}
349+
339350
// change the current active modal
340351
changeActiveModal(name) {
352+
const prevModal = this.activeModal;
353+
341354
// 1. check if there is a modal rendered
342355
if (this.activeModal) {
343356
ModalUtils.close(`GridModal${this.activeModal}`);
@@ -351,6 +364,19 @@ export default class GridCommons {
351364
this.context.updateComplete.then(() => {
352365
if (this.activeModal) {
353366
ModalUtils.show(`GridModal${this.activeModal}`);
367+
368+
// 4. if the active modal has changed, we can perform some action
369+
if (prevModal !== this.activeModal) {
370+
const modalConfig = this.getModalConfig();
371+
372+
// if the clearAfterClosing flag is set, we need to reset the active modal once it is closed
373+
if (modalConfig.clearAfterClosing === true) {
374+
this.registerModalEventListener(this.activeModal, "hidden.bs.modal", () => {
375+
// console.log(`${this.activeModal} modal closed, clearing active modal`);
376+
this.clearActiveModal();
377+
});
378+
}
379+
}
354380
}
355381
});
356382
}
@@ -365,15 +391,20 @@ export default class GridCommons {
365391
this.modals = modals;
366392
}
367393

394+
// method to register an event listener on the specified modal
395+
registerModalEventListener(modalName, eventName, callback) {
396+
if (this.activeModal === modalName) {
397+
const modalElement = this.context.querySelector(`#GridModal${modalName}`);
398+
if (modalElement) {
399+
modalElement.addEventListener(eventName, event => callback(event));
400+
}
401+
}
402+
}
403+
368404
// render the active modal
369405
renderModals() {
370406
if (this.activeModal) {
371-
let modalConfig = this.modals[this.activeModal];
372-
// sometimes the modalConfig is a function that returns a modalConfig
373-
// for example when the configuration dependes on the selected row in the grid
374-
if (modalConfig && typeof modalConfig === "function") {
375-
modalConfig = modalConfig(this.context);
376-
}
407+
const modalConfig = this.getModalConfig();
377408
// check if the modalConfig is a valid object
378409
if (modalConfig && typeof modalConfig.render === "function") {
379410
return ModalUtils.create(this.context, `GridModal${this.activeModal}`, modalConfig);

src/webcomponents/job/job-detail-log.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class JobDetailLog extends LitElement {
2323
constructor() {
2424
super();
2525

26-
this._init();
26+
this.#init();
2727
}
2828

2929
createRenderRoot() {
@@ -47,7 +47,7 @@ export default class JobDetailLog extends LitElement {
4747
};
4848
}
4949

50-
_init() {
50+
#init() {
5151
this._prefix = UtilsNew.randomString(8);
5252
this._config = this.getDefaultConfig();
5353

@@ -56,20 +56,28 @@ export default class JobDetailLog extends LitElement {
5656
this.content = null;
5757
}
5858

59-
async updated(changedProperties) {
59+
disconnectedCallback() {
60+
clearInterval(this.interval);
61+
super.disconnectedCallback();
62+
}
63+
64+
update(changedProperties) {
6065
if (changedProperties.has("job")) {
6166
this.jobId = this.job.id;
62-
if (this.active) {
63-
this.fetchContent(this.job, {command: this.command, type: this.type});
64-
}
6567
}
6668

6769
if (changedProperties.has("active")) {
6870
this.content = null;
69-
this.requestUpdate();
70-
await this.updateComplete;
71+
}
72+
73+
super.update(changedProperties);
74+
}
75+
76+
updated(changedProperties) {
77+
if (changedProperties.has("active") || changedProperties.has("job")) {
7178
if (this.active) {
7279
this.fetchContent(this.job, {command: this.command, type: this.type});
80+
this.setReloadInterval();
7381
} else {
7482
this.clearReload();
7583
}
@@ -93,15 +101,13 @@ export default class JobDetailLog extends LitElement {
93101
// setInterval makes sense only in case of Tail log
94102
setReloadInterval() {
95103
if (this.active && this.command === "tail" && this.job.internal.status.id === "RUNNING") {
96-
this.requestUpdate();
97104
this.interval = setInterval(() => {
98-
if ($(".jobs-details-log", this).is(":visible")) {
105+
if (this.active) {
99106
// tail call is actually head (after the first tail call)
100107
this.fetchContent(this.job, {command: "head", offset: this.contentOffset}, true);
101108
} else {
102109
this.clearReload();
103110
}
104-
this.requestUpdate();
105111
}, 10000);
106112
}
107113
}

src/webcomponents/job/job-grid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export default class JobGrid extends LitElement {
111111

112112
this.gridCommons.registerModals({
113113
"view-job": () => ({
114+
clearAfterClosing: true, // force to clear the active modal when closed
114115
display: {
115116
modalTitle: `Job ${this._selectedJobId}`,
116117
modalSize: "modal-3xl",
@@ -409,7 +410,6 @@ export default class JobGrid extends LitElement {
409410
if (UtilsNew.isNotEmpty(params)) {
410411
html = "<div>";
411412
for (const key of Object.keys(params)) {
412-
debugger
413413
html += `<div style="margin: 2px 0; white-space: nowrap">`;
414414
// 1. Normal parameter
415415
if (typeof params[key] !== "object") {

0 commit comments

Comments
 (0)