@@ -62,6 +62,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
6262 const [ reports , { sourceValue : changedReports } ] = useOnyx ( ONYXKEYS . COLLECTION . REPORT ) ;
6363 const prevReports = usePrevious ( reports ) ;
6464 const [ , { sourceValue : changedReportActions } ] = useOnyx ( ONYXKEYS . COLLECTION . REPORT_ACTIONS ) ;
65+ const [ allPolicies ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY ) ;
6566 const personalDetails = usePersonalDetails ( ) ;
6667 const prevPersonalDetails = usePrevious ( personalDetails ) ;
6768 const privateIsArchivedMap = usePrivateIsArchivedMap ( ) ;
@@ -70,12 +71,12 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
7071 const hasInitialData = useMemo ( ( ) => Object . keys ( personalDetails ?? { } ) . length > 0 , [ personalDetails ] ) ;
7172
7273 const loadOptions = useCallback ( ( ) => {
73- const optionLists = createOptionList ( personalDetails , currentUserAccountID , privateIsArchivedMap , reports , reportAttributes ?. reports ) ;
74+ const optionLists = createOptionList ( personalDetails , currentUserAccountID , privateIsArchivedMap , reports , allPolicies , reportAttributes ?. reports ) ;
7475 setOptions ( {
7576 reports : optionLists . reports ,
7677 personalDetails : optionLists . personalDetails ,
7778 } ) ;
78- } , [ personalDetails , currentUserAccountID , privateIsArchivedMap , reports , reportAttributes ?. reports ] ) ;
79+ } , [ personalDetails , currentUserAccountID , privateIsArchivedMap , reports , allPolicies , reportAttributes ?. reports ] ) ;
7980
8081 /**
8182 * This effect is responsible for generating the options list when their data is not yet initialized
@@ -132,7 +133,8 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
132133 const report = changedReportsEntries [ reportKey ] ;
133134 const reportID = reportKey . replace ( ONYXKEYS . COLLECTION . REPORT , '' ) ;
134135 const privateIsArchived = privateIsArchivedMap [ `${ ONYXKEYS . COLLECTION . REPORT_NAME_VALUE_PAIRS } ${ reportID } ` ] ;
135- const { reportOption} = processReport ( report , personalDetails , privateIsArchived , currentUserAccountID , reportAttributes ?. reports ) ;
136+ const policy = allPolicies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ report ?. policyID } ` ] ;
137+ const { reportOption} = processReport ( report , personalDetails , privateIsArchived , currentUserAccountID , policy , reportAttributes ?. reports ) ;
136138
137139 if ( reportOption ) {
138140 updatedReportsMap . set ( reportID , reportOption ) ;
@@ -146,7 +148,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
146148 reports : Array . from ( updatedReportsMap . values ( ) ) ,
147149 } ;
148150 } ) ;
149- } , [ changedReportsEntries , personalDetails , currentUserAccountID , reports , reportAttributes ?. reports , privateIsArchivedMap ] ) ;
151+ } , [ changedReportsEntries , personalDetails , currentUserAccountID , reports , allPolicies , reportAttributes ?. reports , privateIsArchivedMap ] ) ;
150152
151153 useEffect ( ( ) => {
152154 if ( ! changedReportActions || ! areOptionsInitialized . current ) {
@@ -168,7 +170,8 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
168170 const reportID = key . replace ( ONYXKEYS . COLLECTION . REPORT_ACTIONS , '' ) ;
169171 const reportItem = updatedReportsMap . get ( reportID ) ?. item ;
170172 const privateIsArchived = privateIsArchivedMap [ `${ ONYXKEYS . COLLECTION . REPORT_NAME_VALUE_PAIRS } ${ reportID } ` ] ;
171- const { reportOption} = processReport ( reportItem , personalDetails , privateIsArchived , currentUserAccountID , reportAttributes ?. reports ) ;
173+ const policy = allPolicies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ reportItem ?. policyID } ` ] ;
174+ const { reportOption} = processReport ( reportItem , personalDetails , privateIsArchived , currentUserAccountID , policy , reportAttributes ?. reports ) ;
172175
173176 if ( reportOption ) {
174177 updatedReportsMap . set ( reportID , reportOption ) ;
@@ -180,7 +183,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
180183 reports : Array . from ( updatedReportsMap . values ( ) ) ,
181184 } ;
182185 } ) ;
183- } , [ changedReportActions , personalDetails , currentUserAccountID , reports , reportAttributes ?. reports , privateIsArchivedMap ] ) ;
186+ } , [ changedReportActions , personalDetails , currentUserAccountID , reports , allPolicies , reportAttributes ?. reports , privateIsArchivedMap ] ) ;
184187
185188 /**
186189 * This effect is used to update the options list when personal details change.
@@ -203,6 +206,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
203206 currentUserAccountID ,
204207 privateIsArchivedMap ,
205208 reports ,
209+ allPolicies ,
206210 reportAttributes ?. reports ,
207211 ) ;
208212 setOptions ( ( prevOptions ) => ( {
@@ -238,7 +242,8 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
238242 }
239243
240244 const privateIsArchived = privateIsArchivedMap [ `${ ONYXKEYS . COLLECTION . REPORT_NAME_VALUE_PAIRS } ${ report . reportID } ` ] ;
241- const newReportOption = createOptionFromReport ( report , personalDetails , currentUserAccountID , privateIsArchived , reportAttributes ?. reports , {
245+ const policy = allPolicies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ report . policyID } ` ] ;
246+ const newReportOption = createOptionFromReport ( report , personalDetails , currentUserAccountID , privateIsArchived , policy , reportAttributes ?. reports , {
242247 showPersonalDetails : true ,
243248 } ) ;
244249 const replaceIndex = options . reports . findIndex ( ( option ) => option . reportID === report . reportID ) ;
@@ -250,7 +255,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
250255 }
251256
252257 // since personal details are not a collection, we need to recreate the whole list from scratch
253- const newPersonalDetailsOptions = createOptionList ( personalDetails , currentUserAccountID , privateIsArchivedMap , reports , reportAttributes ?. reports ) . personalDetails ;
258+ const newPersonalDetailsOptions = createOptionList ( personalDetails , currentUserAccountID , privateIsArchivedMap , reports , allPolicies , reportAttributes ?. reports ) . personalDetails ;
254259
255260 setOptions ( ( prevOptions ) => {
256261 const newOptions = { ...prevOptions } ;
0 commit comments