-
Notifications
You must be signed in to change notification settings - Fork 3
refactor(entity-list): add num of rows preference feature #3327
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import {connect} from 'react-redux' | ||
|
|
||
| import { | ||
| displayColumnModal, | ||
| resetSorting, | ||
| resetPreferences, | ||
| resetColumns, | ||
| displayTableRowsModal | ||
| } from '../../modules/preferences/actions' | ||
| import NavigationCellHeader from './NavigationCellHeader' | ||
|
|
||
| const mapActionCreators = { | ||
| displayColumnModal, | ||
| resetSorting, | ||
| resetPreferences, | ||
| resetColumns, | ||
| displayTableRowsModal | ||
| } | ||
|
|
||
| const mapStateToProps = (state, props) => { | ||
| return { | ||
| sortable: state.list.sortable, | ||
| disablePreferencesMenu: state.list.disablePreferencesMenu, | ||
| numOfRows: state.preferences.numOfRows | ||
| } | ||
| } | ||
|
|
||
| export default connect(mapStateToProps, mapActionCreators)(NavigationCellHeader) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import PropTypes from 'prop-types' | ||
| import {useState} from 'react' | ||
| import {EditableValue, Button} from 'tocco-ui' | ||
|
|
||
| import {StyledButtonWrapper, StyledEditableValueWrapper} from './StyledComponents' | ||
|
|
||
| const SelectNumRows = ({onOk, numOfRows}) => { | ||
| const options = [ | ||
| {key: 1, display: '25'}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion(blocking): Use number value as key and use Then we could maybe remove all the type conversions expect the one when loading the preferences initially. |
||
| {key: 2, display: '50'}, | ||
| {key: 3, display: '100'} | ||
| ] | ||
| const matchingValue = options.find(option => Number(option.display) === numOfRows) | ||
| const [value, setValue] = useState(matchingValue) | ||
|
|
||
| return ( | ||
| <> | ||
| <StyledEditableValueWrapper> | ||
| <EditableValue | ||
| value={value} | ||
| type="single-select" | ||
| events={{onChange: setValue}} | ||
| options={{ | ||
| options, | ||
| noResultsText: 'no results found', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: we should use out text resources here as well |
||
| isLoading: false | ||
| }} | ||
| /> | ||
| </StyledEditableValueWrapper> | ||
| <StyledButtonWrapper> | ||
| <Button onClick={() => onOk(value?.display)} look={'raised'}> | ||
| OK | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: we should use our text resources here as well |
||
| </Button> | ||
| </StyledButtonWrapper> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| SelectNumRows.propTypes = { | ||
| onOk: PropTypes.func.isRequired, | ||
| numOfRows: PropTypes.number | ||
| } | ||
|
|
||
| export default SelectNumRows | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -288,7 +288,7 @@ export function* setLazyDataMarked(entityName, markings) { | |
| export function* fetchEntitiesAndAddToStore(page) { | ||
| const state = yield select(stateSelector) | ||
| const {entityName, scope, limit} = state.input | ||
| const {columns: columnPreferences} = state.preferences | ||
| const {columns: columnPreferences, numOfRows} = state.preferences | ||
| const {entityStore, sorting} = state.list | ||
| if (!entityStore[page]) { | ||
| const basicQuery = yield call(getBasicQuery) | ||
|
|
@@ -299,7 +299,7 @@ export function* fetchEntitiesAndAddToStore(page) { | |
| ...basicQuery, | ||
| page, | ||
| sorting, | ||
| limit, | ||
| limit: numOfRows || limit, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion(non-blocking): move to helper function We need to apply this "fallback" logic in 3 places now. We could have a util function This could be used in all three places: |
||
| paths | ||
| } | ||
|
|
||
|
|
@@ -340,6 +340,8 @@ export function* delayedPreloadNextPage(page) { | |
|
|
||
| export function* preloadNextPage(currentPage) { | ||
| const {limit} = yield select(inputSelector) | ||
| const {numOfRows} = yield select(preferencesSelector) | ||
| const actualLimit = numOfRows || limit | ||
| const list = yield select(listSelector) | ||
| const {entityStore} = list | ||
| let {entityCount} = list | ||
|
|
@@ -350,7 +352,7 @@ export function* preloadNextPage(currentPage) { | |
| entityCount = setCountAction.payload.entityCount | ||
| } | ||
|
|
||
| if (currentPage * limit < entityCount && !entityStore[nextPage]) { | ||
| if (currentPage * actualLimit < entityCount && !entityStore[nextPage]) { | ||
| yield call(fetchEntitiesAndAddToStore, nextPage) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,12 @@ import {all, call, put, select, take, takeLatest} from 'redux-saga/effects' | |
| import {rest, notification} from 'tocco-app-extensions' | ||
|
|
||
| import ColumnModal from '../../components/ColumnModal' | ||
| import SelectNumRows from '../../components/Table/SelectRowNums' | ||
| import {getTableColumns} from '../../util/api/forms' | ||
| import * as util from '../../util/preferences' | ||
| import * as listActions from '../list/actions' | ||
| import * as listSagas from '../list/sagas' | ||
| import {setPositions, setSorting, setColumns, setPreferencesLoaded} from './actions' | ||
| import {setPositions, setSorting, setColumns, setPreferencesLoaded, setNumberOfTableRows} from './actions' | ||
| import * as actions from './actions' | ||
|
|
||
| export const inputSelector = state => state.input | ||
|
|
@@ -22,7 +23,8 @@ export default function* sagas() { | |
| takeLatest(actions.RESET_SORTING, resetSorting), | ||
| takeLatest(actions.RESET_COLUMNS, resetColumns), | ||
| takeLatest(actions.RESET_PREFERENCES, resetPreferences), | ||
| takeLatest(actions.DISPLAY_COLUMN_MODAL, displayColumnModal) | ||
| takeLatest(actions.DISPLAY_COLUMN_MODAL, displayColumnModal), | ||
| takeLatest(actions.DISPLAY_TABLE_ROWS_MODAL, displayTableRowsModal) | ||
| ]) | ||
| } | ||
|
|
||
|
|
@@ -33,6 +35,7 @@ export function* loadPreferences() { | |
| yield put(setPositions(util.getPositions(preferences))) | ||
| yield put(setSorting(util.getSorting(preferences))) | ||
| yield put(setColumns(util.getColumns(preferences))) | ||
| yield put(actions.setNumberOfTableRows(Number(preferences[`${formName}.numOfRows`]))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion(non-blocking): create For all the other preferences we have util functions to get those preferences. |
||
| yield put(setPreferencesLoaded(true)) | ||
| } | ||
|
|
||
|
|
@@ -76,6 +79,15 @@ export function* saveSorting() { | |
| } | ||
| } | ||
|
|
||
| export function* saveNumberOfTableRows(answerChannel) { | ||
| const {numOfRows} = yield take(answerChannel) | ||
| const inputState = yield select(inputSelector) | ||
|
|
||
| yield put(setNumberOfTableRows(Number(numOfRows))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion(non-blocking): how about moving the type conversion one step higher Here we need to apply the type conversion twice: Line 86 and Line 88
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These conversions can be removed, when we use the |
||
| yield call(listSagas.reloadData) | ||
| yield call(rest.savePreferences, {[`${inputState.formName}_${inputState.scope}.numOfRows`]: Number(numOfRows)}) | ||
| } | ||
|
|
||
| export function* resetSorting() { | ||
| const inputState = yield select(inputSelector) | ||
| yield all([ | ||
|
|
@@ -120,6 +132,31 @@ export function* displayColumnModal() { | |
| yield saveColumnPreferences(answerChannel, preferencesColumns, formDefinition) | ||
| } | ||
|
|
||
| export function* displayTableRowsModal() { | ||
| const {formDefinition} = yield select(listSagas.listSelector) | ||
| const answerChannel = yield call(channel) | ||
| const {numOfRows: preferencesNumOfRows} = yield select(preferencesSelector) | ||
|
|
||
| yield put( | ||
| notification.modal( | ||
| `${formDefinition.id}-numOfRows-setting`, | ||
| 'client.entity-list.preferences.numOfRows', | ||
| null, | ||
| ({close}) => { | ||
| const onOk = numOfRows => { | ||
| close() | ||
| answerChannel.put({numOfRows}) | ||
| } | ||
|
|
||
| return <SelectNumRows onOk={onOk} numOfRows={preferencesNumOfRows} /> | ||
| }, | ||
| true | ||
| ) | ||
| ) | ||
|
|
||
| yield call(saveNumberOfTableRows, answerChannel) | ||
| } | ||
|
|
||
| function* saveColumnPreferences(answerChannel, preferencesColumns, formDefinition) { | ||
| const columns = (yield take(answerChannel)).reduce( | ||
| (accumulator, item) => ({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nipick:
numOfRowsis not needed on theNavigationCellHeaderand could be removed