generated from vtex-apps/admin-example
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Feat: add async validation on uploading file #150
Merged
ArthurTriis1
merged 11 commits into
master
from
feat/Add-async-validation-pages-B2BTEAM-1544
Jan 26, 2024
+224
−22
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a109ccb
feat: Update bulk-import-ui
ArthurTriis1 9e50d4b
feat: Add useValidateBulkImport
ArthurTriis1 c8c6d74
fix: refresh interval time
ArthurTriis1 5b89ed4
feat: Add Uploading Screen async Validation
ArthurTriis1 9dc6afe
fix: Import List Data filter
ArthurTriis1 aed2834
chore: Add Changelog
ArthurTriis1 b629c64
chore: Add Changelog
ArthurTriis1 1f75c93
fix: fix useBulkImportDetailsQuery onSuccess prop
ArthurTriis1 2bf74ca
fix: Try fix ci/cd
ArthurTriis1 c5efa89
fix: Try fix ci/cd
ArthurTriis1 dc75cd6
ci: update quality-egineering version
ArthurTriis1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { useState } from 'react' | ||
import { UploadingScreen as BulkImportUploadingScreen } from '@vtex/bulk-import-ui' | ||
|
||
import type { UploadFileData } from '../../types/BulkImport' | ||
import ValidatingScreen from './ValidatingScreen' | ||
import useValidateBulkImport from '../../hooks/useValidateBulkImport' | ||
|
||
export type UploadingScreenProps = { | ||
name: string | ||
size: number | ||
uploadFile: () => Promise<UploadFileData> | ||
onUploadFinished: (data: UploadFileData) => void | ||
} | ||
|
||
export type UploadingStep = 'UPLOADING' | 'VALIDATING' | ||
|
||
const UploadingScreen = ({ | ||
uploadFile, | ||
onUploadFinished: onUploadFinishedProp, | ||
...otherProps | ||
}: UploadingScreenProps) => { | ||
const [step, setStep] = useState<UploadingStep>('UPLOADING') | ||
|
||
const [importId, setImportId] = useState<string | undefined>(undefined) | ||
|
||
const { startBulkImportValidation } = useValidateBulkImport({ | ||
onSuccess: () => { | ||
setStep('VALIDATING') | ||
}, | ||
}) | ||
|
||
const onUploadFinished = (data: UploadFileData) => { | ||
if (data.status === 'error') { | ||
onUploadFinishedProp(data) | ||
|
||
return | ||
} | ||
|
||
startBulkImportValidation({ importId: data?.data?.fileData?.importId }) | ||
setImportId(data?.data?.fileData?.importId) | ||
} | ||
|
||
return step === 'UPLOADING' ? ( | ||
<BulkImportUploadingScreen | ||
{...otherProps} | ||
uploadFile={uploadFile} | ||
onUploadFinished={onUploadFinished} | ||
/> | ||
) : ( | ||
<ValidatingScreen | ||
{...otherProps} | ||
importId={importId} | ||
onUploadFinished={onUploadFinishedProp} | ||
/> | ||
) | ||
} | ||
|
||
export default UploadingScreen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React from 'react' | ||
import { Flex, Spinner, Text, csx } from '@vtex/admin-ui' | ||
|
||
import { useTranslate } from '../../hooks' | ||
import { bytesToSize } from '../utils/bytesToSize' | ||
import type { UploadFileData } from '../../types/BulkImport' | ||
import useBulkImportDetailsQuery from '../../hooks/useBulkImportDetailsQuery' | ||
|
||
export type ValidatingScreenProps = { | ||
importId?: string | ||
name: string | ||
size: number | ||
onUploadFinished: (data: UploadFileData) => void | ||
} | ||
|
||
const ValidatingScreen = ({ | ||
name, | ||
size, | ||
importId, | ||
onUploadFinished, | ||
}: ValidatingScreenProps) => { | ||
const { translate: t } = useTranslate() | ||
|
||
useBulkImportDetailsQuery({ | ||
importId, | ||
refreshInterval: 30 * 1000, | ||
onSuccess: data => { | ||
if (data.importState === 'ReadyToImport') { | ||
onUploadFinished({ | ||
status: 'success', | ||
data: { | ||
fileData: { | ||
...data, | ||
percentage: data.percentage.toString(), | ||
}, | ||
}, | ||
}) | ||
|
||
return | ||
} | ||
|
||
onUploadFinished({ | ||
status: 'error', | ||
showReport: data?.importState === 'ValidationFailed', | ||
data: { | ||
error: 'FieldValidationError', | ||
errorDownloadLink: data?.validationResult?.reportDownloadLink ?? '', | ||
validationResult: data?.validationResult?.validationResult ?? [], | ||
fileName: data.fileName, | ||
}, | ||
}) | ||
}, | ||
}) | ||
|
||
return ( | ||
<Flex | ||
className={csx({ backgroundColor: '$gray05', height: '100%' })} | ||
align="center" | ||
direction="column" | ||
justify="center" | ||
> | ||
<Spinner className={csx({ color: '$blue40' })} size={120} /> | ||
<Text | ||
className={csx({ marginBottom: '$space-3', marginTop: '$space-10' })} | ||
variant="pageTitle" | ||
> | ||
{t('uploading')} | ||
</Text> | ||
<div> | ||
<Text>{name}</Text> | ||
<Text tone="secondary"> | ||
{' · '} | ||
{bytesToSize(size)} | ||
</Text> | ||
</div> | ||
</Flex> | ||
) | ||
} | ||
|
||
export default ValidatingScreen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as ValidationScreen } from './UploadingScreen' | ||
export type { UploadingScreenProps } from './UploadingScreen' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const bytesToSize = (bytes: number) => { | ||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'] | ||
|
||
if (bytes === 0) return '0 Bytes' | ||
const i = Math.floor(Math.log(bytes) / Math.log(1024)) | ||
|
||
if (i === 0) return `${bytes} ${sizes[i]}` | ||
|
||
return `${Math.round(bytes / 1024 ** i)}${sizes[i]}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import useSWRMutation from 'swr/mutation' | ||
|
||
import { validateBulkImport } from '../services' | ||
|
||
const useValidateBulkImport = ({ onSuccess }: { onSuccess?: () => void }) => { | ||
const { trigger } = useSWRMutation( | ||
'/buyer-orgs/start', | ||
(_, { arg }: { arg: { importId: string } }) => | ||
validateBulkImport(arg.importId), | ||
{ | ||
onSuccess, | ||
} | ||
) | ||
|
||
return { startBulkImportValidation: trigger } | ||
} | ||
|
||
export default useValidateBulkImport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import bulkImportClient from '.' | ||
|
||
const validateBulkImport = async (importId?: string): Promise<unknown> => { | ||
return bulkImportClient.post(`/buyer-orgs/validate/${importId}`) | ||
} | ||
|
||
export default validateBulkImport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Unchanged files with check annotations Beta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
}, | ||
}) | ||
const MyOrganizationLink: FC = ({ render }: any) => { | ||
const { formatMessage } = useIntl() | ||
const sessionResponse: any = useSessionResponse() | ||
const userEmail = sessionResponse?.namespaces?.profile?.email?.value | ||
const [show, setShow] = useState(false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uid = setGUID(newAddressState) | ||
const duplicated = data?.getCostCenterById?.addresses?.find( | ||
(item: any) => item.addressId === uid | ||
) | ||
let isDuplicatedError = false | ||
</PageBlock> | ||
<PageBlock title={formatMessage(messages.addresses)}> | ||
<div className="flex"> | ||
{addresses.map((address: any, index) => { | ||
return ( | ||
<div key={index} className="w-25 ma3"> | ||
<Card> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface CustomFieldsTableProps { | ||
customFields: CustomField[] | ||
handleDelete: (index: number) => void | ||
handleUpdate: (index: number, customField: any) => void | ||
} | ||
const CustomFieldsTable: React.FC<CustomFieldsTableProps> = ({ | ||
const { data, getBodyCell, getHeadCell, getTable } = useTableState({ | ||
columns, | ||
// item type is built using columns which makes it incompatible with customFields type | ||
items: customFields as any, | ||
}) | ||
return ( | ||
))} | ||
</THead> | ||
<TBody> | ||
{data.map((item: any) => { | ||
return ( | ||
<TBodyRow key={item.name}> | ||
{columns.map(column => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
collectionsState, | ||
setCollectionsState, | ||
}: { | ||
getSchema: (argument?: any) => any | ||
Check warning on line 21 in react/admin/OrganizationDetails/OrganizationDetailsCollections.tsx GitHub Actions / QE / Lint Node.js
|
||
collectionsState: Collection[] | ||
setCollectionsState: (value: any) => void | ||
}) => { | ||
/** | ||
* Hooks |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be translated? In Portuguese I think we use the same term, but not sure if we can guarantee the same for other languages.
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.
Oh, good question! I will ask to translation team and confirm.