Skip to content

Commit 51576aa

Browse files
committed
fix: avoid double fetch of the same page
The all items selected was rendering wrongly triggering a 2nd fetch of the same page of items which was causing duplicated items in the Transfer's source list.
1 parent ff074b3 commit 51576aa

4 files changed

Lines changed: 43 additions & 14 deletions

File tree

i18n/en.pot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ msgstr ""
55
"Content-Type: text/plain; charset=utf-8\n"
66
"Content-Transfer-Encoding: 8bit\n"
77
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
8-
"POT-Creation-Date: 2025-02-24T10:59:13.262Z\n"
9-
"PO-Revision-Date: 2025-02-24T10:59:13.263Z\n"
8+
"POT-Creation-Date: 2025-02-27T14:06:17.569Z\n"
9+
"PO-Revision-Date: 2025-02-27T14:06:17.570Z\n"
1010

1111
msgid "view only"
1212
msgstr "view only"
@@ -336,6 +336,9 @@ msgstr "Search by data item name"
336336
msgid "Selected Items"
337337
msgstr "Selected Items"
338338

339+
msgid "All available items are already selected"
340+
msgstr "All available items are already selected"
341+
339342
msgid "Calculation"
340343
msgstr "Calculation"
341344

@@ -348,9 +351,6 @@ msgstr "All metrics"
348351
msgid "No items selected"
349352
msgstr "No items selected"
350353

351-
msgid "All available items are already selected"
352-
msgstr "All available items are already selected"
353-
354354
msgid "No indicators found"
355355
msgstr "No indicators found"
356356

src/components/DataDimension/ItemOptionsSelector/ItemOptionsSelector.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,31 @@ export const ItemOptionsSelector = ({
168168
<Transfer
169169
onChange={({ selected }) => onChange(selected)}
170170
selected={selectedItems.map((item) => item.value)}
171-
options={[...state.options, ...selectedItems]}
171+
options={[
172+
...state.options,
173+
// remove items already in the options list
174+
...selectedItems.filter(
175+
(selectedItem) =>
176+
!state.options?.find(
177+
(option) => option.value === selectedItem.value
178+
)
179+
),
180+
]}
172181
loading={state.loading}
173182
loadingPicked={state.loading}
174183
sourceEmptyPlaceholder={
175184
<SourceEmptyPlaceholder
176185
loading={state.loading}
177186
searchTerm={debouncedSearchTerm}
178187
options={state.options}
179-
allItemsSelectedMessage={i18n.t(
180-
'All available options are already selected'
181-
)}
188+
allItemsSelectedMessage={
189+
state.options.length === selectedItems.length &&
190+
!state.nextPage
191+
? i18n.t(
192+
'All available options are already selected'
193+
)
194+
: ''
195+
}
182196
noItemsMessage={i18n.t(
183197
'No available options for this item'
184198
)}

src/components/DataDimension/ItemSelector/ItemSelector.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,31 @@ const ItemSelector = ({
350350
<Transfer
351351
onChange={({ selected }) => onChange(selected)}
352352
selected={selectedItems.map((item) => item.value)}
353-
options={[...state.options, ...selectedItems]}
353+
options={[
354+
...state.options,
355+
// remove items already in the options list
356+
...selectedItems.filter(
357+
(selectedItem) =>
358+
!state.options?.find(
359+
(option) => option.value === selectedItem.value
360+
)
361+
),
362+
]}
354363
loading={state.loading}
355364
loadingPicked={state.loading}
356365
sourceEmptyPlaceholder={
357366
<SourceEmptyPlaceholder
358367
loading={state.loading}
359368
searchTerm={debouncedSearchTerm}
360369
options={state.options}
370+
allItemsSelectedMessage={
371+
state.options.length === selectedItems.length &&
372+
!state.nextPage
373+
? i18n.t(
374+
'All available items are already selected'
375+
)
376+
: ''
377+
}
361378
noItemsMessage={noItemsMessage}
362379
dataType={state.filter.dataType}
363380
dataTest={`${dataTest}-empty-source`}

src/components/DataDimension/SourceEmptyPlaceholder.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ export const SourceEmptyPlaceholder = ({
2121
dataTest,
2222
}) => {
2323
let message = ''
24-
if (!loading && options.length && !searchTerm) {
25-
message =
26-
allItemsSelectedMessage ||
27-
i18n.t('All available items are already selected')
24+
if (allItemsSelectedMessage && !loading && options.length && !searchTerm) {
25+
message = allItemsSelectedMessage
2826
} else if (!loading && !options.length && !searchTerm) {
2927
if (noItemsMessage) {
3028
message = noItemsMessage

0 commit comments

Comments
 (0)