Skip to content

Commit

Permalink
fix: add flag to hide geocoding validation by radius (#3974)
Browse files Browse the repository at this point in the history
* fix: add flag to hide geocoding validation by radius

* fix: preference tests

* fix: default enable radius flag to false

* fix: geocoding tests

* fix: set default radius geocoding flag to false
  • Loading branch information
KrissDrawing authored Apr 22, 2024
1 parent d926e8f commit b40198f
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "jurisdictions" ADD COLUMN "enable_geocoding_radius_method" BOOLEAN NOT NULL DEFAULT false;

1 change: 1 addition & 0 deletions api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ model Jurisdictions {
enableAccessibilityFeatures Boolean @default(false) @map("enable_accessibility_features")
enableUtilitiesIncluded Boolean @default(false) @map("enable_utilities_included")
enableGeocodingPreferences Boolean @default(false) @map("enable_geocoding_preferences")
enableGeocodingRadiusMethod Boolean @default(false) @map("enable_geocoding_radius_method")
allowSingleUseCodeLogin Boolean @default(false) @map("allow_single_use_code_login")
amiChart AmiChart[]
multiselectQuestions MultiselectQuestions[]
Expand Down
1 change: 1 addition & 0 deletions api/prisma/seed-helpers/jurisdiction-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export const jurisdictionFactory = (
enableAccessibilityFeatures: true,
enableUtilitiesIncluded: true,
enableGeocodingPreferences: true,
enableGeocodingRadiusMethod: false,
listingApprovalPermissions: listingApprovalPermissions || [],
});
5 changes: 5 additions & 0 deletions api/src/dtos/jurisdictions/jurisdiction.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export class Jurisdiction extends AbstractDTO {
@ApiPropertyOptional()
enableGeocodingPreferences?: boolean;

@Expose()
@IsBoolean({ groups: [ValidationsGroupsEnum.default] })
@ApiPropertyOptional()
enableGeocodingRadiusMethod?: boolean;

@Expose()
@IsBoolean({ groups: [ValidationsGroupsEnum.default] })
@IsDefined({ groups: [ValidationsGroupsEnum.default] })
Expand Down
9 changes: 9 additions & 0 deletions shared-helpers/src/types/backend-swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4261,6 +4261,9 @@ export interface JurisdictionCreate {
/** */
enableGeocodingPreferences?: boolean

/** */
enableGeocodingRadiusMethod?: boolean

/** */
enableAccessibilityFeatures: boolean

Expand Down Expand Up @@ -4308,6 +4311,9 @@ export interface JurisdictionUpdate {
/** */
enableGeocodingPreferences?: boolean

/** */
enableGeocodingRadiusMethod?: boolean

/** */
enableAccessibilityFeatures: boolean

Expand Down Expand Up @@ -4364,6 +4370,9 @@ export interface Jurisdiction {
/** */
enableGeocodingPreferences?: boolean

/** */
enableGeocodingRadiusMethod?: boolean

/** */
enableAccessibilityFeatures: boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("Preference Management Tests", () => {
cy.getByTestId("preference-link").type("https://www.example.com")
cy.getByTestId("preference-link-title").type("Preference Link Title")

cy.getByTestId("preference-jurisdiction").select("Bloomington")
cy.getByID("preference-add-option-button").click()
cy.getByTestId("preference-option-title").type("Preference Option Title")
cy.getByTestId("preference-option-description").type("Preference Option Description", {
Expand All @@ -35,15 +36,15 @@ describe("Preference Management Tests", () => {
cy.getByTestId("exclusive-question-exclusive").check()
cy.getByID("preference-option-save").click()

cy.getByTestId("validation-method-radius").click()
cy.getByTestId("preference-option-radius-size").type("100")
cy.getByTestId("validation-method-map").click()
cy.getByTestId("preference-map-layer").select("Redlined Districts")
cy.getByTestId("collect-name-yes").click()
cy.getByTestId("collect-relationship-yes").click()
cy.getByID("preference-option-save").click()

cy.getByTestId("preference-opt-out-label").clear()
cy.getByTestId("preference-opt-out-label").type("Preference Opt Out Label")
cy.getByTestId("preference-jurisdiction").select("Bloomington")

cy.getByID("preference-save-button").click()
cy.getByTestId("toast-alert")
.contains("Preference Created")
Expand Down Expand Up @@ -71,8 +72,11 @@ describe("Preference Management Tests", () => {
)

cy.getByTestId("collect-address-yes").should("be.checked")
cy.getByTestId("validation-method-radius").should("be.checked")
cy.getByTestId("preference-option-radius-size").should("have.value", "100")
cy.getByTestId("validation-method-map").should("be.checked")
cy.getByTestId("preference-map-layer")
.find("option:selected")
.invoke("text")
.should("equal", "Redlined Districts")
cy.getByTestId("collect-name-yes").should("be.checked")
cy.getByTestId("collect-relationship-yes").should("be.checked")
cy.getByTestId("exclusive-question-exclusive").should("have.value", "exclusive")
Expand Down
114 changes: 67 additions & 47 deletions sites/partners/src/components/settings/PreferenceDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import {
Drawer,
Field,
FieldGroup,
Select,
Textarea,
t,
MinimalTable,
Select,
StandardTableData,
t,
Textarea,
} from "@bloom-housing/ui-components"
import { Button, FormErrorMessage, FieldValue, Card, Grid } from "@bloom-housing/ui-seeds"
import { Button, Card, FieldValue, FormErrorMessage, Grid } from "@bloom-housing/ui-seeds"
import { AuthContext } from "@bloom-housing/shared-helpers"
import { useForm } from "react-hook-form"
import {
MultiselectOption,
MultiselectQuestion,
MultiselectQuestionCreate,
MultiselectQuestionUpdate,
MultiselectQuestionsApplicationSectionEnum,
MultiselectQuestionUpdate,
ValidationMethodEnum,
YesNoEnum,
} from "@bloom-housing/shared-helpers/src/types/backend-swagger"
Expand Down Expand Up @@ -103,6 +103,10 @@ const PreferenceDrawer = ({
((optionData?.collectAddress && watch("collectAddress") === undefined) ||
watch("collectAddress") === YesNoEnum.yes) &&
isAdditionalDetailsEnabled
const isValidationRadiusVisible =
profile?.jurisdictions.find((juris) => juris.id === watch("jurisdictionId"))
?.enableGeocodingRadiusMethod ||
profile?.jurisdictions.every((juris) => juris.enableGeocodingRadiusMethod)
const readiusExpand =
(optionData?.validationMethod === ValidationMethodEnum.radius &&
watch("validationMethod") === undefined) ||
Expand Down Expand Up @@ -173,6 +177,51 @@ const PreferenceDrawer = ({
? t("settings.preferenceEditOption")
: t("settings.preferenceAddOption")

let validationMethodsFields = [
{
label: t("settings.preferenceValidatingAddress.checkWithinRadius"),
value: ValidationMethodEnum.radius,
defaultChecked: optionData?.validationMethod === ValidationMethodEnum.radius,
id: "validationMethodRadius",
dataTestId: "validation-method-radius",
inputProps: {
onChange: () => {
clearErrors("validationMethod")
},
},
},
{
label: t("settings.preferenceValidatingAddress.checkWithArcGisMap"),
value: ValidationMethodEnum.map,
defaultChecked: optionData?.validationMethod === ValidationMethodEnum.map,
id: "validationMethodMap",
dataTestId: "validation-method-map",
inputProps: {
onChange: () => {
clearErrors("validationMethod")
},
},
},
{
label: t("settings.preferenceValidatingAddress.checkManually"),
value: ValidationMethodEnum.none,
defaultChecked: optionData?.validationMethod === ValidationMethodEnum.none,
id: "validationMethodNone",
dataTestId: "validation-method-none",
inputProps: {
onChange: () => {
clearErrors("validationMethod")
},
},
},
]

if (!isValidationRadiusVisible) {
validationMethodsFields = validationMethodsFields.filter(
(field) => field.id !== "validationMethodRadius"
)
}

return (
<>
<Drawer
Expand Down Expand Up @@ -424,6 +473,17 @@ const PreferenceDrawer = ({
}
if (!validation) return
const formValues = getValues()
if (!isValidationRadiusVisible) {
questionData.options = questionData?.options.map((option) =>
option.validationMethod === ValidationMethodEnum.radius
? {
...option,
validationMethod: ValidationMethodEnum.none,
radiusSize: undefined,
}
: option
)
}

const formattedQuestionData: MultiselectQuestionUpdate | MultiselectQuestionCreate = {
applicationSection: MultiselectQuestionsApplicationSectionEnum.preferences,
Expand Down Expand Up @@ -624,47 +684,7 @@ const PreferenceDrawer = ({
register={register}
validation={{ required: true }}
error={errors.validationMethod}
fields={[
{
label: t("settings.preferenceValidatingAddress.checkWithinRadius"),
value: ValidationMethodEnum.radius,
defaultChecked:
optionData?.validationMethod === ValidationMethodEnum.radius,
id: "validationMethodRadius",
dataTestId: "validation-method-radius",
inputProps: {
onChange: () => {
clearErrors("validationMethod")
},
},
},
{
label: t("settings.preferenceValidatingAddress.checkWithArcGisMap"),
value: ValidationMethodEnum.map,
defaultChecked:
optionData?.validationMethod === ValidationMethodEnum.map,
id: "validationMethodMap",
dataTestId: "validation-method-map",
inputProps: {
onChange: () => {
clearErrors("validationMethod")
},
},
},
{
label: t("settings.preferenceValidatingAddress.checkManually"),
value: ValidationMethodEnum.none,
defaultChecked:
optionData?.validationMethod === ValidationMethodEnum.none,
id: "validationMethodNone",
dataTestId: "validation-method-none",
inputProps: {
onChange: () => {
clearErrors("validationMethod")
},
},
},
]}
fields={validationMethodsFields}
fieldClassName="m-0"
fieldGroupClassName="flex flex-col"
dataTestId={"preference-option-validation-method"}
Expand All @@ -673,7 +693,7 @@ const PreferenceDrawer = ({
)}
</Grid.Cell>
<Grid.Cell className="pr-8">
{collectAddressExpand && readiusExpand && (
{collectAddressExpand && readiusExpand && isValidationRadiusVisible && (
<FieldValue label={t("settings.preferenceValidatingAddress.howManyMiles")}>
<Field
id="radiusSize"
Expand Down

0 comments on commit b40198f

Please sign in to comment.