Skip to content

Commit

Permalink
fix: PR review requested changes
Browse files Browse the repository at this point in the history
- Added translation migrations
- Created changesets
  • Loading branch information
samshara committed Jan 29, 2025
1 parent c1f350e commit 4843cb0
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changeset/flat-horses-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ifrc-go/ui": patch
---

- Pass styling props to `BarChart` and `TimeSeriesChart`
- Fix date separation logic in `getDatesSeparatedByYear`
15 changes: 15 additions & 0 deletions .changeset/rotten-ants-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"go-web-app": minor
---

Added Operational Learning 2.0

- Key Figures Overview in Operational Learning
- Map View for Operational Learning
- Learning by Sector Bar Chart
- Learning by Region Bar Chart
- Sources Over Time Line Chart
- Methodology changes for the prioritization step
- Added an option to regenerate cached summaries
- Summary post-processing and cleanup
- Enabled MDR code search in admin
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ interface ClickedPoint {
lngLat: mapboxgl.LngLatLike;
}

const LEARNING_COUNT_LOW_COLOR = '#AEB7C2';
const LEARNING_COUNT_HIGH_COLOR = '#011E41';
const MIN_LEARNING_COUNT = 0;
const LEARNING_COUNT_LOW_COLOR = 'var(--go-ui-color-blue-30)';
const LEARNING_COUNT_HIGH_COLOR = 'var(--go-ui-color-blue-90)';

interface Props {
className?: string;
Expand Down Expand Up @@ -86,7 +87,7 @@ function OperationalLearningMap(props: Props) {
}

const features = learningByCountry
?.map((value) => {
.map((value) => {
const country = countriesMap?.[value.country_id];
if (isNotDefined(country)) {
return undefined;
Expand Down Expand Up @@ -193,7 +194,7 @@ function OperationalLearningMap(props: Props) {
/>
<div className={styles.labelList}>
<NumberOutput
value={0}
value={MIN_LEARNING_COUNT}
/>
<NumberOutput
value={maxLearning}
Expand Down
38 changes: 21 additions & 17 deletions app/src/views/OperationalLearning/Stats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,24 @@ type SourceTypeEnum = components<'read'>['schemas']['ApiAppealTypeEnumKey'];
const SOURCE_TYPE_EMERGENCY = 1 satisfies SourceTypeEnum;
const SOURCE_TYPE_DREF = 0 satisfies SourceTypeEnum;

const transformSourcesOverTimeData = (data: SourcesOverTimeItem[]) => {
const groupedData: Record<string, Record<SourceType, number>> = {};

data.forEach((entry) => {
const transformSourcesOverTimeData = (data: SourcesOverTimeItem[]) => (
data.reduce<Record<string, Record<SourceType, number>>>((acc, entry) => {
const year = getFormattedDateKey(entry.date);
if (!groupedData[year]) {
groupedData[year] = { dref: 0, emergencyAppeal: 0, others: 0 };
if (isNotDefined(acc[year])) {
acc[year] = { dref: 0, emergencyAppeal: 0, others: 0 };
}

if (entry.atype === SOURCE_TYPE_DREF) {
groupedData[year].dref += entry.count;
acc[year].dref += entry.count;
} else if (entry.atype === SOURCE_TYPE_EMERGENCY) {
groupedData[year].emergencyAppeal += entry.count;
acc[year].emergencyAppeal += entry.count;
} else {
groupedData[year].others += entry.count;
acc[year].others += entry.count;
}
});

return groupedData;
};
return acc;
}, {})
);

interface Props {
query: OpsLearningQuery | undefined
Expand Down Expand Up @@ -138,19 +137,23 @@ function Stats(props: Props) {
if (isNotDefined(sourcesOverTimeData)) {
return undefined;
}

const dates = Object.keys(sourcesOverTimeData).map((year) => new Date(year));

if (dates.length < 1) {
return undefined;
}

const oldestDate = new Date(Math.min(...dates.map((date) => date.getTime())));
const latestDate = new Date(Math.max(...dates.map((date) => date.getTime())));

return getDatesSeparatedByYear(oldestDate, latestDate);
}, [sourcesOverTimeData]);

const sourcesOverTimeValueSelector = useCallback(
(key: SourceType, date: Date) => {
const value = sourcesOverTimeData?.[getFormattedDateKey(date)]?.[key];
if (isDefined(value) && value > 0) {
return value;
}
return undefined;
return isDefined(value) && value > 0 ? value : undefined;
},
[sourcesOverTimeData],
);
Expand All @@ -177,7 +180,8 @@ function Stats(props: Props) {
strings.sourceOthers,
]);

const activePointData = activePointKey ? sourcesOverTimeData?.[activePointKey] : undefined;
const activePointData = isDefined(activePointKey)
? sourcesOverTimeData?.[activePointKey] : undefined;

return (
<div className={styles.stats}>
Expand Down
113 changes: 113 additions & 0 deletions translationMigrations/000011-1738138922126.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"parent": "000010-1738067954473.json",
"actions": [
{
"action": "add",
"key": "downloadMapTitle",
"namespace": "operationalLearning",
"value": "Operational learning map"
},
{
"action": "add",
"key": "failedToFetchLearning",
"namespace": "operationalLearning",
"value": "Failed to fetch operational learning"
},
{
"action": "add",
"key": "failedToFetchPerComponents",
"namespace": "operationalLearning",
"value": "Failed to fetch PER components"
},
{
"action": "add",
"key": "failedToFetchStats",
"namespace": "operationalLearning",
"value": "Failed To fetch operational learning statistics."
},
{
"action": "add",
"key": "failedToFetchSummary",
"namespace": "operationalLearning",
"value": "Failed to fetch operational learning summary"
},
{
"action": "add",
"key": "learningByRegions",
"namespace": "operationalLearning",
"value": "Learning by regions"
},
{
"action": "add",
"key": "learningBySector",
"namespace": "operationalLearning",
"value": "Learning by sectors"
},
{
"action": "add",
"key": "learningCount",
"namespace": "operationalLearning",
"value": "Learning count"
},
{
"action": "add",
"key": "learningExtract",
"namespace": "operationalLearning",
"value": "Learning Extracts"
},
{
"action": "add",
"key": "operationsIncluded",
"namespace": "operationalLearning",
"value": "Operations Included"
},
{
"action": "add",
"key": "sectorsCovered",
"namespace": "operationalLearning",
"value": "Sectors Covered"
},
{
"action": "add",
"key": "sourceDREF",
"namespace": "operationalLearning",
"value": "DREF"
},
{
"action": "add",
"key": "sourceEmergencyAppeal",
"namespace": "operationalLearning",
"value": "Emergency Appeal"
},
{
"action": "add",
"key": "sourceOthers",
"namespace": "operationalLearning",
"value": "Others"
},
{
"action": "add",
"key": "sourcesOverTime",
"namespace": "operationalLearning",
"value": "Sources over time"
},
{
"action": "add",
"key": "sourcesTypeLegendLabel",
"namespace": "operationalLearning",
"value": "Type of source"
},
{
"action": "add",
"key": "sourcesUsed",
"namespace": "operationalLearning",
"value": "Sources Used"
},
{
"action": "update",
"key": "opsLearningSummariesHeading",
"namespace": "operationalLearning",
"newValue": "Summary of learning"
}
]
}

0 comments on commit 4843cb0

Please sign in to comment.