Skip to content

Commit

Permalink
[ch31343] [Intermittent] Continuous loading PD/SSFA Data in Programme…
Browse files Browse the repository at this point in the history
… Document (#1830)

* [ch28888] Indicator calculation methods are not displayed sometimes

* added piwik to frontend_cluster

* update common submodule ref

* updated common module ref

* [ch31343] [Intermittent] Continuous loading PD/SSFA Data in Programme Document

* [ch31343] [Intermittent] Continuous loading PD/SSFA Data in Programme Document

* adjustments

* updated circleCi for this branch

* adjustments

* updated prp_common reference
  • Loading branch information
danNordlogic authored Sep 12, 2022
1 parent a0c7a5b commit 613a635
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ workflows:
- master
- staging
- develop
- pd-overview-loading
- update-packages-fixes
- build_and_deploy_fe_cluster:
filters:
Expand Down
30 changes: 10 additions & 20 deletions frontend_ip/src_ts/elements/ip-reporting/pd-details-overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import {Debouncer} from '@polymer/polymer/lib/utils/debounce';
import {timeOut} from '@polymer/polymer/lib/utils/async';
import {EtoolsPrpAjaxEl} from '../../etools-prp-common/elements/etools-prp-ajax';
import Settings from '../../etools-prp-common/settings';
import {currentProgrammeDocument} from '../../etools-prp-common/redux/selectors/programmeDocuments';
import {computeLoaded, hasAmendments, computeReportingRequirements} from './js/pd-details-overview-functions';
import {RootState} from '../../typings/redux.types';
import {pdAdd, pdSetCount} from '../../redux/actions/pd';

/**
* @polymer
Expand Down Expand Up @@ -103,11 +102,6 @@ class PdDetailsOverview extends UtilsMixin(LocalizeMixin(ReduxConnectedElement))
}
</style>
<etools-prp-ajax
id="programmeDocuments"
url="[[programmeDocumentsUrl]]">
</etools-prp-ajax>
<etools-prp-ajax
id="programmeDocumentDetail"
url="[[programmeDocumentDetailUrl]]">
Expand Down Expand Up @@ -291,7 +285,7 @@ class PdDetailsOverview extends UtilsMixin(LocalizeMixin(ReduxConnectedElement))
`;
}

@property({type: Object, computed: '_currentProgrammeDocument(rootState)'})
@property({type: Object})
pd: GenericObject = {};

@property({type: Object})
Expand Down Expand Up @@ -319,9 +313,6 @@ class PdDetailsOverview extends UtilsMixin(LocalizeMixin(ReduxConnectedElement))
@property({type: String, computed: 'getReduxStateValue(rootState.programmeDocuments.current)'})
pdId!: string;

@property({type: String, computed: '_computeProgrammeDocumentsUrl(locationId)'})
programmeDocumentsUrl!: string;

@property({type: String, computed: '_computePdDetailsUrl(locationId, pdId)'})
programmeDocumentDetailUrl!: string;

Expand Down Expand Up @@ -358,10 +349,6 @@ class PdDetailsOverview extends UtilsMixin(LocalizeMixin(ReduxConnectedElement))
return computeReportingRequirements(reportingPeriods, Settings.dateFormat);
}

_computeProgrammeDocumentsUrl(locationId: string) {
return locationId ? Endpoints.programmeDocuments(locationId) : '';
}

_computePdDetailsUrl(locationId: string, pdId: string) {
if (!locationId || !pdId) {
return;
Expand Down Expand Up @@ -393,18 +380,21 @@ class PdDetailsOverview extends UtilsMixin(LocalizeMixin(ReduxConnectedElement))

pdThunk()
.then((res: any) => {
this.pd = res.data;
this.set('pd', res.data);
// if PD is missing from state programmeDocuments need to add it because
// it's loaded from list in other places with currentProgrammeDocument
const pdFromList = this.rootState.programmeDocuments.all.find((x) => String(x.id) === String(res.data.id));
if (!pdFromList) {
this.reduxStore.dispatch(pdAdd(res.data));
this.reduxStore.dispatch(pdSetCount(++this.rootState.programmeDocuments.all.length));
}
})
.catch((err: GenericObject) => {
console.log(err);
});
});
}

_currentProgrammeDocument(rootState: RootState) {
return currentProgrammeDocument(rootState);
}

disconnectedCallback() {
super.disconnectedCallback();

Expand Down
2 changes: 1 addition & 1 deletion frontend_ip/src_ts/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Endpoints = {
},

programmeDocuments(locationId: string) {
return this._buildUrl('/unicef/' + locationId + '/programme-document/?page_size=all');
return this._buildUrl('/unicef/' + locationId + '/programme-document/');
},

programmeDocumentDetail(locationId: string, pdId: string) {
Expand Down
2 changes: 1 addition & 1 deletion frontend_ip/src_ts/etools-prp-common
2 changes: 1 addition & 1 deletion frontend_ip/src_ts/pages/app/ip-reporting/pd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class PageIpReportingPd extends SortingMixin(UtilsMixin(ReduxConnectedElement))
disconnectedCallback() {
super.disconnectedCallback();

if (this.fetchPdsDebouncer && this.fetchPdsDebouncer.isActive) {
if (this.fetchPdsDebouncer && this.fetchPdsDebouncer.isActive()) {
this.fetchPdsDebouncer.cancel();
}
}
Expand Down
7 changes: 7 additions & 0 deletions frontend_ip/src_ts/redux/actions/pd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export const pdSet = function (data: any) {
};
};

export const pdAdd = function (data: any) {
return {
type: Constants.ADD_PROGRAMME_DOCUMENTS,
data: data
};
};

export const pdSetCount = function (count: number) {
return {
type: Constants.SET_PROGRAMME_DOCUMENTS_COUNT,
Expand Down
6 changes: 5 additions & 1 deletion frontend_ip/src_ts/redux/reducers/programmeDocuments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {combineReducers} from 'redux';
import Constants from '../../etools-prp-common/constants';
import {GenericObject} from '../../etools-prp-common/typings/globals.types';

export class ProgrammeDocumentsState {
all: any[] = [];
Expand All @@ -15,11 +16,14 @@ export const ProgrammeDocuments = combineReducers({
loading: loadingPDsReducer
});

function allPDsReducer(state = [], action: any) {
function allPDsReducer(state: GenericObject[] = [], action: any) {
switch (action.type) {
case Constants.SET_PROGRAMME_DOCUMENTS:
return action.data.slice();

case Constants.ADD_PROGRAMME_DOCUMENTS:
return state.concat([action.data]);

case Constants.RESET:
return [];

Expand Down

0 comments on commit 613a635

Please sign in to comment.