Skip to content

Commit

Permalink
feat: support multiple periods
Browse files Browse the repository at this point in the history
  • Loading branch information
BRaimbault committed Nov 19, 2024
1 parent 537c0f7 commit 06d6d71
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"start-server-and-test": "^2.0.3"
},
"dependencies": {
"@dhis2/analytics": "^26.8.4",
"@dhis2/analytics": "git+https://github.com/d2-ci/analytics.git#feat/DHIS2-15796",
"@dhis2/app-runtime": "^3.11.2",
"@dhis2/app-runtime-adapter-d2": "^1.1.0",
"@dhis2/app-service-datastore": "^1.0.0-beta.3",
Expand Down
5 changes: 4 additions & 1 deletion src/components/layers/LayerCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const LayerCard = ({
})}
>
<h2>{title}</h2>
{subtitle && <h3>{subtitle}</h3>}
{
// TODO Handle long list of periods
subtitle && <h3>{subtitle}</h3>
}
</div>
<div className={styles.action}>
{isOverlay && <SortableHandle />}
Expand Down
11 changes: 9 additions & 2 deletions src/components/layers/styles/LayerCard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}

.cardHeader {
height: 54px;
min-height: 54px;
padding: 2px 8px 0 18px;
font-size: 14px;
display: flex;
Expand All @@ -26,15 +26,22 @@
overflow: hidden;
text-overflow: ellipsis;
font-weight: 500;
margin: 8px 0 0 0;
}

.title hz3 {
line-height: 17px;
font-size: 14px;
font-weight: 400;
margin: 0;
color: var(--colors-grey800);
}

.title h3 {
line-height: 17px;
font-size: 14px;
font-weight: 400;
margin: 0;
margin: 4px 32px 8px 0;
color: var(--colors-grey800);
}

Expand Down
17 changes: 14 additions & 3 deletions src/loaders/thematicLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '../constants/layers.js'
import {
getOrgUnitsFromRows,
getPeriodsFromFilters,
getPeriodFromFilters,
getValidDimensionsFromFilters,
getDataItemFromColumns,
Expand Down Expand Up @@ -98,9 +99,13 @@ const thematicLoader = async ({ config, engine, nameProperty }) => {
const isBubbleMap = thematicMapType === THEMATIC_BUBBLE
const isSingleColor = config.method === CLASSIFICATION_SINGLE_COLOR
const period = getPeriodFromFilters(config.filters)
console.log('πŸš€ ~ thematicLoader ~ period:', period)
const periodx = getPeriodsFromFilters(config.filters)
console.log('πŸš€ ~ thematicLoader ~ periodx:', periodx)
const periods = getPeriodsFromMetaData(data.metaData)
const dimensions = getValidDimensionsFromFilters(config.filters)
const names = getApiResponseNames(data)
// TODO Handle multiple maps
const valuesByPeriod = !isSingleMap ? getValuesByPeriod(data) : null
const valueById = getValueById(data)
const valueFeatures = noDataColor
Expand Down Expand Up @@ -150,13 +155,14 @@ const thematicLoader = async ({ config, engine, nameProperty }) => {
const legend = {
title: name,
period: period
? names[period.id] || period.id
? periodx.map((pe) => names[pe.id] || pe.id).join(', ')
: formatStartEndDate(
getDateArray(config.startDate),
getDateArray(config.endDate)
),
items: legendItems,
}
console.log('πŸš€ ~ thematicLoader ~ names:', names)

if (dimensions && dimensions.length) {
legend.filters = dimensions.map(
Expand Down Expand Up @@ -262,6 +268,7 @@ const thematicLoader = async ({ config, engine, nameProperty }) => {
if (noDataColor && Array.isArray(legend.items) && !isBubbleMap) {
legend.items.push({ color: noDataColor, name: i18n.t('No data') })
}
console.log('πŸš€ ~ thematicLoader ~ legend:', legend)

return {
...config,
Expand Down Expand Up @@ -350,6 +357,9 @@ const loadData = async (config, nameProperty) => {
} = config
const orgUnits = getOrgUnitsFromRows(rows)
const period = getPeriodFromFilters(filters)
console.log('πŸš€ ~ loadData ~ period:', period)
const periodx = getPeriodsFromFilters(filters)
console.log('πŸš€ ~ loadData ~ periodx:', periodx)
const dimensions = getValidDimensionsFromFilters(config.filters)
const dataItem = getDataItemFromColumns(columns) || {}
const coordinateField = getCoordinateField(config)
Expand All @@ -371,10 +381,11 @@ const loadData = async (config, nameProperty) => {
.withDisplayProperty(nameProperty)

if (!isSingleMap) {
// TODO Handle multiple maps
analyticsRequest = analyticsRequest.addPeriodDimension(period.id)
} else {
analyticsRequest = period
? analyticsRequest.addPeriodFilter(period.id)
analyticsRequest = periodx
? analyticsRequest.addPeriodFilter(periodx.map((pe) => pe.id))
: analyticsRequest.withStartDate(startDate).withEndDate(endDate)
}

Expand Down

0 comments on commit 06d6d71

Please sign in to comment.