Skip to content

Commit

Permalink
fix: sort analytics params and items
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenrikoverland committed Aug 7, 2024
1 parent c3acdff commit 8fe2bf6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
},
"scripts": {
"build": "d2-app-scripts build",
"postbuild": "yarn build-storybook",
"build-storybook": "build-storybook",
"start-storybook": "start-storybook --port 5000",
"start": "yarn start-storybook",
Expand Down
26 changes: 15 additions & 11 deletions src/api/analytics/AnalyticsBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ const analyticsDataQuery = {
}),
params: ({ dimensions, filters, parameters }) => {
return {
dimension: dimensions.length ? dimensions : undefined,
filter: filters.length ? filters : undefined,
dimension: dimensions.length
? generateDimensionStrings(dimensions, { sorted: true })
: undefined,
filter: filters.length
? generateDimensionStrings(filters, { sorted: true })
: undefined,
...parameters,
skipMeta: true,
skipData: false,
Expand All @@ -45,8 +49,10 @@ const analyticsMetaDataQuery = {
trackedEntityType,
}),
params: ({ dimensions, filters, parameters }) => ({
dimension: dimensions.length ? dimensions : undefined,
filter: filters.length ? filters : undefined,
dimension: dimensions.length
? generateDimensionStrings(dimensions)
: undefined,
filter: filters.length ? generateDimensionStrings(filters) : undefined,
...parameters,
skipMeta: false,
skipData: true,
Expand All @@ -55,11 +61,9 @@ const analyticsMetaDataQuery = {
}

export const generateDimensionStrings = (dimensions = [], options) => {
if (options && options.sorted) {
dimensions = sortBy(dimensions, 'dimension')
}

return dimensions.map(({ dimension, items }) => {
const sortedDimensions = sortBy(dimensions, 'dimension')
console.log('arrays the same?', sortedDimensions === dimensions)
return sortedDimensions.map(({ dimension, items }) => {
if (Array.isArray(items) && items.length) {
if (options && options.sorted) {
items.sort()
Expand Down Expand Up @@ -131,8 +135,8 @@ class AnalyticsBase {
path: req.path,
program: req.program,
trackedEntityType: req.trackedEntityType,
dimensions: generateDimensionStrings(req.dimensions),
filters: generateDimensionStrings(req.filters),
dimensions: req.dimensions,
filters: req.filters,
parameters: req.parameters,
dataParams: dataReq.parameters,
metaDataParams: metaDataReq.parameters,
Expand Down

0 comments on commit 8fe2bf6

Please sign in to comment.