Skip to content

Commit 2ad07e6

Browse files
committed
attemping to hide columns with toggles
1 parent 02d9499 commit 2ad07e6

File tree

9 files changed

+121
-44
lines changed

9 files changed

+121
-44
lines changed

references/ast-WHERE-multiple.png

370 KB
Loading

references/ast-WHERE.png

444 KB
Loading

references/togglecheckboxFunction.png

40 KB
Loading

src/functions/functions.ts

+29-29
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,60 @@
77
* @param second Second number
88
* @returns The sum of the two numbers.
99
*/
10-
export function add(first: number, second: number): number {
11-
return first + second;
12-
}
10+
// export function add(first: number, second: number): number {
11+
// return first + second;
12+
// }
1313

1414
/**
1515
* Displays the current time once a second.
1616
* @customfunction
1717
* @param invocation Custom function handler
1818
*/
19-
export function clock(invocation: CustomFunctions.StreamingInvocation<string>): void {
20-
const timer = setInterval(() => {
21-
const time = currentTime();
22-
invocation.setResult(time);
23-
}, 1000);
19+
// export function clock(invocation: CustomFunctions.StreamingInvocation<string>): void {
20+
// const timer = setInterval(() => {
21+
// const time = currentTime();
22+
// invocation.setResult(time);
23+
// }, 1000);
2424

25-
invocation.onCanceled = () => {
26-
clearInterval(timer);
27-
};
28-
}
25+
// invocation.onCanceled = () => {
26+
// clearInterval(timer);
27+
// };
28+
// }
2929

3030
/**
3131
* Returns the current time.
3232
* @returns String with the current time formatted for the current locale.
3333
*/
34-
export function currentTime(): string {
35-
return new Date().toLocaleTimeString();
36-
}
34+
// export function currentTime(): string {
35+
// return new Date().toLocaleTimeString();
36+
// }
3737

3838
/**
3939
* Increments a value once a second.
4040
* @customfunction
4141
* @param incrementBy Amount to increment
4242
* @param invocation Custom function handler
4343
*/
44-
export function increment(incrementBy: number, invocation: CustomFunctions.StreamingInvocation<number>): void {
45-
let result = 0;
46-
const timer = setInterval(() => {
47-
result += incrementBy;
48-
invocation.setResult(result);
49-
}, 1000);
44+
// export function increment(incrementBy: number, invocation: CustomFunctions.StreamingInvocation<number>): void {
45+
// let result = 0;
46+
// const timer = setInterval(() => {
47+
// result += incrementBy;
48+
// invocation.setResult(result);
49+
// }, 1000);
5050

51-
invocation.onCanceled = () => {
52-
clearInterval(timer);
53-
};
54-
}
51+
// invocation.onCanceled = () => {
52+
// clearInterval(timer);
53+
// };
54+
// }
5555

5656
/**
5757
* Writes a message to console.log().
5858
* @customfunction LOG
5959
* @param message String to write.
6060
* @returns String to write.
6161
*/
62-
export function logMessage(message: string): string {
63-
console.log(message);
62+
// export function logMessage(message: string): string {
63+
// console.log(message);
6464

65-
return message;
66-
}
65+
// return message;
66+
// }

src/taskpane/components/Query.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React, { useState, useEffect, useMemo } from "react";
1+
import React, { useState, useEffect, useMemo, useRef } from "react";
22
import { Parser } from "node-sql-parser"; // Used for onSubmit
33
import Querybox from "./query/Querybox";
44
import QueryTable from "./query/QueryTable"; // reactTable
55
import reloadSheets from "./query/queryFunctions/reloadSheets"; // sets allWorksheets with useEffect
66
import handleQuery from "./query/queryFunctions/handleQuery";
7+
import hideColumns from "./query/queryFunctions/hideColumns";
78

89
/* global JSX console document */
910

