Skip to content

Commit

Permalink
web: Remove spreadsheetRows
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed Oct 25, 2023
1 parent 1ecd300 commit bc00b10
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ export default function FileInfo(props: Props) {
const removeFile = () => {
setState({
selectedFile: undefined,
spreadsheetRows: undefined,
colNames: "",
});
if (props.onRemove) props.onRemove();
};

if (!state.selectedFile && !state.spreadsheetRows) return null;
if (!state.selectedFile) return null;

return (
<div>
Expand All @@ -32,14 +31,10 @@ export default function FileInfo(props: Props) {
>
<span className={css.fileInfo}>
<FiFile className={css.fileIcon} />
<span data-cy="file-name">
{state.selectedFile?.name ?? "editor.csv"}
<span data-cy="file-name">{state.selectedFile.name}</span>
<span className={css.fileSize}>
{fileSize(state.selectedFile.size)}
</span>
{state.selectedFile && (
<span className={css.fileSize}>
{fileSize(state.selectedFile.size)}
</span>
)}
</span>
<div className={cx({ [css.buttons]: props.upload })}>
{props.editButton}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function getComplete(
case UploadStage.Table:
return !!state.tableName;
case UploadStage.Upload:
return !!(state.selectedFile ?? state.spreadsheetRows);
return !!state.selectedFile;
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default function DropZone() {
className={cx(css.dropContainer, {
[css.hover]: dz.hover,
[css.dropped]: state.selectedFile,
[css.faded]: !!state.spreadsheetRows,
})}
onDragOver={dz.dragOver}
onDragLeave={dz.dragLeave}
Expand All @@ -53,11 +52,7 @@ export default function DropZone() {
<div>Drag a file here</div>
<div>or</div>
<div className={css.uploadBottom}>
<Button.Link
onClick={onBrowse}
className={css.browseButton}
disabled={!!state.spreadsheetRows}
>
<Button.Link onClick={onBrowse} className={css.browseButton}>
Browse files
</Button.Link>

Expand All @@ -73,7 +68,7 @@ export default function DropZone() {
</div>
</div>
<ErrorMsg errString={dz.err} />
{!state.selectedFile && !state.spreadsheetRows && (
{!state.selectedFile && (
<div className={css.fileTypes}>File types: {fileTypes}</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,39 @@
import Button from "@components/Button";
import { FiCheck } from "@react-icons/all-files/fi/FiCheck";
import { GrTable } from "@react-icons/all-files/gr/GrTable";
import cx from "classnames";
import FileInfo from "../../FileInfo";
import { useFileUploadContext } from "../../contexts/fileUploadLocalForage";
import useUploadContext from "./contexts/upload";
import css from "./index.module.css";

export default function OpenSpreadsheetZone() {
const { setState } = useUploadContext();
const { state, setItem } = useFileUploadContext();

const onRemove = () => {
setState({ error: undefined });
setItem("selectedFile", undefined);
};
const { state } = useFileUploadContext();

const onClick = () => {
setState({ spreadsheetOverlayOpen: true });
};

const onEdit = () => {
setState({
spreadsheetOverlayOpen: true,
error: undefined,
});
};

return (
<div>
<div
className={cx(css.editableTable, {
[css.dropped]: state.spreadsheetRows,
[css.faded]: state.selectedFile && !state.spreadsheetRows,
[css.faded]: !!state.selectedFile,
})}
>
{state.spreadsheetRows ? (
<div>
<GrTable className={css.tableIcon} />
<h4>Create spreadsheet</h4>
<div>
<span
className={css.success}
data-cy="spreadsheet-upload-successful"
<Button
onClick={onClick}
className={css.openButton}
disabled={!!state.selectedFile}
data-cy="spread-sheet-button"
>
<FiCheck />
Upload successful
</span>
<FileInfo
onRemove={onRemove}
editButton={
<Button.Link onClick={onEdit} className={css.editBtn}>
edit
</Button.Link>
}
upload
/>
</div>
) : (
<div>
<GrTable className={css.tableIcon} />
<h4>Create spreadsheet</h4>
<div>
<Button
onClick={onClick}
className={css.openButton}
disabled={!!state.selectedFile}
data-cy="spread-sheet-button"
>
Open editor
</Button>
</div>
Open editor
</Button>
</div>
)}
</div>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type UploadContextType = {
state: UploadState;
setState: UploadDispatch;
onUpload: () => Promise<void>;
removeSpreadsheet: () => void;
};

export const UploadContext =
Expand All @@ -38,11 +37,7 @@ type Props = {
export function UploadProvider(props: Props) {
const { isDolt } = useIsDolt();
const router = useRouter();
const {
state: fuState,
dbParams,
setState: setForageState,
} = useFileUploadContext();
const { state: fuState, dbParams } = useFileUploadContext();
const [state, setState] = useSetState({
...defaultState,
spreadsheetOverlayOpen:
Expand Down Expand Up @@ -94,22 +89,12 @@ export function UploadProvider(props: Props) {
}
};

const removeSpreadsheet = () => {
setForageState({
spreadsheetRows: undefined,
selectedFile: undefined,
colNames: "",
});
setState({ error: undefined });
};

return (
<UploadContext.Provider
value={{
state,
setState,
onUpload,
removeSpreadsheet,
}}
>
{props.children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ function Inner() {
title="Upload file"
stage={UploadStage.Upload}
disabled={
!!uState.error ||
(!state.spreadsheetRows && !state.selectedFile) ||
updateLoad ||
uState.loading
!!uState.error || !state.selectedFile || updateLoad || uState.loading
}
onNext={onUpload}
backUrl={getUploadUrl("table")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export function getOpVerb(op: ImportOperation): string {
}

export function getUploadMethod(state: FileUploadState): string {
if (state.spreadsheetRows) {
return " using new spreadsheet";
}
if (state.selectedFile) {
return " using uploaded file";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const defaultState = {
tableName: "",
importOp: ImportOperation.Update,
selectedFile: undefined as File | undefined, // file upload only
spreadsheetRows: undefined as string[][] | undefined, // spreadsheet only
fileType: FileType.Csv,
modifier: undefined as LoadDataModifier | undefined,
colNames: "",
Expand Down

0 comments on commit bc00b10

Please sign in to comment.