Skip to content

Commit 18561f7

Browse files
MVarshinidbutenhof
andauthored
Fix Job Status filtering and table pagination (#288)
* Fix OSO Tab Bugs * Fix status filter and Pagination issues Co-authored-by: David Butenhof <dbutenho@redhat.com>
1 parent 260cf72 commit 18561f7

File tree

13 files changed

+86
-42
lines changed

13 files changed

+86
-42
lines changed

backend/app/api/v1/commons/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@
173173
"failed": "failure",
174174
}
175175

176+
JOB_STATUS_OTHERS = "others"
177+
176178
keys_to_keep = ["product", "testName", "jobStatus", "ciSystem", "releaseStream"]
177179

178180
SPLUNK_SEMAPHORE_COUNT = 5 # Arbitrary concurrency limit in an asyncio semaphore

backend/app/api/v1/commons/utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ast
2+
from collections import defaultdict
23
from typing import Optional
34
from urllib.parse import parse_qs
45

@@ -198,6 +199,43 @@ def create_match_phrase(key, item):
198199
return match_phrase
199200

200201

202+
def invert_job_status_map():
203+
inverted = defaultdict(list)
204+
for raw, canonical in constants.JOB_STATUS_MAP.items():
205+
inverted[canonical].append(raw)
206+
return inverted
207+
208+
209+
INVERTED_JOB_STATUS_MAP = invert_job_status_map()
210+
ALL_KNOWN_JOB_STATUSES = set(constants.JOB_STATUS_MAP.keys())
211+
212+
213+
def handle_job_status(values, field, should, must_not):
214+
min_match_inc = 0
215+
216+
# Handle "others"
217+
if "others" in values:
218+
for job_status in ALL_KNOWN_JOB_STATUSES:
219+
must_not.append(create_match_phrase(field, job_status))
220+
221+
values = [v for v in values if v != "others"]
222+
223+
if not values:
224+
return 1 # only others selected
225+
226+
# Handle success / failure
227+
for value in values:
228+
canonical = constants.JOB_STATUS_MAP.get(value, value)
229+
expanded = INVERTED_JOB_STATUS_MAP.get(canonical, [])
230+
231+
for job_status in expanded:
232+
should.append(create_match_phrase(field, job_status))
233+
234+
min_match_inc += 1
235+
236+
return min_match_inc
237+
238+
201239
def construct_ES_filter_query(filter):
202240
should_part = []
203241
must_not_part = []

backend/app/services/search.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ async def buildFilterData(self, filter, total):
313313
values = list(
314314
set(
315315
[
316-
constants.JOB_STATUS_MAP.get(x.lower(), "other")
316+
constants.JOB_STATUS_MAP.get(
317+
x.lower(), constants.JOB_STATUS_OTHERS
318+
)
317319
for x in values
318320
]
319321
)
@@ -342,7 +344,9 @@ async def getSummary(self, filter, total):
342344
buckets = filter.get(key, {}).get("buckets")
343345
if buckets:
344346
for x in buckets:
345-
field = constants.JOB_STATUS_MAP.get(x["key"].lower(), "other")
347+
field = constants.JOB_STATUS_MAP.get(
348+
x["key"].lower(), constants.JOB_STATUS_OTHERS
349+
)
346350
summary[field] = summary.get(field, 0) + x.get("doc_count", 0)
347351
break
348352

frontend/src/actions/commonActions.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,3 @@ export const calculateSummary = (countObj) => {
106106
};
107107
return summary;
108108
};
109-
110-
export const filterOtherStatus = (filterData) => {
111-
const keyWordArr = ["success", "failure"];
112-
113-
const statusValues =
114-
filterData.find((item) => item.key === "jobStatus").value || [];
115-
116-
const filteredStatus = statusValues.filter(
117-
(status) => !keyWordArr.includes(status)
118-
);
119-
return filteredStatus;
120-
};

frontend/src/actions/homeActions.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import { appendDateFilter, appendQueryString } from "@/utils/helper";
99
import {
1010
calculateSummary,
1111
deleteAppliedFilters,
12-
filterOtherStatus,
1312
getRequestParams,
1413
getSelectedFilter,
1514
} from "./commonActions";
1615

