Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: creating views for public and partner lists #1271

Merged
merged 7 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 49 additions & 5 deletions backend/core/src/listings/views/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ views.partnerList = {
select: [
"listings.id",
"listings.name",
"listings.applicationDueDate",
"property.id",
...getBaseAddressSelect(["buildingAddress"]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this address and the one on 73?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the partner site's listing grid we do display the address for the listing, so we do want to have that data

"listings.status",
"listings.waitlistMaxSize",
"listings.waitlistCurrentSize",
"property.unitsAvailable",
"listings.isVerified",
],
leftJoins: [
{ join: "listings.property", alias: "property" },
{ join: "property.buildingAddress", alias: "buildingAddress" },
],
leftJoins: [{ join: "listings.property", alias: "property" }],
}

views.detail = {
Expand Down Expand Up @@ -209,4 +211,46 @@ views.full = {
],
}

views.publicListings = {
select: [
"listings.id",
"listings.name",
"listings.marketingType",
"listings.marketingDate",
"listings.marketingSeason",
"listings.isVerified",
"property.id",
...getBaseAddressSelect(["buildingAddress"]),
"listingImages.ordinal",
"listingImagesImage.id",
"listingImagesImage.fileId",
"listingImagesImage.label",
"listingPrograms.ordinal",
"listingsProgramsProgram.id",
"listingsProgramsProgram.title",
"features.id",
"features.elevator",
"features.wheelchairRamp",
"features.serviceAnimalsAllowed",
"features.accessibleParking",
"features.parkingOnSite",
"features.inUnitWasherDryer",
"features.barrierFreeEntrance",
"features.rollInShower",
"features.grabBars",
"features.heatingInUnit",
"features.acInUnit",
"features.laundryInBuilding",
],
leftJoins: [
{ join: "listings.property", alias: "property" },
{ join: "property.buildingAddress", alias: "buildingAddress" },
{ join: "listings.images", alias: "listingImages" },
{ join: "listingImages.image", alias: "listingImagesImage" },
{ join: "listings.listingPrograms", alias: "listingPrograms" },
{ join: "listingPrograms.program", alias: "listingsProgramsProgram" },
{ join: "listings.features", alias: "features" },
],
}

export { views }
1 change: 1 addition & 0 deletions backend/core/src/listings/views/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum ListingViewEnum {
detail = "detail",
full = "full",
partnerList = "partnerList",
publicListings = "publicListings",
}

export type Views = {
Expand Down
17 changes: 17 additions & 0 deletions backend/core/src/listings/views/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export function getView(qb: SelectQueryBuilder<Listing>, view?: string) {
return new BaseListingView(qb)
case views.detail:
return new DetailView(qb)
case views.publicListings:
return new PublicListingsView(qb)
case views.partnerList:
return new PartnerListView(qb)
case views.full:
default:
return new FullView(qb)
Expand Down Expand Up @@ -51,6 +55,19 @@ export class DetailView extends BaseListingView {
}
}

export class PublicListingsView extends BaseListingView {
constructor(qb: SelectQueryBuilder<Listing>) {
super(qb)
this.view = views.publicListings
}
}
export class PartnerListView extends BaseListingView {
constructor(qb: SelectQueryBuilder<Listing>) {
super(qb)
this.view = views.partnerList
}
}

export class FullView extends BaseListingView {
constructor(qb: SelectQueryBuilder<Listing>) {
super(qb)
Expand Down
4 changes: 3 additions & 1 deletion sites/partners/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type UseUserListProps = PaginationProps

type UseListingsDataProps = PaginationProps & {
listingIds?: string[]
view?: string
}

export function useSingleListingData(listingId: string) {
Expand All @@ -50,11 +51,12 @@ export function useListingsData({
listingIds,
orderBy,
orderDir,
view = "base",
}: UseListingsDataProps) {
const params = {
page,
limit,
view: "base",
view,
orderBy,
orderDir: OrderDirEnum.ASC,
}
Expand Down
1 change: 1 addition & 0 deletions sites/partners/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export default function ListingsList() {
: undefined,
orderBy: sortOptions.orderBy,
orderDir: sortOptions.orderDir,
view: "partnerList",
})

const gridOptions: GridOptions = {
Expand Down
10 changes: 2 additions & 8 deletions sites/public/lib/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
ImageTag,
Tooltip,
} from "@bloom-housing/ui-components"
import { imageUrlFromListing, listingFeatures } from "@bloom-housing/shared-helpers"
import { imageUrlFromListing } from "@bloom-housing/shared-helpers"

export const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

Expand Down Expand Up @@ -55,13 +55,7 @@ const getListingCardSubtitle = (address: Address) => {

export const accessibilityFeaturesExist = (features: ListingFeatures) => {
if (!features) return false
let featuresExist = false
Object.keys(listingFeatures).map((feature) => {
if (features[feature]) {
featuresExist = true
}
})
return featuresExist
return Object.keys(features).some((feature) => features[feature])
}

export const getImageTagLabelFromListing = (listing: Listing) => {
Expand Down
15 changes: 8 additions & 7 deletions sites/public/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const useFormConductor = (stepName: string) => {
return context
}

const listingsFetcher = function () {
const listingsFetcher = function (view: string) {
return async (
url: string,
page: number,
Expand All @@ -60,11 +60,11 @@ const listingsFetcher = function () {
) => {
const res = await axios.get(url, {
params: {
view: "base",
page: page,
limit: limit,
view,
page,
limit,
filter: encodeToBackendFilterArray(filters),
orderBy: orderBy,
orderBy,
},
paramsSerializer: (params) => {
return qs.stringify(params)
Expand All @@ -79,11 +79,12 @@ export function useListingsData(
pageIndex: number,
limit = 10,
filters: ListingFilterState,
orderBy: OrderByFieldsEnum
orderBy: OrderByFieldsEnum,
view = "base"
) {
const { data, error } = useSWR(
[`${process.env.listingServiceUrl}`, pageIndex, limit, filters, orderBy],
listingsFetcher()
listingsFetcher(view)
)

return {
Expand Down
3 changes: 2 additions & 1 deletion sites/public/pages/account/favorites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const FavoritedListingsPage = () => {
currentPage,
itemsPerPage,
filterState,
OrderByFieldsEnum.mostRecentlyUpdated
OrderByFieldsEnum.comingSoon,
"publicListings"
)

const content = useMemo(() => {
Expand Down
3 changes: 2 additions & 1 deletion sites/public/pages/listings/filtered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const FilteredListingsPage = () => {
currentPage,
itemsPerPage,
filterState,
OrderByFieldsEnum.comingSoon
OrderByFieldsEnum.comingSoon,
"publicListings"
)

let numberOfFilters = 0
Expand Down