parent
152f68624c
commit
4349911076
@ -248,6 +248,9 @@ class GroupedAction extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// page number and sort info are optional for backward compatibility
|
||||||
|
const URL_STATE_RE = /^(?:(\d+)(?:_(\d+)(_desc)?)?-)?(.*)$/
|
||||||
|
|
||||||
@propTypes(
|
@propTypes(
|
||||||
{
|
{
|
||||||
defaultColumn: propTypes.number,
|
defaultColumn: propTypes.number,
|
||||||
@ -312,13 +315,24 @@ export default class SortedTable extends Component {
|
|||||||
const urlState = get(
|
const urlState = get(
|
||||||
() => context.router.location.query[props.stateUrlParam]
|
() => context.router.location.query[props.stateUrlParam]
|
||||||
)
|
)
|
||||||
if (urlState !== undefined) {
|
|
||||||
const i = urlState.indexOf('-')
|
let matches
|
||||||
if (i === -1) {
|
if (
|
||||||
state.filter = urlState
|
urlState !== undefined &&
|
||||||
} else {
|
(matches = URL_STATE_RE.exec(urlState)) !== null
|
||||||
state.filter = urlState.slice(i + 1)
|
) {
|
||||||
state.page = +urlState.slice(0, i)
|
state.filter = matches[4]
|
||||||
|
const page = matches[1]
|
||||||
|
if (page !== undefined) {
|
||||||
|
state.page = +page
|
||||||
|
}
|
||||||
|
let selectedColumn = matches[2]
|
||||||
|
if (
|
||||||
|
selectedColumn !== undefined &&
|
||||||
|
(selectedColumn = +selectedColumn) < props.columns.length
|
||||||
|
) {
|
||||||
|
state.selectedColumn = selectedColumn
|
||||||
|
state.sortOrder = matches[3] !== undefined ? 'desc' : 'asc'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,7 +470,7 @@ export default class SortedTable extends Component {
|
|||||||
this.props.columns[columnId].sortOrder === 'desc' ? 'desc' : 'asc'
|
this.props.columns[columnId].sortOrder === 'desc' ? 'desc' : 'asc'
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this._setVisibleState({
|
||||||
selectedColumn: columnId,
|
selectedColumn: columnId,
|
||||||
sortOrder,
|
sortOrder,
|
||||||
})
|
})
|
||||||
@ -481,25 +495,28 @@ export default class SortedTable extends Component {
|
|||||||
this._checkUpdatePage()
|
this._checkUpdatePage()
|
||||||
}
|
}
|
||||||
|
|
||||||
_saveUrlState (filter, page) {
|
_saveUrlState = () => {
|
||||||
const { stateUrlParam } = this.props
|
const { filter, page, selectedColumn, sortOrder } = this.state
|
||||||
if (stateUrlParam === undefined) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const { router } = this.context
|
const { router } = this.context
|
||||||
const { location } = router
|
const { location } = router
|
||||||
router.replace({
|
router.replace({
|
||||||
...location,
|
...location,
|
||||||
query: {
|
query: {
|
||||||
...location.query,
|
...location.query,
|
||||||
[stateUrlParam]: `${page}-${filter}`,
|
[this.props.stateUrlParam]: `${page}_${selectedColumn}${
|
||||||
|
sortOrder === 'desc' ? '_desc' : ''
|
||||||
|
}-${filter}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update state in the state and update the URL param
|
||||||
|
_setVisibleState (state) {
|
||||||
|
this.setState(state, this.props.stateUrlParam && this._saveUrlState)
|
||||||
|
}
|
||||||
|
|
||||||
_setFilter = filter => {
|
_setFilter = filter => {
|
||||||
this._saveUrlState(filter, 1)
|
this._setVisibleState({
|
||||||
this.setState({
|
|
||||||
filter,
|
filter,
|
||||||
page: 1,
|
page: 1,
|
||||||
highlighted: undefined,
|
highlighted: undefined,
|
||||||
@ -525,8 +542,7 @@ export default class SortedTable extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_setPage (page) {
|
_setPage (page) {
|
||||||
this._saveUrlState(this.state.filter, page)
|
this._setVisibleState({ page })
|
||||||
this.setState({ page })
|
|
||||||
}
|
}
|
||||||
_setPage = this._setPage.bind(this)
|
_setPage = this._setPage.bind(this)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user