Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cypress/support/form/helpers/nameToDataTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ export const nameToDataTest = (name) => {
case 'idScheme':
return 'input-id-scheme'

case 'categoryIdScheme':
return 'input-category-id-scheme'

case 'categoryOptionIdScheme':
return 'input-category-option-id-scheme'

case 'categoryOptionComboIdScheme':
return 'input-category-option-combo-id-scheme'

case 'dataSetIdScheme':
return 'input-data-set-id-scheme'

case 'attributeOptionComboIdScheme':
return 'input-attribute-option-combo-id-scheme'

case 'program':
return 'input-program-picker'

Expand Down
49 changes: 30 additions & 19 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2026-09-02T14:17:13.038Z\n"
"PO-Revision-Date: 2026-09-02T14:17:13.038Z\n"
"POT-Creation-Date: 2026-09-17T11:35:01.753Z\n"
"PO-Revision-Date: 2026-09-17T11:35:01.754Z\n"

msgid "Something went wrong when loading the current user!"
msgstr "Something went wrong when loading the current user!"
Expand All @@ -29,18 +29,23 @@ msgstr "Invalid duration"
msgid "Format"
msgstr "Format"

msgid "Something went wrong when loading the additional data element ID schemes"
msgstr "Something went wrong when loading the additional data element ID schemes"
msgid "Uid"
msgstr "Uid"

msgid "Code"
msgstr "Code"

msgid "Name"
msgstr "Name"

msgid "Something went wrong when loading the additional ID schemes"
msgstr "Something went wrong when loading the additional ID schemes"

msgid ""
"Something went wrong when loading the additional organisation unit ID "
"schemes"
msgstr ""
"Something went wrong when loading the additional organisation unit ID "
"schemes"
msgid "(Default)"
msgstr "(Default)"

msgid "(Undefined)"
msgstr "(Undefined)"

msgid "Please select a file"
msgstr "Please select a file"
Expand Down Expand Up @@ -139,15 +144,6 @@ msgstr "Uncompressed"
msgid "Compression mode"
msgstr "Compression mode"

msgid "Uid"
msgstr "Uid"

msgid "Code"
msgstr "Code"

msgid "Name"
msgstr "Name"

msgid "Data element ID scheme"
msgstr "Data element ID scheme"

Expand Down Expand Up @@ -819,6 +815,21 @@ msgstr ""
msgid "Date range to export data for"
msgstr "Date range to export data for"

msgid "Category ID scheme"
msgstr "Category ID scheme"

msgid "Category option ID scheme"
msgstr "Category option ID scheme"

msgid "Category option combo ID scheme"
msgstr "Category option combo ID scheme"

msgid "Data set ID scheme"
msgstr "Data set ID scheme"

msgid "Attribute option combo ID scheme"
msgstr "Attribute option combo ID scheme"

msgid "Export data"
msgstr "Export data"

Expand Down
56 changes: 0 additions & 56 deletions src/components/ElementSchemes/DataElementIdScheme.jsx

This file was deleted.

Empty file.
82 changes: 0 additions & 82 deletions src/components/ElementSchemes/IdScheme.jsx

This file was deleted.

116 changes: 116 additions & 0 deletions src/components/ElementSchemes/IdSchemeSelect.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { useConfig } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { SingleSelectFieldFF } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import { fetchAttributes } from '../../utils/helper.js'
import { StyledField } from '../index.js'

const ID_SCHEME_OPTIONS = (emptyOptionLabel) => [
{ value: '', label: emptyOptionLabel },
{ value: 'UID', label: i18n.t('Uid') },
{ value: 'CODE', label: i18n.t('Code') },
{ value: 'NAME', label: i18n.t('Name') },
]

const NO_ATTRIBUTE_TYPES = []

const intersectByValue = (a, b) =>
a.filter((item) => b.some((other) => other.value === item.value))

const IdSchemeSelect = ({
name,
label,
dataTest,
attributeTypes = NO_ATTRIBUTE_TYPES,
isFallback = false,
}) => {
const { baseUrl } = useConfig()
const [loading, setLoading] = useState(attributeTypes.length > 0)
const [attributeOptions, setAttributeOptions] = useState([])
const [error, setError] = useState(undefined)

useEffect(() => {
if (attributeTypes.length === 0) {
return undefined
}

let cancelled = false

const loadAttributeSchemes = async () => {
let err

const schemesByType = await Promise.all(
attributeTypes.map((type) =>
fetchAttributes(`${baseUrl}/api/`, type).catch((e) => {
err = e
return []
})
)
)

if (cancelled) {
return
}

setError(err)
if (!err) {
const [first, ...rest] = schemesByType
setAttributeOptions(
rest.reduce(
(shared, schemes) => intersectByValue(shared, schemes),
first
)
)
}
setLoading(false)
}

loadAttributeSchemes()

return () => {
cancelled = true
}
}, [baseUrl, attributeTypes])

const validationText =
error &&
`${i18n.t(
'Something went wrong when loading the additional ID schemes'
)} : ${error.message}`

// The fallback (common) ID scheme dropdown omits its parameter to defer
// to the server's own default, so "(Default)" fits there. The other,
// per-object-type dropdowns omit theirs to defer to the fallback
// dropdown instead - labeling that choice "(Default)" too would imply
// it means the same thing in both places, so it's called "(Undefined)".
const emptyOptionLabel = isFallback
? i18n.t('(Default)')
: i18n.t('(Undefined)')

return (
<StyledField
component={SingleSelectFieldFF}
name={name}
label={label}
options={[
...ID_SCHEME_OPTIONS(emptyOptionLabel),
...attributeOptions,
]}
dataTest={dataTest}
loading={loading}
validationText={validationText}
error={!!error}
/>
)
}

IdSchemeSelect.propTypes = {
dataTest: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
attributeTypes: PropTypes.arrayOf(PropTypes.string),
isFallback: PropTypes.bool,
}

export { IdSchemeSelect }
Loading
Loading