diff --git a/i18n/en.pot b/i18n/en.pot index b1a802fd..6708594d 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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: 2024-01-22T08:44:17.768Z\n" -"PO-Revision-Date: 2024-01-22T08:44:17.768Z\n" +"POT-Creation-Date: 2024-01-23T00:34:26.716Z\n" +"PO-Revision-Date: 2024-01-23T00:34:26.716Z\n" msgid "schemas" msgstr "schemas" @@ -81,6 +81,9 @@ msgstr "Category combo" msgid "None" msgstr "None" +msgid "Filter data elements" +msgstr "Filter data elements" + msgid "Filter legend sets" msgstr "Filter legend sets" @@ -627,14 +630,17 @@ msgstr "Required" msgid "Something went wrong when submitting the form" msgstr "Something went wrong when submitting the form" +msgid "Save and close" +msgstr "Save and close" + msgid "Exit without saving" msgstr "Exit without saving" -msgid "Create data element" -msgstr "Create data element" +msgid "Create data element group" +msgstr "Create data element group" -msgid "Selected legends" -msgstr "Selected legends" +msgid "Selected data elements" +msgstr "Selected data elements" msgid "Refresh list" msgstr "Refresh list" @@ -669,8 +675,8 @@ msgstr "@TODO" msgid "Custom attributes" msgstr "Custom attributes" -msgid "Save and close" -msgstr "Save and close" +msgid "Create data element" +msgstr "Create data element" msgid "Choose how this data element is disaggregated" msgstr "Choose how this data element is disaggregated" @@ -718,6 +724,9 @@ msgstr "StandardForm name" msgid "An alternative name used in section or automatic data entry forms." msgstr "An alternative name used in section or automatic data entry forms." +msgid "Selected legends" +msgstr "Selected legends" + msgid "Option set comment" msgstr "Option set comment" diff --git a/src/components/metadataFormControls/DataElementGroupsTransfer/DataElementGroupsTransfer.tsx b/src/components/metadataFormControls/DataElementGroupsTransfer/DataElementGroupsTransfer.tsx new file mode 100644 index 00000000..7ac44e19 --- /dev/null +++ b/src/components/metadataFormControls/DataElementGroupsTransfer/DataElementGroupsTransfer.tsx @@ -0,0 +1,154 @@ +import i18n from '@dhis2/d2-i18n' +import { Transfer } from '@dhis2/ui' +import React, { + ReactElement, + forwardRef, + useCallback, + useImperativeHandle, + useRef, + useState, +} from 'react' +import { SelectOption } from '../../../types' +import { useInitialOptionQuery } from './useInitialOptionQuery' +import { useOptionsQuery } from './useOptionsQuery' + +function computeDisplayOptions({ + selected, + selectedOptions, + options, +}: { + options: SelectOption[] + selected: string[] + selectedOptions: SelectOption[] +}): SelectOption[] { + // This happens only when we haven't fetched the lable for an initially + // selected value. Don't show anything to prevent error that an option is + // missing + if (!selectedOptions.length && selected.length) { + return [] + } + + const missingSelectedOptions = selectedOptions.filter((selectedOption) => { + return !options?.find((option) => option.value === selectedOption.value) + }) + + return [...options, ...missingSelectedOptions] +} + +interface DataElementGroupsSelectProps { + onChange: ({ selected }: { selected: string[] }) => void + selected: string[] + rightHeader?: ReactElement + rightFooter?: ReactElement + leftFooter?: ReactElement + leftHeader?: ReactElement +} + +export const DataElementGroupsTransfer = forwardRef( + function DataElementGroupsSelect( + { + onChange, + selected, + rightHeader, + rightFooter, + leftFooter, + leftHeader, + }: DataElementGroupsSelectProps, + ref + ) { + // Using a ref because we don't want to react to changes. + // We're using this value only when imperatively calling `refetch`, + // nothing that depends on the render-cycle depends on this value + const [searchTerm, setSearchTerm] = useState('') + const pageRef = useRef(0) + + // We need to persist the selected option so we can display an