Skip to content

Commit

Permalink
Handle null language code for content snippets and update query param…
Browse files Browse the repository at this point in the history
…eters in portal schema (#1086)

Co-authored-by: amitjoshi <[email protected]>
  • Loading branch information
amitjoshi438 and amitjoshi authored Dec 23, 2024
1 parent 3c2bdf2 commit ebbb521
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/web/client/dal/remoteFetchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
4 changes: 2 additions & 2 deletions src/web/client/schema/portalSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]),
},
Expand Down Expand Up @@ -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"]]),
},
Expand Down
10 changes: 7 additions & 3 deletions src/web/client/utilities/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit ebbb521

Please sign in to comment.