Skip to content

Commit

Permalink
(PC-34129) fix(venue): avoid empty artist object,
Browse files Browse the repository at this point in the history
takes into account the display conditions of an artist page and add artist with only has an offer in the venue
  • Loading branch information
clesausse-pass committed Jan 21, 2025
1 parent a24e643 commit ad816b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('useVenueOffersArtists', () => {
isDuo: false,
name: 'I want something more',
prices: [28.0],
subcategoryId: SubcategoryIdEnum.CONCERT,
subcategoryId: SubcategoryIdEnum.SUPPORT_PHYSIQUE_MUSIQUE_VINYLE,
thumbUrl:
'https://storage.googleapis.com/passculture-metier-prod-production-assets-fine-grained/thumbs/mediations/CDZQ',
artist: 'Céline Dion',
Expand All @@ -71,7 +71,7 @@ describe('useVenueOffersArtists', () => {
isDuo: false,
name: 'I want something more',
prices: [28.0],
subcategoryId: SubcategoryIdEnum.CONCERT,
subcategoryId: SubcategoryIdEnum.SUPPORT_PHYSIQUE_MUSIQUE_VINYLE,
thumbUrl:
'https://storage.googleapis.com/passculture-metier-prod-production-assets-fine-grained/thumbs/mediations/CDZQ',
artist: 'Céline Dion',
Expand Down Expand Up @@ -117,6 +117,7 @@ describe('useVenueOffersArtists', () => {
artist: `Artist ${index % 35}`,
thumbUrl:
'https://storage.googleapis.com/passculture-metier-prod-production-assets-fine-grained/thumbs/mediations/CDZQ',
subcategoryId: SubcategoryIdEnum.SUPPORT_PHYSIQUE_MUSIQUE_VINYLE,
},
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import _ from 'lodash'
import { UseQueryResult } from 'react-query'

import { VenueResponse } from 'api/gen'
import { COMMA_OR_SEMICOLON_REGEX, EXCLUDED_ARTISTS } from 'features/offer/helpers/constants'
import { useVenueOffers } from 'features/venue/api/useVenueOffers'
import { isArtistPageCompatible } from 'features/venue/helpers/isArtistPageCompatible/isArtistPageCompatible'
import { Artist, VenueOffersArtists } from 'features/venue/types'

export const useVenueOffersArtists = (
Expand All @@ -16,29 +16,28 @@ export const useVenueOffersArtists = (
}

const artists: Artist[] = _.chain(
venueOffers.hits.map((offer) =>
offer.offer.artist
? {
id: Number(offer.objectID),
name: offer.offer.artist,
image: offer.offer.thumbUrl,
}
: <Artist>{}
// `flatMap` is used to map over `venueOffers.hits`, transforming each offer into an artist object if the artist exists,
// and flattening the results into a single array. If no artist is found, it returns an empty array, effectively filtering out
// offers without an artist in a single step.
venueOffers.hits.flatMap((offer) =>
offer.offer.artist && isArtistPageCompatible(offer.offer.artist, offer.offer.subcategoryId)
? [
{
id: Number(offer.objectID),
name: offer.offer.artist,
image: offer.offer.thumbUrl,
},
]
: []
)
)
.groupBy('name')
.pickBy((artistList) => artistList.length > 1)
.orderBy(
[(artistList) => artistList.length, (artistList) => artistList[0]?.name],
['desc', 'asc']
)
.flatten()
.uniqBy('name')
.filter(
(artist) =>
!COMMA_OR_SEMICOLON_REGEX.test(artist.name) &&
!EXCLUDED_ARTISTS.includes(artist.name?.toLowerCase())
)
.slice(0, 30)
.value()

Expand Down

0 comments on commit ad816b0

Please sign in to comment.