Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quay and Telco Tabs #112

Merged
merged 7 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions frontend/src/actions/commonActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as TYPES from "@/actions/types.js";

import { setCatFilters, sliceTableRows } from "./homeActions";
import { setCPTCatFilters, sliceCPTTableRows } from "./homeActions";
import { setOCPCatFilters, sliceOCPTableRows } from "./ocpActions";
import { setQuayCatFilters, sliceQuayTableRows } from "./quayActions";
import { setTelcoCatFilters, sliceTelcoTableRows } from "./telcoActions";

import { DEFAULT_PER_PAGE } from "@/assets/constants/paginationConstants";
import { cloneDeep } from "lodash";
Expand Down Expand Up @@ -45,7 +47,7 @@ const sortedTableRows = (currState, sortedResults) => (dispatch) => {
type: TYPES.SET_FILTERED_DATA,
payload: sortedResults,
});
dispatch(sliceTableRows(0, DEFAULT_PER_PAGE));
dispatch(sliceCPTTableRows(0, DEFAULT_PER_PAGE));
return;
}
if (currState === "ocp") {
Expand All @@ -54,6 +56,22 @@ const sortedTableRows = (currState, sortedResults) => (dispatch) => {
payload: sortedResults,
});
dispatch(sliceOCPTableRows(0, DEFAULT_PER_PAGE));
return;
}
if (currState === "quay") {
dispatch({
type: TYPES.SET_QUAY_FILTERED_DATA,
payload: sortedResults,
});
dispatch(sliceQuayTableRows(0, DEFAULT_PER_PAGE));
return;
}
if (currState === "telco") {
dispatch({
type: TYPES.SET_TELCO_FILTERED_DATA,
payload: sortedResults,
});
dispatch(sliceTelcoTableRows(0, DEFAULT_PER_PAGE));
}
};

Expand Down Expand Up @@ -114,7 +132,19 @@ const setFilterData = (filterData, currState, activeFilter) => (dispatch) => {
type: TYPES.SET_CPT_FILTER_DATA,
payload: filterData,
});
dispatch(setCatFilters(activeFilter));
dispatch(setCPTCatFilters(activeFilter));
} else if (currState === "quay") {
dispatch({
type: TYPES.SET_QUAY_FILTER_DATA,
payload: filterData,
});
dispatch(setQuayCatFilters(activeFilter));
} else if (currState === "telco") {
dispatch({
type: TYPES.SET_TELCO_FILTER_DATA,
payload: filterData,
});
dispatch(setTelcoCatFilters(activeFilter));
}
};

Expand Down
92 changes: 92 additions & 0 deletions frontend/src/actions/filterActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {
removeCPTAppliedFilters,
setCPTAppliedFilters,
setCPTCatFilters,
setCPTDateFilter,
setCPTOtherSummaryFilter,
} from "./homeActions";
import {
removeOCPAppliedFilters,
setOCPAppliedFilters,
setOCPCatFilters,
setOCPDateFilter,
setOCPOtherSummaryFilter,
} from "./ocpActions";
import {
removeQuayAppliedFilters,
setQuayAppliedFilters,
setQuayCatFilters,
setQuayDateFilter,
setQuayOtherSummaryFilter,
} from "./quayActions";
import {
removeTelcoAppliedFilters,
setTelcoAppliedFilters,
setTelcoCatFilters,
setTelcoDateFilter,
setTelcoOtherSummaryFilter,
} from "./telcoActions";

import store from "@/store/store";

const { dispatch } = store;

export const setCatFilters = (category, currType) => {
if (currType === "cpt") {
dispatch(setCPTCatFilters(category));
} else if (currType === "ocp") {
dispatch(setOCPCatFilters(category));
} else if (currType === "quay") {
dispatch(setQuayCatFilters(category));
} else if (currType === "telco") {
dispatch(setTelcoCatFilters(category));
}
};

export const setAppliedFilters = (navigation, currType) => {
if (currType === "cpt") {
dispatch(setCPTAppliedFilters(navigation));
} else if (currType === "ocp") {
dispatch(setOCPAppliedFilters(navigation));
} else if (currType === "quay") {
dispatch(setQuayAppliedFilters(navigation));
} else if (currType === "telco") {
dispatch(setTelcoAppliedFilters(navigation));
}
};

export const removeAppliedFilters = (key, value, navigation, currType) => {
if (currType === "cpt") {
dispatch(removeCPTAppliedFilters(key, value, navigation));
} else if (currType === "ocp") {
dispatch(removeOCPAppliedFilters(key, value, navigation));
} else if (currType === "quay") {
dispatch(removeQuayAppliedFilters(key, value, navigation));
} else if (currType === "telco") {
dispatch(removeTelcoAppliedFilters(key, value, navigation));
}
};

