Skip to content

Commit

Permalink
fix(default-layout): fix bug with spaces (#2835)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricokahler committed Oct 7, 2021
1 parent 554260b commit 31697bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useCallback, useEffect, useState} from 'react'
import {filter, map} from 'rxjs/operators'
import {Select} from '@sanity/ui'
import {isResolvedEvent, state as urlState} from '../datastores/urlState'
import {isSnapshotEvent, state as urlState} from '../datastores/urlState'
import {CONFIGURED_SPACES} from '../util/spaces'
import {useDefaultLayoutRouter} from '../useDefaultLayoutRouter'

Expand All @@ -11,7 +11,7 @@ export function DatasetSelect(props: Omit<React.HTMLProps<HTMLSelectElement>, 'r

useEffect(() => {
const currentSpace$ = urlState.pipe(
filter(isResolvedEvent),
filter(isSnapshotEvent),
map((event) => event.state && event.state.space),
map((spaceName) => CONFIGURED_SPACES.find((sp) => sp.name === spaceName))
)
Expand Down
14 changes: 7 additions & 7 deletions packages/@sanity/default-layout/src/datastores/urlState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import getOrderedTools from '../util/getOrderedTools'
import reconfigureClient from '../util/reconfigureClient'
import {HAS_SPACES, CONFIGURED_SPACES} from '../util/spaces'

interface ResolvedStateEvent {
type: 'resolved'
interface SnapshotStateEvent {
type: 'snapshot'
intent: {
name: string
params: {[key: string]: string}
Expand All @@ -34,7 +34,7 @@ interface ErrorStateEvent {
error: Error
}

type StateEvent = ResolvedStateEvent | ErrorStateEvent
type StateEvent = SnapshotStateEvent | ErrorStateEvent

function resolveUrlStateWithDefaultSpace(state) {
if (!HAS_SPACES || !state || state.space) {
Expand Down Expand Up @@ -133,7 +133,7 @@ function decodeUrlState(locationEvent: {type: string}) {
}
}

function maybeRedirectDefaultState(event: ResolvedStateEvent): StateEvent | null {
function maybeRedirectDefaultState(event: SnapshotStateEvent): StateEvent | null {
const redirectState = resolveDefaultState(event.state)
if (redirectState !== event.state) {
navigate(rootRouter.encode(redirectState), {replace: true})
Expand All @@ -158,15 +158,15 @@ export const state: Observable<StateEvent> = locationStore.state.pipe(
refCount()
)

export function isResolvedEvent(event: StateEvent): event is ResolvedStateEvent {
return event.type === 'resolved'
export function isSnapshotEvent(event: StateEvent): event is SnapshotStateEvent {
return event.type === 'snapshot'
}

if (HAS_SPACES) {
// Uglybugly mutation ahead.
state
.pipe(
filter(isResolvedEvent),
filter(isSnapshotEvent),
map((event) => event.state),
filter(Boolean),
tap(reconfigureClient)
Expand Down

3 comments on commit 31697bd

@vercel
Copy link

@vercel vercel bot commented on 31697bd Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

studio-workshop – ./dev/workshop

studio-workshop-git-next.sanity.build
studio-workshop.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 31697bd Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio.sanity.build
test-studio-git-next.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 31697bd Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

perf-studio – ./

perf-studio.sanity.build
perf-studio-git-next.sanity.build

Please sign in to comment.