Skip to content

Commit

Permalink
sort editor: keep only first variable in composite attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
SteRiccio committed Nov 29, 2024
1 parent b5ca884 commit 6c56fe9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PropTypes from 'prop-types'

import { Button } from '@webapp/components/buttons'
import PanelRight from '@webapp/components/PanelRight'
import { useI18n } from '@webapp/store/system'
import { Sort, SortCriteria } from '@common/model/query'

import { useSortEditor } from './store'
Expand All @@ -13,11 +12,10 @@ import SortCriteriaEditor from './SortCriteriaEditor'
const SortEditor = (props) => {
const { onChange, onClose, query } = props

const i18n = useI18n()
const { draft, sort, sortDraft, setSortDraft, variables, variablesAvailable } = useSortEditor({ query })

return (
<PanelRight onClose={onClose} header={i18n.t('common.orderBy')}>
<PanelRight onClose={onClose} header="common.orderBy">
<div className="sort-editor">
{sortDraft.map((sortCriteria, idx) => (
<SortCriteriaEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useState } from 'react'
import { Objects } from '@openforis/arena-core'

import { Query, Sort } from '@common/model/query'
import * as ObjectUtils from '@core/objectUtils'
import * as Expression from '@core/expressionParser/expression'

import * as ExpressionVariables from '@webapp/components/expression/expressionVariables'
Expand All @@ -21,7 +20,15 @@ const getVariables = ({ survey, cycle, entityDef, attributeDefUuids, lang }) =>
})
if (Objects.isEmpty(attributeDefUuids)) return variables

const variablesByUuid = ObjectUtils.toUuidIndexedObj(variables)
const variablesByUuid = variables.reduce((acc, variable) => {
const { uuid } = variable
if (!acc[uuid]) {
// keep only first variable
// variables for composite attributes have same UUID for different properties (e.g. taxon)
acc[uuid] = variable
}
return acc
}, {})
return attributeDefUuids.map((uuid) => variablesByUuid[uuid]).filter(Boolean)
}

Expand Down

0 comments on commit 6c56fe9

Please sign in to comment.