DataSources - handle missing items in selectedId and checked gracefully
DataSources receive selectedId and checked fields via DataSourceState. These fields contain item IDs, to be displayed in several scenarios - like "show selection" in Picker. In some cases, items with these IDs wouldn't be found in data sources' data. LazyDataSource would attempt to load such items, but this can fail as well.
This is usually caused by misusing DataSources. E.g. - filtering items outside of Data Sources, making them impossible to access selected items.
There are several options to fix this at UUI-user side:
a) move filtering to the DataSource.
If case of ArrayDataSource one can use the 'filter' prop for this.
In case of LazyDataSource, this problem can be caused by applying filter when API is called with 'ids' prop. Please bypass filtering when datasource asks for items with particular ids.
UX-wise, this "a" option would make selected/checked item(s) visible, even if they doesn't pass the filter.
b) clear selectedId and/or filter checked array at your side, when changing the filter. One can either always clear them, or apply the same filter as for items.
NOTE: you can't implement search this way. Technically this would work, but this would ruin UX.
c) bypass your filter for selectedId/checked array. Result would be the same, as in A.
At UUI-side, we have to detect such cases, and provide meaningful error messages in such cases:
"DataSource can't find selected/checked items with following IDs: 43, 21, 5. This can be caused by implementing filtering at your side. Read more here: https://github.com/epam/UUI/issues/89.
The issue can be reproduced in test, by passing a non-existing IDs via value to the PickerList component. We can add the check into BaseListView::getSelectedRows()