@sanity/sdk-react 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -84,7 +84,10 @@ import {useSanityInstance} from '../context/useSanityInstance'
84
84
  export function useDocumentPermissions(
85
85
  actionOrActions: DocumentAction | DocumentAction[],
86
86
  ): DocumentPermissionsResult {
87
- const actions = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions]
87
+ const actions = useMemo(
88
+ () => (Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions]),
89
+ [actionOrActions],
90
+ )
88
91
  // if actions is an array, we need to check that all actions belong to the same project and dataset
89
92
  let projectId
90
93
  let dataset
@@ -111,20 +114,20 @@ export function useDocumentPermissions(
111
114
 
112
115
  const instance = useSanityInstance({projectId, dataset})
113
116
  const isDocumentReady = useCallback(
114
- () => getPermissionsState(instance, actionOrActions).getCurrent() !== undefined,
115
- [actionOrActions, instance],
117
+ () => getPermissionsState(instance, {actions}).getCurrent() !== undefined,
118
+ [actions, instance],
116
119
  )
117
120
  if (!isDocumentReady()) {
118
121
  throw firstValueFrom(
119
- getPermissionsState(instance, actionOrActions).observable.pipe(
122
+ getPermissionsState(instance, {actions}).observable.pipe(
120
123
  filter((result) => result !== undefined),
121
124
  ),
122
125
  )
123
126
  }
124
127
 
125
128
  const {subscribe, getCurrent} = useMemo(
126
- () => getPermissionsState(instance, actionOrActions),
127
- [actionOrActions, instance],
129
+ () => getPermissionsState(instance, {actions}),
130
+ [actions, instance],
128
131
  )
129
132
 
130
133
  return useSyncExternalStore(subscribe, getCurrent) as DocumentPermissionsResult
@@ -52,6 +52,7 @@ describe('usePerspective', () => {
52
52
  _updatedAt: '2021-01-01T00:00:00Z',
53
53
  _rev: 'rev1',
54
54
  name: 'Test Release',
55
+ state: 'scheduled',
55
56
  metadata: {
56
57
  title: 'Test Release',
57
58
  releaseType: 'asap',
@@ -43,7 +43,7 @@ export const usePerspective: UsePerspective = createStateSourceHook({
43
43
  instance: SanityInstance,
44
44
  perspectiveHandle?: PerspectiveHandle,
45
45
  ) => StateSource<string | string[]>,
46
- shouldSuspend: (instance: SanityInstance, options?: PerspectiveHandle): boolean =>
46
+ shouldSuspend: (instance: SanityInstance, options: PerspectiveHandle): boolean =>
47
47
  getPerspectiveState(instance, options).getCurrent() === undefined,
48
48
  suspender: (instance: SanityInstance, _options?: PerspectiveHandle) =>
49
49
  firstValueFrom(getActiveReleasesState(instance).observable.pipe(filter(Boolean))),