From b3e96d4ad689d938654a201ad1430c06d225fc89 Mon Sep 17 00:00:00 2001 From: Sayali Joshi Date: Sat, 7 Dec 2024 18:14:07 +0530 Subject: [PATCH 1/2] Create Test stack button condition added to disable when come from Dashboard --- ui/src/components/TestMigration/index.tsx | 35 +++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/ui/src/components/TestMigration/index.tsx b/ui/src/components/TestMigration/index.tsx index a6388da76..3f63aa0ac 100644 --- a/ui/src/components/TestMigration/index.tsx +++ b/ui/src/components/TestMigration/index.tsx @@ -48,10 +48,12 @@ const TestMigration = () => { const [data, setData] = useState({}); const [isLoading, setIsLoading] = useState(newMigrationData?.isprojectMapped); const [isStackLoading, setIsStackLoading] = useState(false); - const [disableTestMigration, setdisableTestMigration] = useState(newMigrationData?.test_migration?.isMigrationStarted); + const [disableTestMigration, setDisableTestMigration] = useState(newMigrationData?.test_migration?.isMigrationStarted); - const [disableCreateStack, setDisableCreateStack] = useState(newMigrationData?.test_migration?.stack_api_key && ! newMigrationData?.testStacks?.find((stack)=>stack?.stackUid === newMigrationData?.test_migration?.stack_api_key)?.isMigrated || newMigrationData?.test_migration?.isMigrationStarted ); + const [disableCreateStack, setDisableCreateStack] = useState(false); const [stackLimitReached, setStackLimitReached] = useState(false); + + // Extract project ID from URL parameters const { projectId = '' } = useParams(); @@ -78,28 +80,31 @@ const TestMigration = () => { * to disable Create Test Stack and Start Test Migration buttons as per isMigrated state */ useEffect(() => { - if (!newMigrationData?.testStacks?.find((stack) => stack?.stackUid === newMigrationData?.test_migration?.stack_api_key)?.isMigrated && !disableTestMigration) { - //setDisableCreateStack(false); - } + // Check if the stack_api_key exists and evaluate the logic + const shouldDisable = newMigrationData?.test_migration?.stack_api_key + ? !newMigrationData?.testStacks?.some( + (stack) => + stack?.stackUid === newMigrationData?.test_migration?.stack_api_key && + stack.isMigrated + ) || newMigrationData?.test_migration?.isMigrationStarted + : false; + + setDisableCreateStack(shouldDisable); if (newMigrationData?.testStacks?.find((stack) => stack?.stackUid === newMigrationData?.test_migration?.stack_api_key)?.isMigrated === true) { - setdisableTestMigration(true); + setDisableTestMigration(true); } - }, [newMigrationData?.testStacks]); + }, [newMigrationData]); useEffect(() => { - // Retrieve and apply saved state from sessionStorage const savedState = getStateFromLocalStorage(projectId); if (savedState) { - setdisableTestMigration(savedState?.isTestMigrationStarted); + setDisableTestMigration(savedState?.isTestMigrationStarted); setDisableCreateStack(savedState?.isTestMigrationStarted); } - },[]); - - /** * Handles create test stack function */ @@ -152,7 +157,7 @@ const TestMigration = () => { if (res?.status === 200) { setIsStackLoading(false); setDisableCreateStack(true); - setdisableTestMigration(false) + setDisableTestMigration(false) Notification({ notificationContent: { text: 'Test Stack created successfully' }, notificationProps: { @@ -185,7 +190,7 @@ const TestMigration = () => { ); if (testRes?.status === 200) { - setdisableTestMigration(true); + setDisableTestMigration(true); //dispatch test migration started flag in redux const newMigrationDataObj : INewMigration = { @@ -225,7 +230,7 @@ const TestMigration = () => { const handleMigrationState = (newState: boolean) => { setDisableCreateStack(newState); if (newMigrationData?.testStacks?.find((stack) => stack?.stackUid === newMigrationData?.test_migration?.stack_api_key)?.isMigrated === true) { - setdisableTestMigration(!newState); + setDisableTestMigration(!newState); } } ; From 65b1ae28a26aaa0e7339600362a526a0c8e5b78e Mon Sep 17 00:00:00 2001 From: AishDani Date: Sat, 7 Dec 2024 18:15:35 +0530 Subject: [PATCH 2/2] refactor:fetch bugs and disable content type from cs if mapped --- ui/src/components/ContentMapper/index.tsx | 93 ++++++++++++++++------- 1 file changed, 66 insertions(+), 27 deletions(-) diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index a17ae439f..64c4a873a 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -333,7 +333,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R // useEffect for rendering mapped fields with existing stack useEffect(() => { - console.log(otherContentType); if (newMigrationData?.content_mapping?.content_type_mapping?.[selectedContentType?.contentstackUid || ''] === otherContentType?.id) { tableData?.forEach((row) => { @@ -464,7 +463,43 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R matchedKeys.add(key); setExistingField((prevOptions: ExistingFieldType) => ({ ...prevOptions, - [key]: { label: schemaItem?.display_name, value: schemaItem }, + [key]: { label: `${item?.display_name} > ${schemaItem?.display_name}`, value: schemaItem }, + })); + } + }); + } + } + }); + + if(newMigrationData?.content_mapping?.content_type_mapping?.[otherCmsTitle] !== otherContentType?.label){ + setSelectedOptions([]); + } + + } + + },[contentTypeSchema]); + useEffect(() => { + if (existingField) { + const matchedKeys = new Set(); + + contentTypeSchema?.forEach((item) => { + for (const [key, value] of Object.entries(existingField)) { + if (value?.value?.uid === item?.uid) { + matchedKeys.add(key); + + setExistingField((prevOptions: ExistingFieldType) => ({ + ...prevOptions, + [key]: { label: item?.display_name, value: item }, + })); + } + if (item?.data_type === "group" && Array.isArray(item?.schema)) { + item.schema.forEach((schemaItem) => { + if (value?.value?.uid === schemaItem?.uid) { + + matchedKeys.add(key); + setExistingField((prevOptions: ExistingFieldType) => ({ + ...prevOptions, + [key]: { label: `${item?.display_name} > ${schemaItem?.display_name}`, value: schemaItem }, })); } }); @@ -493,7 +528,8 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R }); } - },[contentTypeSchema]); + + },[otherContentType]); // To dispatch the changed dropdown state // useEffect(() => { @@ -1029,6 +1065,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R ...row, contentstackField: selectedValue?.label, contentstackFieldUid: selectedValue?.uid, + contentstackFieldType: selectedValue?.value?.field_metadata?.allow_rich_text ? 'html' : row?.contentstackFieldType, advanced: { validationRegex: selectedValue?.value?.format, mandatory: selectedValue?.value?.mandatory, @@ -1127,6 +1164,8 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R return value?.data_type === 'reference'; case 'boolean': return value?.data_type === 'boolean'; + case 'link': + return value?.data_type === 'link'; default: return false; } @@ -1457,21 +1496,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R ) { setContentTypeMapped((prevState: ContentTypeMap) => ({ ...prevState, - [otherCmsTitle]: otherContentType?.label + [selectedContentType?.contentstackUid]: otherContentType?.id ?? '' })); - const newMigrationDataObj: INewMigration = { - ...newMigrationData, - content_mapping: { - ...newMigrationData?.content_mapping, - content_type_mapping: { - - ...newMigrationData?.content_mapping?.content_type_mapping ?? {}, - [selectedContentType?.contentstackUid]: otherContentType?.id || '' - } - } - }; - dispatch(updateNewMigrationData(newMigrationDataObj)); } if (orgId && contentTypeUid && selectedContentType) { @@ -1506,13 +1533,21 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R type: 'success' }); setIsDropDownChanged(false); - const newMigrationDataObj: INewMigration = { ...newMigrationData, - content_mapping: { ...newMigrationData?.content_mapping, isDropDownChanged: false } + content_mapping: { + ...newMigrationData?.content_mapping, + content_type_mapping: { + + ...newMigrationData?.content_mapping?.content_type_mapping, + [selectedContentType?.contentstackUid]: otherContentType?.id ?? '' + } , + isDropDownChanged: false + } }; - - dispatch(updateNewMigrationData((newMigrationDataObj))); + dispatch(updateNewMigrationData(newMigrationDataObj)); + + const savedCT = filteredContentTypes?.map(ct => ct?.id === data?.data?.updatedContentType?.id ? { ...ct, status: data?.data?.updatedContentType?.status } : ct @@ -1597,7 +1632,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R setContentTypeMapped((prevState: ContentTypeMap) => { const newState = { ...prevState }; - delete newState[otherCmsTitle]; + delete newState[selectedContentType?.contentstackUid ?? '']; newstate = newState; return newstate; @@ -1804,12 +1839,16 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R }); } - const options = contentModels?.map((item) => ({ - label: item?.title, - value: item?.title, - id: item?.uid, - isDisabled: false - })); + const options = contentModels?.map((item) => { + return { + label: item?.title, + value: item?.title, + id: item?.uid, + isDisabled: (contentTypeMapped && Object.values(contentTypeMapped).includes(item?.uid)) + }; + }); + + const adjustedOption = options?.map((option) => ({ ...option,