From d75f0d8909f78a5cdeec4ffe9a4fb78456930ef3 Mon Sep 17 00:00:00 2001 From: Christopher Petty Date: Thu, 3 May 2018 14:58:12 +1200 Subject: [PATCH 1/2] Fixed --- src/pages/StocktakesPage.js | 64 +++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/src/pages/StocktakesPage.js b/src/pages/StocktakesPage.js index ab1c4222d..614420d5d 100644 --- a/src/pages/StocktakesPage.js +++ b/src/pages/StocktakesPage.js @@ -15,11 +15,11 @@ import { buttonStrings, modalStrings, navStrings, tableStrings } from '../locali const DATA_TYPES_SYNCHRONISED = ['Stocktake']; /** -* Renders the page for displaying Stocktakes. -* @prop {Realm} database App wide database. -* @prop {func} navigateTo CallBack for navigation stack. -* @state {Realm.Results} stocktakes Realm.Result object containing all Items. -*/ + * Renders the page for displaying Stocktakes. + * @prop {Realm} database App wide database. + * @prop {func} navigateTo CallBack for navigation stack. + * @state {Realm.Results} stocktakes Realm.Result object containing all Items. + */ export class StocktakesPage extends React.Component { constructor(props) { super(props); @@ -35,15 +35,15 @@ export class StocktakesPage extends React.Component { this.stocktakes = props.database.objects('Stocktake'); } - onRowPress = (stocktake) => { - this.props.navigateTo( - 'stocktakeEditor', - navStrings.stocktake, - { stocktake: stocktake }, - ); - } + onRowPress = stocktake => { + this.clearSelection(); + this.props.navigateTo('stocktakeEditor', navStrings.stocktake, { stocktake: stocktake }); + }; - onNewStockTake = () => this.props.navigateTo('stocktakeManager', navStrings.new_stocktake); + onNewStockTake = () => { + this.clearSelection(); + this.props.navigateTo('stocktakeManager', navStrings.new_stocktake); + }; onDeleteConfirm = () => { const { selection } = this.state; @@ -56,25 +56,22 @@ export class StocktakesPage extends React.Component { } database.delete('Stocktake', stocktakesToDelete); }); - this.setState({ selection: [] }); - this.refreshData(); - } + this.clearSelection(); + }; - onDeleteCancel = () => { - this.setState({ selection: [] }); - this.refreshData(); - } + onToggleStatusFilter = isCurrent => this.setState({ showCurrent: isCurrent }, this.refreshData); - onToggleStatusFilter = (isCurrent) => this.setState({ showCurrent: isCurrent }, this.refreshData); + onSelectionChange = newSelection => this.setState({ selection: newSelection }); - onSelectionChange = (newSelection) => this.setState({ selection: newSelection }); + clearSelection = shouldRefreshData => + this.setState({ selection: [] }, () => shouldRefreshData && this.refreshData()); updateDataFilters = (newSearchTerm, newSortBy, newIsAscending) => { // We use != null, which checks for both null or undefined (undefined coerces to null) if (newSearchTerm != null) this.dataFilters.searchTerm = newSearchTerm; if (newSortBy != null) this.dataFilters.sortBy = newSortBy; if (newIsAscending != null) this.dataFilters.isAscending = newIsAscending; - } + }; /** * Returns updated data according to searchTerm, sortBy and isAscending. @@ -84,11 +81,11 @@ export class StocktakesPage extends React.Component { const { searchTerm, sortBy, isAscending } = this.dataFilters; const toggleFilter = this.state.showCurrent ? 'status != "finalised"' : 'status == "finalised"'; const data = this.stocktakes - .filtered(toggleFilter) - .filtered('name BEGINSWITH[c] $0 OR serialNumber BEGINSWITH[c] $0', searchTerm) - .sorted(sortBy, !isAscending); // 2nd arg: reverse sort order if true + .filtered(toggleFilter) + .filtered('name BEGINSWITH[c] $0 OR serialNumber BEGINSWITH[c] $0', searchTerm) + .sorted(sortBy, !isAscending); // 2nd arg: reverse sort order if true this.setState({ data: data }); - } + }; renderCell = (key, stocktake) => { switch (key) { @@ -106,7 +103,7 @@ export class StocktakesPage extends React.Component { isDisabled: stocktake.isFinalised, }; } - } + }; renderToggleBar = () => ( - ) + ); renderNewStocktakeButton = () => ( - - ) + + ); render() { return ( @@ -183,7 +177,7 @@ export class StocktakesPage extends React.Component { 0 && this.state.showCurrent} questionText={modalStrings.delete_these_stocktakes} - onCancel={() => this.onDeleteCancel()} + onCancel={() => this.clearSelection(true)} onConfirm={() => this.onDeleteConfirm()} confirmText={modalStrings.delete} /> From efd2f66f2c9b5d0b8a5410f5ec65ed907f24db9b Mon Sep 17 00:00:00 2001 From: Christopher Petty Date: Thu, 3 May 2018 15:22:51 +1200 Subject: [PATCH 2/2] Fix RSOD hahaaaaaa --- src/pages/StocktakesPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/StocktakesPage.js b/src/pages/StocktakesPage.js index 614420d5d..fcdf0f272 100644 --- a/src/pages/StocktakesPage.js +++ b/src/pages/StocktakesPage.js @@ -56,7 +56,7 @@ export class StocktakesPage extends React.Component { } database.delete('Stocktake', stocktakesToDelete); }); - this.clearSelection(); + this.clearSelection(true); }; onToggleStatusFilter = isCurrent => this.setState({ showCurrent: isCurrent }, this.refreshData);