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

Feature/amp 30891/filter indicators by program #235

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion app/components/activity/edit/ActivityForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ div.quick_links::after {
vertical-align: top;
padding-right: 4px;
}

.full_width {
width: 100%;
}
Expand Down
43 changes: 43 additions & 0 deletions app/components/activity/edit/components/AFField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import AFRadioList from './AFRadioList';
import FieldDefinition from '../../../../modules/field/FieldDefinition';
import Messages from '../../../common/Messages';
import PossibleValuesHelper from '../../../../modules/helpers/PossibleValuesHelper';
import GlobalSettingsManager from '../../../../modules/util/GlobalSettingsManager';

const logger = new Logger('AF field');

Expand Down Expand Up @@ -235,6 +236,7 @@ class AFField extends Component {
_getSearch() {
const { fieldPath, onAfterUpdate, extraParams } = this.props;
const afOptions = this._toAFOptions(this._getOptions(fieldPath));
console.log('Options', afOptions);
return (<AFSearchList
onSearchSelect={onAfterUpdate} options={afOptions}
placeholder={(extraParams && extraParams.placeholder ? extraParams.placeholder : null)} />);
Expand Down Expand Up @@ -263,8 +265,11 @@ class AFField extends Component {

_getOptions(fieldPath, selectedId) {
const { workspacePrefix } = this.props;
// console.log('Path****', fieldPath);
// console.log('Activity****', this.context.activity);
const somePrefix = workspacePrefix || '';
const options = this.context.activityFieldsManager.possibleValuesMap[fieldPath];

if (options === null || options === undefined) {
// TODO throw error but continue to render (?)
logger.error(`Options not found for ${this.props.fieldPath}`);
Expand All @@ -283,6 +288,44 @@ class AFField extends Component {
if (Object.keys(optionsWithPrefix).length === 0) {
optionsWithPrefix = options;
}
const filterIndicatorByProg = GlobalSettingsManager.getSettingByKey('Filter indicators by program');
console.log('Filter ind', filterIndicatorByProg === 'true');
if (filterIndicatorByProg === 'true') {
if (fieldPath === 'indicators~indicator') {
// return [];
// eslint-disable-next-line max-len
const combinedPrograms = [...this.context.activity.primary_programs, ...this.context.activity.secondary_programs, ...this.context.activity.tertiary_programs];
const activityProgramIdsSet = new Set(combinedPrograms.map(program => program.program.id));
// const optionsProgramIds= options.map()

if (activityProgramIdsSet.size <= 0) {
optionsWithPrefix = { };
} else {
Object.keys(optionsWithPrefix)
.forEach(o => {
if (optionsWithPrefix[o][ActivityConstants.EXTRA_INFO]) {
// console.log("Option ", options[o][ActivityConstants.EXTRA_INFO]);
// if (optionsWithPrefix[o][ActivityConstants.EXTRA_INFO]['program-ids']) {
if (optionsWithPrefix[o][ActivityConstants.EXTRA_INFO]['program-ids'].length <= 0) {
console.log('No program ids related to this indicator');

delete optionsWithPrefix[o];
} else {
// eslint-disable-next-line no-restricted-syntax
for (const id of optionsWithPrefix[o][ActivityConstants.EXTRA_INFO]['program-ids']) {
if (!activityProgramIdsSet.has(id)) {
console.log('Not Found id ****', id);
delete optionsWithPrefix[o];
break;
}
}
}
// }
}
});
}
}
}
const isORFilter = (this.props.extraParams && this.props.extraParams.isORFilter) || false;
return PossibleValuesManager.setVisibility(
optionsWithPrefix, fieldPath, this.context.currencyRatesManager, this.props.filter, isORFilter, selectedId);
Expand Down
2 changes: 2 additions & 0 deletions app/components/activity/edit/sections/AFM_E.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class AFM_E extends Component {
handleAddME(id) {
return PossibleValuesHelper.findById(`${ActivityConstants.INDICATORS}~${ActivityConstants.INDICATOR}`)
.then(data => {
console.log('Datas***' , data);

const { activity } = this.props;
const indicators = activity[ActivityConstants.INDICATORS] || [];
if (!indicators.find(i => i.indicator.id === id)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
"npm": ">=3.x"
},
"config": {
"ampServerUrl": "amp-bfaso-develop.stg.ampsite.net",
"ampServerUrl": "amp-togo-pr-4327.stg.ampsite.net",
"ampServerPort": "443",
"ampServerProtocol": "https"
},
Expand Down