From 9ecd03d59f098cefa54bec7a43729ce2d33e2d8a Mon Sep 17 00:00:00 2001 From: Thomas Noelcke Date: Wed, 10 Oct 2018 15:13:59 -0700 Subject: [PATCH] feat(item bank): add apply button --- src/ItemBank/ItemBankContainer.tsx | 6 +++++- src/ItemEntryTable/ItemEntryTable.tsx | 30 ++++++++++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/ItemBank/ItemBankContainer.tsx b/src/ItemBank/ItemBankContainer.tsx index 8b470846..f8d2e07d 100644 --- a/src/ItemBank/ItemBankContainer.tsx +++ b/src/ItemBank/ItemBankContainer.tsx @@ -419,7 +419,11 @@ export class ItemBankContainer extends React.Component< submitItems = (items: ItemRevisionModel[]) => { // will need to do more stuff here. - this.setState({ items }); + if (items.length >= 2) { + this.setState({ items }); + } else { + this.clearItems(); + } }; onRevisionSelect = (revision: string) => { diff --git a/src/ItemEntryTable/ItemEntryTable.tsx b/src/ItemEntryTable/ItemEntryTable.tsx index 0a8e90f2..2fa4ba13 100644 --- a/src/ItemEntryTable/ItemEntryTable.tsx +++ b/src/ItemEntryTable/ItemEntryTable.tsx @@ -7,6 +7,7 @@ import { SelectOptionProps, SelectOption, Select, + validItemRevisionModel, ItemEntryRow } from "@src/index"; @@ -36,14 +37,18 @@ export class ItemEntryTable extends React.Component< } handleRowUpdate(row: ItemRevisionModel, key: number) { - // TODO: Update this to read in all the rows and pass them to the paren t component. const itemRows = this.state.itemRows; - itemRows.push(row); - this.setState({ itemRows }); - } + itemRows[key] = row; + // If the row is valid we want to add another row + if (validItemRevisionModel(row)) { + row.valid = true; + itemRows.push({}); + } else { + row.valid = false; + } + itemRows[key] = row; - handleSubmit() { - this.props.onSubmit(this.state.itemRows); + this.setState({ itemRows }); } handleDeleteRow(key: number) { @@ -59,6 +64,7 @@ export class ItemEntryTable extends React.Component< handleClearItems() { this.props.onClearItems(); + this.setState({ itemRows: [{}] }); } renderHeader() { @@ -76,7 +82,7 @@ export class ItemEntryTable extends React.Component< } renderBody() { - const rows = this.props.itemRows.map((row, idx) => ( + const rows = this.state.itemRows.map((row, idx) => ( this.handleRowUpdate(editRow, idx)} @@ -88,9 +94,13 @@ export class ItemEntryTable extends React.Component< isLast={idx === this.props.itemRows.length - 1} /> )); - rows.push(this.renderFooter()); - return {rows}; + return ( + + {rows} + {this.renderFooter()} + + ); } renderFooter() { @@ -100,7 +110,7 @@ export class ItemEntryTable extends React.Component< this.props.onSubmit(this.state.itemRows)} type="button" value="apply" />