Skip to content

Commit d76b793

Browse files
authored
Filter operator "not-equals" for "status" (#218)
* Filter operator "not-equals" for "status" Visual-Regression-Tracker/Visual-Regression-Tracker#261 * test updated
1 parent dbbbe87 commit d76b793

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

src/_test/test.data.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export const TEST_UNRESOLVED: TestRun = {
182182
diffTollerancePercent: 3.21,
183183
status: TestStatus.unresolved,
184184
testVariationId: "some test variation id",
185-
name: "test run name",
185+
name: "test run name unresolved",
186186
os: "OS",
187187
browser: "browser",
188188
viewport: "viewport",

src/components/TestRunList/StatusFilterOperators.tsx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useTestRunState } from "../../contexts";
44
import {
55
GridFilterInputValueProps,
66
getGridStringOperators,
7+
GridFilterItem,
8+
GridCellParams,
79
} from "@material-ui/data-grid";
810
import { TestStatus } from "../../types";
911

@@ -42,9 +44,30 @@ const StatusInputComponent = (props: GridFilterInputValueProps) => {
4244
);
4345
};
4446

45-
export const StatusFilterOperators = getGridStringOperators()
46-
.filter((operator) => operator.value === "equals")
47-
.map((operator) => ({
48-
...operator,
47+
export const StatusFilterOperators = [
48+
...getGridStringOperators()
49+
.filter((operator) => operator.value === "equals")
50+
.map((operator) => ({
51+
...operator,
52+
InputComponent: StatusInputComponent,
53+
})),
54+
{
55+
label: "not",
56+
value: "not",
57+
getApplyFilterFn: (filterItem: GridFilterItem) => {
58+
if (
59+
!filterItem.columnField ||
60+
!filterItem.value ||
61+
!filterItem.operatorValue
62+
) {
63+
return null;
64+
}
65+
66+
return (params: GridCellParams): boolean => {
67+
return params.value !== filterItem.value;
68+
};
69+
},
4970
InputComponent: StatusInputComponent,
50-
}));
71+
InputComponentProps: { type: "string" },
72+
},
73+
];

src/components/TestRunList/index.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ import {
1717
GridValueGetterParams,
1818
GridValueFormatterParams,
1919
GridFilterModelParams,
20+
GridCellValue,
21+
GridSortCellParams,
22+
GridSortDirection,
2023
} from "@material-ui/data-grid";
2124
import { DataGridCustomToolbar } from "./DataGridCustomToolbar";
2225
import { StatusFilterOperators } from "./StatusFilterOperators";
2326
import { TagFilterOperators } from "./TagFilterOperators";
24-
import { TestRun } from "../../types";
27+
import { TestRun, TestStatus } from "../../types";
2528

2629
const columnsDef: GridColDef[] = [
2730
{ field: "id", hide: true, filterable: false },
@@ -75,6 +78,18 @@ const columnsDef: GridColDef[] = [
7578
/>
7679
);
7780
},
81+
sortComparator: (
82+
v1: GridCellValue,
83+
v2: GridCellValue,
84+
cellParams1: GridSortCellParams,
85+
cellParams2: GridSortCellParams
86+
) => {
87+
const statusOrder = Object.values(TestStatus);
88+
return (
89+
statusOrder.indexOf(v2 as TestStatus) -
90+
statusOrder.indexOf(v1 as TestStatus)
91+
);
92+
},
7893
filterOperators: StatusFilterOperators,
7994
},
8095
];
@@ -116,6 +131,12 @@ const TestRunList: React.FunctionComponent = () => {
116131
disableColumnSelector
117132
disableColumnMenu
118133
disableSelectionOnClick
134+
sortModel={[
135+
{
136+
field: "status",
137+
sort: "desc" as GridSortDirection,
138+
},
139+
]}
119140
onRowClick={(param: GridRowParams) => {
120141
selectTestRun(
121142
testRunDispatch,

src/pages/ProjectPage.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe("Project page", () => {
7474

7575
cy.vrtTrack("Project page");
7676

77-
cy.contains("test run name").click();
77+
cy.contains(TEST_UNRESOLVED.name).click();
7878

7979
cy.get("[data-testid='image-details']").should(($imageDetails) => {
8080
expect($imageDetails).to.have.length(2);

src/types/testStatus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export enum TestStatus {
22
new = "new",
3-
ok = "ok",
43
unresolved = "unresolved",
54
failed = "failed",
65
approved = "approved",
76
autoApproved = "autoApproved",
7+
ok = "ok",
88
}

0 commit comments

Comments
 (0)