From ac34c5ae952fdc641aff63551cd3667b060ddaf2 Mon Sep 17 00:00:00 2001 From: Saurabh Sircar Date: Thu, 19 Dec 2024 15:39:59 +0530 Subject: [PATCH 1/3] feat: added initial setting of languages and locales --- .../blocks/locui-create/input-actions/view.js | 4 +-- libs/blocks/locui-create/locui-create.js | 3 +- libs/blocks/locui-create/store.js | 1 + libs/blocks/locui-create/utils/utils.js | 29 ++++++++++++++++++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/libs/blocks/locui-create/input-actions/view.js b/libs/blocks/locui-create/input-actions/view.js index c2a9ac48d8..ef08817a14 100644 --- a/libs/blocks/locui-create/input-actions/view.js +++ b/libs/blocks/locui-create/input-actions/view.js @@ -34,13 +34,13 @@ function TranslateActions({ languageCount, handleActionSelect, handleWorkflowSel diff --git a/libs/blocks/locui-create/locui-create.js b/libs/blocks/locui-create/locui-create.js index 5c0be26057..ae5e0d9133 100644 --- a/libs/blocks/locui-create/locui-create.js +++ b/libs/blocks/locui-create/locui-create.js @@ -15,7 +15,7 @@ import InputActions from './input-actions/view.js'; import Header from '../milostudio-header/milostudio-header.js'; import Sidenav from '../milostudio-sidenav/sidenav.js'; import { getConfig, loadStyle } from '../../utils/utils.js'; -import { getEnvQueryParam } from './utils/utils.js'; +import { getEnvQueryParam, setSelectedLocalesAndRegions } from './utils/utils.js'; import Toast from './components/toast.js'; function Create() { @@ -40,6 +40,7 @@ function Create() { type: 'info', message: `Project ${project.value.name} fetched succesfully.`, }); + setSelectedLocalesAndRegions(); } } } catch (error) { diff --git a/libs/blocks/locui-create/store.js b/libs/blocks/locui-create/store.js index 9bc9ebb84e..47e9d2c87a 100644 --- a/libs/blocks/locui-create/store.js +++ b/libs/blocks/locui-create/store.js @@ -206,6 +206,7 @@ export async function fetchDraftProject(projectKey) { editBehavior: resJson.settings?.regionalEditBehaviour, urls: resJson.urls, fragments: [], + languages: resJson?.languages ?? [], }); projectInfo.value = { ...projectInfo.value, diff --git a/libs/blocks/locui-create/utils/utils.js b/libs/blocks/locui-create/utils/utils.js index 3513923bc4..f46a93f6f3 100644 --- a/libs/blocks/locui-create/utils/utils.js +++ b/libs/blocks/locui-create/utils/utils.js @@ -1,6 +1,6 @@ import getServiceConfig from '../../../utils/service-config.js'; import { origin } from '../../locui/utils/franklin.js'; -import { env } from '../store.js'; +import { env, locSelected, locales as stLocales, project as stProject } from '../store.js'; export function getTenantName() { try { @@ -73,3 +73,30 @@ export function getEnvQueryParam() { const urlSearchParams = new URLSearchParams(window.location.search); return urlSearchParams.get('env') ?? 'local'; } + +export function setSelectedLocalesAndRegions() { + const { languages } = stProject.value; + const localeByLanguage = stLocales.value.reduce((acc, curr) => { + const { language } = curr; + acc[language] = curr; + return acc; + }, {}); + const selectedLocale = []; + const activeLocales = {}; + languages.forEach((loc) => { + const { language, locales } = loc; + const { livecopies = '' } = localeByLanguage[language] || {}; + if (locales.length > 0) { + locales.forEach((locale) => { + activeLocales[locale] = language; + }); + } else { + livecopies.split(',').forEach((liveCopy) => { + activeLocales[liveCopy] = language; + }); + } + selectedLocale.push(...livecopies.split(',')); + }); + selectedLocale.sort((a, b) => a.localeCompare(b)); + locSelected.value = { selectedLocale, activeLocales }; +} From d8dfa625ca13d9c121ca34775f04ac94809bf109 Mon Sep 17 00:00:00 2001 From: Saurabh Sircar Date: Thu, 19 Dec 2024 15:56:10 +0530 Subject: [PATCH 2/3] feat: added check for live copies --- libs/blocks/locui-create/utils/utils.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/blocks/locui-create/utils/utils.js b/libs/blocks/locui-create/utils/utils.js index f46a93f6f3..8f3b1eea3d 100644 --- a/libs/blocks/locui-create/utils/utils.js +++ b/libs/blocks/locui-create/utils/utils.js @@ -85,17 +85,21 @@ export function setSelectedLocalesAndRegions() { const activeLocales = {}; languages.forEach((loc) => { const { language, locales } = loc; - const { livecopies = '' } = localeByLanguage[language] || {}; + const { livecopies } = localeByLanguage[language] || {}; + const livecopiesArr = []; + if (livecopies) { + livecopiesArr.push(...livecopies.split('')); + } if (locales.length > 0) { locales.forEach((locale) => { activeLocales[locale] = language; }); } else { - livecopies.split(',').forEach((liveCopy) => { + livecopiesArr.forEach((liveCopy) => { activeLocales[liveCopy] = language; }); } - selectedLocale.push(...livecopies.split(',')); + selectedLocale.push(...livecopiesArr); }); selectedLocale.sort((a, b) => a.localeCompare(b)); locSelected.value = { selectedLocale, activeLocales }; From 15bb54d843053ea94f1ab656d665d25e3690afe7 Mon Sep 17 00:00:00 2001 From: Saurabh Sircar Date: Thu, 19 Dec 2024 16:14:46 +0530 Subject: [PATCH 3/3] feat: addded seperator --- libs/blocks/locui-create/utils/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/blocks/locui-create/utils/utils.js b/libs/blocks/locui-create/utils/utils.js index 8f3b1eea3d..46c4382304 100644 --- a/libs/blocks/locui-create/utils/utils.js +++ b/libs/blocks/locui-create/utils/utils.js @@ -88,7 +88,7 @@ export function setSelectedLocalesAndRegions() { const { livecopies } = localeByLanguage[language] || {}; const livecopiesArr = []; if (livecopies) { - livecopiesArr.push(...livecopies.split('')); + livecopiesArr.push(...livecopies.split(',')); } if (locales.length > 0) { locales.forEach((locale) => {