diff --git a/client/components/Application/Dialogs/FileUpload.tsx b/client/components/Application/Dialogs/FileUpload.tsx index 96a0e3cf2..f13b26bfb 100644 --- a/client/components/Application/Dialogs/FileUpload.tsx +++ b/client/components/Application/Dialogs/FileUpload.tsx @@ -20,18 +20,12 @@ import InputAdornment from '@mui/material/InputAdornment' import * as helpers from '../../../helpers' export default function FileUploadDialog() { - const [errorMessage, setErrorMessage] = React.useState('') + const [value, setValue] = React.useState(0) const handleClose = () => { store.closeDialog() } - const [value, setValue] = React.useState(0) - - const [remoteUrlValue, setRemoteUrlValue] = React.useState('') - - const [loading, setLoading] = React.useState(false) - function a11yProps(index: number) { return { id: `simple-tab-${index}`, @@ -55,46 +49,6 @@ export default function FileUploadDialog() { setValue(newValue) } - const inputFileRef = React.useRef(null) - const inputFolderRef = React.useRef(null) - - const onAddRemoteTextfieldChange = (url: string) => { - if (errorMessage) { - setErrorMessage('') - } else { - setRemoteUrlValue(url) - } - } - - const onAddRemoteConfirm = async (url: string) => { - if (!url) { - setErrorMessage('The URL is blank') - return - } - - if (!helpers.isUrlValid(url)) { - setErrorMessage('The URL is not valid') - return - } - - try { - setLoading(true) - await store.fetchFile(url) - store.openDialog('openLocation') - } catch (error) { - if (url.includes('docs.google.com/spreadsheets')) { - setErrorMessage( - 'The Google Sheets URL is not valid or the table is not publically available' - ) - } else { - setErrorMessage('The URL is not associated with a table') - } - return - } finally { - setLoading(false) - } - } - const isWebkitDirectorySupported = 'webkitdirectory' in document.createElement('input') if (!isWebkitDirectorySupported) return null @@ -141,111 +95,188 @@ export default function FileUploadDialog() { - - - theme.palette.primary.main, - }, - }} - > - ) => { - if (ev.target.files) { - await store.addFiles(ev.target.files) - store.openDialog('openLocation') - } - }} - /> - - - Icon Upload File - - Add one or more Excel or csv files - - Select - - - - theme.palette.primary.main, - }, - }} - > - ) => { - if (ev.target.files) { - store.addFiles(ev.target.files) - store.closeDialog() - } - }} - // @ts-expect-error - webkitdirectory="" - /> - - - Icon Upload File - - Add one or more folders - - Select - - - - - + - - - Link to the external table: - - - - {loading ? ( - - ) : null} - - onAddRemoteConfirm(remoteUrlValue)} - /> - + ) } +function LocalFileForm(props: { tabRefForHeight: React.Ref }) { + const inputFileRef = React.useRef(null) + const inputFolderRef = React.useRef(null) + + return ( + + + theme.palette.primary.main, + }, + }} + > + ) => { + if (ev.target.files) { + await store.addFiles(ev.target.files) + store.openDialog('openLocation') + } + }} + /> + + + Icon Upload File + + Add one or more Excel or csv files + Select + + + theme.palette.primary.main, + }, + }} + > + ) => { + if (ev.target.files) { + store.addFiles(ev.target.files) + store.closeDialog() + } + }} + // @ts-expect-error + webkitdirectory="" + /> + + + Icon Upload File + + Add one or more folders + Select + + + + + ) +} + +function RemoteFileForm(props: { tabHeight: number }) { + const [errorMessage, setErrorMessage] = React.useState('') + const [loading, setLoading] = React.useState(false) + const [value, setValue] = React.useState('') + + const handleChange = (value: string) => { + setValue(value) + + if (errorMessage) { + setErrorMessage('') + } + } + + const handleUpload = async () => { + if (!value) { + setErrorMessage('The URL is blank') + return + } + + if (!helpers.isUrlValid(value)) { + setErrorMessage('The URL is not valid') + return + } + + try { + setLoading(true) + await store.fetchFile(value) + store.openDialog('openLocation') + } catch (error) { + if (value.includes('docs.google.com/spreadsheets')) { + setErrorMessage( + 'The Google Sheets URL is not valid or the table is not publically available' + ) + } else { + setErrorMessage('The URL is not associated with a table') + } + return + } finally { + setLoading(false) + } + } + + return ( + + + Link to the external table: + + + + + + ), + sx: { + '& ::placeholder': { + color: '#D1D4DB', + opacity: 1, // otherwise firefox shows a lighter colorS + fontSize: '14px', + }, + }, + }} + value={value} + onChange={(e) => handleChange(e.target.value)} + /> + {loading ? ( + + ) : null} + + + + ) +} + function CustomTabPanel(props: { children?: React.ReactNode index: number @@ -261,48 +292,11 @@ function CustomTabPanel(props: { aria-labelledby={`simple-tab-${index}`} {...other} > - {value === index && {children}} + {children} ) } -function AddRemoteTextfield(props: { - errorMessage?: string - value: string - onChange(value: string): void -}) { - return ( - - - - ), - sx: { - '& ::placeholder': { - color: '#D1D4DB', - opacity: 1, // otherwise firefox shows a lighter colorS - fontSize: '14px', - }, - }, - }} - value={props.value} - onChange={(e) => props.onChange(e.target.value)} - /> - ) -} - const FileSelectBox = styled(Box)(() => ({ border: '1px solid #E7E9E9', borderRadius: '8px', diff --git a/package.json b/package.json index bb168726e..c3d65b2b8 100644 --- a/package.json +++ b/package.json @@ -52,9 +52,9 @@ "@inovua/reactdatagrid-community": "5.10.1", "@modyfi/vite-plugin-yaml": "1.1.0", "@monaco-editor/react": "4.5.1", - "@mui/icons-material": "5.14.1", - "@mui/material": "5.14.2", - "@mui/system": "5.14.1", + "@mui/icons-material": "5.16.7", + "@mui/material": "5.16.7", + "@mui/system": "5.16.7", "@mui/x-date-pickers": "6.10.1", "@mui/x-tree-view": "6.0.0-alpha.4", "@types/js-yaml": "4.0.5",