Skip to content
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

Use meta.validating instead of manually control state #3994

Merged
merged 1 commit into from
Jun 13, 2024
Merged
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
14 changes: 6 additions & 8 deletions catalog/app/containers/Bucket/PackageDialog/FilesInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,6 @@ interface FilesInputProps {
onChange: (value: FilesState) => void
}
className?: string
disabled?: boolean
errors?: Record<string, React.ReactNode>
meta: RF.FieldMetaState<FilesState> & { initial: FilesState }
onFilesAction?: (
Expand Down Expand Up @@ -1361,7 +1360,6 @@ interface FilesInputProps {
export function FilesInput({
input: { value, onChange },
className,
disabled = false,
errors = {},
meta,
onFilesAction,
Expand Down Expand Up @@ -1391,13 +1389,13 @@ export function FilesInput({
}
}

const submitting = meta.submitting || meta.submitSucceeded
const disabled = meta.submitting || meta.submitSucceeded || meta.validating
const error =
meta.submitFailed && (meta.error || (!meta.dirtySinceLastSubmit && meta.submitError))

const refProps = {
value,
disabled: disabled || submitting,
disabled,
initial: meta.initial,
onChange,
onFilesAction,
Expand Down Expand Up @@ -1509,7 +1507,7 @@ export function FilesInput({
<Header>
<HeaderTitle
state={
submitting || disabled // eslint-disable-line no-nested-ternary
disabled // eslint-disable-line no-nested-ternary
? 'disabled'
: error // eslint-disable-line no-nested-ternary
? 'error'
Expand Down Expand Up @@ -1617,12 +1615,12 @@ export function FilesInput({

<DropzoneMessage error={error && (errors[error] || error)} warn={warn} />
</Contents>
{(submitting || disabled) && <Lock progress={totalProgress} />}
{disabled && <Lock progress={totalProgress} />}
</ContentsContainer>
<div className={classes.actions}>
<M.Button
onClick={open}
disabled={submitting || disabled}
disabled={disabled}
className={classes.action}
variant="outlined"
size="small"
Expand All @@ -1632,7 +1630,7 @@ export function FilesInput({
{isS3FilePickerEnabled ? (
<M.Button
onClick={handleS3Btn}
disabled={submitting || disabled}
disabled={disabled}
className={classes.action}
variant="outlined"
size="small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ function PackageCreationForm({
[nameWarning, nameExistence],
)

const [filesDisabled, setFilesDisabled] = React.useState(false)
const onFormChange = React.useCallback(
({ dirtyFields, values }) => {
if (dirtyFields?.name) handleNameChange(values.name)
Expand All @@ -452,11 +451,9 @@ function PackageCreationForm({
const hashihgError = delayHashing && FI.validateHashingComplete(files)
if (hashihgError) return hashihgError

setFilesDisabled(true)
const entries = filesStateToEntries(files)
const errors = await validateEntries(entries)
setEntriesError(errors || null)
setFilesDisabled(false)
if (errors?.length) {
return 'schema'
}
Expand Down Expand Up @@ -632,7 +629,6 @@ function PackageCreationForm({
validationErrors={
submitFailed ? entriesError : PD.EMPTY_ENTRIES_ERRORS
}
disabled={filesDisabled}
/>
)}

Expand Down