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

TASK-5744 - Memory leak issue in some views of Case Interpreter #889

Merged
merged 2 commits into from
Apr 15, 2024
Merged
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
6 changes: 3 additions & 3 deletions src/webcomponents/commons/json-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ export default class JsonEditor extends LitElement {

return html`
${this._config.showDownloadButton ? html`
<div class="text-right">
<div class="text-right" style="margin-bottom:8px;">
<download-button
.json="${this.data}"
class="btn-sm">
.class="${"btn-sm"}">
</download-button>
</div>
` : null
}

<div style="padding-top: 10px" id="${this.jsonEditorId}"></div>
<div id="${this.jsonEditorId}"></div>
`;
}

Expand Down
72 changes: 45 additions & 27 deletions src/webcomponents/commons/json-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import {LitElement, html} from "lit";
import {JSONEditor} from "vanilla-jsoneditor";
import UtilsNew from "../../core/utils-new.js";
import "../download-button.js";

Expand All @@ -34,43 +35,54 @@ export default class JsonViewer extends LitElement {
data: {
type: Object
},
// title: {
// type: String
// },
showDownloadButton: {
type: Boolean
},
active: {
type: Boolean
}
},
config: {
type: Object,
},
};
}

_init() {
this._prefix = UtilsNew.randomString(8);

this.showDownloadButton = true;
this.active = true;
this.jsonView = null;
this._config = this.getDefaultConfig();
}

connectedCallback() {
super.connectedCallback();

// this._config = {...this.getDefaultConfig(), ...this.config};
update(changedProperties) {
if (changedProperties.has("config")) {
this._config = {
...this.getDefaultConfig(),
...this.config,
};
}
super.update(changedProperties);
}

updated(changedProperties) {
if ((changedProperties.has("data") || changedProperties.has("active")) && this.active) {
if (this.data) {
// $(".json-renderer", this).jsonViewer(this.data);
$(`#${this._prefix}JsonView`, this).jsonViewer(this.data);
if ((changedProperties.has("data") || changedProperties.has("active") || changedProperties.has("config")) && this.active) {
if (!this.jsonView) {
this.initJsonView();
} else {
this.jsonView.update({json: this.data});
}
}
// super.update(changedProperties);
}

getDefaultConfig() {
return {};
initJsonView() {
this.jsonView = new JSONEditor({
target: this.querySelector(`#${this._prefix}JsonView`),
props: {
content: {
json: this.data || {},
},
mode: this._config?.mode || "tree",
indentation: this._config?.indentation || 4,
readOnly: true,
}
});
}

render() {
Expand All @@ -79,20 +91,26 @@ export default class JsonViewer extends LitElement {
}

return html`
${this.showDownloadButton ? html`
<div class="text-right">
${this._config?.showDownloadButton ? html`
<div class="text-right" style="margin-bottom:8px;">
<download-button
.json="${this.data}"
class="btn-sm">
.class="${"btn-sm"}">
</download-button>
</div>
` : null
}

<div id="${this._prefix}JsonView" class="json-renderer"></div>
` : null}
<div id="${this._prefix}JsonView"></div>
`;
}

getDefaultConfig() {
return {
showDownloadButton: true,
indentation: 4,
mode: "tree",
};
}

}

customElements.define("json-viewer", JsonViewer);
Loading