Skip to content

Commit

Permalink
Add filtering for rent price (#531)
Browse files Browse the repository at this point in the history
* add rent price filtering

* update changelog and comments

* Fix code style issues with Prettier

* address comments

* address comments

Co-authored-by: Lint Action <lint-action@samuelmeuli.com>
  • Loading branch information
abbiefarr and lint-action authored Sep 3, 2021
1 parent 9c6ae4f commit 942b977
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. The format
- Number of filters in filter button
([#489](https://github.com/CityOfDetroit/bloom/pull/489))
- Filtering by availability ([#501](https://github.com/CityOfDetroit/bloom/pull/501))
- Filtering by rent price ([#531](https://github.com/CityOfDetroit/bloom/pull/531))

## Detroit Team M10

Expand Down
27 changes: 26 additions & 1 deletion backend/core/src/listings/dto/listing.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ export class ListingFilterParams extends BaseFilter {
example: "48211",
required: false,
})
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
[ListingFilterKeys.zipcode]?: string;

@Expose()
Expand All @@ -799,6 +800,7 @@ export class ListingFilterParams extends BaseFilter {
example: "hasAvailability",
required: false,
})
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
[ListingFilterKeys.availability]?: AvailabilityFilterEnum;

@Expose()
Expand All @@ -807,7 +809,28 @@ export class ListingFilterParams extends BaseFilter {
example: "true",
required: false,
})
[ListingFilterKeys.seniorHousing]?: boolean
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
[ListingFilterKeys.seniorHousing]?: boolean;

@Expose()
@ApiProperty({
type: Number,
example: "300",
required: false,
})
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
@IsNumberString({}, { groups: [ValidationsGroupsEnum.default] })
[ListingFilterKeys.minRent]?: number;

@Expose()
@ApiProperty({
type: Number,
example: "700",
required: false,
})
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
@IsNumberString({}, { groups: [ValidationsGroupsEnum.default] })
[ListingFilterKeys.maxRent]?: number
}

export class ListingsQueryParams extends PaginationAllowsAllQueryParams {
Expand Down Expand Up @@ -867,4 +890,6 @@ export const filterTypeToFieldMap: Record<keyof typeof ListingFilterKeys, string
// Fields for the availability are determined based on the value of the filter, not the
// key. Keep this bogus value to prevent the filter from being rejected.
availability: "",
minRent: "unitsSummary.monthly_rent_max",
maxRent: "unitsSummary.monthly_rent_min",
}
2 changes: 2 additions & 0 deletions backend/core/src/listings/types/listing-filter-keys-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export enum ListingFilterKeys {
zipcode = "zipcode",
availability = "availability",
seniorHousing = "seniorHousing",
minRent = "minRent",
maxRent = "maxRent",
}

export enum AvailabilityFilterEnum {
Expand Down
1 change: 1 addition & 0 deletions backend/core/src/shared/dto/filter.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum Compare {
"<>" = "<>",
"IN" = "IN",
">=" = ">=",
"<=" = "<=",
"NA" = "NA", // For filters that don't use the comparison param
}
export class BaseFilter {
Expand Down
1 change: 1 addition & 0 deletions backend/core/src/shared/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export function addFilters<FilterParams, FilterFieldMap>(
)
break
case Compare[">="]:
case Compare["<="]:
qb.andWhere(`${filterField} ${comparison} :${whereParameterName}`, {
[whereParameterName]: filterValue,
})
Expand Down
7 changes: 7 additions & 0 deletions backend/core/types/src/backend-swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3720,6 +3720,12 @@ export interface ListingFilterParams {

/** */
seniorHousing?: boolean

/** */
minRent?: number

/** */
maxRent?: number
}

export interface UnitType {
Expand Down Expand Up @@ -5722,6 +5728,7 @@ export enum EnumListingFilterParamsComparison {
"<>" = "<>",
"IN" = "IN",
">=" = ">=",
"<=" = "<=",
"NA" = "NA",
}
export enum EnumListingFilterParamsStatus {
Expand Down
34 changes: 31 additions & 3 deletions sites/public/pages/listings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,15 @@ const ListingsPage = () => {
filterState
)

const numberOfFilters = filterState
? Object.keys(filterState).filter((p) => p !== "$comparison").length
: 0
let numberOfFilters = 0
if (filterState) {
numberOfFilters = Object.keys(filterState).filter((p) => p !== "$comparison").length
// We want to consider rent as a single filter, so if both min and max are defined, reduce the count.
if (filterState.minRent !== undefined && filterState.maxRent != undefined) {
numberOfFilters -= 1
}
}

const buttonTitle = numberOfFilters
? t("listingFilters.buttonTitleWithNumber", { number: numberOfFilters })
: t("listingFilters.buttonTitle")
Expand Down Expand Up @@ -175,6 +181,28 @@ const ListingsPage = () => {
errorMessage={t("errors.multipleZipCodeError")}
defaultValue={filterState?.zipcode}
/>
<label className="field-label">Rent Range</label>
<div className="flex flex-row">
<Field
id="minRent"
name={ListingFilterKeys.minRent}
register={register}
type="number"
placeholder={t("t.min")}
prepend="$"
defaultValue={filterState?.minRent}
/>
<div className="flex items-center p-3">{t("t.to")}</div>
<Field
id="maxRent"
name={ListingFilterKeys.maxRent}
register={register}
type="number"
placeholder={t("t.max")}
prepend="$"
defaultValue={filterState?.maxRent}
/>
</div>
<Select
id="neighborhoodOptions"
name={ListingFilterKeys.neighborhood}
Expand Down
3 changes: 3 additions & 0 deletions ui-components/src/helpers/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ function getComparisonForFilter(filterKey: ListingFilterKeys) {
case ListingFilterKeys.status:
return EnumListingFilterParamsComparison["="]
case ListingFilterKeys.bedrooms:
case ListingFilterKeys.minRent:
return EnumListingFilterParamsComparison[">="]
case ListingFilterKeys.maxRent:
return EnumListingFilterParamsComparison["<="]
case ListingFilterKeys.zipcode:
return EnumListingFilterParamsComparison["IN"]
case ListingFilterKeys.seniorHousing:
Expand Down
2 changes: 2 additions & 0 deletions ui-components/src/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,9 @@
"link": "وصلة",
"listing": "القوائم",
"loginIsRequired": "مطلوب تسجيل الدخول لمشاهدة هذه الصفحة.",
"max": "أقصى",
"menu": "قائمة الطعام",
"min": "الحد الأدنى",
"minimumIncome": "الحد الأدنى للدخل",
"minutes": "دقائق",
"month": "شهر",
Expand Down
2 changes: 2 additions & 0 deletions ui-components/src/locales/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,9 @@
"link": "লিঙ্ক",
"listing": "তালিকা",
"loginIsRequired": "এই পৃষ্ঠাটি দেখতে লগইন প্রয়োজন।",
"max": "সর্বোচ্চ",
"menu": "তালিকা",
"min": "ন্যূনতম",
"minimumIncome": "ন্যূনতম আয়",
"minutes": "মিনিট",
"month": "মাস",
Expand Down
2 changes: 2 additions & 0 deletions ui-components/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,9 @@
"link": "Enlace",
"listing": "Listados",
"loginIsRequired": "Es necesario iniciar sesión para ver esta página.",
"max": "Máxima",
"menu": "Menú",
"min": "Mínima",
"minimumIncome": "Renta mínima",
"minutes": "minutos",
"month": "Mes",
Expand Down
2 changes: 2 additions & 0 deletions ui-components/src/locales/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,9 @@
"link": "Link",
"listing": "Listings",
"loginIsRequired": "Login is required to view this page.",
"max": "Max",
"menu": "Menu",
"min": "Min",
"minimumIncome": "Minimum Income",
"minutes": "minutes",
"month": "Month",
Expand Down
2 changes: 2 additions & 0 deletions ui-components/src/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,9 @@
"letter": "Chữ cái",
"less": "Ít hơn",
"loginIsRequired": "Yêu cầu đăng nhập để xem trang này.",
"max": "Tối đa",
"menu": "Trình đơn",
"min": "Tối thiểu",
"minimumIncome": "Thu nhập Tối thiểu",
"month": "Tháng",
"more": "Nhiều hơn",
Expand Down
2 changes: 2 additions & 0 deletions ui-components/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,9 @@
"letter": "信件",
"less": "以下",
"loginIsRequired": "必須登入才能瀏覽本頁。",
"max": "最大值",
"menu": "功能表",
"min": "最低限度",
"minimumIncome": "收入下限",
"month": "",
"more": "其他資訊",
Expand Down

0 comments on commit 942b977

Please sign in to comment.