From ebbb521e4583365fa67531f4979770a98e766989 Mon Sep 17 00:00:00 2001 From: amitjoshi438 <54068463+amitjoshi438@users.noreply.github.com> Date: Mon, 23 Dec 2024 14:41:24 +0530 Subject: [PATCH] Handle null language code for content snippets and update query parameters in portal schema (#1086) Co-authored-by: amitjoshi --- src/web/client/dal/remoteFetchProvider.ts | 9 +++++++-- src/web/client/schema/portalSchema.ts | 4 ++-- src/web/client/utilities/commonUtil.ts | 10 +++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/web/client/dal/remoteFetchProvider.ts b/src/web/client/dal/remoteFetchProvider.ts index 4887b7138..8414b56da 100644 --- a/src/web/client/dal/remoteFetchProvider.ts +++ b/src/web/client/dal/remoteFetchProvider.ts @@ -246,11 +246,16 @@ async function createContentFiles( schemaEntityKey.LANGUAGE_FIELD ); + let languageCode = WebExtensionContext.websiteLanguageCode; + if (languageCodeAttribute && result[languageCodeAttribute] === null) { - throw new Error(ERROR_CONSTANTS.LANGUAGE_CODE_ID_VALUE_NULL); + if (entityName !== schemaEntityName.CONTENTSNIPPETS) { + throw new Error(ERROR_CONSTANTS.LANGUAGE_CODE_ID_VALUE_NULL); + } else { + languageCode = Constants.DEFAULT_LANGUAGE_CODE; // Handles the case where language code is null for content snippets + } } - let languageCode = WebExtensionContext.websiteLanguageCode; if (defaultFileInfo?.fileName === undefined && languageCodeAttribute && result[languageCodeAttribute]) { diff --git a/src/web/client/schema/portalSchema.ts b/src/web/client/schema/portalSchema.ts index c17092c06..5f34b7423 100644 --- a/src/web/client/schema/portalSchema.ts +++ b/src/web/client/schema/portalSchema.ts @@ -123,7 +123,7 @@ export const portal_schema_V1 = { _fetchQueryParameters: "?$filter=adx_contentsnippetid eq {entityId}&$select=adx_name,adx_value,_adx_contentsnippetlanguageid_value", _multiFileFetchQueryParameters: - "?$filter=_adx_websiteid_value eq {websiteId} and _adx_contentsnippetlanguageid_value ne null &$select=adx_name,adx_value,adx_contentsnippetid,_adx_contentsnippetlanguageid_value&$count=true", + "?$filter=_adx_websiteid_value eq {websiteId} &$select=adx_name,adx_value,adx_contentsnippetid,_adx_contentsnippetlanguageid_value&$count=true", _attributes: "adx_value", _attributesExtension: new Map([["adx_value", "html"]]), }, @@ -334,7 +334,7 @@ export const portal_schema_V2 = { _fetchQueryParameters: "?$filter=powerpagecomponentid eq {entityId}&$select=name,content", _multiFileFetchQueryParameters: - "?$filter=_powerpagesiteid_value eq {websiteId} and powerpagecomponenttype eq 7 and _powerpagesitelanguageid_value ne null &$select=name,content,_powerpagesitelanguageid_value&$count=true", + "?$filter=_powerpagesiteid_value eq {websiteId} and powerpagecomponenttype eq 7 &$select=name,content,_powerpagesitelanguageid_value&$count=true", _attributes: "content.value", _attributesExtension: new Map([["content.value", "html"]]), }, diff --git a/src/web/client/utilities/commonUtil.ts b/src/web/client/utilities/commonUtil.ts index c258429d9..b859f8450 100644 --- a/src/web/client/utilities/commonUtil.ts +++ b/src/web/client/utilities/commonUtil.ts @@ -24,6 +24,7 @@ import { doesFileExist, getFileAttributePath, getFileEntityName, updateEntityCol import { isWebFileV2 } from "./schemaHelperUtil"; import { ServiceEndpointCategory } from "../../../common/services/Constants"; import { PPAPIService } from "../../../common/services/PPAPIService"; +import * as Constants from "../common/constants"; // decodes file content to UTF-8 export function convertContentToUint8Array(content: string, isBase64Encoded: boolean): Uint8Array { @@ -42,15 +43,18 @@ export function GetFileNameWithExtension( languageCode: string, extension: string ) { - fileName = isLanguageCodeNeededInFileName(entity) ? `${fileName}.${languageCode}` : fileName; + if (entity === schemaEntityName.CONTENTSNIPPETS) { + fileName = languageCode && languageCode != Constants.DEFAULT_LANGUAGE_CODE ? `${fileName}.${languageCode}` : fileName; // Handle the case where language is not provided for content snippets + } else { + fileName = isLanguageCodeNeededInFileName(entity) ? `${fileName}.${languageCode}` : fileName; + } fileName = isExtensionNeededInFileName(entity) ? `${fileName}.${extension}` : fileName; return getSanitizedFileName(fileName); } export function isLanguageCodeNeededInFileName(entity: string) { - return entity === schemaEntityName.WEBPAGES || - entity === schemaEntityName.CONTENTSNIPPETS; + return entity === schemaEntityName.WEBPAGES ||entity === schemaEntityName.CONTENTSNIPPETS; } export function isExtensionNeededInFileName(entity: string) {