Skip to content
Merged

Dev #374

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
93 changes: 66 additions & 27 deletions ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<string>();

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 },
}));
}
});
Expand Down Expand Up @@ -493,7 +528,8 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
});

}
},[contentTypeSchema]);

},[otherContentType]);

// To dispatch the changed dropdown state
// useEffect(() => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
35 changes: 20 additions & 15 deletions ui/src/components/TestMigration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ const TestMigration = () => {
const [data, setData] = useState<MigrationType>({});
const [isLoading, setIsLoading] = useState(newMigrationData?.isprojectMapped);
const [isStackLoading, setIsStackLoading] = useState<boolean>(false);
const [disableTestMigration, setdisableTestMigration] = useState<boolean>(newMigrationData?.test_migration?.isMigrationStarted);
const [disableTestMigration, setDisableTestMigration] = useState<boolean>(newMigrationData?.test_migration?.isMigrationStarted);

const [disableCreateStack, setDisableCreateStack] = useState<boolean>(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<boolean>(false);
const [stackLimitReached, setStackLimitReached] = useState<boolean>(false);



// Extract project ID from URL parameters
const { projectId = '' } = useParams();
Expand All @@ -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
*/
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -185,7 +190,7 @@ const TestMigration = () => {
);

if (testRes?.status === 200) {
setdisableTestMigration(true);
setDisableTestMigration(true);

//dispatch test migration started flag in redux
const newMigrationDataObj : INewMigration = {
Expand Down Expand Up @@ -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);
}
} ;

Expand Down