-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import {useCallback, useMemo} from 'react' | ||
import {isPublishedPerspective} from 'sanity' | ||
import {useRouter} from 'sanity/router' | ||
|
||
import {useReleases} from '../../store/release' | ||
|
@@ -54,7 +55,10 @@ export function usePerspective(): PerspectiveValue { | |
| `bundle.${string}` | ||
| undefined | ||
|
||
const excludedPerspectives = router.stickyParams.excludedPerspectives?.split(',') || EMPTY_ARRAY | ||
const excludedPerspectives = useMemo( | ||
() => router.stickyParams.excludedPerspectives?.split(',') || EMPTY_ARRAY, | ||
[router.stickyParams.excludedPerspectives], | ||
) | ||
|
||
// TODO: Should it be possible to set the perspective within a pane, rather than globally? | ||
const setPerspective = useCallback( | ||
|
@@ -107,15 +111,15 @@ export function usePerspective(): PerspectiveValue { | |
const toggleExcludedPerspective = useCallback( | ||
(excluded: string) => { | ||
if (excluded === LATEST._id) return | ||
const nextExcludedPerspectives: string[] = excludedPerspectives || [] | ||
const existingPerspectives = excludedPerspectives || [] | ||
|
||
const excludedPerspectiveId = excluded === 'published' ? 'published' : `bundle.${excluded}` | ||
const excludedPerspectiveId = isPublishedPerspective(excluded) | ||
? 'published' | ||
: `bundle.${excluded}` | ||
|
||
if (excludedPerspectives?.includes(excludedPerspectiveId)) { | ||
nextExcludedPerspectives.splice(nextExcludedPerspectives.indexOf(excludedPerspectiveId), 1) | ||
} else { | ||
nextExcludedPerspectives.push(excludedPerspectiveId) | ||
} | ||
const nextExcludedPerspectives = existingPerspectives.includes(excludedPerspectiveId) | ||
? existingPerspectives.filter((id) => id !== excludedPerspectiveId) | ||
: [...existingPerspectives, excludedPerspectiveId] | ||
|
||
router.navigateStickyParams({excludedPerspectives: nextExcludedPerspectives.toString()}) | ||
}, | ||
|
@@ -126,7 +130,7 @@ export function usePerspective(): PerspectiveValue { | |
(perspectiveId: string) => | ||
Boolean( | ||
excludedPerspectives?.includes( | ||
perspectiveId === 'published' ? 'published' : `bundle.${perspectiveId}`, | ||
isPublishedPerspective(perspectiveId) ? 'published' : `bundle.${perspectiveId}`, | ||
), | ||
), | ||
[excludedPerspectives], | ||
|
@@ -140,8 +144,9 @@ export function usePerspective(): PerspectiveValue { | |
setPerspectiveFromRelease, | ||
toggleExcludedPerspective, | ||
currentGlobalBundle, | ||
currentGlobalBundleId: | ||
currentGlobalBundle === 'published' ? 'published' : currentGlobalBundle._id, | ||
currentGlobalBundleId: isPublishedPerspective(currentGlobalBundle) | ||
Check failure on line 147 in packages/sanity/src/core/releases/hooks/usePerspective.tsx GitHub Actions / Test (ubuntu-latest / node 18)src/core/studio/components/navbar/search/components/common/__tests__/FilterLabel.test.tsx > FilterLabel > renders the filter label with field, operator, and value
Check failure on line 147 in packages/sanity/src/core/releases/hooks/usePerspective.tsx GitHub Actions / Test (ubuntu-latest / node 18)src/core/studio/components/navbar/search/components/common/__tests__/FilterLabel.test.tsx > FilterLabel > renders only the field when showContent is false
Check failure on line 147 in packages/sanity/src/core/releases/hooks/usePerspective.tsx GitHub Actions / Test (ubuntu-latest / node 18)src/core/studio/components/navbar/search/components/common/__tests__/FilterLabel.test.tsx > FilterLabel > handles missing operator descriptionKey
Check failure on line 147 in packages/sanity/src/core/releases/hooks/usePerspective.tsx GitHub Actions / Test (ubuntu-latest / node 20)src/core/studio/components/navbar/search/components/common/__tests__/FilterLabel.test.tsx > FilterLabel > renders the filter label with field, operator, and value
Check failure on line 147 in packages/sanity/src/core/releases/hooks/usePerspective.tsx GitHub Actions / Test (ubuntu-latest / node 20)src/core/studio/components/navbar/search/components/common/__tests__/FilterLabel.test.tsx > FilterLabel > renders only the field when showContent is false
Check failure on line 147 in packages/sanity/src/core/releases/hooks/usePerspective.tsx GitHub Actions / Test (ubuntu-latest / node 20)src/core/studio/components/navbar/search/components/common/__tests__/FilterLabel.test.tsx > FilterLabel > handles missing operator descriptionKey
|
||
? 'published' | ||
: currentGlobalBundle._id, | ||
bundlesPerspective, | ||
isPerspectiveExcluded, | ||
}), | ||
|