-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix: use lerna to share code instead of copying resources (#214…
…)" (#216) This reverts commit eecfea0. This reintroduces code duplication that had been removed. The implementation causes the plugin to break in dashboards app. Reverting this now and will re-introduce a better solution with webpack bundling soon. The reason this is being rushed in now is because we are migrating the data-visualizer-app to a mon-repo.
- Loading branch information
1 parent
2538bf2
commit de00b4f
Showing
14 changed files
with
466 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { getInstance } from 'd2'; | ||
|
||
const peId = 'pe'; | ||
|
||
export const apiFetchAnalytics = async (current, options) => { | ||
const d2 = await getInstance(); | ||
|
||
const req = new d2.analytics.request() | ||
.fromModel(current) | ||
.withParameters(options); | ||
|
||
const rawResponse = await d2.analytics.aggregate.get(req); | ||
|
||
return [new d2.analytics.response(rawResponse)]; | ||
}; | ||
|
||
export const apiFetchAnalyticsForYearOverYear = async (current, options) => { | ||
const d2 = await getInstance(); | ||
|
||
let yearlySeriesReq = new d2.analytics.request() | ||
.addPeriodDimension(current.yearlySeries) | ||
.withSkipData(true) | ||
.withSkipMeta(false) | ||
.withIncludeMetadataDetails(true); | ||
|
||
if (options.relativePeriodDate) { | ||
yearlySeriesReq = yearlySeriesReq.withRelativePeriodDate( | ||
options.relativePeriodDate | ||
); | ||
} | ||
|
||
const yearlySeriesRes = await d2.analytics.aggregate.fetch(yearlySeriesReq); | ||
|
||
const requests = []; | ||
const yearlySeriesLabels = []; | ||
|
||
const now = new Date(); | ||
const currentDay = ('' + now.getDate()).padStart(2, 0); | ||
const currentMonth = ('' + (now.getMonth() + 1)).padStart(2, 0); | ||
|
||
yearlySeriesRes.metaData.dimensions[peId].forEach(period => { | ||
yearlySeriesLabels.push(yearlySeriesRes.metaData.items[period].name); | ||
|
||
const startDate = `${period}-${currentMonth}-${currentDay}`; | ||
|
||
const req = new d2.analytics.request() | ||
.fromModel(current) | ||
.withParameters(options) | ||
.withRelativePeriodDate(startDate); | ||
|
||
requests.push(d2.analytics.aggregate.get(req)); | ||
}); | ||
|
||
return Promise.all(requests).then(responses => ({ | ||
responses: responses.map(res => new d2.analytics.response(res)), | ||
yearlySeriesLabels, | ||
})); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getInstance } from 'd2'; | ||
import { getFieldsStringByType } from '../modules/fields'; | ||
|
||
export const apiFetchVisualization = (type, id) => | ||
getInstance().then(d2 => | ||
d2.models[type].get(id, { | ||
fields: getFieldsStringByType(type), | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export const computeGenericPeriodNames = responses => { | ||
const xAxisRes = responses.reduce((out, res) => { | ||
if (out.metaData) { | ||
if ( | ||
res.metaData.dimensions.pe.length > | ||
out.metaData.dimensions.pe.length | ||
) { | ||
out = res; | ||
} | ||
} else { | ||
out = res; | ||
} | ||
|
||
return out; | ||
}, {}); | ||
|
||
const metadata = xAxisRes.metaData; | ||
|
||
return metadata.dimensions.pe.reduce((genericPeriodNames, periodId) => { | ||
const name = metadata.items[periodId].name; | ||
|
||
// until the day the backend will support this in the API: | ||
// trim off the trailing year in the period name | ||
// english names should all have the year at the end of the string | ||
genericPeriodNames.push(name.replace(/\s+\d{4}$/, '')); | ||
|
||
return genericPeriodNames; | ||
}, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const YEAR_OVER_YEAR_LINE = 'YEAR_OVER_YEAR_LINE'; | ||
export const YEAR_OVER_YEAR_COLUMN = 'YEAR_OVER_YEAR_COLUMN'; | ||
|
||
const yearOverYearTypes = [YEAR_OVER_YEAR_LINE, YEAR_OVER_YEAR_COLUMN]; | ||
|
||
export const isYearOverYear = type => yearOverYearTypes.includes(type); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
export const BASE_FIELD_NAME = 'name'; | ||
export const BASE_FIELD_TYPE = 'type'; | ||
export const BASE_FIELD_YEARLY_SERIES = 'yearlySeries'; | ||
|
||
const getFieldObject = (name, props = {}) => ({ | ||
[BASE_FIELD_NAME]: name, | ||
...props, | ||
}); | ||
|
||
// fields by type | ||
|
||
export const fieldsByType = { | ||
reportTable: [ | ||
getFieldObject('cumulative', { option: true }), | ||
getFieldObject('hideEmptyColumns', { option: true }), | ||
getFieldObject('legendDisplayStyle', { option: true }), | ||
getFieldObject('measureCriteria', { option: true }), | ||
getFieldObject('numberType', { option: true }), | ||
getFieldObject('regression', { option: true }), | ||
getFieldObject('reportParams', { option: true }), | ||
getFieldObject('skipRounding', { option: true }), | ||
], | ||
chart: [ | ||
getFieldObject('category', { excluded: true }), | ||
getFieldObject('series', { excluded: true }), | ||
getFieldObject(BASE_FIELD_YEARLY_SERIES), | ||
], | ||
eventReport: [getFieldObject('dataType')], | ||
reportTable_eventReport: [ | ||
getFieldObject('colSubTotals', { option: true }), | ||
getFieldObject('colTotals', { option: true }), | ||
getFieldObject('displayDensity', { option: true }), | ||
getFieldObject('fontSize', { option: true }), | ||
getFieldObject('hideEmptyRows', { option: true }), | ||
getFieldObject('rowSubTotals', { option: true }), | ||
getFieldObject('rowTotals', { option: true }), | ||
getFieldObject('showDimensionLabels', { option: true }), | ||
getFieldObject('showHierarchy', { option: true }), | ||
], | ||
chart_eventChart: [ | ||
getFieldObject('baseLineLabel', { option: true }), | ||
getFieldObject('baseLineValue', { option: true }), | ||
getFieldObject('colorSet', { option: true }), | ||
getFieldObject('cumulativeValues', { option: true }), | ||
getFieldObject('domainAxisLabel', { option: true }), | ||
getFieldObject('hideEmptyRowItems', { option: true }), | ||
getFieldObject('hideLegend', { option: true }), | ||
getFieldObject('noSpaceBetweenColumns', { option: true }), | ||
getFieldObject('percentStackedValues', { option: true }), | ||
getFieldObject('rangeAxisDecimals', { option: true }), | ||
getFieldObject('rangeAxisLabel', { option: true }), | ||
getFieldObject('rangeAxisMaxValue', { option: true }), | ||
getFieldObject('rangeAxisMinValue', { option: true }), | ||
getFieldObject('rangeAxisSteps', { option: true }), | ||
getFieldObject('regressionType', { option: true }), | ||
getFieldObject('showData', { option: true }), | ||
getFieldObject('targetLineLabel', { option: true }), | ||
getFieldObject('targetLineValue', { option: true }), | ||
getFieldObject(BASE_FIELD_TYPE, { option: true }), | ||
], | ||
eventReport_eventChart: [ | ||
getFieldObject('attributeValueDimension'), | ||
getFieldObject('collapseDataDimensions'), | ||
getFieldObject('dataElementValueDimension'), | ||
getFieldObject('endDate'), | ||
getFieldObject('eventStatus', { option: true }), | ||
getFieldObject('hideNaData', { option: true }), | ||
getFieldObject('outputType', { option: true }), | ||
getFieldObject('program'), | ||
getFieldObject('programStage'), | ||
getFieldObject('programStatus', { option: true }), | ||
getFieldObject('startDate'), | ||
getFieldObject('value'), | ||
], | ||
reportTable_chart_eventReport: [ | ||
getFieldObject('legendDisplayStrategy', { option: true }), | ||
getFieldObject('legendSet', { option: true }), | ||
], | ||
reportTable_eventReport_eventChart: [ | ||
getFieldObject('columnDimensions', { excluded: true }), | ||
getFieldObject('rowDimensions', { excluded: true }), | ||
], | ||
reportTable_chart_eventReport_eventChart: [ | ||
getFieldObject('access'), | ||
getFieldObject('aggregationType', { option: true }), | ||
getFieldObject('attributeDimensions', { excluded: true }), | ||
getFieldObject('attributeValues', { excluded: true }), | ||
getFieldObject('categoryDimensions', { excluded: true }), | ||
getFieldObject('categoryOptionGroupSetDimensions', { excluded: true }), | ||
getFieldObject('code', { excluded: true }), | ||
getFieldObject('columns'), | ||
getFieldObject('completedOnly', { option: true }), | ||
getFieldObject('created'), | ||
getFieldObject('dataDimensionItems', { excluded: true }), | ||
getFieldObject('dataElementDimensions', { excluded: true }), | ||
getFieldObject('dataElementGroupSetDimensions', { excluded: true }), | ||
getFieldObject('description'), | ||
getFieldObject('digitGroupSeparator'), | ||
getFieldObject('displayDescription'), | ||
getFieldObject('displayName'), | ||
getFieldObject('displayShortName'), | ||
getFieldObject('externalAccess', { excluded: true }), | ||
getFieldObject('favorite'), | ||
getFieldObject('favorites'), | ||
getFieldObject('filterDimensions', { excluded: true }), | ||
getFieldObject('filters'), | ||
getFieldObject('hideSubtitle', { option: true }), | ||
getFieldObject('hideTitle', { option: true }), | ||
getFieldObject('href', { excluded: true }), | ||
getFieldObject('id'), | ||
getFieldObject('interpretations'), | ||
getFieldObject('itemOrganisationUnitGroups', { excluded: true }), | ||
getFieldObject('lastUpdated'), | ||
getFieldObject('lastUpdatedBy'), | ||
getFieldObject('name'), | ||
getFieldObject('organisationUnitGroupSetDimensions', { | ||
excluded: true, | ||
}), | ||
getFieldObject('organisationUnitLevels', { excluded: true }), | ||
getFieldObject('organisationUnits', { excluded: true }), | ||
getFieldObject('parentGraphMap'), | ||
getFieldObject('periods', { excluded: true }), | ||
getFieldObject('programIndicatorDimensions', { excluded: true }), | ||
getFieldObject('publicAccess'), | ||
getFieldObject('relativePeriods', { excluded: true }), | ||
getFieldObject('rows'), | ||
getFieldObject('shortName'), | ||
getFieldObject('sortOrder', { option: true }), | ||
getFieldObject('subscribed'), | ||
getFieldObject('subscribers'), | ||
getFieldObject('subtitle', { option: true }), | ||
getFieldObject('timeField'), | ||
getFieldObject('title', { option: true }), | ||
getFieldObject('topLimit', { option: true }), | ||
getFieldObject('translations'), | ||
getFieldObject('user'), | ||
getFieldObject('userAccesses'), | ||
getFieldObject('userGroupAccesses'), | ||
getFieldObject('userOrganisationUnit', { excluded: true }), | ||
getFieldObject('userOrganisationUnitChildren', { excluded: true }), | ||
getFieldObject('userOrganisationUnitGrandChildren', { excluded: true }), | ||
], | ||
}; | ||
|
||
// actions | ||
|
||
export const extractName = propObj => propObj[BASE_FIELD_NAME]; | ||
|
||
export const markExcluded = fieldObj => | ||
fieldObj.excluded === true | ||
? { ...fieldObj, [BASE_FIELD_NAME]: `!${fieldObj[BASE_FIELD_NAME]}` } | ||
: fieldObj; | ||
|
||
export const moveExcludedToEnd = (acc, current, curIndex, array) => { | ||
!acc && (acc = array.slice()); | ||
current.charAt(0) === '!' && acc.push(acc.shift()); | ||
return acc; | ||
}; | ||
|
||
// getters | ||
|
||
export const getAllFieldObjectsByType = type => | ||
Object.entries(fieldsByType).reduce( | ||
(fields, [key, value]) => | ||
key.includes(type) ? fields.concat(value) : fields, | ||
[] | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
getAllFieldObjectsByType, | ||
extractName, | ||
markExcluded, | ||
moveExcludedToEnd, | ||
} from './baseFields'; | ||
import { extendFields } from './nestedFields'; | ||
|
||
export { getAllFieldObjectsByType }; | ||
|
||
export const getOptionsByType = type => | ||
getAllFieldObjectsByType(type).filter(fieldObj => fieldObj.option === true); | ||
|
||
export const getIncludedByType = type => | ||
getAllFieldObjectsByType(type).filter(fieldObj => !fieldObj.excluded); | ||
|
||
export const getExcludedByType = type => | ||
getAllFieldObjectsByType(type).filter( | ||
fieldObj => fieldObj.excluded === true | ||
); | ||
|
||
export const getFieldsStringByType = type => | ||
getAllFieldObjectsByType(type) | ||
.map(markExcluded) | ||
.map(extractName) | ||
.sort() | ||
.reduce(moveExcludedToEnd, null) | ||
.map(extendFields) | ||
.join(','); |
Oops, something went wrong.