1716
import API from "@/utils/axiosInstance";
1817
import { setLastUpdatedTime } from "./headerActions";
18+
import { OTHERS } from "@/assets/constants/jobStatusConstants";
1919

2020
const getCloneDeep = async () => (await import("lodash/cloneDeep")).default;
2121

@@ -158,11 +158,9 @@ export const setCPTAppliedFilters = (navigate) => (dispatch, getState) => {
158158
};
159159

160160
export const setCPTOtherSummaryFilter = () => (dispatch, getState) => {
161-
const filterData = [...getState().cpt.filterData];
162161
const summary = getState().cpt.summary;
163162
if (summary?.othersCount !== 0) {
164-
const filteredStatus = filterOtherStatus(filterData);
165-
dispatch(setSelectedFilter("jobStatus", filteredStatus, false));
163+
dispatch(setSelectedFilter("jobStatus", OTHERS, false));
166164
dispatch(setCPTAppliedFilters());
167165
}
168166
};

frontend/src/actions/ocpActions.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import { appendDateFilter, appendQueryString } from "@/utils/helper.js";
99
import {
1010
calculateSummary,
1111
deleteAppliedFilters,
12-
filterOtherStatus,
1312
getRequestParams,
1413
getSelectedFilter,
1514
} from "./commonActions";
1615

1716
import API from "@/utils/axiosInstance";
1817
import { cloneDeep } from "lodash";
1918
import { setLastUpdatedTime } from "./headerActions";
19+
import { OTHERS } from "@/assets/constants/jobStatusConstants.js";
2020

