export default()

in src/reducers/nav.ts [57:102]


export default (state: INav = INITIAL_STATE, action: Action): INav => {
  if (isType(action, actions.nav.selectType)) {
    return makeSelected(action.payload.type, state)
  }

  if (isType(action, actions.nav.expandType)) {
    const newExpandedTypes = withParentTypes(action.payload.type)
    return { ...state, expandedTypes: state.expandedTypes.concat(newExpandedTypes) }
  }

  if (isType(action, actions.nav.collapseType)) {
    // This makes sure to also collapse any child nodes
    const expandedTypes = state.expandedTypes.filter((t) => !t.startsWith(action.payload.type))
    return {
      ...state,
      expandedTypes
    }
  }

  if (isType(action, actions.nav.search)) {
    return { ...state, query: action.payload.query }
  }

  if (isType(action, actions.nav.showTree)) {
    return { ...state, showTree: true }
  }

  if (isType(action, actions.nav.hideTree)) {
    return { ...state, showTree: false }
  }

  if (action.type === LOCATION_CHANGE) {
    const locationChangeAction = action as LocationChangeAction
    const match = matchPath(locationChangeAction.payload.pathname, { path: '/:fullName' })
    if (match) {
      const params = match.params
      if ('fullName' in params) {
        const typedParams = params as {fullName: string}
        const type = '.' + typedParams.fullName
        return makeSelected(type, state)
      }
    }
  }

  return state
}