Skip to content

Commit

Permalink
[desk-tool] Fix fallback edit intent pane not updating properly (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Sep 28, 2018
1 parent a06e11d commit 5db1f4b
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions packages/@sanity/desk-tool/src/DeskTool.js
Expand Up @@ -171,7 +171,15 @@ export default withRouterHOC(

shouldComponentUpdate(nextProps, nextState) {
// @todo move this out of sCU - cWRP is deprecated, gDSFP does not have previous props
if (!shallowEquals(nextProps.router.state.panes, this.props.router.state.panes)) {
const nextRouterState = nextProps.router.state
const prevRouterState = this.props.router.state
if (
!shallowEquals(nextRouterState.panes, prevRouterState.panes) ||
nextRouterState.editDocumentId !== prevRouterState.editDocumentId ||
nextRouterState.legacyEditDocumentId !== prevRouterState.legacyEditDocumentId ||
nextRouterState.type !== prevRouterState.type ||
nextRouterState.action !== prevRouterState.action
) {
this.derivePanes(nextProps)
}

Expand Down Expand Up @@ -208,20 +216,24 @@ export default withRouterHOC(
}
}

getFallbackKeys() {
const routerState = this.props.router.state
return routerState.type && routerState.editDocumentId
? [`${routerState.type}-${routerState.editDocumentId}`]
: EMPTY_PANE_KEYS
}

render() {
const {panes, error} = this.state
if (error) {
return <StructureError error={error} />
}

const keys = this.props.router.state.panes || this.getFallbackKeys()

return (
<div className={styles.deskTool}>
{panes && (
<DeskToolPanes
panes={this.state.panes}
keys={this.props.router.state.panes || EMPTY_PANE_KEYS}
/>
)}
{panes && <DeskToolPanes panes={this.state.panes} keys={keys} />}
</div>
)
}
Expand Down

0 comments on commit 5db1f4b

Please sign in to comment.