From 5daed6b945baa404b7547bb345581f2067ca34d7 Mon Sep 17 00:00:00 2001 From: Viktor Stefanov Date: Wed, 18 Sep 2024 15:29:37 +0300 Subject: [PATCH] file name formating before render, tooltip added for full file name view on hover --- .../client/irregularity/helpers/FileList.tsx | 18 ++++++++++--- .../irregularity/helpers/formatFileName.ts | 12 +++++++++ .../client/irregularity/steps/Info.tsx | 26 ++++++++++++------- 3 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 src/components/client/irregularity/helpers/formatFileName.ts diff --git a/src/components/client/irregularity/helpers/FileList.tsx b/src/components/client/irregularity/helpers/FileList.tsx index 2755affd7..60cce893a 100644 --- a/src/components/client/irregularity/helpers/FileList.tsx +++ b/src/components/client/irregularity/helpers/FileList.tsx @@ -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[] @@ -24,8 +34,10 @@ function FileList({ files, onDelete }: Props) { - - + + + + ))} diff --git a/src/components/client/irregularity/helpers/formatFileName.ts b/src/components/client/irregularity/helpers/formatFileName.ts new file mode 100644 index 000000000..37d875e77 --- /dev/null +++ b/src/components/client/irregularity/helpers/formatFileName.ts @@ -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}` + } +} diff --git a/src/components/client/irregularity/steps/Info.tsx b/src/components/client/irregularity/steps/Info.tsx index 873dc92c7..0f3074be9 100644 --- a/src/components/client/irregularity/steps/Info.tsx +++ b/src/components/client/irregularity/steps/Info.tsx @@ -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' @@ -103,21 +104,28 @@ export default function Info({ files, setFiles }: Props) { {t('steps.info.files')} - + { setFiles((prevFiles: File[]) => [...prevFiles, ...newFiles]) }} buttonLabel={t('cta.upload-files')} /> - - setFiles((prevFiles: File[]) => - prevFiles.filter((file: File) => file.name !== deletedFile.name), - ) - } - /> + + + setFiles((prevFiles: File[]) => + prevFiles.filter((file: File) => file.name !== deletedFile.name), + ) + } + /> +