@@ -32,7 +33,7 @@ export default (): JSX.Element => {
3233
/**
3334
* ourTable renders the allColumns and data into the react table
3435
*/
35-
const ourTable = useMemo(() => <QueryTable columns={allColumns} data={data} />, [allWorksheets]);
36+
const ourTable = useMemo(() => <QueryTable columns={allColumns} data={data}/>, [allWorksheets]);
3637

3738
/**
3839
* Loads Current sheets and sets current state
@@ -59,8 +60,10 @@ export default (): JSX.Element => {
5960

6061
console.log("queryHeaders:", queryHeaders);
6162
console.log("conditions:", queryConditions);
62-
6363
setShowTable(true);
64+
65+
// QueryTable.ourFunction({ queryHeaders, allColumns });
66+
6467
} catch (err) {
6568
console.log("Invalid query:", err);
6669
setShowTable(false);
@@ -71,7 +74,8 @@ export default (): JSX.Element => {
7174
return (
7275
<>
7376
<Querybox onSubmit={onSubmit} />
74-
{showTable ? ourTable : null}
77+
{/* {showTable ? ourTable : null} */}
78+
{ourTable}
7579
<button
7680
onClick={() => {
7781
setShowTable(false);

src/taskpane/components/query/QueryTable.tsx

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from "react";
22
import { useTable, useFilters } from "react-table";
33

4-
/* global */
5-
export default (props: any) => {
4+
/* global console */
5+
export default (props: any): any => {
66
const { columns, data } = props;
77

88
const tableInstance: any = useTable(
@@ -15,14 +15,33 @@ export default (props: any) => {
1515

1616
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow, allColumns } = tableInstance;
1717

18+
// type hideColumnsProps = {
19+
// queryHeaders: any;
20+
// allColumns: any;
21+
// };
22+
23+
// const ourFunction = ({ queryHeaders, allColumns }: hideColumnsProps) => {
24+
// const columnIDs: any = {};
25+
26+
// for (const headerInfo of queryHeaders) {
27+
// columnIDs[headerInfo.accessor] = true;
28+
// console.log("columnIDs ", columnIDs[headerInfo.accessor]);
29+
// }
30+
31+
// allColumns.map((column: any) => {
32+
// column.toggleHidden(columnIDs[column.id]);
33+
// });
34+
// };
35+
1836
return (
1937
<div id="query-table">
2038
<div>
2139
<div>
2240
{allColumns.map((column: any) => (
2341
<div key={column.id}>
2442
<label>
25-
<input id={column.id} type="checkbox" {...column.getToggleHiddenProps()} />
43+
<input id={`check${column.id}`} type="checkbox" {...column.getToggleHiddenProps()} />
44+
{console.log(column.getToggleHiddenProps().onChange)}
2645
{column.Header}
2746
</label>
2847
</div>

src/taskpane/components/query/Querybox.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import { QueryBoxProps } from "src/types";
44
/* global JSX */
55

66
export default (props: QueryBoxProps): JSX.Element => {
7+
const str: string = "SELECT country FROM world_population";
78
return (
89
<>
9-
<textarea id="sqlQueryBox" placeholder="Enter SQL Query"></textarea>
10+
<textarea id="sqlQueryBox" placeholder="Enter SQL Query">
11+
{str}
12+
</textarea>
1013
<br />
1114
<button onClick={props.onSubmit}>Submit</button>
1215
</>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* global document console */
2+
3+
type hideColumnsProps = {
4+
queryHeaders: any;
5+
allColumns: any;
6+
};
7+
8+
export default ({ queryHeaders, allColumns }: hideColumnsProps) => {
9+
console.log("queryHeaders from hideColumns", queryHeaders);
10+
11+
const columnIDs: any = {};
12+
13+
// queryHeaders { Header: column, accessor: `${accessorValue++}`, Filter: ColumnFilter }
14+
15+
for (const headerInfo of queryHeaders) {
16+
columnIDs[headerInfo.accessor] = true;
17+
18+
console.log("columnIDs ", columnIDs[headerInfo.accessor]);
19+
}
20+
21+
// console.log('hashmap:',columnIDs);
22+
23+
// console.log("an html element:", document.getElementById("sqlQueryBox") as HTMLInputElement);
24+
25+
// const checkbox = document.getElementById('check0') as HTMLInputElement;
26+
// console.log("checkbox", checkbox);
27+
28+
for (const column of allColumns) {
29+
const checkbox = document.getElementById(`check${column.accessor}`) as HTMLInputElement;
30+
checkbox.checked = columnIDs[column.accessor];
31+
// checkbox.dispatchEvent("change");
32+
}
33+
};

src/taskpane/components/query/queryFunctions/selectParser.ts

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* global console */
2-
2+
/**
3+
* setting the types for the result of the AST parser
4+
*/
35
type astType = {
46
columns: any;
57
from: any;
@@ -9,47 +11,63 @@ type astType = {
911
having: any;
1012
};
1113

12-
1314
/**
14-
* Get all headers selected in the query
15+
* returns the selected headers and selected conditions of the query (i.e. WHERE, FROM, GROUPBY, ORDER_By)
1516
*/
1617
export default ({ columns, from, where, groupby, orderby, having }: astType, allWorksheets: any) => {
1718
// get the headers for the tables that are requested in FROM arguments
19+
/**
20+
* Populating queryHeaders with all the selected column names/ headers
21+
* an array of objects that has the column name, accessor and Filter: ColumnFilter (built-in from react table)
22+
* ex.) { Header: column, accessor: `${accessorValue++}`, Filter: ColumnFilter };
23+
*/
1824
let queryHeaders: any = [];
1925

2026
// Create an object will to hold requested columns with O(1) lookup time
27+
/**
28+
* Creating an object with all headers if SELECT *
29+
*/
2130
const objWithColumns: any = {};
31+
2232
if (columns === "*") {
2333
objWithColumns["*"] = true;
2434
} else {
2535
for (const column of columns) {
2636
objWithColumns[column.expr.column] = true;
2737
}
2838
}
29-
39+
40+
/**
41+
* destructuring fromObj to get the worksheet names (.table is worksheet name)
42+
* reformatting AST data for use in react-table
43+
*/
3044
for (const fromObj of from) {
3145
// make sure that the table they are looking for is in
3246
if (allWorksheets[fromObj.table]) {
3347
const headersArray = allWorksheets[fromObj.table].headerInfo;
34-
48+
/**
49+
* checking if SELECT * exists in objWithColumns, we are selecting all the headers
50+
*/
3551
if (objWithColumns["*"]) {
3652
queryHeaders = queryHeaders.concat(headersArray);
3753
} else {
3854
for (const headerInfo of headersArray) {
3955
if (objWithColumns[headerInfo.Header]) queryHeaders.push(headerInfo);
4056
}
4157
}
58+
} else {
59+
//error handling for if the table they requested isn't in the worksheets
4260
}
4361
}
4462

4563
// here is only 1 condition then return it in an array
46-
let queryConditions = {
64+
const queryConditions = {
4765
where: [where],
4866
groupby: groupby,
4967
orderby: orderby,
5068
having: having,
5169
};
52-
if (where?.value) queryConditions = where.value;
70+
if (queryConditions.where[0]?.value) queryConditions.where = where.value;
5371

5472
console.log("headers, conditions", queryHeaders, queryConditions);
5573

0 commit comments

Comments
 (0)