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

Added filters to the ada and preferences #1039

Merged
merged 4 commits into from
Mar 9, 2021
Merged
Changes from all 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
105 changes: 75 additions & 30 deletions sites/partners/src/applications/ApplicationsColDefs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
import { t, formatIncome, formatYesNoLabel } from "@bloom-housing/ui-components"
import { IncomePeriod, ApplicationSubmissionType } from "@bloom-housing/backend-core/types"
import { convertDataToPst } from "../../lib/helpers"
import moment from "moment"

function compareDates(a, b, node, nextNode, isInverted) {
const dateStringFormat = "MM/DD/YYYY at hh:mm:ss A"

const dateA = moment(a, dateStringFormat)
const dateB = moment(b, dateStringFormat)

if (a && b && dateA.isSame(dateB)) {
return 0
} else if (a === "") {
return isInverted ? -1 : 1
} else if (b === "") {
return isInverted ? 1 : -1
} else {
return dateA.unix() - dateB.unix()
}
}

function compareStrings(a, b, node, nextNode, isInverted) {
if (a === b) {
return 0
} else if (a === "") {
return isInverted ? -1 : 1
} else if (b === "") {
return isInverted ? 1 : -1
} else {
return a.localeCompare(b)
}
}

export function getColDefs(maxHouseholdSize: number) {
const defs = [
Expand All @@ -26,6 +56,7 @@ export function getColDefs(maxHouseholdSize: number) {

return `${dateTime.date} ${t("t.at")} ${dateTime.time}`
},
comparator: compareDates,
},
{
headerName: t("application.details.number"),
Expand All @@ -49,6 +80,7 @@ export function getColDefs(maxHouseholdSize: number) {
pinned: "left",
type: "leftAligned",
valueFormatter: ({ value }) => t(`application.details.submissionType.${value}`),
comparator: compareStrings,
},
{
headerName: t("application.name.firstName"),
Expand All @@ -59,6 +91,7 @@ export function getColDefs(maxHouseholdSize: number) {
pinned: "left",
width: 125,
minWidth: 100,
comparator: compareStrings,
},
{
headerName: t("application.name.lastName"),
Expand All @@ -69,6 +102,7 @@ export function getColDefs(maxHouseholdSize: number) {
pinned: "left",
width: 125,
minWidth: 100,
comparator: compareStrings,
},
{
headerName: t("application.details.householdSize"),
Expand All @@ -89,13 +123,16 @@ export function getColDefs(maxHouseholdSize: number) {
width: 180,
minWidth: 150,
type: "rightAligned",
valueFormatter: ({ data, value }) => {
if (!value) return ""
valueGetter: (row) => {
if (!row?.data?.income || !row?.data?.incomePeriod) return ""

return data.incomePeriod === IncomePeriod.perYear
? formatIncome(value, data.incomePeriod, IncomePeriod.perYear)
: t("t.n/a")
const { income, incomePeriod } = row.data

return incomePeriod === IncomePeriod.perYear
? formatIncome(income, incomePeriod, IncomePeriod.perYear)
: ""
},
comparator: compareStrings,
},
{
headerName: t("applications.table.declaredMonthlyIncome"),
Expand All @@ -106,13 +143,16 @@ export function getColDefs(maxHouseholdSize: number) {
width: 180,
minWidth: 150,
type: "rightAligned",
valueFormatter: ({ data, value }) => {
if (!value) return ""
valueGetter: (row) => {
if (!row?.data?.income || !row?.data?.incomePeriod) return ""

return data.incomePeriod === IncomePeriod.perMonth
? formatIncome(value, data.incomePeriod, IncomePeriod.perMonth)
: t("t.n/a")
const { income, incomePeriod } = row.data

return incomePeriod === IncomePeriod.perYear
? formatIncome(income, incomePeriod, IncomePeriod.perMonth)
: ""
},
comparator: compareStrings,
},
{
headerName: t("applications.table.subsidyOrVoucher"),
Expand All @@ -127,19 +167,22 @@ export function getColDefs(maxHouseholdSize: number) {

return data.value ? t("t.yes") : t("t.no")
},
comparator: compareStrings,
},
{
headerName: t("applications.table.requestAda"),
field: "accessibility",
sortable: true,
sortable: false,
unSortIcon: true,
filter: false,
filter: true,
width: 120,
minWidth: 100,
valueFormatter: (data) => {
if (!data.value) return ""
valueGetter: (row) => {
if (!row?.data?.accessibility) return ""

const { accessibility } = row.data

const posiviveValues = Object.entries(data.value).reduce((acc, curr) => {
const posiviveValues = Object.entries(accessibility).reduce((acc, curr) => {
if (curr[1] && !["id", "createdAt", "updatedAt"].includes(curr[0])) {
acc.push(t(`application.ada.${curr[0]}`))
}
Expand All @@ -153,15 +196,17 @@ export function getColDefs(maxHouseholdSize: number) {
{
headerName: t("applications.table.preferenceClaimed"),
field: "preferences",
sortable: true,
sortable: false,
unSortIcon: true,
filter: false,
filter: true,
width: 150,
minWidth: 100,
valueFormatter: ({ value }) => {
if (!value) return ""
valueGetter: (row) => {
if (!row?.data?.preferences) return ""

const { preferences } = row.data

const claimed = value?.reduce((acc, curr) => {
const claimed = preferences.reduce((acc, curr) => {
const options = curr.options
.filter((option) => option?.checked)
?.map((item) => t(`application.preferences.options.${item.key}`))
Expand Down Expand Up @@ -466,9 +511,9 @@ export function getColDefs(maxHouseholdSize: number) {
width: 125,
minWidth: 100,
valueFormatter: ({ value }) => {
if (!value) return t("n/a")
if (!value) return ""

return value[i]?.firstName ? value[i].firstName : t("t.n/a")
return value[i]?.firstName ? value[i].firstName : ""
},
},
{
Expand All @@ -479,9 +524,9 @@ export function getColDefs(maxHouseholdSize: number) {
width: 125,
minWidth: 100,
valueFormatter: ({ value }) => {
if (!value) return t("t.n/a")
if (!value) return ""

return value[i]?.lastName ? value[i].lastName : t("t.n/a")
return value[i]?.lastName ? value[i].lastName : ""
},
},
{
Expand All @@ -492,13 +537,13 @@ export function getColDefs(maxHouseholdSize: number) {
width: 125,
minWidth: 100,
valueFormatter: ({ value }) => {
if (!value) return t("t.n/a")
if (!value) return ""

const isValidDOB = !!value[i]?.birthMonth && !!value[i]?.birthDay && value[i]?.birthYear

return isValidDOB
? `${value[i].birthMonth}/${value[i].birthDay}/${value[i].birthYear}`
: t("t.n/a")
: ""
},
},
{
Expand All @@ -509,11 +554,11 @@ export function getColDefs(maxHouseholdSize: number) {
width: 125,
minWidth: 100,
valueFormatter: ({ value }) => {
if (!value) return t("t.n/a")
if (!value) return ""

return value[i]?.relationship
? t(`application.form.options.relationship.${value[i].relationship}`)
: t("t.n/a")
: ""
},
},
{
Expand All @@ -524,7 +569,7 @@ export function getColDefs(maxHouseholdSize: number) {
width: 125,
minWidth: 100,
valueFormatter: ({ value }) => {
if (!value) return t("t.n/a")
if (!value) return ""
return formatYesNoLabel(value[i]?.sameAddress)
},
},
Expand All @@ -536,7 +581,7 @@ export function getColDefs(maxHouseholdSize: number) {
width: 125,
minWidth: 100,
valueFormatter: ({ value }) => {
if (!value) return t("t.n/a")
if (!value) return ""
return formatYesNoLabel(value[i]?.workInRegion)
},
}
Expand Down