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

Handle multi step form with bad step data #977

Merged
merged 2 commits into from
Jun 21, 2024
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
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
Loading