Skip to content

Commit

Permalink
add reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Yinger committed Sep 22, 2020
1 parent db6bbb2 commit cd7abf5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 225 deletions.
26 changes: 23 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useState, useRef } from "react";
import { WorkBook } from "xlsx/types";
import { Row, Col, Select } from "antd";

Expand All @@ -19,19 +19,22 @@ function App() {
const [leftsheetlist, setLeftSheetlist] = useState<any[] | null>(null);
const [hotTableComponentLeft] = useState(React.createRef());
const [leftsheetdata, setLeftSheetData] = useState(
JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 10)))
JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 8)))
);
const [leftWorkbook, setLeftWorkbook] = useState<WorkBook>();
const [rightsheetname, setRightSheetname] = useState("Sheet1");
const [rightsheetlist, setRightSheetlist] = useState<any[] | null>(null);
const [hotTableComponentRight] = useState(React.createRef());
const [rightsheetdata, setRightSheetData] = useState(
JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 10)))
JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 8)))
);
const [rightWorkbook, setRightWorkbook] = useState<WorkBook>();
const [diffBtnText] = useState(">> Diff <<");
const [hotTableComponentDiffResult] = useState(React.createRef());

const leftFileSelectRef = useRef<any>(null);
const rightFileSelectRef = useRef<any>(null);

const fileHandler = (
event: React.ChangeEvent<HTMLInputElement>,
field: string
Expand Down Expand Up @@ -110,6 +113,7 @@ function App() {
onSheetSelectChange={(e) => onSheetFieldChange(e, "left")}
hotTableComponentLeft={hotTableComponentLeft}
sheetdata={leftsheetdata}
fileRef={leftFileSelectRef}
/>
</Col>
<Col span={2}>
Expand All @@ -122,6 +126,21 @@ function App() {
setLeftSheetData(ExcelHelper.SampleDataLeft);
setRightSheetData(ExcelHelper.SampleDataRight);
}}
onResetBtnClick={(e) => {
// window.location.reload();
leftFileSelectRef.current.value = "";
rightFileSelectRef.current.value = "";
setLeftSheetlist(null);
setRightSheetlist(null);
setLeftSheetname("Sheet1");
setRightSheetname("Sheet1");
setLeftSheetData(
JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 8)))
);
setRightSheetData(
JSON.parse(JSON.stringify(ExcelHelper.BlankData(12, 8)))
);
}}
/>
</Col>
<Col span={11}>
Expand All @@ -132,6 +151,7 @@ function App() {
onSheetSelectChange={(e) => onSheetFieldChange(e, "right")}
hotTableComponentRight={hotTableComponentRight}
sheetdata={rightsheetdata}
fileRef={rightFileSelectRef}
/>
</Col>
<Col span={24} style={{ textAlign: "center" }}>
Expand Down
10 changes: 10 additions & 0 deletions src/components/Center.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface DiffBtn {
btntext: string;
onDiffBtnClick(e: React.MouseEvent<HTMLElement, MouseEvent>): any;
onSampleBtnClick(e: React.MouseEvent<HTMLElement, MouseEvent>): any;
onResetBtnClick(e: React.MouseEvent<HTMLElement, MouseEvent>): any;
}

const CenterHooks = (props: DiffBtn) => {
Expand All @@ -29,6 +30,15 @@ const CenterHooks = (props: DiffBtn) => {
>
{props.btntext}
</Button>
<Button
ref={React.createRef()}
id="btn-clean"
type="default"
style={{ marginTop: 10 }}
onClick={(e) => props.onResetBtnClick(e)}
>
{" << reset >> "}
</Button>
</div>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/Import.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "antd/dist/antd.css";
interface Import {
sheetname: string;
sheetlist: any;
fileRef: React.RefObject<any>;
onFileSelectChange(e: React.ChangeEvent<HTMLInputElement>): any;
onSheetSelectChange(e: string): any;
}
Expand All @@ -23,6 +24,7 @@ const ImportHooks = (props: Import) => {
accept={ExcelHelper.SheetJSFT()}
aria-label="Select original file"
onChange={(e) => props.onFileSelectChange(e)}
ref={props.fileRef}
></input>
<Select
style={{ width: "40%" }}
Expand Down
10 changes: 6 additions & 4 deletions src/components/Left.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ImportHooks from "../components/Import";
interface Left {
sheetname: string;
sheetlist: any;
fileRef: React.RefObject<any>;

sheetdata: any[][] | Handsontable.RowObject[];
hotTableComponentLeft: React.RefObject<any>;
Expand All @@ -19,9 +20,9 @@ const LeftHooks = (props: Left) => {
colHeaders: true,
rowHeaders: true,
height: 305,
minRows: 5,
minCols: 5,
colWidth: 100,
minRows: 12,
minCols: 8,
// colWidth: 100,
licenseKey: "non-commercial-and-evaluation",
id: "table-left",
};
Expand All @@ -36,11 +37,12 @@ const LeftHooks = (props: Left) => {
props.onFileSelectChange(e)
}
onSheetSelectChange={(e: string) => props.onSheetSelectChange(e)}
fileRef={props.fileRef}
/>
<HotTable
ref={props.hotTableComponentLeft}
data={props.sheetdata}
style={{ width: "100%" }}
style={{ width: "98%" }}
settings={hotLeftSettings}
stretchH={"all"}
/>
Expand Down
10 changes: 6 additions & 4 deletions src/components/Right.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ImportHooks from "../components/Import";
interface Right {
sheetname: string;
sheetlist: any;
fileRef: React.RefObject<any>;

sheetdata: any[][] | Handsontable.RowObject[];
hotTableComponentRight: React.RefObject<any>;
Expand All @@ -19,9 +20,9 @@ const RightHooks = (props: Right) => {
colHeaders: true,
rowHeaders: true,
height: 305,
minRows: 5,
minCols: 5,
colWidth: 100,
minRows: 12,
minCols: 8,
// colWidth: 100,
licenseKey: "non-commercial-and-evaluation",
id: "table-right",
};
Expand All @@ -36,11 +37,12 @@ const RightHooks = (props: Right) => {
props.onFileSelectChange(e)
}
onSheetSelectChange={(e: string) => props.onSheetSelectChange(e)}
fileRef={props.fileRef}
/>
<HotTable
ref={props.hotTableComponentRight}
data={props.sheetdata}
style={{ width: "100%" }}
style={{ width: "98%" }}
settings={hotRightSettings}
stretchH={"all"}
/>
Expand Down
Loading

0 comments on commit cd7abf5

Please sign in to comment.