export const setDateFilter = (date, key, navigation, currType) => {
if (currType === "cpt") {
dispatch(setCPTDateFilter(date, key, navigation));
} else if (currType === "ocp") {
dispatch(setOCPDateFilter(date, key, navigation));
} else if (currType === "quay") {
dispatch(setQuayDateFilter(date, key, navigation));
} else if (currType === "telco") {
dispatch(setTelcoDateFilter(date, key, navigation));
}
};

export const setOtherSummaryFilter = (currType) => {
if (currType === "cpt") {
dispatch(setCPTOtherSummaryFilter());
} else if (currType === "ocp") {
dispatch(setOCPOtherSummaryFilter());
} else if (currType === "quay") {
dispatch(setQuayOtherSummaryFilter());
} else if (currType === "telco") {
dispatch(setTelcoOtherSummaryFilter());
}
};
35 changes: 19 additions & 16 deletions frontend/src/actions/homeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,26 @@ export const fetchOCPJobsData = () => async (dispatch, getState) => {
...(end_date && { end_date }),
},
});
if (response?.data?.results?.length > 0) {
if (response.status === 200) {
const startDate = response.data.startDate,
endDate = response.data.endDate;
//on initial load startDate and endDate are empty, so from response append to url
appendDateFilter(startDate, endDate);

dispatch({
type: TYPES.SET_CPT_JOBS_DATA,
payload: response.data.results,
});
dispatch({
type: TYPES.SET_CPT_DATE_FILTER,
payload: {
start_date: startDate,
end_date: endDate,
},
});
}

if (response?.data?.results?.length > 0) {
dispatch({
type: TYPES.SET_CPT_JOBS_DATA,
payload: response.data.results,
});

dispatch(applyFilters());
dispatch(sortTable("cpt"));
dispatch(tableReCalcValues());
Expand All @@ -67,7 +70,7 @@ export const setCPTSortDir = (direction) => ({
payload: direction,
});

export const sliceTableRows = (startIdx, endIdx) => (dispatch, getState) => {
export const sliceCPTTableRows = (startIdx, endIdx) => (dispatch, getState) => {
const results = [...getState().cpt.filteredResults];

dispatch({
Expand All @@ -76,7 +79,7 @@ export const sliceTableRows = (startIdx, endIdx) => (dispatch, getState) => {
});
};

export const setCatFilters = (category) => (dispatch, getState) => {
export const setCPTCatFilters = (category) => (dispatch, getState) => {
const filterData = [...getState().cpt.filterData];
const options = filterData.filter((item) => item.name === category)[0].value;
const list = options.map((item) => ({ name: item, value: item }));
Expand Down Expand Up @@ -112,7 +115,7 @@ export const setSelectedFilter =
});
};

export const setAppliedFilters = (navigate) => (dispatch, getState) => {
export const setCPTAppliedFilters = (navigate) => (dispatch, getState) => {
const { selectedFilters, start_date, end_date } = getState().cpt;

const appliedFilterArr = selectedFilters.filter((i) => i.value.length > 0);
Expand All @@ -130,7 +133,7 @@ export const setAppliedFilters = (navigate) => (dispatch, getState) => {
dispatch(applyFilters());
};

export const setOtherSummaryFilter = () => (dispatch, getState) => {
export const setCPTOtherSummaryFilter = () => (dispatch, getState) => {
const filteredResults = [...getState().cpt.filteredResults];
const keyWordArr = ["success", "failure"];
const data = filteredResults.filter(
Expand All @@ -142,7 +145,7 @@ export const setOtherSummaryFilter = () => (dispatch, getState) => {
});
dispatch(tableReCalcValues());
};
export const removeAppliedFilters =
export const removeCPTAppliedFilters =
(filterKey, filterValue, navigate) => (dispatch, getState) => {
const { start_date, end_date } = getState().cpt;

Expand Down Expand Up @@ -184,7 +187,7 @@ export const setFilterFromURL = (searchParams) => ({
payload: searchParams,
});

export const setDateFilter =
export const setCPTDateFilter =
(start_date, end_date, navigate) => (dispatch, getState) => {
const appliedFilters = getState().cpt.appliedFilters;

Expand All @@ -201,12 +204,12 @@ export const setDateFilter =
dispatch(fetchOCPJobsData());
};

export const setPage = (pageNo) => ({
export const setCPTPage = (pageNo) => ({
type: TYPES.SET_PAGE,
payload: pageNo,
});

export const setPageOptions = (page, perPage) => ({
export const setCPTPageOptions = (page, perPage) => ({
type: TYPES.SET_PAGE_OPTIONS,
payload: { page, perPage },
});
Expand All @@ -223,6 +226,6 @@ export const getCPTSummary = () => (dispatch, getState) => {

export const tableReCalcValues = () => (dispatch) => {
dispatch(getCPTSummary());
dispatch(setPageOptions(START_PAGE, DEFAULT_PER_PAGE));
dispatch(sliceTableRows(0, DEFAULT_PER_PAGE));
dispatch(setCPTPageOptions(START_PAGE, DEFAULT_PER_PAGE));
dispatch(sliceCPTTableRows(0, DEFAULT_PER_PAGE));
};
Loading
Loading