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

[TS migration] Migrate 'Policy.js' lib to TypeScript #33691

Merged
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c037865
Rename Policy file
BartoszGrajdek Nov 28, 2023
ddaf7b9
TS migration
BartoszGrajdek Nov 30, 2023
66fbaf9
Merge remote-tracking branch 'origin/main' into ts-migration/policy-a…
BartoszGrajdek Nov 30, 2023
a5ea5d1
TS migration of Policy.js
BartoszGrajdek Dec 6, 2023
bc82922
Resolve merge conflicts
BartoszGrajdek Dec 6, 2023
ecb7dfe
Add changes to ReportUtils & merge main
BartoszGrajdek Dec 13, 2023
a793486
add remaining typescript typing to the policy lib
cdOut Dec 28, 2023
ab6b95f
Merge branch 'main' into ts-migration/policy-action-lib
cdOut Jan 2, 2024
1097bc1
add review suggested changes
cdOut Jan 2, 2024
fa05286
Fix typecheck and lint
blazejkustra Jan 2, 2024
f9ec088
Merge branch 'main' into ts-migration/policy-action-lib
blazejkustra Jan 2, 2024
18a8891
Final Policy adjustements
blazejkustra Jan 2, 2024
55648a3
Add missing return types and change Record to stricter types
blazejkustra Jan 2, 2024
87610b2
Merge branch 'main' into ts-migration/policy-action-lib
blazejkustra Jan 2, 2024
fa42c08
Make isHarvestingEnabled optional
blazejkustra Jan 2, 2024
11c7a4c
Merge branch 'main' into ts-migration/policy-action-lib
cdOut Jan 2, 2024
46e4bba
Merge branch 'main' into ts-migration/policy-action-lib
blazejkustra Jan 3, 2024
4f1adec
add suggested review changes and refactor
cdOut Jan 4, 2024
d0e0cbb
Merge branch 'main' into ts-migration/policy-action-lib
cdOut Jan 4, 2024
bd95ad8
fix correct type imports
cdOut Jan 4, 2024
81d9208
Merge branch 'main' into ts-migration/policy-action-lib
cdOut Jan 8, 2024
b0a9ed9
implement fix and review suggestions
cdOut Jan 9, 2024
6d8d468
Merge branch 'main' into ts-migration/policy-action-lib
cdOut Jan 9, 2024
97e9b11
add minor code refactors
cdOut Jan 9, 2024
7613c69
Merge branch 'main' into ts-migration/policy-action-lib
cdOut Jan 9, 2024
d9ef0b2
fix if statement in unit and rate update
cdOut Jan 10, 2024
5a2541f
Merge branch 'main' into ts-migration/policy-action-lib
cdOut Jan 10, 2024
7e534e9
Merge branch 'main' into ts-migration/policy-action-lib
cdOut Jan 11, 2024
ef4c055
implement finallyData and fix merge errors
cdOut Jan 11, 2024
5ba57d1
include required areChatRoomsEnabled in policy creation
cdOut Jan 11, 2024
58ac053
change properties from optional to required for CustomUnit
cdOut Jan 11, 2024
ce0205d
remove NewCustomUnit type and refactor rest accordingly
cdOut Jan 11, 2024
2d67506
refactor two api writes for finallyData
cdOut Jan 11, 2024
cdc8486
refactor return type of getNewPersonalDetailsOnyxData
cdOut Jan 17, 2024
59556b2
fix CustomUnit rates typing
cdOut Jan 17, 2024
6c72ef8
remove usage of isNotEmptyObject for in PR related files
cdOut Jan 17, 2024
b1e2aeb
Merge branch 'main' into ts-migration/policy-action-lib
cdOut Jan 17, 2024
b9f4551
fix double negation lint error
cdOut Jan 17, 2024
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
4 changes: 2 additions & 2 deletions src/libs/DistanceRequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import * as CurrencyUtils from './CurrencyUtils';
import * as PolicyUtils from './PolicyUtils';

type DefaultMileageRate = {
rate: number;
currency: string;
rate?: number;
currency?: string;
unit: Unit;
};

Expand Down
53 changes: 25 additions & 28 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails, PersonalDetailsList, PrivatePersonalDetails} from '@src/types/onyx';
import type {OnyxData} from '@src/types/onyx/Request';
import * as LocalePhoneNumber from './LocalePhoneNumber';
import * as Localize from './Localize';
import * as UserUtils from './UserUtils';
Expand Down Expand Up @@ -91,16 +92,15 @@ function getLoginsByAccountIDs(accountIDs: number[]): string[] {
* @param accountIDs Array of user accountIDs
* @returns Object with optimisticData, successData and failureData (object of personal details objects)
*/
function getNewPersonalDetailsOnyxData(logins: string[], accountIDs: number[]) {
const optimisticData: PersonalDetailsList = {};
const successData: PersonalDetailsList = {};
const failureData: PersonalDetailsList = {};
function getNewPersonalDetailsOnyxData(logins: string[], accountIDs: number[]): OnyxData {
const personalDetailsNew: PersonalDetailsList = {};
const personalDetailsCleanup: PersonalDetailsList = {};

logins.forEach((login, index) => {
const accountID = accountIDs[index];

if (allPersonalDetails && Object.keys(allPersonalDetails?.[accountID] ?? {}).length === 0) {
optimisticData[accountID] = {
personalDetailsNew[accountID] = {
login,
accountID,
avatar: UserUtils.getDefaultAvatarURL(accountID),
Expand All @@ -111,32 +111,29 @@ function getNewPersonalDetailsOnyxData(logins: string[], accountIDs: number[]) {
* Cleanup the optimistic user to ensure it does not permanently persist.
* This is done to prevent duplicate entries (upon success) since the BE will return other personal details with the correct account IDs.
*/
successData[accountID] = null;
personalDetailsCleanup[accountID] = null;
}
});

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: personalDetailsNew,
},
];

const finallyData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: personalDetailsCleanup,
},
];

return {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: optimisticData,
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: successData,
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: failureData,
},
],
optimisticData,
finallyData,
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1643,9 +1643,9 @@ function isUnreadWithMention(reportOrOption: OnyxEntry<Report> | OptionData): bo

/**
* Determines if the option requires action from the current user. This can happen when it:
- is unread and the user was mentioned in one of the unread comments
- is for an outstanding task waiting on the user
- has an outstanding child money request that is waiting for an action from the current user (e.g. pay, approve, add bank account)
- is unread and the user was mentioned in one of the unread comments
- is for an outstanding task waiting on the user
- has an outstanding child money request that is waiting for an action from the current user (e.g. pay, approve, add bank account)
*
* @param option (report or optionItem)
* @param parentReportAction (the report action the current report is a thread of)
Expand Down Expand Up @@ -4535,4 +4535,4 @@ export {
shouldDisableThread,
};

export type {ExpenseOriginalMessage, OptionData, OptimisticChatReport, OptimisticCreatedReportAction};
export type {ExpenseOriginalMessage, OptionData, OptimisticChatReport, OptimisticClosedReportAction, OptimisticCreatedReportAction};
Loading
Loading