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-6933 - IVA Configuration Admin - Unable to select multiple studies #1003

Open
wants to merge 3 commits into
base: release-3.x.x
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
8 changes: 8 additions & 0 deletions src/core/clients/opencga/opencga-catalog-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,22 @@ export default class OpencgaCatalogUtils {
};
return {
attributes: {
// 1. Other attributes that the study might have
...study.attributes,
// 2. BACKUP previous settings
// eslint-disable-next-line no-undef
[SETTINGS_NAME + "_BACKUP"]:
// eslint-disable-next-line no-undef
UtilsNew.objectClone(study.attributes[SETTINGS_NAME]),
// 3. New tool settings
// eslint-disable-next-line no-undef
[SETTINGS_NAME]: {
userId: opencgaSession.user.id,
version: opencgaSession.ivaDefaultSettings.version.split("-")[0],
date: UtilsNew.getDatetime(),
settings: getSettings(),
},

}
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/webcomponents/commons/forms/select-field-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export default class SelectFieldFilter extends LitElement {
renderShowSelectAll() {
return html`
<span class="input-group-text rounded-start-0">
<input class="form-check-input mt-0" id="${this._prefix}-all-checkbox" type="checkbox" aria-label="..." @click=${this.selectAll}>
<input class="form-check-input mt-0 me-2" id="${this._prefix}-all-checkbox" type="checkbox" aria-label="..." @click=${this.selectAll}>
<span class="fw-bold ms-1">All</span>
</span>
`;
Expand Down Expand Up @@ -380,7 +380,7 @@ export default class SelectFieldFilter extends LitElement {
id="${this._prefix}"
@change="${this.filterChange}">
</select>
${this.all ? this.renderShowSelectAll() : nothing}
${this._config?.all ? this.renderShowSelectAll() : nothing}
</div>
`;
}
Expand Down
141 changes: 56 additions & 85 deletions src/webcomponents/commons/tool-settings-restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/

import {html, LitElement} from "lit";
import UtilsNew from "../../core/utils-new";
import NotificationUtils from "./utils/notification-utils";
import LitUtils from "./utils/lit-utils";
import OpencgaCatalogUtils from "../../core/clients/opencga/opencga-catalog-utils";
import {guardPage} from "./html-utils";
import {guardPage} from "./html-utils.js";
import OpencgaCatalogUtils from "../../core/clients/opencga/opencga-catalog-utils.js";
import NotificationUtils from "./utils/notification-utils.js";
import UtilsNew from "../../core/utils-new.js";
import LitUtils from "./utils/lit-utils.js";

export default class ToolSettingsRestore extends LitElement {

Expand Down Expand Up @@ -48,8 +48,8 @@ export default class ToolSettingsRestore extends LitElement {

// --- PRIVATE METHODS ---
#init() {
this._study = {};
this.isLoading = false;
this._studyFqnList = [];
this._activeTab = {
0: "default",
1: "backup",
Expand All @@ -63,73 +63,45 @@ export default class ToolSettingsRestore extends LitElement {
}

#initOriginalObjects() {
// The original settings and study are maintained. A copy is used for previewing the ongoing changes in json
this._study = UtilsNew.objectClone(this.study);
this._studyFqnList = this.opencgaSession?.study?.fqn ? [this.opencgaSession.study.fqn] : [];
this._config = {
...this.getDefaultConfig(),
// ...this.config,
this._study = this.study || this.opencgaSession.study;
this._data = {
listStudies: [UtilsNew.objectClone(this._study.fqn)],
};
}

// --- UPDATE ---
update(changedProperties) {
if (changedProperties.has("study")) {
this.studyObserver();
}
if (changedProperties.has("opencgaSession")) {
this.opencgaSessionObserver();
}
super.update(changedProperties);
}

// --- OBSERVERS ---
studyObserver() {
if (this.study && this.opencgaSession) {
this.#initOriginalObjects();
}
}

opencgaSessionObserver() {
// Read Projects and Study to prepare the Study select dropdown
this.allowedValues = [];
if (this.opencgaSession?.projects) {
// Prepare allowedValues for the select options menu
for (const project of this.opencgaSession.projects) {
const fields = [];
if (project.studies?.length > 0) {
for (const study of project.studies) {
if (OpencgaCatalogUtils.isAdmin(study, this.opencgaSession.user.id)) {
fields.push({id: study.fqn, name: study.fqn, disabled: study.fqn === this.opencgaSession.study.fqn});
}
}
if (fields.length > 0) {
this.allowedValues.push({name: `Project '${project.name}'`, fields: fields});
for (const study of project.studies) {
if (OpencgaCatalogUtils.isAdmin(study, this.opencgaSession.user.id)) {
fields.push({
id: study.fqn,
name: study.fqn,
disabled: study.fqn === this.opencgaSession.study.fqn
});
}
}
if (fields.length > 0) {
this.allowedValues.push({name: `Project '${project.name}'`, fields: fields});
}
}
}
this._config = this.getDefaultConfig();
}

// Refresh configuration object to read new this.allowedValues array.
this._config = {
...this.getDefaultConfig(),
// ...this.config,
};
// --- UPDATE ---
update(changedProperties) {
if (changedProperties.has("study") || changedProperties.has("opencgaSession")) {
this.#initOriginalObjects();
}
super.update(changedProperties);
}

// --- EVENTS ---
onFieldChange(e, field) {
const param = field || e.detail.param;
// 1. Update the list of studies
// NOTE Vero: In restoring settings, only changes in the study need to be listened.
// Changes in the json editor are for read-only purposes (preview default/backup settings per tool)
if (param === "fqn") {
this._study.fqn = "";
this._studyFqnList = e.detail.value?.length > 0 ? e.detail.value?.split(",") : [];
// Shallow copy just for refreshing the memory direction of this._study
this._study = {...this._study};
this.requestUpdate();
}
onFieldChange() {
this._data = {...this._data};
this.requestUpdate();
}

onClear() {
Expand All @@ -151,31 +123,29 @@ export default class ToolSettingsRestore extends LitElement {
};
// 2. Query
this.#setLoading(true);
this._studyFqnList.forEach(studyFqn => {
// 2.1. Get new study tool settings
const _toolSettingsRestorePromises = this._data.listStudies.map(studyFqn => {
// 2.1. Retrieve the backup or default tool settings of each study
const study = OpencgaCatalogUtils.getStudyInSession(this.opencgaSession, studyFqn);
const allToolSettings = OpencgaCatalogUtils.getRestoreIVASettings(this.opencgaSession, study, activeTab);
// 2.2 Query
this.opencgaSession.opencgaClient.studies()
// 2.2 Return the query
return this.opencgaSession.opencgaClient.studies()
.update(studyFqn, allToolSettings, params)
.then(response => {
// 1. Dispatch success notification
.then(() => {
NotificationUtils.dispatch(this, NotificationUtils.NOTIFY_SUCCESS, {
title: `${UtilsNew.capitalize(activeTab)} Settings Update`,
message: `${UtilsNew.capitalize(activeTab)} settings updated correctly`,
title: `${UtilsNew.capitalize(activeTab)} Settings Restore in study ${studyFqn}`,
message: `${UtilsNew.capitalize(activeTab)} settings restored correctly`,
});
// 2. Dispatch study update event
LitUtils.dispatchCustomEvent(this, "studyUpdateRequest",
UtilsNew.objectClone(response.responses[0].results[0].fqn)
);
})
.catch(reason => {
NotificationUtils.dispatch(this, NotificationUtils.NOTIFY_RESPONSE, reason);
})
.finally(() => {
this.#setLoading(false);
});
});
// 2. Execute all changes and refresh session
Promise.all(_toolSettingsRestorePromises)
.finally(() => {
this.#setLoading(false);
LitUtils.dispatchCustomEvent(this, "studyUpdateRequest", {});
});
}

// --- RENDER ---
Expand All @@ -186,7 +156,7 @@ export default class ToolSettingsRestore extends LitElement {

return html `
<data-form
.data="${this._study}"
.data="${this._data}"
.config="${this._config}"
@fieldChange="${e => this.onFieldChange(e)}"
@clear="${this.onClear}"
Expand All @@ -210,7 +180,6 @@ export default class ToolSettingsRestore extends LitElement {
buttonsVisible: true,
buttonsLayout: "top",
buttonsClassName: "mt-2",
// buttonOkDisabled: () => this._studyFqnList?.length === 0
},
buttons: {
clearText: "Discard Changes",
Expand All @@ -229,11 +198,12 @@ export default class ToolSettingsRestore extends LitElement {
elements: [
{
title: "Study",
field: "fqn",
field: "listStudies",
type: "select",
multiple: true,
all: true,
required: true,
save: value => value?.split(",") || [], // Array when select and multiple
defaultValue: `${this._study.fqn}`,
allowedValues: this.allowedValues,
display: {
Expand All @@ -245,14 +215,14 @@ export default class ToolSettingsRestore extends LitElement {
type: "custom",
display: {
defaultLayout: "vertical",
render: study => {
render: () => {
return html `
<div class="pt-3 pe-3">
<tool-settings-editor
.toolSettings="${UtilsNew.objectClone(this.opencgaSession.ivaDefaultSettings.settings)}"
.selectSettings="${true}"
.readOnly="${true}"
.study="${study}"
.study="${this._study}"
.opencgaSession="${this.opencgaSession}">
</tool-settings-editor>
</div>
Expand All @@ -278,34 +248,35 @@ export default class ToolSettingsRestore extends LitElement {
type: "notification",
text: "No backup avaliable",
display: {
visible: study => !study?.attributes[SETTINGS_NAME + "_BACKUP"]?.settings,
visible: !this._study?.attributes[SETTINGS_NAME + "_BACKUP"]?.settings,
notificationType: "warning",
},
},
{
title: "Study",
field: "fqn",
field: "listStudies",
type: "select",
multiple: true,
all: true,
required: true,
save: value => value?.split(",") || [], // Array when select and multiple
defaultValue: `${this._study.fqn}`,
allowedValues: this.allowedValues,
display: {
visible: study => !!study?.attributes[SETTINGS_NAME + "_BACKUP"]?.settings,
visible: !!this._study?.attributes[SETTINGS_NAME + "_BACKUP"]?.settings,
placeholder: "Select study or studies..."
},
},
{
type: "custom",
display: {
visible: study => !!study?.attributes[SETTINGS_NAME + "_BACKUP"]?.settings,
render: study => {
visible: !!this._study?.attributes[SETTINGS_NAME + "_BACKUP"]?.settings,
render: () => {
return html `
<tool-settings-editor
.toolSettings="${UtilsNew.objectClone(study.attributes[SETTINGS_NAME + "_BACKUP"].settings)}"
.toolSettings="${UtilsNew.objectClone(this._study.attributes[SETTINGS_NAME + "_BACKUP"].settings)}"
.readOnly="${true}"
.study="${study}"
.study="${this._study}"
.opencgaSession="${this.opencgaSession}">
</tool-settings-editor>
`;
Expand Down
Loading