Skip to content
This repository was archived by the owner on Dec 28, 2022. It is now read-only.

Commit 6e4bdce

Browse files
committed
chore: fix review issues
Refs: TOCDEV-5494
1 parent f10ea12 commit 6e4bdce

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

packages/core/entity-list/src/components/Table/NavigationCellHeaderContainer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ const mapActionCreators = {
2020
const mapStateToProps = (state, props) => {
2121
return {
2222
sortable: state.list.sortable,
23-
disablePreferencesMenu: state.list.disablePreferencesMenu,
24-
numOfRows: state.preferences.numOfRows
23+
disablePreferencesMenu: state.list.disablePreferencesMenu
2524
}
2625
}
2726

packages/core/entity-list/src/components/Table/SelectRowNums.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import PropTypes from 'prop-types'
22
import {useState} from 'react'
3+
import {injectIntl, FormattedMessage} from 'react-intl'
34
import {EditableValue, Button} from 'tocco-ui'
45

56
import {StyledButtonWrapper, StyledEditableValueWrapper} from './StyledComponents'
67

7-
const SelectNumRows = ({onOk, numOfRows}) => {
8+
const SelectNumRows = injectIntl(({intl, onOk, numOfRows}) => {
9+
const msg = id => intl.formatMessage({id})
810
const options = [
9-
{key: 1, display: '25'},
10-
{key: 2, display: '50'},
11-
{key: 3, display: '100'}
11+
{key: 25, display: '25'},
12+
{key: 50, display: '50'},
13+
{key: 100, display: '100'}
1214
]
13-
const matchingValue = options.find(option => Number(option.display) === numOfRows)
15+
const matchingValue = options.find(option => option.key === numOfRows)
1416
const [value, setValue] = useState(matchingValue)
1517

1618
return (
@@ -22,21 +24,22 @@ const SelectNumRows = ({onOk, numOfRows}) => {
2224
events={{onChange: setValue}}
2325
options={{
2426
options,
25-
noResultsText: 'no results found',
27+
noResultsText: msg('client.entity-list.preferences.numOfRows.noResultsText'),
2628
isLoading: false
2729
}}
2830
/>
2931
</StyledEditableValueWrapper>
3032
<StyledButtonWrapper>
31-
<Button onClick={() => onOk(value?.display)} look={'raised'}>
32-
OK
33+
<Button onClick={() => onOk(value?.key)} look={'raised'}>
34+
<FormattedMessage id="client.entity-list.preferences.numOfRows.okButton" />
3335
</Button>
3436
</StyledButtonWrapper>
3537
</>
3638
)
37-
}
39+
})
3840

3941
SelectNumRows.propTypes = {
42+
intl: PropTypes.object.isRequired,
4043
onOk: PropTypes.func.isRequired,
4144
numOfRows: PropTypes.number
4245
}

packages/core/entity-list/src/containers/TableContainer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {changePage, refresh, initialize, onRowClick, setSortingInteractive} from
66
import {changePosition, resetSorting, changeWidth} from '../modules/preferences/actions'
77
import {onSelectChange, setSelection} from '../modules/selection/actions'
88
import {getFormDefinition, getClickable, getDisablePreferencesMenu, getSelectable} from '../util/api/forms'
9+
import {getActualLimit} from '../util/preferences'
910
import {getTableSelectionStyle} from '../util/selection'
1011

1112
const mapActionCreators = {
@@ -25,7 +26,7 @@ const mapStateToProps = (state, props) => ({
2526
currentPage: state.list.currentPage,
2627
entities: state.list.entities,
2728
entityCount: state.list.entityCount,
28-
limit: state.preferences.numOfRows || state.input.limit,
29+
limit: getActualLimit(state),
2930
inProgress: state.list.inProgress,
3031
tableSelectionStyle: getTableSelectionStyle(state.input.selectionStyle, getSelectable(getFormDefinition(state))),
3132
clickable: getClickable(getFormDefinition(state)),

packages/core/entity-list/src/modules/list/sagas.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
getSorting,
1717
splitFormId
1818
} from '../../util/api/forms'
19+
import {getActualLimit} from '../../util/preferences'
1920
import * as preferencesActions from '../preferences/actions'
2021
import * as searchFormActions from '../searchForm/actions'
2122
import {getSearchFormValues} from '../searchForm/sagas'
@@ -287,8 +288,8 @@ export function* setLazyDataMarked(entityName, markings) {
287288

288289
export function* fetchEntitiesAndAddToStore(page) {
289290
const state = yield select(stateSelector)
290-
const {entityName, scope, limit} = state.input
291-
const {columns: columnPreferences, numOfRows} = state.preferences
291+
const {entityName, scope} = state.input
292+
const {columns: columnPreferences} = state.preferences
292293
const {entityStore, sorting} = state.list
293294
if (!entityStore[page]) {
294295
const basicQuery = yield call(getBasicQuery)
@@ -299,7 +300,7 @@ export function* fetchEntitiesAndAddToStore(page) {
299300
...basicQuery,
300301
page,
301302
sorting,
302-
limit: numOfRows || limit,
303+
limit: getActualLimit(state),
303304
paths
304305
}
305306

@@ -339,9 +340,8 @@ export function* delayedPreloadNextPage(page) {
339340
}
340341

341342
export function* preloadNextPage(currentPage) {
342-
const {limit} = yield select(inputSelector)
343-
const {numOfRows} = yield select(preferencesSelector)
344-
const actualLimit = numOfRows || limit
343+
const state = yield select(stateSelector)
344+
const actualLimit = getActualLimit(state)
345345
const list = yield select(listSelector)
346346
const {entityStore} = list
347347
let {entityCount} = list

packages/core/entity-list/src/modules/preferences/sagas.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function* loadPreferences() {
3535
yield put(setPositions(util.getPositions(preferences)))
3636
yield put(setSorting(util.getSorting(preferences)))
3737
yield put(setColumns(util.getColumns(preferences)))
38-
yield put(actions.setNumberOfTableRows(Number(preferences[`${formName}.numOfRows`])))
38+
yield put(setNumberOfTableRows(Number(preferences[`${formName}.numOfRows`])))
3939
yield put(setPreferencesLoaded(true))
4040
}
4141

@@ -82,10 +82,11 @@ export function* saveSorting() {
8282
export function* saveNumberOfTableRows(answerChannel) {
8383
const {numOfRows} = yield take(answerChannel)
8484
const inputState = yield select(inputSelector)
85+
const formName = `${inputState.formName}_${inputState.scope}`
8586

86-
yield put(setNumberOfTableRows(Number(numOfRows)))
87+
yield put(setNumberOfTableRows(numOfRows))
8788
yield call(listSagas.reloadData)
88-
yield call(rest.savePreferences, {[`${inputState.formName}_${inputState.scope}.numOfRows`]: Number(numOfRows)})
89+
yield call(rest.savePreferences, {[`${formName}.numOfRows`]: numOfRows})
8990
}
9091

9192
export function* resetSorting() {

packages/core/entity-list/src/util/preferences.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,5 @@ export const getColumnPreferencesToSave = (formName, columns) =>
9696
}),
9797
{}
9898
)
99+
100+
export const getActualLimit = state => state.preferences.numOfRows || state.input.limit

0 commit comments

Comments
 (0)