Skip to content

Commit

Permalink
fix(#831): Remove sort field when only one is applied (#1116)
Browse files Browse the repository at this point in the history
This PR allows to remove sort field from cross button when only one is applied

Closes #831

* SortList test

* SorlList snap

(cherry picked from commit f446974)
  • Loading branch information
leiyre authored and frascuchon committed Feb 10, 2022
1 parent 6c48fc2 commit 36b276b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
6 changes: 5 additions & 1 deletion frontend/components/commons/header/filters/SortList.vue
Expand Up @@ -78,7 +78,11 @@ export default {
this.numberOfSortFields += 1;
},
onRemoveSortField(index) {
this.selectedFields.splice(index - 1, 1);
if (this.selectedFields.length === 1) {
this.$emit("sortBy", []);
} else {
this.selectedFields.splice(index - 1, 1);
}
if (this.numberOfSortFields > 1) {
this.numberOfSortFields -= 1;
}
Expand Down
45 changes: 45 additions & 0 deletions frontend/specs/components/filters/SortList.spec.js
@@ -0,0 +1,45 @@
import { mount } from "@vue/test-utils";
import SortList from "@/components/commons/header/filters/SortList";

function mountSortList() {
return mount(SortList, {
propsData: {
sort: [
{
disabled: false,
group: "Predictions",
id: "predicted_as",
key: "predicted_as",
name: "Predicted as",
options: Object,
order: "asc",
placeholder: "Select labels",
type: "select",
}
],
sortOptions: [
{
disabled: false,
group: "Predictions",
id: "predicted_as",
key: "predicted_as",
name: "Predicted as",
options: Object,
placeholder: "Select labels",
selected: undefined,
type: "select",
}
]
},
});
}

describe("SortList", () => {
let spy = jest.spyOn(console, "error");
afterEach(() => spy.mockReset());

test("renders properly", () => {
const wrapper = mountSortList();
expect(wrapper.html()).toMatchSnapshot();
});
});
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SortList renders properly 1`] = `
<div>
<sortfilter sort-options="[object Object]" class="sort"></sortfilter>
<!---->
<div class="sort__buttons">
<re-button class="button-tertiary--small button-tertiary--outline">Cancel</re-button>
<re-button class="button-primary--small">Sort</re-button>
</div>
</div>
`;

0 comments on commit 36b276b

Please sign in to comment.