Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
feat(item bank): add apply button
Browse files Browse the repository at this point in the history
  • Loading branch information
tnoelcke committed Oct 10, 2018
1 parent 518924a commit 9ecd03d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/ItemBank/ItemBankContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
30 changes: 20 additions & 10 deletions src/ItemEntryTable/ItemEntryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
SelectOptionProps,
SelectOption,
Select,
validItemRevisionModel,
ItemEntryRow
} from "@src/index";

Expand Down Expand Up @@ -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) {
Expand All @@ -59,6 +64,7 @@ export class ItemEntryTable extends React.Component<

handleClearItems() {
this.props.onClearItems();
this.setState({ itemRows: [{}] });
}

renderHeader() {
Expand All @@ -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) => (
<ItemEntryRow
row={row}
onRowUpdate={editRow => this.handleRowUpdate(editRow, idx)}
Expand All @@ -88,9 +94,13 @@ export class ItemEntryTable extends React.Component<
isLast={idx === this.props.itemRows.length - 1}
/>
));
rows.push(this.renderFooter());

return <tbody>{rows}</tbody>;
return (
<tbody>
{rows}
<tr>{this.renderFooter()}</tr>
</tbody>
);
}

renderFooter() {
Expand All @@ -100,7 +110,7 @@ export class ItemEntryTable extends React.Component<
<td>
<input
className="btn btn-primary submit-button bg-primary"
onClick={this.handleSubmit}
onClick={apply => this.props.onSubmit(this.state.itemRows)}
type="button"
value="apply"
/>
Expand Down

0 comments on commit 9ecd03d

Please sign in to comment.