Skip to content

Commit

Permalink
Handle multi step form with bad step data (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyaginidhi committed Jun 21, 2024
1 parent 6a61876 commit 2b535c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
35 changes: 22 additions & 13 deletions src/web/client/dal/remoteFetchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isPortalVersionV2,
isWebfileContentLoadNeeded,
setFileContent,
isNullOrUndefined,
} from "../utilities/commonUtil";
import { getCustomRequestURL, getMappingEntityContent, getMetadataInfo, getMappingEntityId, getMimeType, getRequestURL } from "../utilities/urlBuilderUtil";
import { getCommonHeadersForDataverse } from "../../../common/services/AuthenticationProvider";
Expand Down Expand Up @@ -333,7 +334,7 @@ async function processDataAndCreateFile(
if (fileExtension === undefined) {
const expandedContent = getAttributeContent(result, attributePath, entityName, entityId);

if (expandedContent !== Constants.NO_CONTENT) {
if (!isNullOrUndefined(expandedContent)) {
await processExpandedData(
entityName,
expandedContent,
Expand Down Expand Up @@ -459,7 +460,7 @@ async function createFile(
await createVirtualFile(
portalsFS,
fileUri,
convertContentToUint8Array(fileContent, base64Encoded),
convertContentToUint8Array(fileContent ?? Constants.NO_CONTENT, base64Encoded),
entityId,
attributePath,
encodeAsBase64(entityName, attribute),
Expand Down Expand Up @@ -576,20 +577,28 @@ export async function preprocessData(

// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?.forEach((dataItem: any) => {
const webFormSteps = getAttributeContent(dataItem, attributePath, entityType, fetchedFileId as string) as [];
try {
const webFormSteps = getAttributeContent(dataItem, attributePath, entityType, fetchedFileId as string) as [];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const steps: any[] = [];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const steps: any[] = [];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
webFormSteps?.forEach((step: any) => {
const formStepData = advancedFormStepData.get(step);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
!isNullOrUndefined(webFormSteps) && webFormSteps?.forEach((step: any) => {
const formStepData = advancedFormStepData.get(step);

if (formStepData) {
steps.push(formStepData);
}
});
setFileContent(dataItem, attributePath, steps);
if (formStepData) {
steps.push(formStepData);
}
});
setFileContent(dataItem, attributePath, steps);
}
catch (error) {
const errorMsg = (error as Error)?.message;
WebExtensionContext.telemetry.sendErrorTelemetry(telemetryEventNames.WEB_EXTENSION_PREPROCESS_DATA_WEBFORM_STEPS_FAILED,
preprocessData.name,
errorMsg);
}
});
WebExtensionContext.telemetry.sendInfoTelemetry(telemetryEventNames.WEB_EXTENSION_PREPROCESS_DATA_SUCCESS, { entityType: entityType });
}
Expand Down
1 change: 1 addition & 0 deletions src/web/client/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export enum telemetryEventNames {
WEB_EXTENSION_CREATE_ENTITY_FOLDER_FAILED = "webExtensionCreateEntityFolderFailed",
WEB_EXTENSION_PREPROCESS_DATA_FAILED = "webExtensionPreprocessDataFailed",
WEB_EXTENSION_PREPROCESS_DATA_SUCCESS = "webExtensionPreprocessDataSuccess",
WEB_EXTENSION_PREPROCESS_DATA_WEBFORM_STEPS_FAILED = "webExtensionPreprocessDataWebFormStepsFailed",
WEB_EXTENSION_ATTRIBUTE_CONTENT_ERROR = "webExtensionAttributeContentError",
WEB_EXTENSION_SET_FILE_CONTENT_ERROR = "webExtensionSetFileContentError",
WEB_EXTENSION_FAILED_TO_PREPARE_WORKSPACE = "webExtensionFailedToPrepareWorkspace",
Expand Down
6 changes: 3 additions & 3 deletions src/web/client/utilities/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
CO_PRESENCE_FEATURE_SETTING_NAME,
DATA,
MULTI_FILE_FEATURE_SETTING_NAME,
NO_CONTENT,
STUDIO_PROD_REGION,
VERSION_CONTROL_FOR_WEB_EXTENSION_SETTING_NAME,
portalSchemaVersion,
Expand Down Expand Up @@ -63,19 +62,20 @@ export function isExtensionNeededInFileName(entity: string) {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getAttributeContent(result: any, attributePath: IAttributePath, entityName: string, entityId: string) {
let value = result[attributePath.source] ?? NO_CONTENT;
let value = result[attributePath.source];

try {
if (result[attributePath.source] && attributePath.relativePath.length) {
value =
JSON.parse(result[attributePath.source])[attributePath.relativePath] ?? NO_CONTENT;
JSON.parse(result[attributePath.source])[attributePath.relativePath];
}
}
catch (error) {
const errorMsg = (error as Error)?.message;
WebExtensionContext.telemetry.sendErrorTelemetry(telemetryEventNames.WEB_EXTENSION_ATTRIBUTE_CONTENT_ERROR,
getAttributeContent.name,
`For ${entityName} with entityId ${entityId} and attributePath ${JSON.stringify(attributePath)} error: ${errorMsg}`);
return undefined;
}

return value;
Expand Down

0 comments on commit 2b535c2

Please sign in to comment.