Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Regional 3W #1152

Merged
merged 14 commits into from
Apr 29, 2020
Merged
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
36 changes: 35 additions & 1 deletion app/assets/scripts/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,48 @@ export const getMe = () => (
fetchJSON('api/v2/user/me/', GET_ME, withToken())
);

export const GET_REGIONAL_PROJECTS = 'GET_REGIONAL_PROJECTS';
export const getRegionalProjects = (regionId, filterValues) => {
const filters = {
region: regionId,
limit: 9999,
...filterValues
};
const query = buildAPIQS(filters, { arrayFormat: 'comma' });
return fetchJSON(`api/v2/project/?${query}`, GET_REGIONAL_PROJECTS, withToken());
};

export const GET_REGIONAL_PROJECTS_OVERVIEW = 'GET_REGIONAL_PROJECTS_OVERVIEW';
export function getRegionalProjectsOverview (regionId) {
return fetchJSON(`api/v2/region-project/${regionId}/overview/`, GET_REGIONAL_PROJECTS_OVERVIEW, withToken());
}

export const GET_REGIONAL_MOVEMENT_ACTIVITIES = 'GET_REGIONAL_MOVEMENT_ACTIVITIES';
export function getRegionalMovementActivities (regionId, filters) {
const query = buildAPIQS(filters, { arrayFormat: 'comma' });
return fetchJSON(`api/v2/region-project/${regionId}/movement-activities/?${query}`, GET_REGIONAL_MOVEMENT_ACTIVITIES, withToken());
}

export const GET_NATIONAL_SOCIETY_ACTIVITIES = 'GET_NATIONAL_SOCIETY_ACTIVITIES';
export function getNationalSocietyActivities (regionId, filters) {
const query = buildAPIQS(filters, { arrayFormat: 'comma' });

return fetchJSON(`api/v2/region-project/${regionId}/national-society-activities/?${query}`, GET_NATIONAL_SOCIETY_ACTIVITIES, withToken());
}

export const GET_NATIONAL_SOCIETY_ACTIVITIES_WO_FILTERS = 'GET_NATIONAL_SOCIETY_ACTIVITIES_WO_FILTERS';
export function getNationalSocietyActivitiesWoFilters (regionId) {
return fetchJSON(`api/v2/region-project/${regionId}/national-society-activities/`, GET_NATIONAL_SOCIETY_ACTIVITIES_WO_FILTERS, withToken());
}

export const GET_PROJECTS = 'GET_PROJECTS';
export function getProjects (countryId, filterValues) {
const filters = {
country: countryIsoMapById[countryId],
...filterValues
};
const f = buildAPIQS(filters);
return fetchJSON(`api/v2/project/?${f}`, GET_PROJECTS, withToken());
return fetchJSON(`api/v2/project/?${f}`, GET_PROJECTS, withToken(), { countryId });
}

