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

fix: prevent removal of last character on no filename extension #120

Merged
merged 2 commits into from
Feb 3, 2023
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
19 changes: 5 additions & 14 deletions src/components/DialogAssetEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import AssetMetadata from '../AssetMetadata'
import Dialog from '../Dialog'
import DocumentList from '../DocumentList'
import FileAssetPreview from '../FileAssetPreview'
import FormFieldInputFilename from '../FormFieldInputFilename'
import FormFieldInputTags from '../FormFieldInputTags'
import FormFieldInputText from '../FormFieldInputText'
import FormFieldInputTextarea from '../FormFieldInputTextarea'
Expand All @@ -35,14 +34,9 @@ type Props = {
type FormData = yup.InferType<typeof formSchema>

const formSchema = yup.object().shape({
originalFilename: yup.string().required('Filename cannot be empty')
originalFilename: yup.string().trim().required('Filename cannot be empty')
})

const getFilenameWithoutExtension = (asset?: Asset): string | undefined => {
const extensionIndex = asset?.originalFilename?.toLowerCase().lastIndexOf(`.${asset.extension}`)
return asset?.originalFilename?.slice(0, extensionIndex)
}

const DialogAssetEdit = (props: Props) => {
const {
children,
Expand Down Expand Up @@ -73,7 +67,7 @@ const DialogAssetEdit = (props: Props) => {
const generateDefaultValues = (asset?: Asset) => ({
altText: asset?.altText || '',
description: asset?.description || '',
originalFilename: asset ? getFilenameWithoutExtension(asset) : undefined,
originalFilename: asset?.originalFilename || '',
opt: {media: {tags: assetTagOptions}},
title: asset?.title || ''
})
Expand Down Expand Up @@ -165,9 +159,7 @@ const DialogAssetEdit = (props: Props) => {
_weak: true
})) || null
}
},
// Append extension to filename
originalFilename: `${sanitizedFormData.originalFilename}.${assetItem?.asset.extension}`
}
}
})
)
Expand Down Expand Up @@ -323,14 +315,13 @@ const DialogAssetEdit = (props: Props) => {
value={assetTagOptions}
/>
{/* Filename */}
<FormFieldInputFilename
<FormFieldInputText
disabled={formUpdating}
error={errors?.originalFilename}
extension={currentAsset?.extension || ''}
label="Filename"
name="originalFilename"
ref={register}
value={getFilenameWithoutExtension(currentAsset)}
value={currentAsset?.originalFilename}
/>
{/* Title */}
<FormFieldInputText
Expand Down
50 changes: 0 additions & 50 deletions src/components/FormFieldInputFilename/index.tsx

This file was deleted.