-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more work adding excel style functionality to table
- Loading branch information
Showing
6 changed files
with
291 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe("ExcelTable.spec", () => { | ||
it(`adding rows should update formula correctly`, () => { | ||
cy.visit("#/DataTable%20-%20ExcelTable"); | ||
cy.get(`[data-test="tgCell_Thing 1"]:contains(88)`).rightclick(); | ||
cy.contains("Add Row Above").click(); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import React, { useMemo, useRef, useState } from "react"; | ||
import DataTable from "../../../src/DataTable"; | ||
import DemoWrapper from "../DemoWrapper"; | ||
import { useToggle } from "../useToggle"; | ||
import OptionsSection from "../OptionsSection"; | ||
import { nanoid } from "nanoid"; | ||
import { forEach, map } from "lodash"; | ||
import { getColLetFromIndex } from "packages/ui/src/DataTable/editCellHelper"; | ||
// import ExcelCell from "packages/ui/src/ExcelCell"; | ||
|
||
export default function SimpleTable(p) { | ||
const key = useRef(0); | ||
const [simpleCircularLoop, simpleCircularLoopComp] = useToggle({ | ||
type: "simpleCircularLoop" | ||
}); | ||
const [manyColumns, manyColumnsComp] = useToggle({ | ||
type: "manyColumns" | ||
}); | ||
const [simpleRangeExample, simpleRangeExampleComp] = useToggle({ | ||
type: "simpleRangeExample" | ||
}); | ||
const [entities, _setEnts] = useState([]); | ||
const setEnts = ents => { | ||
_setEnts(ents.map(e => ({ id: nanoid(), ...e }))); | ||
}; | ||
const schema = useMemo(() => { | ||
key.current++; | ||
if (simpleCircularLoop) { | ||
setEnts([ | ||
{ | ||
a: "=sum(b1,a2)", | ||
b: 44 | ||
}, | ||
{ | ||
a: "=sum(b1,b2,a1)", | ||
b: 44 | ||
} | ||
]); | ||
return { | ||
fields: [ | ||
{ path: "a", allowFormulas: true }, | ||
{ path: "b", allowFormulas: true } | ||
] | ||
}; | ||
} | ||
if (manyColumns) { | ||
setEnts([ | ||
{ | ||
a: "=sum(cc1:cc3)", | ||
b: 44, | ||
cc: 87 | ||
}, | ||
{ | ||
a: "=sum(b1,b2,a1)", | ||
b: 44, | ||
aa: 42, | ||
cc: 88 | ||
} | ||
,{ | ||
a: "=sum(1:1)", | ||
aa: 42, | ||
cc: 89, | ||
} | ||
,{ | ||
a: "=sum(aa:aa)", | ||
aa: 42, | ||
cc: 89, | ||
} | ||
]); | ||
return { | ||
fields: [ | ||
...map(new Array(100), (v, i) => ({ | ||
path: getColLetFromIndex(i).toLowerCase(), | ||
allowFormulas: true | ||
})) | ||
] | ||
}; | ||
} | ||
if (simpleRangeExample) { | ||
setEnts([ | ||
{ | ||
a: "=sum(b1:b3)", | ||
b: 44 | ||
}, | ||
{ | ||
a: "=sum(B:B)", | ||
b: 44 | ||
}, | ||
{ | ||
a: "=sum(2:2)", | ||
b: 44 | ||
} | ||
]); | ||
return { | ||
fields: [ | ||
{ path: "a", allowFormulas: true }, | ||
{ path: "b", allowFormulas: true }, | ||
{ path: "c", allowFormulas: true } | ||
] | ||
}; | ||
} | ||
setEnts([ | ||
{ | ||
"Thing 1": "=sum(b1,a2)", | ||
thing2: 44 | ||
}, | ||
{ | ||
"Thing 1": "=sum(b1,c1)", | ||
thing2: 44, | ||
c: "=e1" | ||
} | ||
]); | ||
|
||
return { | ||
fields: [ | ||
{ path: "Thing 1", allowFormulas: true }, | ||
{ path: "thing2", allowFormulas: true }, | ||
{ path: "c", allowFormulas: true }, | ||
{ path: "d", allowFormulas: true }, | ||
{ path: "e", allowFormulas: true } | ||
] | ||
}; | ||
}, [simpleCircularLoop, manyColumns, simpleRangeExample]); | ||
return ( | ||
<div> | ||
{/* <ExcelCell></ExcelCell> */} | ||
<OptionsSection> | ||
{simpleCircularLoopComp} | ||
{manyColumnsComp} | ||
{simpleRangeExampleComp} | ||
</OptionsSection> | ||
<DemoWrapper> | ||
<DataTable | ||
allowFormulas={true} | ||
key={key.current} | ||
formName="excelTable" | ||
isSimple | ||
isCellEditable | ||
entities={entities} | ||
initialEntities={entities} | ||
schema={schema} | ||
{...p} | ||
></DataTable> | ||
</DemoWrapper> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.