Skip to content

Commit

Permalink
[desk-tool] Make since an exclusice parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 6, 2020
1 parent a827894 commit a208935
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 40 deletions.
6 changes: 3 additions & 3 deletions packages/@sanity/desk-tool/src/contexts/PaneRouterContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function missingContext<T = any>(): T {
throw new Error('Pane is missing router context')
}

export const exclusiveParams = ['view']
export const exclusiveParams = ['view', 'since']

type PaneSegment = {id: string; payload?: unknown; params?: Record<string, any>}
type RouterPanesState = Array<PaneSegment[]>
Expand Down Expand Up @@ -88,8 +88,8 @@ export const PaneRouterContext = React.createContext<PaneRouterContextShape>({
hasGroupSiblings: false,
groupLength: 0,
routerPanesState: [],
ChildLink: ({}) => missingContext(),
ParameterizedLink: ({}) => missingContext(),
ChildLink: () => missingContext(),
ParameterizedLink: () => missingContext(),
replaceCurrent: () => missingContext(),
closeCurrent: () => missingContext(),
duplicateCurrent: () => missingContext(),
Expand Down
46 changes: 9 additions & 37 deletions packages/@sanity/desk-tool/src/tool/DeskToolPanes.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable react/jsx-filename-extension */
/* eslint-disable react/jsx-filename-extension, react/prop-types */

import React from 'react'
import PropTypes from 'prop-types'
import {sumBy} from 'lodash'
import {omit, sumBy} from 'lodash'
import {merge, of} from 'rxjs'
import {mapTo, delay, distinctUntilChanged} from 'rxjs/operators'
import SplitController from 'part:@sanity/components/panes/split-controller'
import SplitPaneWrapper from 'part:@sanity/components/panes/split-pane-wrapper'
import {ResizeObserver} from './resize-observer'
import {DeskToolPane, LoadingPane} from '../panes'
import windowWidth$ from '../utils/windowWidth'
import isNarrowScreen from '../utils/isNarrowScreen'
import {LOADING_PANE} from '../constants'
import {PaneRouterContext, getPaneRouterContextFactory} from '../contexts/PaneRouterContext'
import {
PaneRouterContext,
getPaneRouterContextFactory,
exclusiveParams
} from '../contexts/PaneRouterContext'
import {ResizeObserver} from './resize-observer'

import styles from './DeskToolPanes.css'

Expand Down Expand Up @@ -52,37 +55,6 @@ function getWaitMessages(path) {

// eslint-disable-next-line react/require-optimization
export default class DeskToolPanes extends React.Component {
static propTypes = {
keys: PropTypes.arrayOf(PropTypes.string).isRequired,
groupIndexes: PropTypes.arrayOf(PropTypes.number).isRequired,
autoCollapse: PropTypes.bool,
panes: PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.shape({
id: PropTypes.string.isRequired,
params: PropTypes.object
}),
PropTypes.symbol
])
).isRequired,
router: PropTypes.shape({
navigate: PropTypes.func.isRequired,
navigateIntent: PropTypes.func.isRequired,
state: PropTypes.shape({
panes: PropTypes.arrayOf(
PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
params: PropTypes.object
})
)
),
payload: PropTypes.object,
params: PropTypes.object
})
}).isRequired
}

static defaultProps = {
autoCollapse: false
}
Expand Down Expand Up @@ -231,7 +203,7 @@ export default class DeskToolPanes extends React.Component {
const wrapperKey = pane === LOADING_PANE ? `loading-${i}` : `${i}-${pane.id}`
path.push(pane.id || `[${i}]`)

const {view: rootView, ...rootParams} = groupRoot.params || {}
const rootParams = omit(groupRoot.params || {}, exclusiveParams)
const params = isDuplicate ? {...rootParams, ...sibling.params} : sibling.params
const payload = isDuplicate ? sibling.payload || groupRoot.payload : sibling.payload

Expand Down

0 comments on commit a208935

Please sign in to comment.