Skip to content

Commit

Permalink
SelectCollection: add comments to collectionLabel(), explaining Gromm…
Browse files Browse the repository at this point in the history
…et changes
  • Loading branch information
shaunanoordin committed Feb 11, 2025
1 parent dc0be0e commit f41f10a
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ function SelectCollection ({
return displayNameLowerCase.includes(searchText.toLowerCase())
}

/*
Determines the display label for the specific collection.
Returns "Example Collection" if that collection belongs to the current user,
otherwise returns "Example Collection (Another User's Name)"
NOTE: sometime between Grommet > 2.41.0 and <= 2.45.1, the behaviour of
<Select> changed. Now, when <Select> initially renders and _nothing_ is
selected, labelKey is called with an empty object {} argument. Prior to this
change, collectionLabel() was only called when there's a valid collection
object to render. (e.g. when clicking on Select to display list of options.)
As a result, collectionLabel() now handles "no selection" (collection === {})
without crashing, returning a meaningless "undefined (undefined)". The
<Select> still shows blank ("") when there's no selection, though. Go figure.
*/
function collectionLabel(collection) {
if (collection?.links?.owner?.id === userID) {
return collection?.display_name
Expand Down

0 comments on commit f41f10a

Please sign in to comment.