Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/#1043-data-table-rewrite' into #…
Browse files Browse the repository at this point in the history
…1065-remove-old-code
  • Loading branch information
josh-griffin committed Sep 24, 2019
2 parents 6af1f17 + 2e35f1e commit e2caf08
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 116 deletions.
1 change: 1 addition & 0 deletions src/globalStyles/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export const SUSSOL_ORANGE = '#e95c30';
export const TRANSPARENT = 'rgba(0, 0, 0, 0)';
export const WARM_GREY = '#9b9b9b';
export const WARMER_GREY = '#a8aaac';
export const WHITE = '#FFFFFF';
21 changes: 9 additions & 12 deletions src/pages/CustomerInvoicePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,13 @@ export const CustomerInvoicePage = ({ transaction, runWithLoadingIndicator, rout
const onAddMasterList = () =>
runWithLoadingIndicator(() => dispatch(PageActions.addMasterListItems('Transaction')));

const renderPageInfo = useCallback(
() => (
<PageInfo
columns={getPageInfoColumns(pageObject, dispatch, PageActions)}
isEditingDisabled={isFinalised}
/>
),
[comment, theirRef, isFinalised]
);
const pageInfoColumns = useCallback(getPageInfoColumns(pageObject, dispatch, PageActions), [
comment,
theirRef,
isFinalised,
]);

const getAction = (colKey, propName) => {
const getAction = useCallback((colKey, propName) => {
switch (colKey) {
case 'totalQuantity':
return PageActions.editTotalQuantity;
Expand All @@ -96,7 +92,7 @@ export const CustomerInvoicePage = ({ transaction, runWithLoadingIndicator, rout
default:
return null;
}
};
}, []);

const getModalOnSelect = () => {
switch (modalKey) {
Expand All @@ -114,6 +110,7 @@ export const CustomerInvoicePage = ({ transaction, runWithLoadingIndicator, rout
const renderRow = useCallback(
listItem => {
const { item, index } = listItem;

const rowKey = keyExtractor(item);
return (
<DataTableRow
Expand Down Expand Up @@ -155,7 +152,7 @@ export const CustomerInvoicePage = ({ transaction, runWithLoadingIndicator, rout
<DataTablePageView>
<View style={pageTopSectionContainer}>
<View style={pageTopLeftSectionContainer}>
{renderPageInfo()}
<PageInfo columns={pageInfoColumns} isEditingDisabled={isFinalised} />
<SearchBar onChangeText={onFilterData} style={searchBar} value={searchTerm} />
</View>
<View style={pageTopRightSectionContainer}>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/CustomerInvoicesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ export const CustomerInvoicesPage = ({
[showFinalised]
);

const getAction = (colKey, propName) => {
const getAction = useCallback((colKey, propName) => {
switch (colKey) {
case 'remove':
if (propName === 'onCheckAction') return PageActions.selectRow;
return PageActions.deselectRow;
default:
return null;
}
};
}, []);

const getModalOnSelect = () => {
switch (modalKey) {
Expand Down
19 changes: 7 additions & 12 deletions src/pages/CustomerRequisitionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,19 @@ export const CustomerRequisitionPage = ({ requisition, runWithLoadingIndicator,
const onSetSuppliedToSuggested = () =>
runWithLoadingIndicator(() => dispatch(PageActions.setSuppliedToSuggested()));

const renderPageInfo = useCallback(
() => (
<PageInfo
columns={getPageInfoColumns(pageObject, dispatch, PageActions)}
isEditingDisabled={isFinalised}
/>
),
[comment, isFinalised]
);
const pageInfoColumns = useCallback(getPageInfoColumns(pageObject, dispatch, PageActions), [
comment,
isFinalised,
]);

const getAction = colKey => {
const getAction = useCallback(colKey => {
switch (colKey) {
case 'suppliedQuantity':
return PageActions.editSuppliedQuantity;
default:
return null;
}
};
}, []);

const getModalOnSelect = () => {
switch (modalKey) {
Expand Down Expand Up @@ -145,7 +140,7 @@ export const CustomerRequisitionPage = ({ requisition, runWithLoadingIndicator,
<DataTablePageView>
<View style={pageTopSectionContainer}>
<View style={pageTopLeftSectionContainer}>
{renderPageInfo()}
<PageInfo columns={pageInfoColumns} isEditingDisabled={isFinalised} />
<SearchBar onChangeText={onFilterData} value={searchTerm} />
</View>
<View style={pageTopRightSectionContainer}>
Expand Down
19 changes: 7 additions & 12 deletions src/pages/StocktakeEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,12 @@ export const StocktakeEditPage = ({
const onManageStocktake = () =>
reduxDispatch(gotoStocktakeManagePage({ stocktake, stocktakeName: stocktake.name }));

const renderPageInfo = useCallback(
() => (
<PageInfo
columns={getPageInfoColumns(pageObject, dispatch, PageActions)}
isEditingDisabled={isFinalised}
/>
),
[comment, isFinalised]
);
const pageInfoColumns = useCallback(getPageInfoColumns(pageObject, dispatch, PageActions), [
comment,
isFinalised,
]);

const getAction = (colKey, propName) => {
const getAction = useCallback((colKey, propName) => {
switch (colKey) {
case 'countedTotalQuantity':
return PageActions.editCountedQuantity;
Expand All @@ -118,7 +113,7 @@ export const StocktakeEditPage = ({
default:
return null;
}
};
}, []);

const getModalOnSelect = () => {
switch (modalKey) {
Expand Down Expand Up @@ -178,7 +173,7 @@ export const StocktakeEditPage = ({
<DataTablePageView>
<View style={pageTopSectionContainer}>
<View style={pageTopLeftSectionContainer}>
{renderPageInfo()}
<PageInfo columns={pageInfoColumns} isEditingDisabled={isFinalised} />
<SearchBar onChangeText={onFilterData} value={searchTerm} />
</View>
<View style={pageTopRightSectionContainer}>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/StocktakeManagePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ export const StocktakeManagePage = ({
if (stocktake) dispatch(PageActions.selectItems(stocktake.itemsInStocktake));
}, []);

const getAction = (colKey, propName) => {
const getAction = useCallback((colKey, propName) => {
switch (colKey) {
case 'selected':
if (propName === 'onCheckAction') return PageActions.selectRow;
return PageActions.deselectRow;
default:
return null;
}
};
}, []);

const onFilterData = value => dispatch(PageActions.filterData(value));
const onNameChange = value => dispatch(PageActions.editName(value));
Expand Down
4 changes: 2 additions & 2 deletions src/pages/StocktakesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ export const StocktakesPage = ({ routeName, currentUser, dispatch: reduxDispatch
return reduxDispatch(gotoStocktakeManagePage({ stocktakeName: '' }));
};

const getAction = (colKey, propName) => {
const getAction = useCallback((colKey, propName) => {
switch (colKey) {
case 'remove':
if (propName === 'onCheckAction') return PageActions.selectRow;
return PageActions.deselectRow;
default:
return null;
}
};
}, []);

const getModalOnSelect = () => {
switch (modalKey) {
Expand Down
20 changes: 8 additions & 12 deletions src/pages/SupplierInvoicePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ export const SupplierInvoicePage = ({ routeName, transaction }) => {
const onConfirmDelete = () => dispatch(PageActions.deleteTransactionBatches());
const onCloseModal = () => dispatch(PageActions.closeModal());

const renderPageInfo = useCallback(
() => (
<PageInfo
columns={getPageInfoColumns(pageObject, dispatch, PageActions)}
isEditingDisabled={isFinalised}
/>
),
[comment, theirRef, isFinalised]
);
const pageInfoColumns = useCallback(getPageInfoColumns(pageObject, dispatch, PageActions), [
comment,
theirRef,
isFinalised,
]);

const getAction = (columnKey, propName) => {
const getAction = useCallback((columnKey, propName) => {
switch (columnKey) {
case 'totalQuantity':
return PageActions.editTotalQuantity;
Expand All @@ -77,7 +73,7 @@ export const SupplierInvoicePage = ({ routeName, transaction }) => {
default:
return null;
}
};
}, []);

const getModalOnSelect = () => {
switch (modalKey) {
Expand Down Expand Up @@ -134,7 +130,7 @@ export const SupplierInvoicePage = ({ routeName, transaction }) => {
<DataTablePageView>
<View style={pageTopSectionContainer}>
<View style={pageTopLeftSectionContainer}>
{renderPageInfo()}
<PageInfo columns={pageInfoColumns} isEditingDisabled={isFinalised} />
<SearchBar onChangeText={onFilterData} value={searchTerm} />
</View>
<View style={pageTopRightSectionContainer}>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/SupplierInvoicesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ export const SupplierInvoicesPage = ({
onCloseModal();
};

const getAction = (colKey, propName) => {
const getAction = useCallback((colKey, propName) => {
switch (colKey) {
case 'remove':
if (propName === 'onCheckAction') return PageActions.selectRow;
return PageActions.deselectRow;
default:
return null;
}
};
}, []);

const getModalOnSelect = () => {
switch (modalKey) {
Expand Down
20 changes: 8 additions & 12 deletions src/pages/SupplierRequisitionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,13 @@ export const SupplierRequisitionPage = ({ requisition, runWithLoadingIndicator,
const onAddFromMasterList = () =>
runWithLoadingIndicator(() => dispatch(PageActions.addMasterListItems('Requisition')));

const renderPageInfo = useCallback(
() => (
<PageInfo
columns={getPageInfoColumns(pageObject, dispatch, PageActions)}
isEditingDisabled={isFinalised}
/>
),
[comment, theirRef, isFinalised]
);
const pageInfoColumns = useCallback(getPageInfoColumns(pageObject, dispatch, PageActions), [
comment,
theirRef,
isFinalised,
]);

const getAction = (colKey, propName) => {
const getAction = useCallback((colKey, propName) => {
switch (colKey) {
case 'requiredQuantity':
return PageActions.editRequisitionItemRequiredQuantity;
Expand All @@ -108,7 +104,7 @@ export const SupplierRequisitionPage = ({ requisition, runWithLoadingIndicator,
default:
return null;
}
};
}, []);

const getModalOnSelect = () => {
switch (modalKey) {
Expand Down Expand Up @@ -259,7 +255,7 @@ export const SupplierRequisitionPage = ({ requisition, runWithLoadingIndicator,
<DataTablePageView>
<View style={pageTopSectionContainer}>
<View style={pageTopLeftSectionContainer}>
{renderPageInfo()}
<PageInfo columns={pageInfoColumns} isEditingDisabled={isFinalised} />
<SearchBar onChangeText={onFilterData} value={searchTerm} />
</View>
<View style={pageTopRightSectionContainer}>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/SupplierRequisitionsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ export const SupplierRequisitionsPage = ({
reduxDispatch(createSupplierRequisition({ ...requisitionParameters, currentUser }));
};

const getAction = (colKey, propName) => {
const getAction = useCallback((colKey, propName) => {
switch (colKey) {
case 'remove':
if (propName === 'onCheckAction') return PageActions.selectRow;
return PageActions.deselectRow;
default:
return null;
}
};
}, []);

const getModalOnSelect = () => {
switch (modalKey) {
Expand Down
17 changes: 7 additions & 10 deletions src/widgets/DataTable/CheckableCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ const CheckableCell = React.memo(

const onPressAction = isChecked ? onUncheckAction : onCheckAction;

const renderCheck = () => {
if (isDisabled) {
return isChecked ? DisabledCheckedComponent : DisabledUncheckedComponent;
}
return isChecked ? CheckedComponent : UncheckedComponent;
};
const renderCheck = isChecked
? (isDisabled && DisabledCheckedComponent) || CheckedComponent
: (isDisabled && DisabledUncheckedComponent) || UncheckedComponent;

return (
<TouchableCell
Expand All @@ -80,10 +77,10 @@ CheckableCell.propTypes = {
columnKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
isChecked: PropTypes.bool,
isDisabled: PropTypes.bool,
CheckedComponent: PropTypes.element.isRequired,
UncheckedComponent: PropTypes.element.isRequired,
DisabledCheckedComponent: PropTypes.element,
DisabledUncheckedComponent: PropTypes.element,
CheckedComponent: PropTypes.func.isRequired,
UncheckedComponent: PropTypes.func.isRequired,
DisabledCheckedComponent: PropTypes.func,
DisabledUncheckedComponent: PropTypes.func,
onCheckAction: PropTypes.func.isRequired,
onUncheckAction: PropTypes.func.isRequired,
dispatch: PropTypes.func.isRequired,
Expand Down
7 changes: 6 additions & 1 deletion src/widgets/DataTable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ const DataTable = React.memo(({ renderRow, renderHeader, style, data, columns, .
[numberOfEditableCells]
);

const renderItem = useCallback(
rowItem => renderRow(rowItem, focusNextCell, getCellRef, adjustToTop),
[renderRow]
);

return (
<RefContext.Provider value={contextValue}>
{renderHeader && renderHeader()}
Expand All @@ -105,7 +110,7 @@ const DataTable = React.memo(({ renderRow, renderHeader, style, data, columns, .
data={data}
keyboardShouldPersistTaps="always"
style={style}
renderItem={rowItem => renderRow(rowItem, focusNextCell, getCellRef, adjustToTop)}
renderItem={renderItem}
{...otherProps}
/>
</RefContext.Provider>
Expand Down
8 changes: 5 additions & 3 deletions src/widgets/PageInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const renderInfoComponent = (isEditingDisabled, columnIndex, color, rowData, row
* col1: row1 col2: row1
* col1: row2 col2: row2
*/
export const PageInfo = props => {
const PageInfoComponent = props => {
const { columns, isEditingDisabled, titleColor, infoColor } = props;

return (
Expand Down Expand Up @@ -148,16 +148,18 @@ export const PageInfo = props => {
);
};

export const PageInfo = React.memo(PageInfoComponent);

export default PageInfo;

PageInfo.propTypes = {
PageInfoComponent.propTypes = {
columns: PropTypes.array.isRequired,
isEditingDisabled: PropTypes.bool,
titleColor: PropTypes.string,
infoColor: PropTypes.string,
};

PageInfo.defaultProps = {
PageInfoComponent.defaultProps = {
isEditingDisabled: false,
infoColor: SUSSOL_ORANGE,
titleColor: DARK_GREY,
Expand Down
Loading

0 comments on commit e2caf08

Please sign in to comment.