diff --git a/binocular-frontend/src/visualizations/merge-request-ownership/chart/index.tsx b/binocular-frontend/src/visualizations/merge-request-ownership/chart/index.tsx index 5f0b3068..0326dac4 100644 --- a/binocular-frontend/src/visualizations/merge-request-ownership/chart/index.tsx +++ b/binocular-frontend/src/visualizations/merge-request-ownership/chart/index.tsx @@ -11,6 +11,8 @@ const mapStateToProps = (state) => { mergeRequests: mergeRequestOwnershipState.data.data.mergeRequests, selectedAuthors: universalSettings.selectedAuthorsGlobal, allAuthors: universalSettings.allAuthors, + firstSignificantTimestamp: mergeRequestOwnershipState.data.data.firstSignificantTimestamp, + lastSignificantTimestamp: mergeRequestOwnershipState.data.data.lastSignificantTimestamp, }; }; diff --git a/binocular-frontend/src/visualizations/merge-request-ownership/sagas/index.ts b/binocular-frontend/src/visualizations/merge-request-ownership/sagas/index.ts index 96ad7567..0aaf97b9 100644 --- a/binocular-frontend/src/visualizations/merge-request-ownership/sagas/index.ts +++ b/binocular-frontend/src/visualizations/merge-request-ownership/sagas/index.ts @@ -3,6 +3,7 @@ import { fetchFactory, timestampedActionFactory } from '../../../sagas/utils'; import Database from '../../../database/database'; import { createAction } from 'redux-actions'; +import { fork, select, takeEvery } from 'redux-saga/effects'; export const setActiveVisualizations = createAction('SET_ACTIVE_VISUALIZATIONS'); export const requestMergeRequestOwnershipData = createAction('REQUEST_MERGE_REQUEST_OWNERSHIP_DATA'); @@ -13,6 +14,11 @@ export const onlyShowAuthors = createAction('SET_ONLY_SHOW_AUTHORS'); export default function* () { yield* fetchMergeRequestOwnershipData(); + yield fork(watchTimeSpan); +} + +function* watchTimeSpan() { + yield takeEvery('SET_TIME_SPAN', fetchMergeRequestOwnershipData); } export const fetchMergeRequestOwnershipData = fetchFactory( @@ -22,10 +28,21 @@ export const fetchMergeRequestOwnershipData = fetchFactory( const firstMergeRequestTimestamp = Date.parse(firstMergeRequest.date); const lastMergeRequestTimestamp = Date.parse(firstMergeRequest.date); + let firstSignificantTimestamp = firstMergeRequestTimestamp; + let lastSignificantTimestamp = lastMergeRequestTimestamp; + + const state = yield select(); + + const timeSpan = state.universalSettings.chartTimeSpan; + firstSignificantTimestamp = timeSpan.from === undefined ? firstSignificantTimestamp : new Date(timeSpan.from).getTime(); + lastSignificantTimestamp = timeSpan.to === undefined ? lastSignificantTimestamp : new Date(timeSpan.to).getTime(); + + console.log(firstSignificantTimestamp); + return yield Promise.resolve( Database.getMergeRequestData( [firstMergeRequestTimestamp, lastMergeRequestTimestamp], - [firstMergeRequestTimestamp, lastMergeRequestTimestamp], + [firstSignificantTimestamp, lastSignificantTimestamp], ), ).then((result) => { const mergeRequests = result;