Skip to content

Commit

Permalink
read options
Browse files Browse the repository at this point in the history
  • Loading branch information
wandyezj committed Jul 30, 2020
1 parent a014d9e commit 1039104
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
34 changes: 31 additions & 3 deletions src/taskpane/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import getOccupationOptions from "../data/getOccupationOptions";
import getHousingOptions from "../data/getHousingOptions";
import getTaxForIncome from "../data/getTaxForIncome";
import run from "../excel/run";
import writeOptionSheet from "../excel/writeOptionSheet";
import OccupationOptionProperties from "../data/OccupationOptionProperties";
import ExpenseOptionProperties from "../data/ExpenseOptionProperties";
import writeOptions from "../excel/writeOptions";
import readOptionSheet from "../excel/readOptionSheet";

export interface AppProps {
title: string;
Expand Down Expand Up @@ -76,8 +76,36 @@ export default class App extends React.Component<AppProps, AppState> {
}
};

// need to disable changes while loading
clickReadOptions = async () => {};
// TODO: disable changes while loading
// lock input in sheets, lock input in UI
clickReadOptions = async () => {
await Excel.run(async context => {
const categoryNames = Object.getOwnPropertyNames(this.categories);
for (let categoryName of categoryNames) {
const category = this.categories[categoryName];
const { properties } = category;

// map options to table rows
const dataRows = await readOptionSheet(context, categoryName, properties);

// build objects
const newOptions = dataRows.map(row =>
row
.map((value, index) => {
const key = properties[index];
return {
[key]: value
};
})
.reduce((previous, current) => {
return { ...previous, ...current };
}, {})
);

console.log(newOptions);
}
});
};

clickWriteOptions = async () => {
writeOptions(this.categories);
Expand Down
6 changes: 3 additions & 3 deletions src/taskpane/excel/readOptionSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export default async function readOptionSheet(

const header = headerRaw[0];

console.log(columnTitles);
console.log(header);
console.log(data);
// console.log(columnTitles);
// console.log(header);
// console.log(data);

const titleIndices = columnTitles.map(title => header.indexOf(title));

Expand Down

0 comments on commit 1039104

Please sign in to comment.