From 225304f9c7498fcdd5473ae903c9c89688a7d561 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Tue, 17 Sep 2024 21:21:01 +0100 Subject: [PATCH] refactor(debug): apply suggestions --- src/libs/DebugUtils.ts | 44 +++++++++++++++------------------------ src/pages/ProfilePage.tsx | 2 +- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index af54dd721608..3efba2dcd161 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -31,15 +31,7 @@ class ObjectError extends SyntaxError { } } -type ObjectType = Record< - string, - | 'string' - | 'number' - | 'object' - | 'array' - | 'boolean' // Constant enum - | ConstantEnum ->; +type ObjectType = Record; type ConstantEnum = Record; @@ -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, ) { if (value === 'undefined') { return; @@ -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'); @@ -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'); @@ -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) => { diff --git a/src/pages/ProfilePage.tsx b/src/pages/ProfilePage.tsx index 693ae6ea9a60..2b732bb5506a 100755 --- a/src/pages/ProfilePage.tsx +++ b/src/pages/ProfilePage.tsx @@ -301,7 +301,7 @@ function ProfilePage({route}: ProfilePageProps) { })} /> )} - {!isEmptyObject(report) && report.reportID && isDebugModeEnabled && ( + {!!report?.reportID && isDebugModeEnabled && (