Skip to content

Commit 76f39e9

Browse files
authored
PLU-336: show error message when invalid file selected for tiles import (#787)
## Changes 1. show error message when file is too large / invalid file type 2. change default dropzone background color <img width="899" alt="image" src="https://github.com/user-attachments/assets/aef903b6-934f-4932-8988-e4825840d7f0">
1 parent 39ee755 commit 76f39e9

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

packages/frontend/src/pages/Tile/components/TableBanner/ImportCsvButton.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ const CHUNK_SIZE = 100
5454

5555
const ImportStatus = ({
5656
columnsToCreate,
57-
errorMsg,
5857
importStatus,
5958
rowsImported,
6059
rowsToImport,
6160
}: {
6261
columnsToCreate: string[]
63-
errorMsg: string | null
6462
importStatus: IMPORT_STATUS
6563
rowsImported: number
6664
rowsToImport: number
@@ -83,7 +81,7 @@ const ImportStatus = ({
8381
isColumnDataExpanded ? <BiChevronUp /> : <BiChevronDown />
8482
}
8583
>
86-
{columnsToCreate.length} column(s) to create
84+
{columnsToCreate.length} column(s) will be created
8785
</Button>
8886
<Collapse in={isColumnDataExpanded}>
8987
<List spacing={3} mt={4}>
@@ -121,7 +119,7 @@ const ImportStatus = ({
121119
</Box>
122120
)
123121
case 'error':
124-
return <Text color="red.500">Error: {errorMsg}</Text>
122+
return null
125123
}
126124
}
127125

@@ -236,6 +234,10 @@ export const ImportCsvModalContent = ({
236234
[],
237235
)
238236

237+
useEffect(() => {
238+
setErrorMsg(null)
239+
}, [file])
240+
239241
const onImport = useCallback(async () => {
240242
// do not import if no rows or columns to create
241243
if (!result?.length && !columnsToCreate.length) {
@@ -280,7 +282,7 @@ export const ImportCsvModalContent = ({
280282
} catch (e) {
281283
setImportStatus('error')
282284
if (e instanceof Error) {
283-
setErrorMsg(e.message)
285+
setErrorMsg('Error: ' + e.message)
284286
}
285287
}
286288
}, [
@@ -321,6 +323,7 @@ export const ImportCsvModalContent = ({
321323
onChange={setFile}
322324
title="Upload CSV"
323325
name="file-upload"
326+
onError={setErrorMsg}
324327
colorScheme="primary"
325328
showFileSize={true}
326329
accept={['.csv']}
@@ -337,14 +340,18 @@ export const ImportCsvModalContent = ({
337340
) : (
338341
<ImportStatus
339342
columnsToCreate={columnsToCreate}
340-
errorMsg={errorMsg}
341343
importStatus={importStatus}
342344
rowsImported={rowsImported}
343345
rowsToImport={rowsToImport}
344346
/>
345347
)}
346348
</Card>
347349
)}
350+
{errorMsg && (
351+
<Text color="red.500" textStyle="caption-2" fontSize="sm" mt={1}>
352+
{errorMsg}
353+
</Text>
354+
)}
348355
</ModalBody>
349356

350357
<ModalFooter>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { createMultiStyleConfigHelpers } from '@chakra-ui/react'
2+
import { anatomy } from '@chakra-ui/theme-tools'
3+
4+
const parts = anatomy('attachment').parts(
5+
'container',
6+
'dropzone',
7+
'icon',
8+
'fileInfoContainer',
9+
'fileInfo',
10+
'fileInfoDescription',
11+
'fileInfoImage',
12+
'fileInfoTitle',
13+
'fileInfoIcon',
14+
'fileErrorIcon',
15+
'fileErrorMessage',
16+
)
17+
18+
const { definePartsStyle, defineMultiStyleConfig } =
19+
createMultiStyleConfigHelpers(parts.keys)
20+
21+
const getDropzoneColors = definePartsStyle(({ colorScheme: c }) => {
22+
return {
23+
dropzone: {
24+
borderColor: `${c}.700`,
25+
bg: `${c}.100`,
26+
_hover: {
27+
bg: `${c}.200`,
28+
},
29+
_active: {
30+
bg: `${c}.200`,
31+
},
32+
},
33+
}
34+
})
35+
36+
const variantOutline = definePartsStyle((props) => {
37+
const colorProps = getDropzoneColors(props)
38+
39+
return {
40+
dropzone: {
41+
...colorProps.dropzone,
42+
},
43+
}
44+
})
45+
46+
const variants = {
47+
outline: variantOutline,
48+
}
49+
50+
export const Attachment = defineMultiStyleConfig({
51+
variants,
52+
})

packages/frontend/src/theme/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Attachment } from './Attachment'
12
import { Button } from './Button'
23
import { Container } from './Container'
34
import { FormLabel } from './FormLabel'
@@ -20,4 +21,5 @@ export const components = {
2021
Sidebar,
2122
SingleSelect,
2223
Radio,
24+
Attachment,
2325
}

0 commit comments

Comments
 (0)