Skip to content

Commit

Permalink
refactor(debug): apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
pac-guerreiro committed Sep 17, 2024
1 parent 7d71f79 commit 225304f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
44 changes: 17 additions & 27 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ class ObjectError extends SyntaxError {
}
}

type ObjectType = Record<
string,
| 'string'
| 'number'
| 'object'
| 'array'
| 'boolean' // Constant enum
| ConstantEnum
>;
type ObjectType = Record<string, 'string' | 'number' | 'object' | 'array' | 'boolean' | ConstantEnum>;

type ConstantEnum = Record<string, unknown>;

Expand Down Expand Up @@ -271,24 +263,7 @@ function validateConstantEnum(value: string, constEnum: ConstantEnum) {
*/
function validateArray(
value: string,
arrayType:
| 'string'
| 'number'
| 'boolean'
// Constant enum
| ConstantEnum
// Object
| Record<
string,
| 'string'
| 'number'
| 'object'
| 'boolean'
| 'array'
| PropertyTypes
// Constant enum
| ConstantEnum
>,
arrayType: 'string' | 'number' | 'boolean' | ConstantEnum | Record<string, 'string' | 'number' | 'object' | 'boolean' | 'array' | PropertyTypes | ConstantEnum>,
) {
if (value === 'undefined') {
return;
Expand Down Expand Up @@ -412,6 +387,12 @@ function validateString(value: string) {
}
}

/**
* Validates if a property of Report is of the expected type
*
* @param key - property key
* @param value - value provided by the user
*/
function validateReportDraftProperty(key: keyof Report, value: string) {
if (REPORT_REQUIRED_PROPERTIES.includes(key) && value === 'undefined') {
throw SyntaxError('debug.missingValue');
Expand Down Expand Up @@ -493,6 +474,12 @@ function validateReportDraftProperty(key: keyof Report, value: string) {
validateString(value);
}

/**
* Validates if a property of ReportAction is of the expected type
*
* @param key - property key
* @param value - value provided by the user
*/
function validateReportActionDraftProperty(key: keyof ReportAction, value: string) {
if (REPORT_ACTION_REQUIRED_PROPERTIES.includes(key) && value === 'undefined') {
throw SyntaxError('debug.missingValue');
Expand Down Expand Up @@ -539,6 +526,9 @@ function validateReportActionDraftProperty(key: keyof ReportAction, value: strin
validateString(value);
}

/**
* Validates if the ReportAction JSON that the user provided is of the expected type
*/
function validateReportActionJSON(json: string) {
const parsedReportAction = parseJSON(json) as ReportAction;
REPORT_ACTION_REQUIRED_PROPERTIES.forEach((key) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function ProfilePage({route}: ProfilePageProps) {
})}
/>
)}
{!isEmptyObject(report) && report.reportID && isDebugModeEnabled && (
{!!report?.reportID && isDebugModeEnabled && (
<MenuItem
title={translate('debug.debug')}
icon={Expensicons.Bug}
Expand Down

0 comments on commit 225304f

Please sign in to comment.