WIP for Reporting. Pulled out calculations to utility functions.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { all, call, takeLatest, select, put } from "redux-saga/effects";
|
||||
import GetJobTarget from "../../util/GetJobTarget";
|
||||
import { setSelectedJobTargetPcSuccess } from "./application.actions";
|
||||
import ApplicationActionTypes from "./application.types";
|
||||
|
||||
@@ -12,17 +13,18 @@ export function* CalculateTarget({ payload }) {
|
||||
const { group, v_age } = payload;
|
||||
const targets = yield select((state) => state.user.bodyshop.targets);
|
||||
|
||||
const targetsForGroup = targets.filter((t) => t.group === group);
|
||||
if (!targetsForGroup) return 0;
|
||||
const targetPc = targetsForGroup.filter(
|
||||
(t) => t.ageGte <= v_age && (t.ageLt ? t.ageLt > v_age : true)
|
||||
);
|
||||
if (targetPc.length === 0) yield put(setSelectedJobTargetPcSuccess(100));
|
||||
else if (targetPc.length === 1)
|
||||
yield put(setSelectedJobTargetPcSuccess(targetPc[0].target));
|
||||
else {
|
||||
yield put(setSelectedJobTargetPcSuccess(100));
|
||||
}
|
||||
yield put(setSelectedJobTargetPcSuccess(GetJobTarget(group, v_age, targets)));
|
||||
// const targetsForGroup = targets.filter((t) => t.group === group);
|
||||
// if (!targetsForGroup) return 0;
|
||||
// const targetPc = targetsForGroup.filter(
|
||||
// (t) => t.ageGte <= v_age && (t.ageLt ? t.ageLt > v_age : true)
|
||||
// );
|
||||
// if (targetPc.length === 0) yield put(setSelectedJobTargetPcSuccess(100));
|
||||
// else if (targetPc.length === 1)
|
||||
// yield put(setSelectedJobTargetPcSuccess(targetPc[0].target));
|
||||
// else {
|
||||
// yield put(setSelectedJobTargetPcSuccess(100));
|
||||
// }
|
||||
}
|
||||
|
||||
export function* applicationSagas() {
|
||||
|
||||
24
src/redux/reporting/reporting.actions.js
Normal file
24
src/redux/reporting/reporting.actions.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import ReportingActionTypes from "./reporting.types";
|
||||
|
||||
export const queryReportingData = ({ startDate, endDate }) => ({
|
||||
type: ReportingActionTypes.QUERY_REPORTING_DATA,
|
||||
payload: { startDate, endDate },
|
||||
});
|
||||
|
||||
export const setReportingData = (data) => ({
|
||||
type: ReportingActionTypes.SET_REPORTING_DATA,
|
||||
payload: data,
|
||||
});
|
||||
|
||||
export const calculateScorecard = (data) => ({
|
||||
type: ReportingActionTypes.CALCULATE_SCORE_CARD,
|
||||
payload: data,
|
||||
});
|
||||
export const setScoreCard = (data) => ({
|
||||
type: ReportingActionTypes.SET_SCORE_CARD,
|
||||
payload: data,
|
||||
});
|
||||
export const setReportingError = (data) => ({
|
||||
type: ReportingActionTypes.SET_REPORTING_ERROR,
|
||||
payload: data,
|
||||
});
|
||||
23
src/redux/reporting/reporting.reducer.js
Normal file
23
src/redux/reporting/reporting.reducer.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import ReportingActionTypes from "./reporting.types";
|
||||
const INITIAL_STATE = {
|
||||
dates: { startDate: null, endDate: null },
|
||||
data: [],
|
||||
scoreCard: null,
|
||||
error: null,
|
||||
loading: false,
|
||||
};
|
||||
|
||||
const applicationReducer = (state = INITIAL_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case ReportingActionTypes.QUERY_REPORTING_DATA:
|
||||
return { ...state, loading: true, dates: action.payload };
|
||||
case ReportingActionTypes.SET_REPORTING_DATA:
|
||||
return { ...state, data: action.payload };
|
||||
case ReportingActionTypes.SET_SCORE_CARD:
|
||||
return { ...state, loading: false, scoreCard: action.payload };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default applicationReducer;
|
||||
57
src/redux/reporting/reporting.sagas.js
Normal file
57
src/redux/reporting/reporting.sagas.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import { all, call, takeLatest, select, put } from "redux-saga/effects";
|
||||
import { calculateScorecard, setReportingData } from "./reporting.actions";
|
||||
import ReportingApplicationTypes from "./reporting.types";
|
||||
import client from "../../graphql/GraphQLClient";
|
||||
import { REPORTING_GET_JOBS } from "../../graphql/reporting.queries";
|
||||
const { log } = window;
|
||||
|
||||
export function* onQueryReportData() {
|
||||
yield takeLatest(
|
||||
ReportingApplicationTypes.QUERY_REPORTING_DATA,
|
||||
queryReportingData
|
||||
);
|
||||
}
|
||||
export function* queryReportingData({ payload: { startDate, endDate } }) {
|
||||
const result = yield client.query({
|
||||
query: REPORTING_GET_JOBS,
|
||||
variables: { startDate, endDate },
|
||||
});
|
||||
if (result.errors) {
|
||||
log.error("Error fetching report data.", result.errors);
|
||||
yield put(setReportingData(null));
|
||||
} else {
|
||||
yield put(setReportingData(result.data.jobs));
|
||||
}
|
||||
}
|
||||
|
||||
export function* onSetReportData() {
|
||||
yield takeLatest(
|
||||
ReportingApplicationTypes.SET_REPORTING_DATA,
|
||||
handleSetReportData
|
||||
);
|
||||
}
|
||||
export function* handleSetReportData({ payload: jobs }) {
|
||||
yield put(calculateScorecard(jobs));
|
||||
}
|
||||
|
||||
export function* onCalculateScoreCard() {
|
||||
yield takeLatest(
|
||||
ReportingApplicationTypes.CALCULATE_SCORE_CARD,
|
||||
handleCalculateScoreCard
|
||||
);
|
||||
}
|
||||
export function* handleCalculateScoreCard({ payload: jobs }) {
|
||||
console.log("jobs", jobs);
|
||||
// yield put(calculateScorecard(jobs));
|
||||
|
||||
//Get the RPS on a per job basis.
|
||||
|
||||
}
|
||||
|
||||
export function* reportingSagas() {
|
||||
yield all([
|
||||
call(onQueryReportData),
|
||||
call(onSetReportData),
|
||||
call(onCalculateScoreCard),
|
||||
]);
|
||||
}
|
||||
49
src/redux/reporting/reporting.selectors.js
Normal file
49
src/redux/reporting/reporting.selectors.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import { createSelector } from "reselect";
|
||||
|
||||
const selectReporting = (state) => state.reporting;
|
||||
|
||||
export const selectReportLoading = createSelector(
|
||||
[selectReporting],
|
||||
(reporting) => reporting.loading
|
||||
);
|
||||
export const selectDates = createSelector(
|
||||
[selectReporting],
|
||||
(reporting) => reporting.dates
|
||||
);
|
||||
export const selectScorecard = createSelector(
|
||||
[selectReporting],
|
||||
(reporting) => reporting.scoreCard
|
||||
);
|
||||
export const selectReportingError = createSelector(
|
||||
[selectReporting],
|
||||
(reporting) => reporting.error
|
||||
);
|
||||
export const selectReportData = createSelector(
|
||||
[selectReporting],
|
||||
(reporting) => reporting.data
|
||||
);
|
||||
|
||||
// export const selectWatchedPaths = createSelector(
|
||||
// [selectReporting],
|
||||
// (application) => application.watchedPaths
|
||||
// );
|
||||
|
||||
// export const selectWatcherError = createSelector(
|
||||
// [selectReporting],
|
||||
// (application) => application.watcherError
|
||||
// );
|
||||
|
||||
// export const selectSelectedJobId = createSelector(
|
||||
// [selectReporting],
|
||||
// (application) => application.selectedJobId
|
||||
// );
|
||||
|
||||
// export const selectSelectedJobTargetPc = createSelector(
|
||||
// [selectReporting],
|
||||
// (application) => application.selectedJobTargetPc
|
||||
// );
|
||||
|
||||
// export const selectSettings = createSelector(
|
||||
// [selectReporting],
|
||||
// (application) => application.settings
|
||||
// );
|
||||
8
src/redux/reporting/reporting.types.js
Normal file
8
src/redux/reporting/reporting.types.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const ReportingActionTypes = {
|
||||
QUERY_REPORTING_DATA: "QUERY_REPORTING_DATA",
|
||||
CALCULATE_SCORE_CARD: "CALCULATE_SCORE_CARD",
|
||||
SET_REPORTING_DATA: "SET_REPORTING_DATA",
|
||||
SET_SCORE_CARD: "SET_SCORE_CARD",
|
||||
SET_REPORTING_ERROR: "SET_REPORTING_ERROR",
|
||||
};
|
||||
export default ReportingActionTypes;
|
||||
@@ -3,16 +3,18 @@ import { persistReducer } from "redux-persist";
|
||||
import storage from "redux-persist/lib/storage";
|
||||
import applicationReducer from "./application/application.reducer";
|
||||
import userReducer from "./user/user.reducer";
|
||||
import reportingReducer from "./reporting/reporting.reducer";
|
||||
|
||||
const persistConfig = {
|
||||
key: "root",
|
||||
storage,
|
||||
blacklist: ["application", "user"],
|
||||
blacklist: ["application", "user", "reporting"],
|
||||
};
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
application: applicationReducer,
|
||||
user: userReducer,
|
||||
reporting: reportingReducer,
|
||||
});
|
||||
|
||||
export default persistReducer(persistConfig, rootReducer);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { all, call } from "redux-saga/effects";
|
||||
import { applicationSagas } from "./application/application.sagas";
|
||||
import { userSagas } from "./user/user.sagas";
|
||||
|
||||
import { reportingSagas } from "./reporting/reporting.sagas";
|
||||
export default function* rootSaga() {
|
||||
yield all([call(applicationSagas), call(userSagas)]);
|
||||
yield all([call(applicationSagas), call(userSagas), call(reportingSagas)]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user