Skip to content

Commit

Permalink
more work adding excel style functionality to table
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrich committed Jan 29, 2024
1 parent dff416e commit 215d93e
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 102 deletions.
9 changes: 9 additions & 0 deletions packages/ui/cypress/e2e/ExcelTable.spec.js
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();

});

});
54 changes: 1 addition & 53 deletions packages/ui/demo/src/examples/EditableCellTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import DemoWrapper from "../DemoWrapper";
import { useToggle } from "../useToggle";
import OptionsSection from "../OptionsSection";
import { toNumber } from "lodash";
// import ExcelCell from "packages/ui/src/ExcelCell";

const chance = new Chance();
function getEnts(num) {
Expand Down Expand Up @@ -54,58 +53,8 @@ export default function SimpleTable(p) {
const [allowFormulas, allowFormulasComp] = useToggle({
type: "allowFormulas"
});
// const [tagValuesAsObjects, tagValuesAsObjectsComp] = useToggle({
// type: "tagValuesAsObjects"
// });
let entsToUse;
const [entities, setEnts] = useState([]);
entsToUse = entities;

// const depGraph = {
// a1: ["a3"],
// a2: ["a1"],
// a3: [],
// b1: ["a1", "a2"],
// b2: ["a2"],
// b3: ["a3"]
// };
const schema = useMemo(() => {
if (allowFormulas) {
// eslint-disable-next-line react-hooks/exhaustive-deps
entsToUse = [
// {
// id: 'asdfoi',
// a: "=sum(b1,a2)",
// b: 44
// },
// {
// id: 'f22f2f',
// a: "=sum(b2)",
// b: 44
// },
{
id: "asdfoi",
a: "=sum(b1,a2)",
b: 44
},
{
id: "f22f2f",
a: "=sum(b1,b2,a1)",
b: 44
}
// {
// id: '22f3f',
// a: "=sum(a1,b3)",
// b: 44
// }
];
return {
fields: [
{ path: "a", allowFormulas: true },
{ path: "b", allowFormulas: true }
]
};
}
return {
fields: [
{
Expand Down Expand Up @@ -163,7 +112,6 @@ export default function SimpleTable(p) {
}, [defaultValAsFunc, allowFormulas]);
return (
<div>
{/* <ExcelCell></ExcelCell> */}
<OptionsSection>
{numComp}
{defaultValAsFuncComp}
Expand All @@ -177,7 +125,7 @@ export default function SimpleTable(p) {
formName="editableCellTable"
isSimple
isCellEditable
entities={entsToUse}
entities={entities}
schema={schema}
// isEntityDisabled={
// isEntityDisabled
Expand Down
147 changes: 147 additions & 0 deletions packages/ui/demo/src/examples/ExcelTable.js
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>
);
}
4 changes: 4 additions & 0 deletions packages/ui/demo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import ScrollToTopDemo from "./examples/ScrollToTop";

import showAppSpinnerDemo from "./examples/showAppSpinnerDemo";
import EditableCellTable from "./examples/EditableCellTable";
import ExcelTable from "./examples/ExcelTable";
import "./style.css";
import React from "react";
import { render } from "react-dom";
Expand All @@ -49,6 +50,9 @@ const demos = {
"DataTable - EditableCellTable": {
demo: EditableCellTable
},
"DataTable - ExcelTable": {
demo: ExcelTable
},
"DataTable - SimpleTable": {
demo: SimpleTable
},
Expand Down
Loading

0 comments on commit 215d93e

Please sign in to comment.