Merged in feat/SW-1232-filter-improvements-select-hot (pull request #2168)
feat: SW-1232 Implemented disabling of filters and show hotel count * feat: SW-1232 Implemented disabling of filters and show hotel count * feat: SW-1232 Optimised code Approved-by: Niclas Edenvin
This commit is contained in:
@@ -9,13 +9,16 @@ import type {
|
||||
AlternativeHotelsAvailabilityInput,
|
||||
AvailabilityInput,
|
||||
} from "@/types/components/hotelReservation/selectHotel/availabilityInput"
|
||||
import type { CategorizedFilters } from "@/types/components/hotelReservation/selectHotel/hotelFilters"
|
||||
import type {
|
||||
CategorizedFilters,
|
||||
HotelFilter,
|
||||
} from "@/types/components/hotelReservation/selectHotel/hotelFilters"
|
||||
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||
import type {
|
||||
AlternativeHotelsSearchParams,
|
||||
SelectHotelSearchParams,
|
||||
} from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
||||
import type { AdditionalData, DetailedFacility, Hotel } from "@/types/hotel"
|
||||
import type { AdditionalData, Hotel } from "@/types/hotel"
|
||||
import type { HotelsAvailabilityItem } from "@/types/trpc/routers/hotel/availability"
|
||||
import type {
|
||||
HotelLocation,
|
||||
@@ -253,12 +256,31 @@ export function getFiltersFromHotels(
|
||||
return defaultFilters
|
||||
}
|
||||
|
||||
const filters = hotels.flatMap(({ hotel }) => hotel.detailedFacilities)
|
||||
const filters = hotels.flatMap(({ hotel }) =>
|
||||
hotel.detailedFacilities.map(
|
||||
(facility) =>
|
||||
<HotelFilter>{
|
||||
...facility,
|
||||
hotelId: hotel.operaId,
|
||||
hotelIds: [hotel.operaId],
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
const uniqueFilterIds = [...new Set(filters.map((filter) => filter.id))]
|
||||
const filterList: DetailedFacility[] = uniqueFilterIds
|
||||
.map((filterId) => filters.find((filter) => filter.id === filterId))
|
||||
.filter((filter): filter is DetailedFacility => filter !== undefined)
|
||||
const filterList: HotelFilter[] = uniqueFilterIds
|
||||
.map((filterId) => {
|
||||
const filter = filters.find((f) => f.id === filterId)
|
||||
|
||||
// List and include all hotel Ids having same filter / amenity
|
||||
if (filter) {
|
||||
filter.hotelIds = filters
|
||||
.filter((f) => f.id === filterId)
|
||||
.map((f) => f.hotelId)
|
||||
}
|
||||
return filter
|
||||
})
|
||||
.filter((filter): filter is HotelFilter => filter !== undefined)
|
||||
.sort((a, b) => b.sortOrder - a.sortOrder)
|
||||
|
||||
return filterList.reduce<CategorizedFilters>((filters, filter) => {
|
||||
|
||||
Reference in New Issue
Block a user