-
Notifications
You must be signed in to change notification settings - Fork 8
feat:updated validation code and UI components related to upload #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| { | ||
| "semi": true, | ||
| "tabWidth": 2, | ||
| "printWidth": 100, | ||
| "singleQuote": true, | ||
| "trailingComma": "none", | ||
| "jsxBracketSameLine": true | ||
| } | ||
| "semi": true, | ||
| "tabWidth": 2, | ||
| "printWidth": 100, | ||
| "singleQuote": true, | ||
| "trailingComma": "none", | ||
| "jsxBracketSameLine": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { useParams } from 'react-router'; | |
|
|
||
| // Service | ||
| import { updateLegacyCMSData } from '../../../services/api/migration.service'; | ||
| import { fileValidation } from '../../../services/api/upload.service'; | ||
|
|
||
| // Utilities | ||
| import { isEmptyString, validateArray } from '../../../utilities/functions'; | ||
|
|
@@ -88,43 +89,58 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => { | |
| updateCMSFilters(cmsFilter); | ||
| }; | ||
|
|
||
| const getCmsType = async() => { | ||
| const res:any = await fileValidation(); | ||
| const cmsType = res?.data?.file_details?.cmsType; | ||
| return cmsType; | ||
| } | ||
| // Filter CMS Data | ||
| const filterCMSData = (searchText: string) => { | ||
| const filterCMSData = async (searchText: string) => { | ||
| const { all_cms = [] } = migrationData.legacyCMSData; | ||
|
|
||
| //Default set to all CMS if Filter and search text is empty | ||
| if (isEmptyString(searchText) && !validateArray(cmsFilter)) { | ||
| setCmsData(all_cms); | ||
| return; | ||
| const cmsType = await getCmsType(); // Fetch the specific CMS type | ||
|
|
||
| let filteredCmsData: ICMSType[] = []; | ||
| if (isEmptyString(searchText) && !validateArray(cmsFilter) && !cmsType) { | ||
| filteredCmsData = all_cms; | ||
| } else { | ||
| if (cmsType) { | ||
| filteredCmsData = all_cms?.filter((cms: ICMSType) => cms?.cms_id === cmsType); | ||
| } | ||
|
|
||
| if (validateArray(cmsFilter) || !isEmptyString(searchText)) { | ||
| const searchTextLower = searchText?.toLowerCase(); | ||
| filteredCmsData = all_cms | ||
| .filter(({ parent }: ICMSType) => !cmsFilter?.length || cmsFilter?.includes(parent)) | ||
| .filter(({ title, cms_id }: ICMSType) => | ||
| title?.toLowerCase()?.includes(searchTextLower) || | ||
| cms_id?.toLowerCase()?.includes(searchTextLower) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| setCmsData(filteredCmsData); // Set filtered CMS data | ||
|
|
||
| // Determine if a new card should be selected | ||
| const newSelectedCard = filteredCmsData?.find(cms => cms?.cms_id === selectedCard?.cms_id) || filteredCmsData[0] || null; | ||
|
|
||
| if (newSelectedCard?.cms_id !== selectedCard?.cms_id) { | ||
| setSelectedCard(newSelectedCard); | ||
|
|
||
| //search base on filter applied | ||
| if (validateArray(cmsFilter)) { | ||
| const _filterCmsData = validateArray(all_cms) | ||
| ? all_cms | ||
| ?.filter(({ parent }: ICMSType) => cmsFilter?.includes(parent)) | ||
| .filter( | ||
| ({ title, cms_id }: ICMSType) => | ||
| //Filtering Criteria base on SearchText | ||
| title?.toLowerCase()?.includes(searchText) || | ||
| cms_id?.toLowerCase().includes(searchText) | ||
| ) | ||
| : []; | ||
| setCmsData(_filterCmsData); | ||
|
|
||
| return; | ||
| const newMigrationDataObj: INewMigration = { | ||
| ...newMigrationData, | ||
| legacy_cms: { | ||
| ...newMigrationData?.legacy_cms, | ||
| selectedCms: newSelectedCard | ||
| } | ||
| }; | ||
|
|
||
| updateNewMigrationData(newMigrationDataObj); | ||
|
|
||
| // API call for saving selected CMS, if a new card is selected | ||
| if (newSelectedCard) { | ||
| updateLegacyCMSData(selectedOrganisation?.value, projectId, { legacy_cms: newSelectedCard?.cms_id }); | ||
| } | ||
| } | ||
|
|
||
| //Normal Search | ||
| const _filterCmsData = validateArray(all_cms) | ||
| ? all_cms?.filter( | ||
| ({ title, cms_id }: ICMSType) => | ||
| //Filtering Criteria base on SearchText | ||
| title?.toLowerCase()?.includes(searchText) || cms_id?.toLowerCase().includes(searchText) | ||
| ) | ||
| : []; | ||
|
|
||
| setCmsData(_filterCmsData); | ||
| }; | ||
|
|
||
| /**** ALL USEEffects HERE ****/ | ||
|
|
@@ -138,7 +154,7 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => { | |
|
|
||
| return ( | ||
| <div className="row bg-white action-content-wrapper p-3"> | ||
| <div className="col-12"> | ||
| {/* <div className="col-12"> | ||
| <div className="service_list_search"> | ||
| <Search | ||
| className="service_list_search_bar" | ||
|
|
@@ -168,8 +184,8 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => { | |
| </div> | ||
| </div> | ||
| <Line type="solid" /> | ||
| </div> | ||
| <div className="col-12 mt-2"> | ||
| </div> */} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this commented code if not required
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kept for future use case ( as per my understanding if we are showing only the card for cms which user has given in config of upload service, then search will not be useful) |
||
| <div className="col-12"> | ||
| {validateArray(cmsData) ? ( | ||
|
||
| <div className="service_list"> | ||
| {cmsData?.map((data: ICMSType) => ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import { AppContext } from '../../../context/app/app.context'; | |
| import { DEFAULT_FILE, IFile, INewMigration } from '../../../context/app/app.interface'; | ||
| import { validateArray } from '../../../utilities/functions'; | ||
| import { useParams } from 'react-router'; | ||
|
|
||
| import { fileValidation } from '../../../services/api/upload.service'; | ||
| interface LoadUploadFileProps { | ||
| stepComponentProps: any; | ||
| currentStep: number; | ||
|
|
@@ -18,28 +18,46 @@ const LoadUploadFile = (props: LoadUploadFileProps) => { | |
| const { projectId = '' } = useParams(); | ||
|
|
||
| //Handle further action on file is uploaded to server | ||
| const handleOnFileUploadCompletion = (files: IFile[]) => { | ||
| const file = validateArray(files) ? files?.[0] : DEFAULT_FILE; | ||
| const handleOnFileUploadCompletion = async() => { | ||
|
|
||
| const res : any = await fileValidation(); | ||
|
|
||
| const newMigrationDataObj: INewMigration = { | ||
| ...newMigrationData, | ||
| legacy_cms: { | ||
| ...newMigrationData.legacy_cms, | ||
| uploadedFile: { ...file } | ||
| uploadedFile: { | ||
| name: res?.data?.file_details?.localPath, | ||
| url : res?.data?.file_details?.localPath, | ||
| validation: res?.data?.message, | ||
| isValidated: res?.data?.status== 200 ? true : false, | ||
| file_details: { | ||
| isLocalPath:res?.data?.file_details?.isLocalPath, | ||
| cmsType: res?.data?.file_details?.cmsType, | ||
| localPath: res?.data?.file_details?.localPath, | ||
| awsData: { | ||
| awsRegion: res?.data?.file_details?.awsData?.awsRegion, | ||
| bucketName:res?.data?.file_details?.awsData?.bucketName, | ||
| buketKey:res?.data?.file_details?.awsData?.buketKey, | ||
| } | ||
| }}, | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| updateNewMigrationData(newMigrationDataObj); | ||
| console.log(newMigrationData); | ||
|
||
|
|
||
|
|
||
| props.handleStepChange(props.currentStep, true); | ||
|
|
||
| props.handleStepChange(props.currentStep, true); | ||
|
|
||
| }; | ||
|
|
||
| const allowedFileExtentions = `.${ | ||
| newMigrationData?.legacy_cms?.selectedFileFormat?.title || 'zip' | ||
| }`; | ||
| useEffect(() => { | ||
| handleOnFileUploadCompletion([]); | ||
| }); | ||
| handleOnFileUploadCompletion(); | ||
| },[newMigrationData]); | ||
|
|
||
| return ( | ||
| <div className="row"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| import { useContext } from 'react'; | ||
| import { AppContext } from '../../../context/app/app.context'; | ||
| import { Icon } from '@contentstack/venus-components'; | ||
| import './summary.scss'; | ||
| import { TRASH } from '../../../common/assets'; | ||
| import { isEmptyString } from '../../../utilities/functions'; | ||
| import { IStep } from '../../../context/app/app.interface'; | ||
|
|
||
|
|
@@ -11,31 +9,60 @@ interface UploadFileSummaryProps { | |
| stepData: IStep; | ||
| } | ||
|
|
||
| import { FileDetails } from '../../../context/app/app.interface'; | ||
|
|
||
| interface Props { | ||
| fileDetails: FileDetails; | ||
| } | ||
|
|
||
| const FileComponent : React.FC<Props>= ({fileDetails}) => { | ||
| return ( | ||
| <div className='col-11'> | ||
| <p className="summary-title">Is Local Path: {fileDetails.isLocalPath ? 'Yes' : 'No'}</p> | ||
| <p className="summary-title">CMS Type: {fileDetails.cmsType}</p> | ||
| <p className="summary-title">Local Path: {fileDetails.localPath}</p> | ||
| <p className="summary-title">AWS Region: {fileDetails.awsData.awsRegion}</p> | ||
| <p className="summary-title">Bucket Name: {fileDetails.awsData.bucketName}</p> | ||
| <p className="summary-title">Bucket Key: {fileDetails.awsData.buketKey}</p> | ||
| </div> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add validation
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| ); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| const UploadFileSummary = ({ | ||
| stepComponentProps, | ||
| stepData | ||
| }: UploadFileSummaryProps): JSX.Element => { | ||
| const { newMigrationData } = useContext(AppContext); | ||
|
|
||
|
|
||
| return ( | ||
| <div className="row bg-white"> | ||
| {!isEmptyString(newMigrationData?.legacy_cms?.uploadedFile?.name) ? ( | ||
| <> | ||
| {!isEmptyString(newMigrationData?.legacy_cms?.uploadedFile?.name) | ||
| ? ( | ||
| <div className="col-11 "> | ||
| <Icon icon="File" size="medium" className="configure_action_logo" /> | ||
| <span className="summary-title"> | ||
| {newMigrationData?.legacy_cms?.uploadedFile?.name || ''} | ||
| </span> | ||
| </div> | ||
| <div className="col-1 "> | ||
| <button className="btn p-0" onClick={stepComponentProps?.handleDeleteFile}> | ||
| {TRASH} | ||
| </button> | ||
| <FileComponent fileDetails={newMigrationData?.legacy_cms?.uploadedFile?.file_details}/> | ||
| <br></br> | ||
| <span className="summary-title">{newMigrationData?.legacy_cms?.uploadedFile?.validation}</span> | ||
|
|
||
| {!newMigrationData?.legacy_cms?.uploadedFile?.isValidated | ||
| ? | ||
| (<p className=' ValidationMessage__v2'>Please upload the correct file</p>) : | ||
| (<></>) | ||
| } | ||
|
|
||
| </div> | ||
| </> | ||
|
|
||
|
|
||
| ) : ( | ||
| <div className="col-12 bg-white"> | ||
| <span className="summary-title">{stepData?.empty_step_placeholder}</span> | ||
| {!newMigrationData?.legacy_cms?.uploadedFile?.isValidated | ||
| ? | ||
| (<p className=' ValidationMessage__v2'>Please upload the correct file</p>) : | ||
| (<></>) | ||
| } | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add ?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done