2121
export const fetchOCPJobs = () => async (dispatch) => {
2222
try {
@@ -194,11 +194,9 @@ export const setOCPFilterFromURL = (searchParams) => ({
194194
});
195195

196196
export const setOCPOtherSummaryFilter = () => (dispatch, getState) => {
197-
const filterData = [...getState().ocp.filterData];
198197
const summary = getState().ocp.summary;
199198
if (summary?.othersCount !== 0) {
200-
const filteredStatus = filterOtherStatus(filterData);
201-
dispatch(setSelectedFilter("jobStatus", filteredStatus, false));
199+
dispatch(setSelectedFilter("jobStatus", OTHERS, false));
202200
dispatch(setOCPAppliedFilters());
203201
}
204202
};

frontend/src/actions/olsActions.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import { appendDateFilter, appendQueryString } from "@/utils/helper.js";
99
import {
1010
calculateSummary,
1111
deleteAppliedFilters,
12-
filterOtherStatus,
1312
getRequestParams,
1413
getSelectedFilter,
1514
} from "./commonActions";
1615

1716
import API from "@/utils/axiosInstance";
1817
import { cloneDeep } from "lodash";
1918
import { setLastUpdatedTime } from "./headerActions";
19+
import { OTHERS } from "@/assets/constants/jobStatusConstants";
2020

2121
export const fetchOLSJobsData = () => async (dispatch) => {
2222
try {
@@ -200,11 +200,9 @@ export const applyOLSDateFilter =
200200
};
201201

202202
export const setOLSOtherSummaryFilter = () => (dispatch, getState) => {
203-
const filterData = [...getState().ols.filterData];
204203
const summary = getState().ols.summary;
205204
if (summary?.othersCount !== 0) {
206-
const filteredStatus = filterOtherStatus(filterData);
207-
dispatch(setSelectedFilter("jobStatus", filteredStatus, false));
205+
dispatch(setSelectedFilter("jobStatus", OTHERS, false));
208206
dispatch(setOLSAppliedFilters());
209207
}
210208
};

frontend/src/actions/openstackActions.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
} from "@/assets/constants/paginationConstants";
99
import {
1010
deleteAppliedFilters,
11-
filterOtherStatus,
1211
getRequestParams,
1312
calculateSummary,
1413
getSelectedFilter,
@@ -17,6 +16,7 @@ import { appendDateFilter, appendQueryString } from "@/utils/helper.js";
1716
import { setLastUpdatedTime } from "./headerActions";
1817

1918
import { cloneDeep } from "lodash";
19+
import { OTHERS } from "@/assets/constants/jobStatusConstants.js";
2020

2121
export const fetchOSOJobs = () => async (dispatch) => {
2222
try {
@@ -114,11 +114,9 @@ export const setOSOSortDir = (direction) => ({
114114
});
115115

116116
export const setOSOOtherSummaryFilter = () => (dispatch, getState) => {
117-
const filterData = [...getState().oso.filterData];
118117
const summary = getState().oso.summary;
119-
if (summary?.othersCount !== 0) {
120-
const filteredStatus = filterOtherStatus(filterData);
121-
dispatch(setSelectedFilter("jobStatus", filteredStatus, false));
118+
if (summary?.othersCount > 0) {
119+
dispatch(setSelectedFilter("jobStatus", OTHERS, false));
122120
dispatch(setOSOAppliedFilters());
123121
}
124122
};

frontend/src/actions/paginationActions.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ import {
3636
setIlabPageOptions,
3737
} from "./ilabActions";
3838

39+
import {
40+
setOSOPage,
41+
setOSOPageOptions,
42+
fetchOSOJobs,
43+
setOSOoffset,
44+
} from "./openstackActions";
45+
3946
export const setPage = (newPage, currType) => (dispatch) => {
4047
const actions = {
4148
cpt: setCPTPage,
@@ -44,6 +51,7 @@ export const setPage = (newPage, currType) => (dispatch) => {
4451
telco: setTelcoPage,
4552
ols: setOLSPage,
4653
ilab: setIlabPage,
54+
oso: setOSOPage,
4755
};
4856
dispatch(actions[currType](newPage));
4957
};
@@ -56,6 +64,7 @@ export const setPageOptions = (newPage, newPerPage, currType) => (dispatch) => {
5664
telco: setTelcoPageOptions,
5765
ols: setOLSPageOptions,
5866
ilab: setIlabPageOptions,
67+
oso: setOSOPageOptions,
5968
};
6069
dispatch(actions[currType](newPage, newPerPage));
6170
};
@@ -71,6 +80,7 @@ const fetchActions = {
7180
cpt: fetchOCPJobsData,
7281
ols: fetchOLSJobsData,
7382
ilab: fetchIlabJobs,
83+
oso: fetchOSOJobs,
7484
};
7585
const offsetActions = {
7686
ocp: setOCPOffset,
@@ -79,6 +89,7 @@ const offsetActions = {
7989
cpt: setCPTOffset,
8090
ols: setOLSOffset,
8191
ilab: setIlabOffset,
92+
oso: setOSOoffset,
8293
};
8394

8495
export const checkTableData = (newPage, currType) => (dispatch, getState) => {

frontend/src/actions/quayActions.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { appendDateFilter, appendQueryString } from "@/utils/helper.js";
99
import {
1010
calculateSummary,
1111
deleteAppliedFilters,
12-
filterOtherStatus,
1312
getRequestParams,
1413
getSelectedFilter,
1514
} from "./commonActions";
@@ -18,6 +17,7 @@ import API from "@/utils/axiosInstance";
1817
import { cloneDeep } from "lodash";
1918
import { setLastUpdatedTime } from "./headerActions";
2019
import { showFailureToast } from "@/actions/toastActions";
20+
import { OTHERS } from "@/assets/constants/jobStatusConstants";
2121

2222
export const fetchQuayJobsData = () => async (dispatch) => {
2323
try {
@@ -203,11 +203,9 @@ export const applyQuayDateFilter =
203203
};
204204

205205
export const setQuayOtherSummaryFilter = () => (dispatch, getState) => {
206-
const filterData = [...getState().quay.filterData];
207206
const summary = getState().quay.summary;
208207
if (summary?.othersCount !== 0) {
209-
const filteredStatus = filterOtherStatus(filterData);
210-
dispatch(setSelectedFilter("jobStatus", filteredStatus, false));
208+
dispatch(setSelectedFilter("jobStatus", OTHERS, false));
211209
dispatch(setQuayAppliedFilters());
212210
}
213211
};

0 commit comments

Comments
 (0)