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

file name formating before render, tooltip added for full file name #1940

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 15 additions & 3 deletions src/components/client/irregularity/helpers/FileList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import React from 'react'

import { Delete, UploadFile } from '@mui/icons-material'
import { Avatar, IconButton, List, ListItem, ListItemAvatar, ListItemText } from '@mui/material'
import {
Avatar,
IconButton,
List,
ListItem,
ListItemAvatar,
ListItemText,
Tooltip,
} from '@mui/material'

import { formatFileName } from './formatFileName'

type Props = {
files: File[]
Expand All @@ -24,8 +34,10 @@ function FileList({ files, onDelete }: Props) {
<UploadFile />
</Avatar>
</ListItemAvatar>
<ListItemText primary={file.type} />
<ListItemText primary={file.name} />
<ListItemText primary={file.type} sx={{ maxWidth: '300px' }} />
<Tooltip title={file.name}>
<ListItemText primary={formatFileName(file.name)} />
</Tooltip>
</ListItem>
))}
</List>
Expand Down
12 changes: 12 additions & 0 deletions src/components/client/irregularity/helpers/formatFileName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const formatFileName = (fileName: string) => {
const maxLength = 15
if (fileName.length <= maxLength) return fileName

const fileExtension = fileName.split('.').pop()
if (fileExtension) {
const nameWithoutExtension = fileName.slice(0, -(fileExtension.length + 1))
return `${nameWithoutExtension.slice(0, 6)}...${nameWithoutExtension.slice(
-6,
)}.${fileExtension}`
}
}
26 changes: 17 additions & 9 deletions src/components/client/irregularity/steps/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Subtitle from '../helpers/Subtitle'
import FileList from '../helpers/FileList'
import { NotifierTypes } from '../helpers/irregularity.types'
import IrregularityReasonSelect from '../helpers/IrregularityReasonSelect'
import { Box } from '@mui/material'

import theme from 'common/theme'

Expand Down Expand Up @@ -103,21 +104,28 @@ export default function Info({ files, setFiles }: Props) {
{t('steps.info.files')}
</Typography>
</Grid>
<Grid container justifyContent="center" mt={2}>
<Grid
container
justifyContent={'center'}
flexDirection={'column'}
alignItems={'center'}
mt={4}>
<FileUpload
onUpload={(newFiles) => {
setFiles((prevFiles: File[]) => [...prevFiles, ...newFiles])
}}
buttonLabel={t('cta.upload-files')}
/>
<FileList
files={files}
onDelete={(deletedFile) =>
setFiles((prevFiles: File[]) =>
prevFiles.filter((file: File) => file.name !== deletedFile.name),
)
}
/>
<Box sx={{ width: '100%', marginTop: theme.spacing(2) }}>
<FileList
files={files}
onDelete={(deletedFile) =>
setFiles((prevFiles: File[]) =>
prevFiles.filter((file: File) => file.name !== deletedFile.name),
)
}
/>
</Box>
</Grid>
</Grid>
<Grid item xs={12}>
Expand Down
Loading