Skip to content

Commit

Permalink
fix: DAH-2790 fix checkmarks not showing up after perf improvements (#…
Browse files Browse the repository at this point in the history
…676)

* fix: adding to deps list

* fix: removing feature flag and filter check

* fix: not adding layered prefs for listings without application prefs

* fix: cleaning up logs

* chore: increasing code coverage

* chore: improving comments
  • Loading branch information
alulabeshue-sfgov authored Oct 2, 2024
1 parent 5c0210f commit 8d60db2
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { capitalize, compact, map, cloneDeep } from 'lodash'

import StatusModalWrapper from 'components/organisms/StatusModalWrapper'
import { LISTING_TYPE_FIRST_COME_FIRST_SERVED } from 'utils/consts'
import { useFeatureFlag } from 'utils/hooks/useFeatureFlag'
import { addLayeredValidation } from 'utils/layeredPreferenceUtil'

import { withContext } from './context'
Expand Down Expand Up @@ -63,6 +62,35 @@ export const buildRowData = (application) => {
return rowData
}

export const buildApplicationsWithLayeredValidations = (
listingId,
applications,
preferences,
setPrefMap
) => {
// don't need layered validation for fcfs or listings that do not have preferences
if (!preferences) return

// don't need to make additional calls to the backend for listings w/out veterans
if (preferences.every((pref) => !pref.includes('Veteran'))) {
const prefMap = {}
addLayeredValidation(applications).forEach((preference) => {
prefMap[`${preference.application_id}-${preference.preference_name}`] =
preference.layered_validation
})
setPrefMap(prefMap)
} else {
getApplications(listingId, 0, {}, true, false).then(({ records }) => {
const prefMap = {}
records.forEach((preference) => {
prefMap[`${preference.application_id}-${preference.preference_name}`] =
preference.layered_validation
})
setPrefMap(prefMap)
})
}
}

const LeaseUpTableContainer = ({
store: {
applications,
Expand All @@ -86,39 +114,10 @@ const LeaseUpTableContainer = ({
}
}) => {
const [prefMap, setPrefMap] = useState(null)
const { flagsReady, unleashFlag: usePerformanceUpdates } = useFeatureFlag(
'partners_lease_up_perf',
false
)

useEffect(() => {
if (flagsReady) {
// don't need layered validation for fcfs
// don't need layered validation for non-veteran listings
// don't need layered validation for initial call
if (
usePerformanceUpdates &&
(!hasFilters || (preferences && preferences.every((pref) => !pref.includes('Veteran'))))
) {
const prefMap = {}
addLayeredValidation(applications).forEach((preference) => {
prefMap[`${preference.application_id}-${preference.preference_name}`] =
preference.layered_validation
})
setPrefMap(prefMap)
} else if (listingType !== LISTING_TYPE_FIRST_COME_FIRST_SERVED) {
getApplications(listingId, 0, {}, true, false).then(({ records }) => {
const prefMap = {}
records.forEach((preference) => {
prefMap[`${preference.application_id}-${preference.preference_name}`] =
preference.layered_validation
})
setPrefMap(prefMap)
})
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasFilters, listingId, listingType, preferences, usePerformanceUpdates])
buildApplicationsWithLayeredValidations(listingId, applications, preferences, setPrefMap)
}, [applications, hasFilters, listingId, listingType, preferences])

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import {
buildApplicationsWithLayeredValidations,
buildRowData,
getAccessibilityKeys
} from 'components/lease_ups/LeaseUpApplicationsTableContainer'
import { getApplications } from 'components/lease_ups/utils/leaseUpRequestUtils'

jest.mock('components/lease_ups/utils/leaseUpRequestUtils.js', () => ({
getApplications: jest.fn()
}))

describe('LeaseUpApplicationsTableContainer', () => {
describe('buildRowData', () => {
Expand Down Expand Up @@ -54,4 +60,50 @@ describe('LeaseUpApplicationsTableContainer', () => {
expect(getAccessibilityKeys(application)).toBe('HCBS Units, Mobility')
})
})

describe('buildApplicationsWithLayeredValidations', () => {
test('should not call api when there are no preferences', async () => {
buildApplicationsWithLayeredValidations('listingId', [], [], () => {})
expect(getApplications).not.toHaveBeenCalled()
})

test('should not call api when there are no veteran preferences', async () => {
buildApplicationsWithLayeredValidations(
'listingId',
[],
[
'Live or Work in San Francisco Preference',
'Neighborhood Resident Housing Preference (NRHP)'
],
() => {}
)
expect(getApplications).not.toHaveBeenCalled()
})

test('should call api when there are veteran preferences', async () => {
getApplications.mockImplementation(() =>
Promise.resolve({
records: [
{
application_id: 'application_id',
preference_name: 'preference_name',
layered_validation: 'Confirmed'
}
]
})
)

buildApplicationsWithLayeredValidations(
'listingId',
[],
[
'Tier 1 Veteran with Certificate of Preference',
'Live or Work in San Francisco Preference',
'Neighborhood Resident Housing Preference (NRHP)'
],
() => {}
)
expect(getApplications).toHaveBeenCalledTimes(1)
})
})
})

0 comments on commit 8d60db2

Please sign in to comment.