export const POST_PROJECT = 'POST_PROJECT';
Expand Down
3 changes: 2 additions & 1 deletion app/assets/scripts/components/formatted-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const FormattedNumber = ({
if (addSeparator) {
displayNumber = addCommaSeparator(displayNumber);
} else if (fixedTo) {
displayNumber = Number.parseFloat(displayNumber).toFixed(fixedTo);
const shouldFix = (displayNumber - Math.floor(displayNumber)) !== 0;
displayNumber = Number.parseFloat(displayNumber).toFixed(shouldFix ? fixedTo : 0);
}
}

Expand Down
78 changes: 48 additions & 30 deletions app/assets/scripts/components/text-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,54 @@ import _cs from 'classnames';
import FormattedNumber from './formatted-number';
import FormattedDate from './formatted-date';

const TextOutput = ({
className,
label,
value,
addSeparatorToValue,
normalizeValue,
fixedTo,
type = 'string',
}) => (
<div className={_cs('tc-text-output', className)}>
<div className='tc-label'>
{label}
</div>
<div className='tc-value'>
{ type === 'string' && value }
{ type === 'number' && (
<FormattedNumber
value={value}
addSeparator={addSeparatorToValue}
fixedTo={fixedTo}
normalize={normalizeValue}
/>
)}
{ type === 'date' && (
<FormattedDate
value={value}
/>
)}
</div>
</div>
const isValueEmpty = (value) => (
value === null || value === '' || value === undefined
);

function TextOutput (p) {
const {
className,
label,
value,
addSeparatorToValue,
normalizeValue,
fixedTo,
type = 'string',
reverseOrder,
hideEmptyValue,
} = p;

return (
(hideEmptyValue && isValueEmpty(value)) ? (
null
) : (
<div className={_cs(
'tc-text-output',
reverseOrder && 'tc-text-output-reversed',
className,
)}>
<div className='tc-label'>
{label}
</div>
<div className='tc-value'>
{ type === 'string' && value }
{ type === 'number' && (
<FormattedNumber
value={value}
addSeparator={addSeparatorToValue}
fixedTo={fixedTo}
normalize={normalizeValue}
/>
)}
{ type === 'date' && (
<FormattedDate
value={value}
/>
)}
</div>
</div>
)
);
}

export default TextOutput;
7 changes: 7 additions & 0 deletions app/assets/scripts/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { combineReducers } from 'redux';

import { systemAlertsReducer } from '../components/system-alerts';
import { createReducer } from '../utils/reducer-utils';

import user from './user';
import profile from './profile';
import countries from './countries';
Expand Down Expand Up @@ -66,6 +68,11 @@ export const reducers = {
projectForm,
projectDelete,
countryOverview,
regionalProjectsOverview: createReducer('GET_REGIONAL_PROJECTS_OVERVIEW'),
regionalMovementActivities: createReducer('GET_REGIONAL_MOVEMENT_ACTIVITIES'),
nationalSocietyActivities: createReducer('GET_NATIONAL_SOCIETY_ACTIVITIES'),
nationalSocietyActivitiesWoFilters: createReducer('GET_NATIONAL_SOCIETY_ACTIVITIES_WO_FILTERS'),
regionalProjects: createReducer('GET_REGIONAL_PROJECTS'),
me,
};

Expand Down
22 changes: 4 additions & 18 deletions app/assets/scripts/reducers/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,19 @@ import {
stateSuccess,
} from '../utils/reducer-utils';

const initialState = {
fetching: false,
fetched: false,
receivedAt: null,
data: {}
};
const initialState = {};

export default function reducer (state = initialState, action) {
let newState = { ...state };
switch (action.type) {
case 'GET_PROJECTS_INFLIGHT':
newState = {
...newState,
...stateInflight(state, action),
};
newState[action.countryId] = stateInflight(state, action);
break;
case 'GET_PROJECTS_FAILED':
newState = {
...newState,
...stateError(state, action),
};
newState[action.countryId] = stateError(state, action);
break;
case 'GET_PROJECTS_SUCCESS':
newState = {
...newState,
...stateSuccess(state, action),
};
newState[action.countryId] = stateSuccess(state, action);
break;
}

Expand Down
31 changes: 31 additions & 0 deletions app/assets/scripts/selectors/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
const initialState = {
fetching: false,
fetched: false,
receivedAt: null,
data: {}
};

export const countryOverviewSelector = (state) => (
state.countryOverview
);

export const countryProjectSelector = (state, id) => (
state.projects[id] || initialState
);

export const meSelector = (state) => (
state.me
);

export const regionalMovementActivitiesSelector = (state) => (
state.regionalMovementActivities
);

export const regionalProjectsOverviewSelector = (state) => (
state.regionalProjectsOverview
);

export const nationalSocietyActivitiesSelector = (state) => (
state.nationalSocietyActivities
);

export const nationalSocietyActivitiesWoFiltersSelector = (state) => (
state.nationalSocietyActivitiesWoFilters
);

export const regionalProjectsSelector = (state) => (
state.regionalProjects
);
Loading