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

fix: region and variable naming update #1304

Merged
merged 11 commits into from
Jun 7, 2022
8 changes: 4 additions & 4 deletions backend/core/src/listings/tests/listings.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ describe("ListingsService", () => {
mockListingsRepo.createQueryBuilder
.mockReturnValueOnce(mockInnerQueryBuilder)
.mockReturnValueOnce(mockQueryBuilder)
const expectedRegionString = "Downtown,Eastside," // intentional extra and trailing commas for test
const expectedRegionString = "Greater Downtown,Eastside," // intentional extra and trailing commas for test
// lowercased, trimmed spaces, filtered empty
const expectedRegionArray = ["Downtown", "Eastside"]
const expectedRegionArray = ["Greater Downtown", "Eastside"]

const queryParams: ListingsQueryParams = {
filter: [
Expand All @@ -280,9 +280,9 @@ describe("ListingsService", () => {
mockListingsRepo.createQueryBuilder
.mockReturnValueOnce(mockInnerQueryBuilder)
.mockReturnValueOnce(mockQueryBuilder)
const neighborhoodString = "Downtown,Eastside," // intentional extra and trailing commas for test
const neighborhoodString = "Greater Downtown,Eastside," // intentional extra and trailing commas for test
// lowercased, trimmed spaces, filtered empty
const expectedNeighborhoodArray = ["Downtown", "Eastside"]
const expectedNeighborhoodArray = ["Greater Downtown", "Eastside"]

const queryParams: ListingsQueryParams = {
filter: [
Expand Down
58 changes: 29 additions & 29 deletions backend/core/src/migration/1649062179928-add-property-region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Region } from "../property/types/region-enum"

export interface Neighborhood {
name: string
region: Region
region: string
}

export class addPropertyRegion1649062179928 implements MigrationInterface {
Expand All @@ -12,34 +12,34 @@ export class addPropertyRegion1649062179928 implements MigrationInterface {
// NOTE: imported from https://github.com/CityOfDetroit/bloom/blob/main/ui-components/src/helpers/regionNeighborhoodMap.ts
// Issue comment: https://github.com/CityOfDetroit/bloom/issues/1015#issuecomment-1068056607
neighborhoods: Neighborhood[] = [
{ name: "Airport Sub area", region: Region.Eastside },
{ name: "Barton McFarland area", region: Region.Westside },
{ name: "Boston-Edison/North End area", region: Region.Westside },
{ name: "Boynton", region: Region.Southwest },
{ name: "Campau/Banglatown", region: Region.Eastside },
{ name: "Dexter Linwood", region: Region.Westside },
{ name: "Farwell area", region: Region.Eastside },
{ name: "Gratiot Town/Kettering area", region: Region.Eastside },
{ name: "Gratiot/7 Mile area", region: Region.Eastside },
{ name: "Greater Corktown area", region: Region.Downtown },
Copy link
Collaborator

@emilyjablonski emilyjablonski Jun 6, 2022

Choose a reason for hiding this comment

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

Making an update to an existing migration is a flow we can't use. It will work locally on a db:reseed because this runs every single migration from the first, but once this gets to dev/production where we have an existing db, all the migration files are not run, just any new ones. You can test this locally by reseeding on dev, and then on this branch just running yarn db:migration:run to test what would happen in our environments. I'd suggest keeping the update to the region-enum and then running yarn db:migration:generate -n 'region-rename' and the backend will auto-generate a new migration file for you based on whatever changes were made. Sometimes doing this results in some extra db queries we don't always need, so some things may need to be removed other than altering the enum.

{ name: "Greater Downtown area", region: Region.Downtown },
{ name: "Greater Downtown area", region: Region.Downtown },
{ name: "Islandview/Greater Villages area", region: Region.Eastside },
{ name: "Islandview/Greater Villages area", region: Region.Eastside },
{ name: "Islandview/Greater Villages area", region: Region.Westside },
{ name: "Jefferson Chalmers area", region: Region.Eastside },
{ name: "Livernois/McNichols area", region: Region.Westside },
{ name: "Livernois/McNichols area", region: Region.Westside },
{ name: "Morningside area", region: Region.Eastside },
{ name: "North Campau area", region: Region.Eastside },
{ name: "Northwest Grand River area", region: Region.Westside },
{ name: "Northwest University District area", region: Region.Westside },
{ name: "Palmer Park area", region: Region.Westside },
{ name: "Russell Woods/Nardin Park area", region: Region.Westside },
{ name: "Southwest/Vernor area", region: Region.Southwest },
{ name: "Southwest/Vernor area", region: Region.Southwest },
{ name: "Warrendale/Cody Rouge", region: Region.Westside },
{ name: "West End area", region: Region.Eastside },
{ name: "Airport Sub area", region: "Eastside" },
{ name: "Barton McFarland area", region: "Westside" },
{ name: "Boston-Edison/North End area", region: "Westside" },
{ name: "Boynton", region: "Southwest" },
{ name: "Campau/Banglatown", region: "Eastside" },
{ name: "Dexter Linwood", region: "Westside" },
{ name: "Farwell area", region: "Eastside" },
{ name: "Gratiot Town/Kettering area", region: "Eastside" },
{ name: "Gratiot/7 Mile area", region: "Eastside" },
{ name: "Greater Corktown area", region: "Downtown" },
{ name: "Greater Downtown area", region: "Downtown" },
{ name: "Greater Downtown area", region: "Downtown" },
{ name: "Islandview/Greater Villages area", region: "Eastside" },
{ name: "Islandview/Greater Villages area", region: "Eastside" },
{ name: "Islandview/Greater Villages area", region: "Westside" },
{ name: "Jefferson Chalmers area", region: "Eastside" },
{ name: "Livernois/McNichols area", region: "Westside" },
{ name: "Livernois/McNichols area", region: "Westside" },
{ name: "Morningside area", region: "Eastside" },
{ name: "North Campau area", region: "Eastside" },
{ name: "Northwest Grand River area", region: "Westside" },
{ name: "Northwest University District area", region: "Westside" },
{ name: "Palmer Park area", region: "Westside" },
{ name: "Russell Woods/Nardin Park area", region: "Westside" },
{ name: "Southwest/Vernor area", region: "Southwest" },
{ name: "Southwest/Vernor area", region: "Southwest" },
{ name: "Warrendale/Cody Rouge", region: "Westside" },
{ name: "West End area", region: "Eastside" },
]

public async up(queryRunner: QueryRunner): Promise<void> {
Expand Down
37 changes: 37 additions & 0 deletions backend/core/src/migration/1654549186207-region-rename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class regionRename1654549186207 implements MigrationInterface {
name = "regionRename1654549186207"

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`BEGIN TRANSACTION`)
await queryRunner.query(`ALTER TYPE "property_region_enum" ADD VALUE 'Greater Downtown'`)
await queryRunner.query(`COMMIT TRANSACTION`)
await queryRunner.query(
`UPDATE "property" SET "region" = 'Greater Downtown' WHERE "region" = 'Downtown'`
)
await queryRunner.query(
`ALTER TYPE "property_region_enum" RENAME TO "property_region_enum_old"`
)
await queryRunner.query(
`CREATE TYPE "property_region_enum" AS ENUM('Greater Downtown', 'Eastside', 'Southwest', 'Westside')`
)
await queryRunner.query(
`ALTER TABLE "property" ALTER COLUMN "region" TYPE "property_region_enum" USING "region"::"text"::"property_region_enum"`
)
await queryRunner.query(`DROP TYPE "property_region_enum_old"`)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "property_region_enum_old" AS ENUM('Greater Downtown', 'Eastside', 'Midtown - New Center', 'Southwest', 'Westside')`
)
await queryRunner.query(
`ALTER TABLE "property" ALTER COLUMN "region" TYPE "property_region_enum_old" USING "region"::"text"::"property_region_enum_old"`
)
await queryRunner.query(`DROP TYPE "property_region_enum"`)
await queryRunner.query(
`ALTER TYPE "property_region_enum_old" RENAME TO "property_region_enum"`
)
}
}
3 changes: 1 addition & 2 deletions backend/core/src/property/types/region-enum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export enum Region {
Downtown = "Downtown",
GreaterDowntown = "Greater Downtown",
Eastside = "Eastside",
MidtownNewCenter = "Midtown - New Center",
Southwest = "Southwest",
Westside = "Westside",
}
3 changes: 1 addition & 2 deletions backend/core/types/src/backend-swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7102,9 +7102,8 @@ export enum ListingSeasonEnum {
}

export enum Region {
"Downtown" = "Downtown",
"Greater Downtown" = "Greater Downtown",
"Eastside" = "Eastside",
"Midtown - New Center" = "Midtown - New Center",
"Southwest" = "Southwest",
"Westside" = "Westside",
}
Expand Down
3 changes: 1 addition & 2 deletions shared-helpers/src/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ export interface ListingFilterState {
[FrontendListingFilterStateKeys.SupportiveHousingfortheHomeless]?: string | number
// region
[FrontendListingFilterStateKeys.region]?: string
[FrontendListingFilterStateKeys.Downtown]?: string | boolean
[FrontendListingFilterStateKeys.GreaterDowntown]?: string | boolean
[FrontendListingFilterStateKeys.Eastside]?: string | boolean
[FrontendListingFilterStateKeys.MidtownNewCenter]?: string | boolean
[FrontendListingFilterStateKeys.Southwest]?: string | boolean
[FrontendListingFilterStateKeys.Westside]?: string | boolean
// accessibility
Expand Down
13 changes: 4 additions & 9 deletions shared-helpers/src/regions.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
export enum Region {
Downtown = "Downtown",
GreaterDowntown = "Greater Downtown",
Eastside = "Eastside",
MidtownNewCenter = "Midtown - New Center",
Southwest = "Southwest",
Westside = "Westside",
}

// TODO(#674): Get official hosted images
export const regionImageUrls: Map<Region, string> = new Map([
[Region.Downtown, "https://pbs.twimg.com/media/DSzZwQKVAAASkw_?format=jpg&name=large"],
[Region.GreaterDowntown, "https://pbs.twimg.com/media/DSzZwQKVAAASkw_?format=jpg&name=large"],
[
Region.Eastside,
"https://d12kp1agyyb87s.cloudfront.net/wp-content/uploads/2019/10/image001.jpg",
],
[
Region.MidtownNewCenter,
"https://cdn.pixabay.com/photo/2019/03/17/04/00/detroit-4060269_960_720.jpg",
],
[
Region.Southwest,
"https://www.theneighborhoods.org/sites/the-neighborhoods/files/2020-10/Southwest-Mural_1.jpg",
Expand All @@ -42,8 +37,8 @@ export const neighborhoodRegions: Neighborhood[] = [
{ name: "Farwell area", region: Region.Eastside },
{ name: "Gratiot Town / Kettering area", region: Region.Eastside },
{ name: "Gratiot / 7 Mile area", region: Region.Eastside },
{ name: "Greater Corktown area", region: Region.Downtown },
{ name: "Greater Downtown area", region: Region.Downtown },
{ name: "Greater Corktown area", region: Region.GreaterDowntown },
{ name: "Greater Downtown area", region: Region.GreaterDowntown },
{ name: "Islandview / Greater Villages area", region: Region.Eastside },
{ name: "Jefferson Chalmers area", region: Region.Eastside },
{ name: "Livernois / McNichols area", region: Region.Westside },
Expand Down
2 changes: 1 addition & 1 deletion sites/public/src/forms/filters/FilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const FilterForm = (props: FilterFormProps) => {
setRegionOptions(
Object.entries(Region).map((elem) => ({
value: elem[1],
label: elem[0] === "MidtownNewCenter" ? "Midtown" : elem[1],
label: elem[1],
}))
)

Expand Down