Skip to content

Commit

Permalink
Merge pull request #76 from dartmouth-cs52-20X/cs/file-validation
Browse files Browse the repository at this point in the history
File and Alias Validation
  • Loading branch information
jeffzyliu authored Sep 1, 2020
2 parents 67e8739 + 2de26ef commit bbd1377
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/pages/codeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ Statistics/Data Analysis`;
const [uploading, setUploading] = useState(false);
const [runLoading, setRunLoading] = useState(false);

// const validFileExtensions = ['.csv'];

const tabStyle = {
minWidth: 124,
paddingLeft: 10,
Expand Down Expand Up @@ -237,7 +239,10 @@ Statistics/Data Analysis`;

// handles the situation where we are uploading by file
const handleFileUpload = () => {
if (fileToUpload && alias) {
// alias cannot have whitespace
if (alias.indexOf(' ') >= 0) {
handleAlert('error: Alias must not contain any white space characters', 'error');
} else if (fileToUpload && alias) {
setUploading(true);
uploadFile(fileToUpload)
.then((url) => {
Expand All @@ -263,8 +268,11 @@ Statistics/Data Analysis`;

// handles the situation where we are uploading by URL
const handleURLUpload = () => {
// directly save the non-s3 url and alias to endpoint Jeff is creating
if (urlToUpload && alias) {
// alias cannot have whitespace
if (alias.indexOf(' ') >= 0) {
handleAlert('error: Alias must not contain any white space characters', 'error');
} else if (urlToUpload && alias) {
// directly save the non-s3 url and alias to endpoint Jeff is creating
setUploading(true);
const post = {
fileName: alias,
Expand Down Expand Up @@ -562,6 +570,7 @@ Statistics/Data Analysis`;
type="file"
name="uploadFile"
onChange={onFileChosen}
accept=".csv, .dta, .xlsx, .xls, .pkl, .hdf"
/>
<TextField
value={alias}
Expand Down

0 comments on commit bbd1377

Please sign in to comment.