Skip to content
Closed
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
36 changes: 12 additions & 24 deletions ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ const FileComponent = ( { fileDetails, fileFormatId }: Props ) =>
<div>
{ isSQL ? (
// ✅ SQL format (from legacyCms.json allowed_file_formats): show MySQL details
fileDetails?.mySQLDetails && (
fileDetails?.mysql && (
<div>
<p className="pb-2">Host: { fileDetails?.mySQLDetails?.host }</p>
<p className="pb-2">Database: { fileDetails?.mySQLDetails?.database }</p>
<p className="pb-2">User: { fileDetails?.mySQLDetails?.user }</p>
<p className="pb-2">Host: { fileDetails?.mysql?.host }</p>
<p className="pb-2">Database: { fileDetails?.mysql?.database }</p>
<p className="pb-2">User: { fileDetails?.mysql?.user }</p>
</div>
)
) : fileDetails?.isLocalPath ? (
Expand Down Expand Up @@ -176,11 +176,11 @@ const LoadUploadFile = ( props: LoadUploadFileProps ) =>
bucketName: responseFileDetails?.awsData?.bucketName,
bucketKey: responseFileDetails?.awsData?.bucketKey
},
mySQLDetails: {
host: responseFileDetails?.mySQLDetails?.host,
user: responseFileDetails?.mySQLDetails?.user,
database: responseFileDetails?.mySQLDetails?.database,
port: responseFileDetails?.mySQLDetails?.port
mysql: {
host: responseFileDetails?.mysql?.host,
user: responseFileDetails?.mysql?.user,
database: responseFileDetails?.mysql?.database,
port: responseFileDetails?.mysql?.port
},
assetsConfig: {
base_url: responseFileDetails?.assetsConfig?.base_url,
Expand All @@ -206,7 +206,7 @@ const LoadUploadFile = ( props: LoadUploadFileProps ) =>

// Update the ref immediately before dispatching to avoid stale data in subsequent operations
newMigrationDataRef.current = newMigrationDataObj;
dispatch( updateNewMigrationData( newMigrationDataObj ) );


// Derive SQL check from selectedFileFormat (data-driven via legacyCms.json)
const currentFormatId = newMigrationDataObj?.legacy_cms?.selectedFileFormat?.fileformat_id?.toLowerCase();
Expand Down Expand Up @@ -295,6 +295,7 @@ const LoadUploadFile = ( props: LoadUploadFileProps ) =>
setProcessing( 'Processing...100%' );

await new Promise( ( resolve ) => setTimeout( resolve, 1000 ) );
dispatch( updateNewMigrationData( newMigrationDataObj ) );

setTimeout( () =>
{
Expand Down Expand Up @@ -437,24 +438,11 @@ const LoadUploadFile = ( props: LoadUploadFileProps ) =>
}
};

// Update fileDetails whenever Redux state changes
useEffect( () =>
{
const latestFileDetails = newMigrationData?.legacy_cms?.uploadedFile?.file_details;

// Always update fileDetails from Redux, even if it's empty (to clear stale data)
setFileDetails( latestFileDetails );

}, [ newMigrationData?.legacy_cms?.uploadedFile?.file_details ] );

useEffect( () =>
{
getConfigDetails();
}, [
// Re-run when selectedFileFormat or file_details change (e.g., after LoadSelectCms or fetchProjectData dispatches)
newMigrationData?.legacy_cms?.selectedFileFormat?.fileformat_id,
newMigrationData?.legacy_cms?.uploadedFile?.file_details?.localPath
] );
}, [] );

useEffect( () =>
{
Expand Down
2 changes: 1 addition & 1 deletion ui/src/context/app/app.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface FileDetails {
bucketName?: string;
bucketKey?: string;
};
mySQLDetails?: {
mysql?: {
host?: string;
user?: string;
database?: string;
Expand Down
34 changes: 32 additions & 2 deletions ui/src/pages/Migration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ const Migration = () => {
awsRegion: data?.awsData?.awsRegion,
bucketName: data?.awsData?.bucketName,
bucketKey: data?.awsData?.bucketKey
},
mysql: {
host: data?.mysql?.host,
user: data?.mysql?.user,
database: data?.mysql?.database,
port: data?.mysql?.port
},
assetsConfig: {
base_url: data?.assetsConfig?.base_url,
public_path: data?.assetsConfig?.public_path
}
},
cmsType: data?.cmsType
Expand Down Expand Up @@ -382,7 +392,17 @@ const Migration = () => {
bucketName: projectData?.legacy_cms?.awsDetails?.bucketName,
bucketKey: projectData?.legacy_cms?.awsDetails?.bucketKey
},
isLocalPath: projectData?.legacy_cms?.is_localPath
isLocalPath: projectData?.legacy_cms?.is_localPath,
mysql: {
host: projectData?.legacy_cms?.myql?.host,
user: projectData?.legacy_cms?.mysql?.user,
database: projectData?.legacy_cms?.mysql?.database,
port: projectData?.legacy_cms?.mysql?.port
},
assetsConfig: {
base_url: projectData?.legacy_cms?.assetsConfig?.base_url,
public_path: projectData?.legacy_cms?.assetsConfig?.public_path
}
},
isValidated: projectData?.legacy_cms?.is_fileValid,
reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate,
Expand All @@ -400,7 +420,17 @@ const Migration = () => {
awsRegion: uploadObj?.file_details?.awsData?.awsRegion || newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details?.awsData?.awsRegion,
bucketName: uploadObj?.file_details?.awsData?.bucketName || newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details?.awsData?.bucketName,
bucketKey: uploadObj?.file_details?.awsData?.bucketKey || newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details?.awsData?.bucketKey,
}
},
mysql: {
host: uploadObj?.file_details?.mysql?.host || newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details?.mysql?.host,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can optimized this code
const fromUpload = uploadObj?.file_details;
const fromLegacy =
newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details;

mysql: {
host: fromUpload?.mysql?.host || fromLegacy?.mysql?.host,
user: fromUpload?.mysql?.user || fromLegacy?.mysql?.user,
database: fromUpload?.mysql?.database || fromLegacy?.mysql?.database,
port: fromUpload?.mysql?.port || fromLegacy?.mysql?.port,
},
assetsConfig: {
base_url: fromUpload?.assetsConfig?.base_url || fromLegacy?.assetsConfig?.base_url,
public_path:
fromUpload?.assetsConfig?.public_path || fromLegacy?.assetsConfig?.public_path,
},

user: uploadObj?.file_details?.mysql?.user || newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details?.mysql?.user,
database: uploadObj?.file_details?.mysql?.database || newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details?.mysql?.database,
port: uploadObj?.file_details?.mysql?.port || newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details?.mysql?.port,
},
assetsConfig: {
base_url: uploadObj?.file_details?.assetsConfig?.base_url || newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details?.assetsConfig?.base_url,
public_path: uploadObj?.file_details?.assetsConfig?.public_path || newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details?.assetsConfig?.public_path,
}
}
},
isFileFormatCheckboxChecked: true,
Expand Down
Loading