Skip to content

Commit 4a42aa2

Browse files
Allow normal click to open items in same tab from table (#1468)
1 parent c8e0dc4 commit 4a42aa2

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

webapp/cypress/component/FormattedItemNameTest.cy.jsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ describe("FormattedItemName.vue", () => {
1313
const item_id = "Test";
1414
const itemType = ["samples", "cells", "starting_materials", "equipment"];
1515

16+
beforeEach(() => {
17+
cy.window().then((win) => {
18+
cy.stub(win, "open").as("windowOpen");
19+
});
20+
});
21+
1622
it("should display item details and apply correct color based on item type", () => {
1723
itemType.forEach((type) => {
1824
cy.mount(FormattedItemName, {
@@ -63,42 +69,38 @@ describe("FormattedItemName.vue", () => {
6369

6470
it("should emit 'itemIdClicked' event when item_id is clicked", () => {
6571
const item_id = "Test";
66-
67-
cy.window().then((win) => {
68-
cy.spy(win, "open").as("windowOpen");
69-
});
72+
const onItemIdClicked = cy.spy().as("itemIdClickedSpy");
7073

7174
cy.mount(FormattedItemName, {
7275
props: {
7376
item_id,
7477
itemType: "samples",
7578
enableClick: true,
79+
onItemIdClicked,
7680
},
7781
});
7882

7983
cy.get(".formatted-item-name").click();
8084

81-
cy.get("@windowOpen").should("have.been.calledWith", `/edit/${item_id}`, "_blank");
85+
cy.get("@itemIdClickedSpy").should("have.been.calledOnce");
8286
});
8387

8488
it("should emit 'itemIdClicked' event when clicked with Ctrl or Meta key", () => {
8589
const item_id = "Test";
86-
87-
cy.window().then((win) => {
88-
cy.spy(win, "open").as("windowOpen");
89-
});
90+
const onItemIdClicked = cy.spy().as("itemIdClickedSpy");
9091

9192
cy.mount(FormattedItemName, {
9293
props: {
9394
item_id,
9495
itemType: "samples",
9596
enableModifiedClick: true,
97+
onItemIdClicked,
9698
},
9799
});
98100

99101
cy.get(".formatted-item-name").click({ ctrlKey: true });
100102

101-
cy.get("@windowOpen").should("have.been.calledWith", `/edit/${item_id}`, "_blank");
103+
cy.get("@itemIdClickedSpy").should("have.been.calledOnce");
102104
});
103105

104106
it("should display chemical formula when chemform is provided", () => {

webapp/src/components/DynamicDataTable.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,17 +703,28 @@ export default {
703703
return null;
704704
}
705705
706+
const clickedElement = event.originalEvent.target;
707+
const isFormattedCollectionName = clickedElement.closest(" .formatted-collection-name");
708+
if (isFormattedCollectionName && isFormattedCollectionName.classList.contains("clickable")) {
709+
return null;
710+
}
711+
706712
if (window.Cypress) {
707713
window.location.href = `/${this.editPageRoutePrefix}/${row_id}`;
708714
} else {
709-
window.open(`/${this.editPageRoutePrefix}/${row_id}`, "_blank");
715+
if (event.originalEvent.ctrlKey || event.originalEvent.metaKey) {
716+
window.open(`/${this.editPageRoutePrefix}/${row_id}`, "_blank");
717+
} else {
718+
window.location.href = `/${this.editPageRoutePrefix}/${row_id}`;
719+
}
710720
}
711721
},
712722
getComponentProps(componentName, data) {
713723
const propsConfig = {
714724
FormattedItemName: {
715725
item_id: "item_id",
716726
itemType: "type",
727+
enableClick: true,
717728
enableModifiedClick: true,
718729
},
719730
FormattedRefcode: {
@@ -727,6 +738,7 @@ export default {
727738
},
728739
FormattedCollectionName: {
729740
collection_id: "collection_id",
741+
enableClick: true,
730742
enableModifiedClick: true,
731743
},
732744
ChemicalFormula: {

webapp/src/components/FormattedCollectionName.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class="formatted-collection-name badge badge-light"
44
:class="{ clickable: enableClick || enableModifiedClick }"
55
:style="{ 'border-color': badgeColor, color: badgeColor }"
6-
@click.exact="enableClick ? openEditPageInNewTab() : null"
6+
@click.exact="enableClick ? openEditPageInSameTab() : null"
77
@click.meta.stop="enableModifiedClick ? openEditPageInNewTab() : null"
88
@click.ctrl.stop="enableModifiedClick ? openEditPageInNewTab() : null"
99
>
@@ -57,6 +57,10 @@ export default {
5757
},
5858
},
5959
methods: {
60+
openEditPageInSameTab() {
61+
this.$emit("collectionIdClicked");
62+
window.location.href = `/collections/${this.collection_id}`;
63+
},
6064
openEditPageInNewTab() {
6165
this.$emit("collectionIdClicked");
6266
window.open(`/collections/${this.collection_id}`, "_blank");

webapp/src/components/FormattedItemName.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class="formatted-item-name badge badge-light"
55
:class="{ clickable: enableClick || enableModifiedClick }"
66
:style="{ backgroundColor: badgeColor }"
7-
@click.exact="enableClick ? openEditPageInNewTab() : null"
7+
@click.exact="enableClick ? openEditPageInSameTab() : null"
88
@click.meta.stop="enableModifiedClick ? openEditPageInNewTab() : null"
99
@click.ctrl.stop="enableModifiedClick ? openEditPageInNewTab() : null"
1010
>
@@ -69,8 +69,18 @@ export default {
6969
},
7070
},
7171
methods: {
72+
openEditPageInSameTab() {
73+
this.$emit("itemIdClicked");
74+
if (window.Cypress && window.location.href.includes("__cypress")) {
75+
return;
76+
}
77+
window.location.href = `/edit/${this.item_id}`;
78+
},
7279
openEditPageInNewTab() {
7380
this.$emit("itemIdClicked");
81+
if (window.Cypress && window.location.href.includes("__cypress")) {
82+
return;
83+
}
7484
window.open(`/edit/${this.item_id}`, "_blank");
7585
},
7686
},

0 commit comments

Comments
 (0)