From 90272eae9bec5f41ad47c5fc5d8fc2def92ecf90 Mon Sep 17 00:00:00 2001 From: Mohammadreza Ghorbani Date: Thu, 27 Jun 2019 12:28:56 +0430 Subject: [PATCH] Fix partial loading of now items when filtering the past --- .../Modules/Profit/Helpers/format-request.js | 19 +++++++++++++++---- .../app/Stores/Modules/Profit/profit-store.js | 9 ++++++++- .../Modules/Statement/statement-store.js | 9 ++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/javascript/app/Stores/Modules/Profit/Helpers/format-request.js b/src/javascript/app/Stores/Modules/Profit/Helpers/format-request.js index ddd723dd0a16..62b6003516d7 100644 --- a/src/javascript/app/Stores/Modules/Profit/Helpers/format-request.js +++ b/src/javascript/app/Stores/Modules/Profit/Helpers/format-request.js @@ -4,7 +4,13 @@ import { } from 'Utils/Date'; const getDateTo = (partial_fetch_time, date_to) => { - if (partial_fetch_time) { + const today = toMoment().startOf('day').unix(); + if (date_to && today > date_to) { + return epochToMoment(date_to) + .add(1, 'd') + .subtract(1, 's') + .unix(); + } else if (partial_fetch_time) { return toMoment().endOf('day').unix(); } else if (date_to) { return epochToMoment(date_to) @@ -15,13 +21,18 @@ const getDateTo = (partial_fetch_time, date_to) => { return toMoment().endOf('day').unix(); }; -const getDateFrom = (should_load_partially, partial_fetch_time, date_from) => - should_load_partially && partial_fetch_time ? partial_fetch_time : date_from; +const getDateFrom = (should_load_partially, partial_fetch_time, date_from, date_to) => { + const today = toMoment().startOf('day').unix(); + if (today > date_to) { + return date_from; + } + return should_load_partially && partial_fetch_time ? partial_fetch_time : date_from; +}; const getDateBoundaries = (date_from, date_to, partial_fetch_time, should_load_partially = false) => ( { // eslint-disable-next-line max-len - ...(date_from || should_load_partially) && { date_from: getDateFrom(should_load_partially, partial_fetch_time, date_from) }, + ...(date_from || should_load_partially) && { date_from: getDateFrom(should_load_partially, partial_fetch_time, date_from, date_to) }, ...(date_to || should_load_partially) && { date_to: getDateTo(partial_fetch_time, date_to) }, } ); diff --git a/src/javascript/app/Stores/Modules/Profit/profit-store.js b/src/javascript/app/Stores/Modules/Profit/profit-store.js index ab37cb8e6e47..5f40ba470901 100644 --- a/src/javascript/app/Stores/Modules/Profit/profit-store.js +++ b/src/javascript/app/Stores/Modules/Profit/profit-store.js @@ -45,9 +45,16 @@ export default class ProfitTableStore extends BaseStore { return !!(this.date_from || this.date_to); } + shouldFetchNextBatch(should_load_partially) { + if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return false; + const today = toMoment().startOf('day'); + if (should_load_partially && this.date_to && this.date_to < today) return false; + return true; + } + @action.bound async fetchNextBatch(should_load_partially = false) { - if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return; + if (!this.shouldFetchNextBatch(should_load_partially)) return; this.is_loading = true; const response = await WS.profitTable( diff --git a/src/javascript/app/Stores/Modules/Statement/statement-store.js b/src/javascript/app/Stores/Modules/Statement/statement-store.js index 9a1bf1c6f93d..2332fa4151ad 100644 --- a/src/javascript/app/Stores/Modules/Statement/statement-store.js +++ b/src/javascript/app/Stores/Modules/Statement/statement-store.js @@ -49,9 +49,16 @@ export default class StatementStore extends BaseStore { this.date_to = 0; } + shouldFetchNextBatch(should_load_partially) { + if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return false; + const today = toMoment().startOf('day'); + if (should_load_partially && this.date_to && this.date_to < today) return false; + return true; + } + @action.bound async fetchNextBatch(should_load_partially = false) { - if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return; + if (!this.shouldFetchNextBatch(should_load_partially)) return; this.is_loading = true; const response = await WS.statement(