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

feat: add types for report fields #33034

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_',
Expand Down Expand Up @@ -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<string, number>;
[ONYXKEYS.COLLECTION.REPORT]: OnyxTypes.Report;
Expand Down
28 changes: 28 additions & 0 deletions src/types/onyx/PolicyReportField.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
type PolicyReportFieldType = 'text' | 'date' | 'dropdown' | 'formula';

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;

/** Tells if the field is required or not */
deletable: boolean;

/** Options to select from if field is of type dropdown */
values: string[];
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need a couple more here

value, and values (for dropdown values)

and then I'm still looking into this but possible required (looking into this today)

Copy link
Contributor

@thienlnam thienlnam Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out we'll need the deletable key as well, that will indicate whether or not it is required or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thienlnam Can we rename these in our code? I was thinking that it makes more sense to call it required and options instead of deletable and values?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean we can update them just for the front-end but to modify these keys in the BE it will be more work than it is worth due to updating oldApp as well.

I will update these keys when we re-format them from onyx to be required and options

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually thinking about this more, I think this will just end up adding more confusion in the future with the disconnect between the keys

Deletable is also representative of the fields that no longer exist on old reports but no longer on the policy, and I don't know if we should just rename a single key (values is still pretty intuitive)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me. I'll change this so that it matches what we have already.


type PolicyReportFields = Record<string, PolicyReportField>;
export default PolicyReportField;
export type {PolicyReportFields};
3 changes: 3 additions & 0 deletions src/types/onyx/RecentlyUsedReportFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type RecentlyUsedReportFields = Record<string, string[]>;

export default RecentlyUsedReportFields;
3 changes: 3 additions & 0 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ type Report = {
text?: string;
privateNotes?: Record<number, Note>;
isLoadingPrivateNotes?: boolean;

/** If the report contains reportFields, save the field id and its value */
reportFields?: Record<string, string>;
};

export default Report;
Expand Down
4 changes: 4 additions & 0 deletions src/types/onyx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -124,4 +126,6 @@ export type {
WalletTerms,
WalletTransfer,
ReportUserIsTyping,
PolicyReportField,
RecentlyUsedReportFields,
};
Loading