Skip to content
This repository was archived by the owner on Dec 28, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import styled, {createGlobalStyle} from 'styled-components'
import {Button, scale, StyledScrollbar, StyledTether, theme} from 'tocco-ui'
import {Button, scale, StyledScrollbar, StyledTether, themeSelector} from 'tocco-ui'

export const basePadding = scale.space(0.5)

export const StyledModalContent = styled.div`
position: relative;
background-color: ${theme.color('paper')};
background-color: ${themeSelector.color('paper')};
padding: ${basePadding};
display: grid;
grid-template-rows: [header] auto [body] 1fr;
Expand Down Expand Up @@ -77,7 +77,6 @@ export const StyledTitleWrapper = styled.div`
export const StyledModalBody = styled.div`
grid-row-start: body;
overflow: hidden auto;
padding-right: ${scale.space(0)};
${StyledScrollbar}
`

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import PropTypes from 'prop-types'
import {FormattedMessage} from 'react-intl'
import {connect} from 'react-redux'
import {BallMenu, MenuItem} from 'tocco-ui'

import {displayColumnModal, resetSorting, resetPreferences, resetColumns} from '../../modules/preferences/actions'

const NavigationCellHeader = props =>
!props.disablePreferencesMenu ? (
const NavigationCellHeader = ({
disablePreferencesMenu,
displayColumnModal,
resetColumns,
sortable,
resetSorting,
resetPreferences,
displayTableRowsModal
}) =>
!disablePreferencesMenu ? (
<BallMenu buttonProps={{icon: 'ellipsis-v'}}>
<MenuItem onClick={props.displayColumnModal}>
<MenuItem onClick={displayColumnModal}>
<FormattedMessage id="client.entity-list.preferences.columns" />
</MenuItem>
<MenuItem onClick={props.resetColumns}>
<MenuItem onClick={displayTableRowsModal}>
<FormattedMessage id="client.entity-list.preferences.numOfRows" />
</MenuItem>
<MenuItem onClick={resetColumns}>
<FormattedMessage id="client.entity-list.preferences.columns.reset" />
</MenuItem>
{props.sortable && (
<MenuItem onClick={props.resetSorting}>
{sortable && (
<MenuItem onClick={resetSorting}>
<FormattedMessage id="client.entity-list.sorting.reset" />
</MenuItem>
)}
<MenuItem onClick={props.resetPreferences}>
<MenuItem onClick={resetPreferences}>
<FormattedMessage id="client.entity-list.preferences.reset" />
</MenuItem>
</BallMenu>
Expand All @@ -31,19 +39,8 @@ NavigationCellHeader.propTypes = {
resetPreferences: PropTypes.func.isRequired,
resetColumns: PropTypes.func.isRequired,
sortable: PropTypes.bool,
disablePreferencesMenu: PropTypes.bool
disablePreferencesMenu: PropTypes.bool,
displayTableRowsModal: PropTypes.func.isRequired
}

const mapActionCreators = {
displayColumnModal,
resetSorting,
resetPreferences,
resetColumns
}

const mapStateToProps = (state, props) => ({
sortable: state.input.sortable,
disablePreferencesMenu: state.list.disablePreferencesMenu
})

export default connect(mapStateToProps, mapActionCreators)(NavigationCellHeader)
export default NavigationCellHeader
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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
}
}

export default connect(mapStateToProps, mapActionCreators)(NavigationCellHeader)
47 changes: 47 additions & 0 deletions packages/core/entity-list/src/components/Table/SelectRowNums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import PropTypes from 'prop-types'
import {useState} from 'react'
import {injectIntl, FormattedMessage} from 'react-intl'
import {EditableValue, Button} from 'tocco-ui'

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

const SelectNumRows = injectIntl(({intl, onOk, numOfRows}) => {
const msg = id => intl.formatMessage({id})
const options = [
{key: 25, display: '25'},
{key: 50, display: '50'},
{key: 100, display: '100'}
]
const matchingValue = options.find(option => option.key === numOfRows)
const [value, setValue] = useState(matchingValue)

return (
<>
<StyledEditableValueWrapper>
<EditableValue
value={value}
type="single-select"
events={{onChange: setValue}}
options={{
options,
noResultsText: msg('client.entity-list.preferences.numOfRows.noResultsText'),
isLoading: false
}}
/>
</StyledEditableValueWrapper>
<StyledButtonWrapper>
<Button onClick={() => onOk(value?.key)} look={'raised'}>
<FormattedMessage id="client.entity-list.preferences.numOfRows.okButton" />
</Button>
</StyledButtonWrapper>
</>
)
})

SelectNumRows.propTypes = {
intl: PropTypes.object.isRequired,
onOk: PropTypes.func.isRequired,
numOfRows: PropTypes.number
}

export default SelectNumRows
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components'
import {themeSelector, declareFont} from 'tocco-ui'
import {themeSelector, declareFont, scale, StyledButton, colorizeBorder} from 'tocco-ui'

export const StyledMarkingWrapper = styled.span`
${declareFont()}
Expand All @@ -13,3 +13,22 @@ export const StyledMarkingWrapper = styled.span`
}
${({marked, theme}) => marked && `color: ${theme.colors.secondary};`}
`

export const StyledButtonWrapper = styled.div`
position: sticky;
bottom: 0;
padding-top: ${scale.space(0)};
background-color: ${themeSelector.color('paper')};
display: flex;
justify-content: flex-end;

${StyledButton} {
margin-right: 0;
}
`

export const StyledEditableValueWrapper = styled.div`
border: 1px solid ${colorizeBorder.shade1};
padding-right: ${scale.space(-1)};
padding-left: ${scale.space(-1)};
`
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types'
import {Icon} from 'tocco-ui'

import NavigationCellHeader from './NavigationCellHeader'
import NavigationCellHeader from './NavigationCellHeaderContainer'

const CellRenderer = ({showNavigation, rowData, navigationStrategy, parent}) =>
showNavigation && navigationStrategy.DetailLinkRelative ? (
Expand Down
3 changes: 2 additions & 1 deletion packages/core/entity-list/src/containers/TableContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {changePage, refresh, initialize, onRowClick, setSortingInteractive} from
import {changePosition, resetSorting, changeWidth} from '../modules/preferences/actions'
import {onSelectChange, setSelection} from '../modules/selection/actions'
import {getFormDefinition, getClickable, getDisablePreferencesMenu, getSelectable} from '../util/api/forms'
import {getActualLimit} from '../util/preferences'
import {getTableSelectionStyle} from '../util/selection'

const mapActionCreators = {
Expand All @@ -25,7 +26,7 @@ const mapStateToProps = (state, props) => ({
currentPage: state.list.currentPage,
entities: state.list.entities,
entityCount: state.list.entityCount,
limit: state.input.limit,
limit: getActualLimit(state),
inProgress: state.list.inProgress,
tableSelectionStyle: getTableSelectionStyle(state.input.selectionStyle, getSelectable(getFormDefinition(state))),
clickable: getClickable(getFormDefinition(state)),
Expand Down
10 changes: 6 additions & 4 deletions packages/core/entity-list/src/modules/list/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getSorting,
splitFormId
} from '../../util/api/forms'
import {getActualLimit} from '../../util/preferences'
import * as preferencesActions from '../preferences/actions'
import * as searchFormActions from '../searchForm/actions'
import {getSearchFormValues} from '../searchForm/sagas'
Expand Down Expand Up @@ -287,7 +288,7 @@ export function* setLazyDataMarked(entityName, markings) {

export function* fetchEntitiesAndAddToStore(page) {
const state = yield select(stateSelector)
const {entityName, scope, limit} = state.input
const {entityName, scope} = state.input
const {columns: columnPreferences} = state.preferences
const {entityStore, sorting} = state.list
if (!entityStore[page]) {
Expand All @@ -299,7 +300,7 @@ export function* fetchEntitiesAndAddToStore(page) {
...basicQuery,
page,
sorting,
limit,
limit: getActualLimit(state),
paths
}

Expand Down Expand Up @@ -339,7 +340,8 @@ export function* delayedPreloadNextPage(page) {
}

export function* preloadNextPage(currentPage) {
const {limit} = yield select(inputSelector)
const state = yield select(stateSelector)
const actualLimit = getActualLimit(state)
const list = yield select(listSelector)
const {entityStore} = list
let {entityCount} = list
Expand All @@ -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)
}
}
Expand Down
11 changes: 11 additions & 0 deletions packages/core/entity-list/src/modules/preferences/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const RESET_COLUMNS = 'preferences/RESET_COLUMNS'
export const RESET_PREFERENCES = 'preferences/RESET_PREFERENCES'
export const DISPLAY_COLUMN_MODAL = 'preferences/DISPLAY_COLUMN_MODAL'
export const SET_PREFERENCES_LOADED = 'preferences/SET_PREFERENCES_LOADED'
export const SET_NUMBER_OF_TABLE_ROWS = 'preferences/SET_NUMBER_OF_TABLE_ROWS'
export const DISPLAY_TABLE_ROWS_MODAL = 'preferences/DISPLAY_TABLE_ROWS_MODAL'

export const loadPreferences = () => ({
type: LOAD_PREFERENCES
Expand Down Expand Up @@ -78,3 +80,12 @@ export const resetColumns = () => ({
type: RESET_COLUMNS,
payload: {}
})

export const displayTableRowsModal = () => ({
type: DISPLAY_TABLE_ROWS_MODAL
})

export const setNumberOfTableRows = numOfRows => ({
type: SET_NUMBER_OF_TABLE_ROWS,
payload: {numOfRows}
})
12 changes: 10 additions & 2 deletions packages/core/entity-list/src/modules/preferences/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ const resetPreferences = state => ({
...state,
positions: {},
sorting: [],
columns: {}
columns: {},
numOfRows: undefined
})

const setNumberOfTableRows = (state, {payload: {numOfRows}}) => ({
...state,
numOfRows
})

const ACTION_HANDLERS = {
Expand All @@ -36,14 +42,16 @@ const ACTION_HANDLERS = {
[actions.SET_PREFERENCES_LOADED]: reducerUtil.singleTransferReducer('preferencesLoaded'),
[actions.RESET_SORTING]: resetSorting,
[actions.RESET_COLUMNS]: resetColumns,
[actions.RESET_PREFERENCES]: resetPreferences
[actions.RESET_PREFERENCES]: resetPreferences,
[actions.SET_NUMBER_OF_TABLE_ROWS]: setNumberOfTableRows
}

const initialState = {
positions: {},
sorting: [],
columns: {},
widths: {},
numOfRows: undefined,
preferencesLoaded: false
}

Expand Down
Loading