Skip to content

Commit 7e3753f

Browse files
authored
Merge pull request #1047 from opencb/TASK-7762
TASK-7762 - Prevent or re-direct session refresh when making changes in the admin interface
2 parents 7793558 + b750e25 commit 7e3753f

File tree

11 files changed

+123
-31
lines changed

11 files changed

+123
-31
lines changed

src/sites/iva/iva-app.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,7 @@ class IvaApp extends LitElement {
12671267
content = html`
12681268
<organization-admin
12691269
.opencgaSession="${this.opencgaSession}"
1270+
.tool="${this.queries[this.tool]?.tool}"
12701271
@studyUpdateRequest="${this.onStudyUpdateRequest}"
12711272
@sessionUpdateRequest="${this.onSessionUpdateRequest}">
12721273
</organization-admin>
@@ -1290,6 +1291,7 @@ class IvaApp extends LitElement {
12901291
content = html`
12911292
<study-admin
12921293
.opencgaSession="${this.opencgaSession}"
1294+
.tool="${this.queries[this.tool]?.tool}"
12931295
@studyUpdateRequest="${this.onStudyUpdateRequest}">
12941296
</study-admin>
12951297
`;
@@ -1298,6 +1300,7 @@ class IvaApp extends LitElement {
12981300
content = html`
12991301
<study-admin-iva
13001302
.opencgaSession="${this.opencgaSession}"
1303+
.tool="${this.queries[this.tool]?.tool}"
13011304
.settings="${this.settings}"
13021305
@studyUpdateRequest="${this.onStudyUpdateRequest}">
13031306
</study-admin-iva>
@@ -1307,6 +1310,7 @@ class IvaApp extends LitElement {
13071310
content = html`
13081311
<operations-admin
13091312
.opencgaSession="${this.opencgaSession}"
1313+
.tool="${this.queries[this.tool]?.tool}"
13101314
@studyUpdateRequest="${this.onStudyUpdateRequest}">
13111315
</operations-admin>
13121316
`;
@@ -1343,7 +1347,8 @@ class IvaApp extends LitElement {
13431347
case "analysis-tools":
13441348
content = html`
13451349
<analysis-tools
1346-
.opencgaSession="${this.opencgaSession}">
1350+
.opencgaSession="${this.opencgaSession}"
1351+
.tool="${this.queries[this.tool]?.tool}">
13471352
</analysis-tools>
13481353
`;
13491354
break;

src/webcomponents/commons/analysis/analysis-tools.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {LitElement, html, nothing, render} from "lit";
1+
import {LitElement, html} from "lit";
2+
import WebUtils from "../utils/web-utils.js";
23
import "../tool-header.js";
34
import "../view/vertical-menu.js";
45
import "../../clinical/analysis/mutational-signature-analysis.js";
@@ -42,19 +43,31 @@ export default class AnalysisTools extends LitElement {
4243
opencgaSession: {
4344
type: Object,
4445
},
46+
tool: {
47+
type: String,
48+
},
4549
};
4650
}
4751

4852
#init() {
4953
this._config = this.getDefaultConfig();
5054
}
5155

56+
onChangeActiveItem(event) {
57+
const [app, tool] = WebUtils.getApplicationAndToolFromHash();
58+
WebUtils.redirectTo(this.opencgaSession, app, tool, {
59+
tool: event.detail.value,
60+
});
61+
}
62+
5263
render() {
5364
return html`
5465
<tool-header .title="${this._config.title}"></tool-header>
5566
<vertical-menu
5667
.opencgaSession="${this.opencgaSession}"
57-
.config="${this._config || {}}">
68+
.activeItem="${this.tool}"
69+
.config="${this._config || {}}"
70+
@changeActiveItem="${event => this.onChangeActiveItem(event)}">
5871
</vertical-menu>
5972
`;
6073
}

src/webcomponents/commons/filters-toolbar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ export default class FiltersToolbar extends LitElement {
439439

440440
onCopyLink() {
441441
// 1. Generate the url to the tool with the current query
442-
const link = WebUtils.getIVALink(this.opencgaSession, this.toolId, this.preparedQuery);
442+
const [app, tool] = WebUtils.getApplicationAndToolFromHash();
443+
const link = WebUtils.getIVALink(this.opencgaSession, app, tool, this.preparedQuery);
443444

444445
// 2. Copy this link to the user clipboard
445446
UtilsNew.copyToClipboard(link);

src/webcomponents/commons/opencga-active-filters.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,8 @@ export default class OpencgaActiveFilters extends LitElement {
719719

720720
onCopyLink() {
721721
// 1. Generate the url to the tool with the current query
722-
const link = WebUtils.getIVALink(this.opencgaSession, this.toolId, this.query);
722+
const [app, tool] = WebUtils.getApplicationAndToolFromHash();
723+
const link = WebUtils.getIVALink(this.opencgaSession, app, tool, this.query);
723724
// 2. Copy this link to the user clipboard
724725
UtilsNew.copyToClipboard(link);
725726
// 3. Notify user that the link has been copied to the clipboard

src/webcomponents/commons/utils/web-utils.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,27 @@ export default class WebUtils {
6060
return (resource && mapResourcePermissionId[resource] && mode) ? `${mode.toUpperCase()}_${mapResourcePermissionId[resource]}` : "";
6161
}
6262

63-
static getIVALink(opencgaSession, tool, query = {}) {
64-
const baseUrl = (new URL(window.location.pathname, window.location.origin));
65-
let queryStr = "";
66-
// Check if query object has been provided
67-
if (query) {
68-
queryStr = "?" + (new URLSearchParams(query)).toString();
69-
}
70-
return `${baseUrl}#${tool}/${opencgaSession.project.id}/${opencgaSession.study.id}${queryStr}`;
71-
}
72-
73-
static getInterpreterLink(opencgaSession, caseId = "") {
63+
static getLink(opencgaSession, app = "", tool = "", query = null) {
7464
const hashItems = [
75-
// ...window.location.hash.replace("#", "").split("/").slice(0, -3), // '#clinical/portal/project/study' --> ['clinical']
76-
"clinical",
77-
"interpreter",
65+
app,
66+
tool,
7867
opencgaSession?.project?.id || "",
7968
opencgaSession?.study?.id || "",
8069
];
8170

82-
return `#${hashItems.filter(Boolean).join("/")}${!!caseId ? "?id=" + caseId : ""}`;
71+
// build the querystring fragment of the URL if a query object is provided
72+
const queryStr = (query && Object.keys(query || {}).length > 0) ? "?" + (new URLSearchParams(query)).toString() : "";
73+
74+
// build and return the internal link
75+
return `#${hashItems.filter(Boolean).join("/")}${queryStr}`;
76+
}
77+
78+
static getIVALink(opencgaSession, app, tool, query = null) {
79+
return (new URL(window.location.pathname, window.location.origin)) + WebUtils.getLink(opencgaSession, app, tool, query);
80+
}
81+
82+
static getInterpreterLink(opencgaSession, query = null) {
83+
return WebUtils.getLink(opencgaSession, "clinical", "interpreter", query);
8384
}
8485

8586
static getClinicalAnalysisPriorityColour(rank) {
@@ -100,4 +101,13 @@ export default class WebUtils {
100101
});
101102
}
102103

104+
static getApplicationAndToolFromHash(hash = "") {
105+
// '#clinical/portal/project/study' --> ['clinical', 'portal]
106+
// '#portal/project/study' --> ['portal']
107+
return (hash || window.location.hash).replace("#", "").split("/").slice(0, -2);
108+
}
109+
110+
static redirectTo(opencgaSession, app = "", tool = "", query = {}) {
111+
window.location.hash = WebUtils.getLink(opencgaSession, app, tool, query);
112+
}
103113
}

src/webcomponents/commons/view/vertical-menu.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {LitElement, html, nothing} from "lit";
22
import UtilsNew from "../../../core/utils-new.js";
3+
import LitUtils from "../utils/lit-utils.js";
34

45
export default class VerticalMenu extends LitElement {
56

@@ -17,6 +18,9 @@ export default class VerticalMenu extends LitElement {
1718
opencgaSession: {
1819
type: Object,
1920
},
21+
activeItem: {
22+
type: String,
23+
},
2024
config: {
2125
type: Object,
2226
},
@@ -35,8 +39,15 @@ export default class VerticalMenu extends LitElement {
3539
...this.getDefaultConfig(),
3640
...this.config,
3741
};
38-
// initialize the active item
39-
if (!this._activeItem) {
42+
}
43+
44+
if (changedProperties.has("config") || changedProperties.has("activeItem")) {
45+
// check if we have to change the active item
46+
if (this.activeItem && this.activeItem !== this._activeItem) {
47+
this._activeItem = this.activeItem;
48+
}
49+
// initialize the active item if not set
50+
if (!this._activeItem && !this.activeItem) {
4051
this._activeItem = this._config.menu[0].submenu[0].id;
4152
}
4253
}
@@ -46,6 +57,7 @@ export default class VerticalMenu extends LitElement {
4657

4758
onChangeActiveItem(newActiveItem) {
4859
this._activeItem = newActiveItem;
60+
LitUtils.dispatchCustomEvent(this, "changeActiveItem", this._activeItem);
4961
this.requestUpdate();
5062
}
5163

src/webcomponents/organization/admin/organization-admin.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import {LitElement, html} from "lit";
17+
import WebUtils from "../../commons/utils/web-utils.js";
1718
import OpencgaCatalogUtils from "../../../core/clients/opencga/opencga-catalog-utils.js";
1819
import "./group-admin-browser.js";
1920
import "./user-admin-browser.js";
@@ -40,7 +41,10 @@ export default class OrganizationAdmin extends LitElement {
4041
static get properties() {
4142
return {
4243
opencgaSession: {
43-
type: Object
44+
type: Object,
45+
},
46+
tool: {
47+
type: String,
4448
},
4549
};
4650
}
@@ -49,6 +53,13 @@ export default class OrganizationAdmin extends LitElement {
4953
this._config = this.getDefaultConfig();
5054
}
5155

56+
onChangeActiveItem(event) {
57+
const [app, tool] = WebUtils.getApplicationAndToolFromHash();
58+
WebUtils.redirectTo(this.opencgaSession, app, tool, {
59+
tool: event.detail.value,
60+
});
61+
}
62+
5263
render() {
5364
if (!this.opencgaSession?.organization || !OpencgaCatalogUtils.isOrganizationAdmin(this.opencgaSession?.organization, this.opencgaSession?.user?.id)) {
5465
return html`
@@ -62,7 +73,9 @@ export default class OrganizationAdmin extends LitElement {
6273
<tool-header title="Organization Admin: ${this.opencgaSession?.organization?.id}"></tool-header>
6374
<vertical-menu
6475
.opencgaSession="${this.opencgaSession}"
65-
.config="${this._config || {}}">
76+
.activeItem="${this.tool}"
77+
.config="${this._config || {}}"
78+
@changeActiveItem="${event => this.onChangeActiveItem(event)}">
6679
</vertical-menu>
6780
`;
6881
}

src/webcomponents/study/admin/study-admin-iva.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
*/
1616

1717
import {LitElement, html} from "lit";
18-
import LitUtils from "../../commons/utils/lit-utils";
19-
import NotificationUtils from "../../commons/utils/notification-utils";
20-
import UtilsNew from "../../../core/utils-new";
18+
import WebUtils from "../../commons/utils/web-utils.js";
2119
import OpencgaCatalogUtils from "../../../core/clients/opencga/opencga-catalog-utils";
2220
import "../../commons/view/vertical-menu.js";
2321
import "../../commons/pages/restricted-access-page.js";
@@ -41,6 +39,9 @@ export default class StudyAdminIva extends LitElement {
4139
opencgaSession: {
4240
type: Object,
4341
},
42+
tool: {
43+
type: String,
44+
},
4445
settings: {
4546
type: Object,
4647
},
@@ -78,6 +79,13 @@ export default class StudyAdminIva extends LitElement {
7879
return (title === "Clinical Analysis Browser") ? "Clinical Analysis Portal" : title;
7980
}
8081

82+
onChangeActiveItem(event) {
83+
const [app, tool] = WebUtils.getApplicationAndToolFromHash();
84+
WebUtils.redirectTo(this.opencgaSession, app, tool, {
85+
tool: event.detail.value,
86+
});
87+
}
88+
8189
render() {
8290
const isOrganizationAdmin = OpencgaCatalogUtils.isOrganizationAdmin(this.opencgaSession?.organization, this.opencgaSession?.user?.id);
8391
const isAdmin = OpencgaCatalogUtils.isAdmin(this.opencgaSession?.study, this.opencgaSession?.user?.id);
@@ -94,7 +102,9 @@ export default class StudyAdminIva extends LitElement {
94102
<tool-header title="${this._config.name}"></tool-header>
95103
<vertical-menu
96104
.opencgaSession="${this.opencgaSession}"
97-
.config="${this._config || {}}">
105+
.activeItem="${this.tool}"
106+
.config="${this._config || {}}"
107+
@changeActiveItem="${event => this.onChangeActiveItem(event)}">
98108
</vertical-menu>
99109
`;
100110
}

src/webcomponents/study/admin/study-admin.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import {LitElement, html} from "lit";
18+
import WebUtils from "../../commons/utils/web-utils.js";
1819
import OpencgaCatalogUtils from "../../../core/clients/opencga/opencga-catalog-utils.js";
1920
import "./study-admin-users.js";
2021
import "./study-admin-permissions.js";
@@ -44,13 +45,23 @@ export default class StudyAdmin extends LitElement {
4445
opencgaSession: {
4546
type: Object,
4647
},
48+
tool: {
49+
type: String,
50+
},
4751
};
4852
}
4953

5054
#init() {
5155
this._config = this.getDefaultConfig();
5256
}
5357

58+
onChangeActiveItem(event) {
59+
const [app, tool] = WebUtils.getApplicationAndToolFromHash();
60+
WebUtils.redirectTo(this.opencgaSession, app, tool, {
61+
tool: event.detail.value,
62+
});
63+
}
64+
5465
render() {
5566
const isOrganizationAdmin = OpencgaCatalogUtils.isOrganizationAdmin(this.opencgaSession?.organization, this.opencgaSession?.user?.id);
5667
const isAdmin = OpencgaCatalogUtils.isAdmin(this.opencgaSession?.study, this.opencgaSession?.user?.id);
@@ -67,7 +78,9 @@ export default class StudyAdmin extends LitElement {
6778
<tool-header title="${this._config.name}"></tool-header>
6879
<vertical-menu
6980
.opencgaSession="${this.opencgaSession}"
70-
.config="${this._config || {}}">
81+
.activeItem="${this.tool}"
82+
.config="${this._config || {}}"
83+
@changeActiveItem="${event => this.onChangeActiveItem(event)}">
7184
</vertical-menu>
7285
`;
7386
}

src/webcomponents/study/admin/variant/operations-admin.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import {LitElement, html} from "lit";
18+
import WebUtils from "../../../commons/utils/web-utils.js";
1819
import OpencgaCatalogUtils from "../../../../core/clients/opencga/opencga-catalog-utils";
1920
import "../../../variant/operation/variant-index-operation.js";
2021
import "../../../variant/operation/variant-stats-index-operation.js";
@@ -40,6 +41,9 @@ export default class OperationsAdmin extends LitElement {
4041
opencgaSession: {
4142
type: Object
4243
},
44+
tool: {
45+
type: String,
46+
},
4347
};
4448
}
4549

@@ -48,6 +52,13 @@ export default class OperationsAdmin extends LitElement {
4852
this._config = this.getDefaultConfig();
4953
}
5054

55+
onChangeActiveItem(event) {
56+
const [app, tool] = WebUtils.getApplicationAndToolFromHash();
57+
WebUtils.redirectTo(this.opencgaSession, app, tool, {
58+
tool: event.detail.value,
59+
});
60+
}
61+
5162
render() {
5263
const isOrganizationAdmin = OpencgaCatalogUtils.isOrganizationAdmin(this.opencgaSession?.organization, this.opencgaSession?.user?.id);
5364
const isAdmin = OpencgaCatalogUtils.isAdmin(this.opencgaSession?.study, this.opencgaSession?.user?.id);
@@ -64,7 +75,9 @@ export default class OperationsAdmin extends LitElement {
6475
<tool-header title="${this._config.name}"></tool-header>
6576
<vertical-menu
6677
.opencgaSession="${this.opencgaSession}"
67-
.config="${this._config || {}}">
78+
.activeItem="${this.tool}"
79+
.config="${this._config || {}}"
80+
@changeActiveItem="${event => this.onChangeActiveItem(event)}">
6881
</vertical-menu>
6982
`;
7083
}

0 commit comments

Comments
 (0)