From ce83d2b23c6f129546b2b43e27d32df41e3aa41d Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Thu, 14 Dec 2023 06:03:27 +0500 Subject: [PATCH 1/3] feat: add types for report fields --- src/ONYXKEYS.ts | 4 ++++ src/types/onyx/PolicyReportField.ts | 22 ++++++++++++++++++++++ src/types/onyx/RecentlyUsedReportFields.ts | 3 +++ src/types/onyx/Report.ts | 3 +++ src/types/onyx/index.ts | 4 ++++ 5 files changed, 36 insertions(+) create mode 100644 src/types/onyx/PolicyReportField.ts create mode 100644 src/types/onyx/RecentlyUsedReportFields.ts diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 0cc7934ad007..76de820aedd6 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -254,6 +254,8 @@ const ONYXKEYS = { POLICY_RECENTLY_USED_CATEGORIES: 'policyRecentlyUsedCategories_', POLICY_TAGS: 'policyTags_', POLICY_RECENTLY_USED_TAGS: 'policyRecentlyUsedTags_', + POLICY_REPORT_FIELDS: 'policyReportFields_', + POLICY_RECENTLY_USED_REPORT_FIELDS: 'policyRecentlyUsedReportFields_', WORKSPACE_INVITE_MEMBERS_DRAFT: 'workspaceInviteMembersDraft_', WORKSPACE_INVITE_MESSAGE_DRAFT: 'workspaceInviteMessageDraft_', REPORT: 'report_', @@ -443,6 +445,8 @@ type OnyxValues = { [ONYXKEYS.COLLECTION.POLICY_MEMBERS]: OnyxTypes.PolicyMembers; [ONYXKEYS.COLLECTION.POLICY_MEMBERS_DRAFTS]: OnyxTypes.PolicyMember; [ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES]: OnyxTypes.RecentlyUsedCategories; + [ONYXKEYS.COLLECTION.POLICY_REPORT_FIELDS]: OnyxTypes.PolicyReportField; + [ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_REPORT_FIELDS]: OnyxTypes.RecentlyUsedReportFields; [ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST]: OnyxTypes.PolicyMembers; [ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT]: Record; [ONYXKEYS.COLLECTION.REPORT]: OnyxTypes.Report; diff --git a/src/types/onyx/PolicyReportField.ts b/src/types/onyx/PolicyReportField.ts new file mode 100644 index 000000000000..855ca2d06870 --- /dev/null +++ b/src/types/onyx/PolicyReportField.ts @@ -0,0 +1,22 @@ +type PolicyReportFieldType = "text" | "date" | "dropdown"; + +type PolicyReportField = { + /** Name of the field */ + name: string; + + /** Default value assigned to the field */ + defaultValue: string; + + /** Unique id of the field */ + fieldId: string; + + /** Position at which the field should show up relative to the other fields */ + orderWeight: number; + + /** Type of report field */ + type: PolicyReportFieldType; +}; + +type PolicyReportFields = Record; +export default PolicyReportField; +export type {PolicyReportFields}; diff --git a/src/types/onyx/RecentlyUsedReportFields.ts b/src/types/onyx/RecentlyUsedReportFields.ts new file mode 100644 index 000000000000..2b3d046c8316 --- /dev/null +++ b/src/types/onyx/RecentlyUsedReportFields.ts @@ -0,0 +1,3 @@ +type RecentlyUsedReportFields = Record; + +export default RecentlyUsedReportFields; diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 25c544f6f5c3..bad6b6a942ea 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -157,6 +157,9 @@ type Report = { text?: string; privateNotes?: Record; isLoadingPrivateNotes?: boolean; + + /** If the report contains reportFields, save the field id and its value */ + reportFields?: Record, }; export default Report; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index 110bdb024a8c..d105a21c6144 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -54,6 +54,8 @@ import WalletOnfido from './WalletOnfido'; import WalletStatement from './WalletStatement'; import WalletTerms from './WalletTerms'; import WalletTransfer from './WalletTransfer'; +import PolicyReportField from './PolicyReportField'; +import RecentlyUsedReportFields from './RecentlyUsedReportFields'; export type { Account, @@ -124,4 +126,6 @@ export type { WalletTerms, WalletTransfer, ReportUserIsTyping, + PolicyReportField, + RecentlyUsedReportFields, }; From e41e5750b38575aeff6a59b375da90c5f59be9af Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Fri, 15 Dec 2023 11:22:17 +0500 Subject: [PATCH 2/3] feat: add more fields --- src/types/onyx/PolicyReportField.ts | 10 ++++++++-- src/types/onyx/Report.ts | 2 +- src/types/onyx/index.ts | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/types/onyx/PolicyReportField.ts b/src/types/onyx/PolicyReportField.ts index 855ca2d06870..04876ea690b5 100644 --- a/src/types/onyx/PolicyReportField.ts +++ b/src/types/onyx/PolicyReportField.ts @@ -1,4 +1,4 @@ -type PolicyReportFieldType = "text" | "date" | "dropdown"; +type PolicyReportFieldType = 'text' | 'date' | 'dropdown' | 'formula'; type PolicyReportField = { /** Name of the field */ @@ -8,13 +8,19 @@ type PolicyReportField = { defaultValue: string; /** Unique id of the field */ - fieldId: string; + fieldID: string; /** Position at which the field should show up relative to the other fields */ orderWeight: number; /** Type of report field */ type: PolicyReportFieldType; + + /** Tells if the field is required or not */ + required: boolean; + + /** Options to select from if field is of type dropdown */ + options: string[]; }; type PolicyReportFields = Record; diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index bad6b6a942ea..509f27f9e95d 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -159,7 +159,7 @@ type Report = { isLoadingPrivateNotes?: boolean; /** If the report contains reportFields, save the field id and its value */ - reportFields?: Record, + reportFields?: Record; }; export default Report; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index d105a21c6144..c76dbe72192e 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -25,9 +25,11 @@ import PlaidData from './PlaidData'; import Policy from './Policy'; import PolicyCategory, {PolicyCategories} from './PolicyCategory'; import PolicyMember, {PolicyMembers} from './PolicyMember'; +import PolicyReportField from './PolicyReportField'; import PolicyTag, {PolicyTags} from './PolicyTag'; import PrivatePersonalDetails from './PrivatePersonalDetails'; import RecentlyUsedCategories from './RecentlyUsedCategories'; +import RecentlyUsedReportFields from './RecentlyUsedReportFields'; import RecentlyUsedTags from './RecentlyUsedTags'; import RecentWaypoint from './RecentWaypoint'; import ReimbursementAccount from './ReimbursementAccount'; @@ -54,8 +56,6 @@ import WalletOnfido from './WalletOnfido'; import WalletStatement from './WalletStatement'; import WalletTerms from './WalletTerms'; import WalletTransfer from './WalletTransfer'; -import PolicyReportField from './PolicyReportField'; -import RecentlyUsedReportFields from './RecentlyUsedReportFields'; export type { Account, From 56d4762fc5f70f34f553bd7e4b3b759f96a2a8a4 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Tue, 19 Dec 2023 15:31:21 +0500 Subject: [PATCH 3/3] fix: use same types as backend --- src/types/onyx/PolicyReportField.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/onyx/PolicyReportField.ts b/src/types/onyx/PolicyReportField.ts index 04876ea690b5..6a3be23c0a0b 100644 --- a/src/types/onyx/PolicyReportField.ts +++ b/src/types/onyx/PolicyReportField.ts @@ -17,10 +17,10 @@ type PolicyReportField = { type: PolicyReportFieldType; /** Tells if the field is required or not */ - required: boolean; + deletable: boolean; /** Options to select from if field is of type dropdown */ - options: string[]; + values: string[]; }; type PolicyReportFields = Record;