Skip to content

Commit 3c913b7

Browse files
authored
Merge pull request #37 from FAIRsharing/reset-results-and-filters-36
Adding code to reset the results if principle selection is changed
2 parents 34423ba + 08df94e commit 3c913b7

File tree

10 files changed

+275
-29
lines changed

10 files changed

+275
-29
lines changed

src/components/Registry/ApplyFilterButton.vue

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,20 @@ export default {
2222
name: "ApplyFilterButton",
2323
data: () => {
2424
return {
25-
filtersSelected: [],
2625
isClicked: false,
2726
};
2827
},
2928
setup() {
3029
const store = useAdvancedSearchStore();
31-
const {
32-
getFairassistID,
33-
getRecordTypeSelected,
34-
getFilterSelected,
35-
getFairassistName,
36-
} = storeToRefs(store);
30+
const { getRecordTypeSelected, getFilterSelected, getFairassistName } =
31+
storeToRefs(store);
3732
return {
3833
store,
39-
getFairassistID,
4034
getRecordTypeSelected,
4135
getFilterSelected,
4236
getFairassistName,
4337
};
4438
},
45-
watch: {
46-
getFairassistID(newValue, oldValue) {
47-
if (newValue !== oldValue) {
48-
this.filtersSelected = [];
49-
this.store.advancedSearchResponse = [];
50-
}
51-
},
52-
},
5339
5440
methods: {
5541
async fetchResults() {

src/components/Registry/CollapseTreeGraph.vue

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
<template>
22
<div>
3+
<WarningDailog
4+
:show-dialog="showDialog"
5+
@noReset="noResetSelection"
6+
@yesReset="yesResetSelection"
7+
/>
38
<v-select
49
v-model="fairassistID"
510
:items="itemList"
611
data-testid="selectGraph"
712
item-title="name"
813
item-value="id"
9-
@update:model-value="getGraphData()"
10-
/>
14+
@update:model-value="resetPopup()"
15+
>
16+
</v-select>
1117
<div v-if="noData">No data available</div>
1218
<div v-else ref="chartdiv" class="chartdiv" />
1319
</div>
@@ -16,9 +22,12 @@
1622
import axios from "axios";
1723
import d3Graph from "@/utils/d3Graph";
1824
import { useAdvancedSearchStore } from "@/stores/advancedSearch.js";
25+
import { storeToRefs } from "pinia";
26+
import WarningDialog from "@/components/Registry/WarningDialog.vue";
1927
2028
export default {
2129
name: "CollapseTreeGraph",
30+
components: { WarningDailog: WarningDialog },
2231
data: () => {
2332
return {
2433
noData: false,
@@ -33,17 +42,24 @@ export default {
3342
name: "FAIR Principles for Research Software",
3443
},
3544
],
45+
showDialog: false,
46+
currentId: Number,
3647
};
3748
},
3849
setup() {
3950
const store = useAdvancedSearchStore();
40-
return { store };
51+
const { getAdvancedSearchResponse, getNoData } = storeToRefs(store);
52+
return {
53+
store,
54+
getAdvancedSearchResponse,
55+
getNoData,
56+
};
4157
},
4258
4359
watch: {
44-
fairassistID(newValue, oldValue) {
60+
fairassistID(oldValue, newValue) {
4561
if (newValue !== oldValue) {
46-
this.store.advancedSearchResponse = [];
62+
this.currentId = newValue;
4763
}
4864
},
4965
},
@@ -52,6 +68,9 @@ export default {
5268
this.getGraphData();
5369
},
5470
methods: {
71+
/**
72+
* Get the graph data from the API
73+
*/
5574
async getGraphData() {
5675
this.store.fairassistID = this.fairassistID;
5776
try {
@@ -68,6 +87,40 @@ export default {
6887
this.noData = true;
6988
}
7089
}
90+
this.store.resetSelection = false;
91+
},
92+
93+
/**
94+
* Reset the graph data if there is any selection or no data available else get the graph data
95+
*/
96+
resetPopup() {
97+
if (this.getAdvancedSearchResponse.length || this.getNoData) {
98+
this.showDialog = true;
99+
} else {
100+
this.getGraphData();
101+
}
102+
},
103+
104+
/**
105+
* On Reset of the selection call graph and hide the dialog
106+
* @param value
107+
*/
108+
yesResetSelection(value) {
109+
if (value) {
110+
this.getGraphData();
111+
this.showDialog = false;
112+
}
113+
},
114+
115+
/**
116+
* On Cancel of the selection hide the dialog and keep the current graph data
117+
* @param value
118+
*/
119+
noResetSelection(value) {
120+
if (value) {
121+
this.fairassistID = this.currentId;
122+
this.showDialog = false;
123+
}
71124
},
72125
},
73126
};

src/components/Registry/UtilComponents/SelectComponent.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
<script>
5252
import { capitalize } from "lodash";
5353
import stringUtils from "@/utils/stringUtils.js";
54+
import { useAdvancedSearchStore } from "@/stores/advancedSearch.js";
55+
import { storeToRefs } from "pinia";
5456
5557
export default {
5658
name: "SelectComponent",
@@ -82,6 +84,15 @@ export default {
8284
},
8385
},
8486
emits: ["input"],
87+
setup() {
88+
const store = useAdvancedSearchStore();
89+
const { getFairassistID, getResetSelection } = storeToRefs(store);
90+
return {
91+
store,
92+
getFairassistID,
93+
getResetSelection,
94+
};
95+
},
8596
computed: {
8697
model: {
8798
get() {
@@ -107,9 +118,12 @@ export default {
107118
this.model = [];
108119
}
109120
},
110-
// model(newValue) {
111-
// this.$emit("input", newValue);
112-
// },
121+
//Reset the selections when getResetSelection is true
122+
getResetSelection(newValue) {
123+
if (newValue) {
124+
this.model = [];
125+
}
126+
},
113127
},
114128
methods: {
115129
capitalize,

src/components/Registry/UtilComponents/__tests__/SelectComponent.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("SelectComponent.vue", function () {
3535

3636
it("can be instantiated", () => {
3737
wrapper.vm.$options.watch.disabled.call(wrapper.vm, true);
38-
// wrapper.vm.$options.watch.model.call(wrapper.vm, ["xyz"]);
38+
wrapper.vm.$options.watch.getResetSelection.call(wrapper.vm, true);
3939
expect(wrapper.vm.$options.name).toMatch("SelectComponent");
4040
});
4141

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<template>
2+
<div>
3+
<v-dialog :model-value="showPopup" max-width="400">
4+
<v-card class="pa-4">
5+
<v-card-text>
6+
<div>
7+
Changing between FAIR and FAIR4RS principles will clear your search
8+
results.
9+
</div>
10+
</v-card-text>
11+
<v-card-actions
12+
:class="{
13+
'flex-column align-center': $vuetify.display.smAndDown,
14+
}"
15+
class="px-6 justify-space-between"
16+
>
17+
<v-btn
18+
:class="{
19+
'mb-3': $vuetify.display.smAndDown,
20+
}"
21+
:width="$vuetify.display.smAndDown ? '100%' : '150'"
22+
class="text-white bg-green"
23+
data-testid="resetSelection"
24+
elevation="2"
25+
fdfdfd
26+
variant="text"
27+
@click="resetSelection()"
28+
>
29+
OK
30+
</v-btn>
31+
<v-btn
32+
:width="$vuetify.display.smAndDown ? '100%' : '150'"
33+
class="ml-0 bg-accent3"
34+
data-testid="noResetSelection"
35+
elevation="2"
36+
variant="text"
37+
@click="noResetSelection()"
38+
>
39+
Cancel
40+
</v-btn>
41+
</v-card-actions>
42+
</v-card>
43+
</v-dialog>
44+
</div>
45+
</template>
46+
<script>
47+
import { useAdvancedSearchStore } from "@/stores/advancedSearch.js";
48+
49+
export default {
50+
name: "WarningDialog",
51+
emits: ["yesReset", "noReset"],
52+
props: {
53+
showDialog: { type: Boolean, default: false },
54+
},
55+
data: () => {
56+
return {
57+
showPopup: false,
58+
};
59+
},
60+
setup() {
61+
const store = useAdvancedSearchStore();
62+
return {
63+
store,
64+
};
65+
},
66+
watch: {
67+
showDialog(newValue) {
68+
if (newValue) {
69+
this.showPopup = true;
70+
}
71+
},
72+
},
73+
74+
methods: {
75+
/**
76+
* Reset the selection and the results
77+
*/
78+
resetSelection() {
79+
this.showPopup = false;
80+
this.store.resetSelection = true;
81+
this.store.resetAdvancedSearch();
82+
this.$router.replace("/registry");
83+
this.$emit("yesReset", true);
84+
},
85+
86+
/**
87+
* Do not reset the selection and keep the results
88+
*/
89+
noResetSelection() {
90+
this.$emit("noReset", true);
91+
// this.fairassistID = this.currentId;
92+
this.showPopup = false;
93+
},
94+
},
95+
};
96+
</script>

src/components/Registry/__tests__/ApplyFilterButton.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ describe("ApplyFilterButton.vue", function () {
2525
});
2626

2727
it("can be instantiated", () => {
28-
wrapper.vm.$options.watch.getFairassistID.call(wrapper.vm, 12);
2928
expect(wrapper.vm.$options.name).toMatch("ApplyFilterButton");
3029
});
3130

src/components/Registry/__tests__/CollapseTreeGraph.spec.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ import sinon from "sinon";
77
import d3GraphData from "./data/d3GraphData.json";
88
import { createPinia, setActivePinia } from "pinia";
99
import { createTestingPinia } from "@pinia/testing";
10+
import { useAdvancedSearchStore } from "@/stores/advancedSearch.js";
1011

1112
const vuetify = createVuetify();
13+
const $router = { replace: vi.fn() };
14+
15+
if (!globalThis.visualViewport) {
16+
vi.stubGlobal("visualViewport", new EventTarget());
17+
}
1218

1319
describe("CollapseTreeGraph.vue", function () {
1420
vi.mock("d3", () => ({}));
@@ -18,10 +24,12 @@ describe("CollapseTreeGraph.vue", function () {
1824

1925
beforeEach(() => {
2026
setActivePinia(createPinia());
27+
2128
wrapper = mount(CollapseTreeGraph, {
2229
global: {
2330
plugins: [vuetify, createTestingPinia()],
2431
stubs: { vSelect: true },
32+
mocks: { $router },
2533
},
2634
});
2735
});
@@ -30,7 +38,7 @@ describe("CollapseTreeGraph.vue", function () {
3038
expect(wrapper.vm.$options.name).toMatch("CollapseTreeGraph");
3139
});
3240

33-
it("getGraphData method is called on v-select when mounted", async () => {
41+
it("getGraphData() method is called on v-select when mounted", async () => {
3442
let itemList = [
3543
{
3644
id: 1,
@@ -47,9 +55,30 @@ describe("CollapseTreeGraph.vue", function () {
4755
expect(component.vm.modelValue).toBe("2");
4856
});
4957

50-
it("can check if getGraphData method have the error in catch block", async () => {
58+
it("can check if getGraphData() method have the error in catch block", async () => {
5159
getStub.returns(new Error("error"));
5260
await wrapper.vm.getGraphData();
5361
expect(wrapper.vm.noData).toBe(true);
5462
});
63+
64+
it("can check resetPopup() method", () => {
65+
let store = useAdvancedSearchStore();
66+
store.advancedSearchResponse = ["test", "test1", "test2"];
67+
store.noData = true;
68+
wrapper.vm.resetPopup();
69+
expect(wrapper.vm.showDialog).toBe(true);
70+
});
71+
72+
it("can check if yesResetSelection() method ", () => {
73+
wrapper.vm.yesResetSelection(true);
74+
expect(wrapper.vm.getGraphData).toHaveBeenCalled;
75+
expect(wrapper.vm.showDialog).toBe(false);
76+
});
77+
78+
it("can check if noResetSelection() method ", () => {
79+
wrapper.vm.currentId = 1;
80+
wrapper.vm.noResetSelection(true);
81+
expect(wrapper.vm.fairassistID).toBe(1);
82+
expect(wrapper.vm.showDialog).toBe(false);
83+
});
5584
});

0 commit comments

Comments
 (0)