sanity-plugin-media 4.3.5 → 4.3.6

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.
Files changed (65) hide show
  1. package/dist/index.cjs +2529 -3561
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +190 -413
  4. package/dist/index.d.cts.map +1 -0
  5. package/dist/index.d.ts +190 -413
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +2532 -3564
  8. package/dist/index.js.map +1 -1
  9. package/package.json +26 -23
  10. package/src/__tests__/fixtures/mockSanityClient.ts +3 -3
  11. package/src/components/AssetGridVirtualized/index.tsx +3 -3
  12. package/src/components/AssetMetadata/index.tsx +1 -1
  13. package/src/components/AssetTableVirtualized/index.tsx +2 -2
  14. package/src/components/AutoTagInputWrapper/index.tsx +1 -3
  15. package/src/components/CardAsset/CardAsset.test.tsx +6 -6
  16. package/src/components/DialogAssetEdit/Details.tsx +2 -2
  17. package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +1 -1
  18. package/src/components/DialogAssetEdit/index.tsx +5 -4
  19. package/src/components/DialogConfirm/index.tsx +2 -0
  20. package/src/components/DialogSearchFacets/index.tsx +1 -1
  21. package/src/components/DialogTagCreate/index.tsx +10 -2
  22. package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +1 -1
  23. package/src/components/DialogTagEdit/index.tsx +18 -7
  24. package/src/components/DialogTags/index.tsx +1 -1
  25. package/src/components/Dialogs/index.tsx +1 -1
  26. package/src/components/Header/index.tsx +1 -1
  27. package/src/components/Items/index.tsx +1 -1
  28. package/src/components/Notifications/index.tsx +2 -2
  29. package/src/components/SearchFacet/index.tsx +1 -1
  30. package/src/components/SearchFacetSelect/index.tsx +2 -2
  31. package/src/components/SearchFacets/index.tsx +1 -1
  32. package/src/components/TableRowAsset/index.tsx +0 -1
  33. package/src/components/TagsVirtualized/index.tsx +2 -2
  34. package/src/components/UploadDropzone/index.tsx +1 -1
  35. package/src/config/orders.ts +1 -1
  36. package/src/contexts/AssetSourceDispatchContext.tsx +7 -6
  37. package/src/contexts/DropzoneDispatchContext.tsx +2 -4
  38. package/src/contexts/ToolOptionsContext.tsx +1 -0
  39. package/src/formSchema/index.ts +1 -1
  40. package/src/hooks/useBreakpointIndex.ts +5 -4
  41. package/src/modules/assets/deleteAndUpdateEpics.test.ts +2 -2
  42. package/src/modules/assets/fetchEpic.test.ts +1 -1
  43. package/src/modules/assets/index.ts +26 -69
  44. package/src/modules/assets/reducer.test.ts +3 -3
  45. package/src/modules/assets/tagsAndListenerEpics.test.ts +3 -3
  46. package/src/modules/dialog/epics.test.ts +1 -1
  47. package/src/modules/dialog/index.ts +2 -2
  48. package/src/modules/index.ts +3 -10
  49. package/src/modules/notifications/epics.test.ts +5 -5
  50. package/src/modules/notifications/index.ts +1 -1
  51. package/src/modules/search/index.test.ts +2 -2
  52. package/src/modules/search/index.ts +1 -1
  53. package/src/modules/tags/epics.test.ts +2 -2
  54. package/src/modules/tags/index.test.ts +2 -2
  55. package/src/modules/tags/index.ts +19 -19
  56. package/src/modules/uploads/epics.test.ts +2 -2
  57. package/src/modules/uploads/index.test.ts +3 -3
  58. package/src/modules/uploads/index.ts +3 -13
  59. package/src/styled/react-select/creatable.tsx +4 -4
  60. package/src/styled/react-select/single.tsx +9 -9
  61. package/src/types/index.ts +0 -33
  62. package/src/types/sanity-ui.d.ts +0 -1
  63. package/src/utils/generatePreviewBlobUrl.test.ts +0 -2
  64. package/src/utils/getDocumentAssetIds.ts +2 -2
  65. package/src/hooks/useOnScreen.ts +0 -34
@@ -47,7 +47,7 @@ describe('assetsDeleteEpic', () => {
47
47
  store.dispatch(assetsActions.deleteRequest({assets: [sampleAsset]}))
48
48
 
49
49
  await vi.waitFor(() => {
50
- expect(store.getState().assets.byIds.a1).toBeUndefined()
50
+ expect(store.getState().assets.byIds['a1']).toBeUndefined()
51
51
  expect(client.observable.delete).toHaveBeenCalled()
52
52
  })
53
53
  })
@@ -81,7 +81,7 @@ describe('assetsUpdateEpic', () => {
81
81
 
82
82
  await vi.waitFor(() => {
83
83
  expect(chain.commit).toHaveBeenCalled()
84
- expect(store.getState().assets.byIds.a1.asset.title).toBe('Updated')
84
+ expect(store.getState().assets.byIds['a1']!.asset.title).toBe('Updated')
85
85
  })
86
86
  })
87
87
  })
@@ -9,7 +9,7 @@ import type {ImageAsset} from '../../types'
9
9
  import {assetsActions, assetsFetchEpic} from './index'
10
10
 
11
11
  function assertFetchSucceeded(store: ReturnType<typeof createEpicTestStore>, asset: ImageAsset) {
12
- expect(store.getState().assets.byIds.a1?.asset).toEqual(asset)
12
+ expect(store.getState().assets.byIds['a1']?.asset).toEqual(asset)
13
13
  expect(store.getState().assets.fetching).toBe(false)
14
14
  }
15
15
 
@@ -110,37 +110,37 @@ const assetsSlice = createSlice({
110
110
  .addCase(ASSETS_ACTIONS.tagsAddComplete, (state, action) => {
111
111
  const {assets} = action.payload
112
112
  assets.forEach((asset) => {
113
- state.byIds[asset.asset._id].updating = false
113
+ state.byIds[asset.asset._id]!.updating = false
114
114
  })
115
115
  })
116
116
  .addCase(ASSETS_ACTIONS.tagsAddError, (state, action) => {
117
117
  const {assets} = action.payload
118
118
  assets.forEach((asset) => {
119
- state.byIds[asset.asset._id].updating = false
119
+ state.byIds[asset.asset._id]!.updating = false
120
120
  })
121
121
  })
122
122
  .addCase(ASSETS_ACTIONS.tagsAddRequest, (state, action) => {
123
123
  const {assets} = action.payload
124
124
  assets.forEach((asset) => {
125
- state.byIds[asset.asset._id].updating = true
125
+ state.byIds[asset.asset._id]!.updating = true
126
126
  })
127
127
  })
128
128
  .addCase(ASSETS_ACTIONS.tagsRemoveComplete, (state, action) => {
129
129
  const {assets} = action.payload
130
130
  assets.forEach((asset) => {
131
- state.byIds[asset.asset._id].updating = false
131
+ state.byIds[asset.asset._id]!.updating = false
132
132
  })
133
133
  })
134
134
  .addCase(ASSETS_ACTIONS.tagsRemoveError, (state, action) => {
135
135
  const {assets} = action.payload
136
136
  assets.forEach((asset) => {
137
- state.byIds[asset.asset._id].updating = false
137
+ state.byIds[asset.asset._id]!.updating = false
138
138
  })
139
139
  })
140
140
  .addCase(ASSETS_ACTIONS.tagsRemoveRequest, (state, action) => {
141
141
  const {assets} = action.payload
142
142
  assets.forEach((asset) => {
143
- state.byIds[asset.asset._id].updating = true
143
+ state.byIds[asset.asset._id]!.updating = true
144
144
  })
145
145
  })
146
146
  },
@@ -170,20 +170,20 @@ const assetsSlice = createSlice({
170
170
  )
171
171
 
172
172
  assetIds?.forEach((id) => {
173
- state.byIds[id].updating = false
173
+ state.byIds[id]!.updating = false
174
174
  })
175
175
  itemErrors?.forEach((item) => {
176
- state.byIds[item.id].error = item.description
176
+ state.byIds[item.id]!.error = item.description
177
177
  })
178
178
  },
179
179
  deleteRequest(state, action: PayloadAction<{assets: Asset[]; closeDialogId?: string}>) {
180
180
  const {assets} = action.payload
181
181
  assets.forEach((asset) => {
182
- state.byIds[asset?._id].updating = true
182
+ state.byIds[asset?._id]!.updating = true
183
183
  })
184
184
 
185
185
  Object.keys(state.byIds).forEach((key) => {
186
- delete state.byIds[key].error
186
+ delete state.byIds[key]!.error
187
187
  })
188
188
  },
189
189
  fetchComplete(state, action: PayloadAction<{assets: Asset[]}>) {
@@ -284,7 +284,7 @@ const assetsSlice = createSlice({
284
284
  const {assets} = action.payload
285
285
  assets?.forEach((asset) => {
286
286
  if (state.byIds[asset?._id]?.asset) {
287
- state.byIds[asset._id].asset = asset
287
+ state.byIds[asset._id]!.asset = asset
288
288
  }
289
289
  })
290
290
  },
@@ -308,7 +308,7 @@ const assetsSlice = createSlice({
308
308
  const {assets} = action.payload
309
309
  assets?.forEach((asset) => {
310
310
  if (state.byIds[asset?._id]?.asset) {
311
- state.byIds[asset._id].asset = asset
311
+ state.byIds[asset._id]!.asset = asset
312
312
  }
313
313
  })
314
314
  },
@@ -326,18 +326,18 @@ const assetsSlice = createSlice({
326
326
  pick(state, action: PayloadAction<{assetId: string; picked: boolean}>) {
327
327
  const {assetId, picked} = action.payload
328
328
 
329
- state.byIds[assetId].picked = picked
329
+ state.byIds[assetId]!.picked = picked
330
330
  state.lastPicked = picked ? assetId : undefined
331
331
  },
332
332
  pickAll(state) {
333
333
  state.allIds.forEach((id) => {
334
- state.byIds[id].picked = true
334
+ state.byIds[id]!.picked = true
335
335
  })
336
336
  },
337
337
  pickClear(state) {
338
338
  state.lastPicked = undefined
339
339
  Object.values(state.byIds).forEach((asset) => {
340
- state.byIds[asset.asset._id].picked = false
340
+ state.byIds[asset.asset._id]!.picked = false
341
341
  })
342
342
  },
343
343
  pickRange(state, action: PayloadAction<{endId: string; startId: string}>) {
@@ -347,15 +347,15 @@ const assetsSlice = createSlice({
347
347
  // Sort numerically, ascending order
348
348
  const indices = [startIndex, endIndex].sort((a, b) => a - b)
349
349
 
350
- state.allIds.slice(indices[0], indices[1] + 1).forEach((key) => {
351
- state.byIds[key].picked = true
350
+ state.allIds.slice(indices[0], indices[1]! + 1).forEach((key) => {
351
+ state.byIds[key]!.picked = true
352
352
  })
353
353
  state.lastPicked = state.allIds[endIndex]
354
354
  },
355
355
  sort(state) {
356
356
  state.allIds.sort((a, b) => {
357
- const tagA = state.byIds[a].asset[state.order.field]
358
- const tagB = state.byIds[b].asset[state.order.field]
357
+ const tagA = state.byIds[a]!.asset[state.order.field]
358
+ const tagB = state.byIds[b]!.asset[state.order.field]
359
359
 
360
360
  if (tagA < tagB) {
361
361
  return state.order.direction === 'asc' ? -1 : 1
@@ -367,22 +367,22 @@ const assetsSlice = createSlice({
367
367
  },
368
368
  updateComplete(state, action: PayloadAction<{asset: Asset; closeDialogId?: string}>) {
369
369
  const {asset} = action.payload
370
- state.byIds[asset._id].updating = false
371
- state.byIds[asset._id].asset = asset
370
+ state.byIds[asset._id]!.updating = false
371
+ state.byIds[asset._id]!.asset = asset
372
372
  },
373
373
  updateError(state, action: PayloadAction<{asset: Asset; error: HttpError}>) {
374
374
  const {asset, error} = action.payload
375
375
 
376
376
  const assetId = asset?._id
377
- state.byIds[assetId].error = error.message
378
- state.byIds[assetId].updating = false
377
+ state.byIds[assetId]!.error = error.message
378
+ state.byIds[assetId]!.updating = false
379
379
  },
380
380
  updateRequest(
381
381
  state,
382
382
  action: PayloadAction<{asset: Asset; closeDialogId?: string; formData: Record<string, any>}>,
383
383
  ) {
384
384
  const assetId = action.payload?.asset?._id
385
- state.byIds[assetId].updating = true
385
+ state.byIds[assetId]!.updating = true
386
386
  },
387
387
  viewSet(state, action: PayloadAction<{view: BrowserView}>) {
388
388
  state.view = action.payload?.view
@@ -523,49 +523,6 @@ const patchOperationTagUnset =
523
523
  (patch: Patch) =>
524
524
  patch.ifRevisionId(asset?.asset?._rev).unset([`opt.media.tags[_ref == "${tag._id}"]`])
525
525
 
526
- export const assetsRemoveTagsEpic: MyEpic = (action$, state$, {client}) => {
527
- return action$.pipe(
528
- filter(ASSETS_ACTIONS.tagsAddRequest.match),
529
- withLatestFrom(state$),
530
- mergeMap(([action, state]) => {
531
- const {assets, tag} = action.payload
532
-
533
- return of(action).pipe(
534
- // Optionally throttle
535
- debugThrottle(state.debug.badConnection),
536
- // Add tag references to all picked assets
537
- mergeMap(() => {
538
- const pickedAssets = selectAssetsPicked(state)
539
-
540
- // Filter out picked assets which already include tag
541
- const pickedAssetsFiltered = pickedAssets?.filter(filterAssetWithoutTag(tag))
542
-
543
- const transaction: Transaction = pickedAssetsFiltered.reduce(
544
- (tx, pickedAsset) => tx.patch(pickedAsset?.asset?._id, patchOperationTagAppend({tag})),
545
- client.transaction(),
546
- )
547
-
548
- return from(transaction.commit())
549
- }),
550
- // Dispatch complete action
551
- mergeMap(() => of(ASSETS_ACTIONS.tagsAddComplete({assets, tag}))),
552
- catchError((error: ClientError) =>
553
- of(
554
- ASSETS_ACTIONS.tagsAddError({
555
- assets,
556
- error: {
557
- message: error?.message || 'Internal error',
558
- statusCode: error?.statusCode || 500,
559
- },
560
- tag,
561
- }),
562
- ),
563
- ),
564
- )
565
- }),
566
- )
567
- }
568
-
569
526
  export const assetsOrderSetEpic: MyEpic = (action$) =>
570
527
  action$.pipe(
571
528
  filter(assetsActions.orderSet.match),
@@ -804,9 +761,9 @@ export const selectAssetById = createSelector(
804
761
  },
805
762
  )
806
763
 
807
- export const selectAssets: Selector<RootReducerState, AssetItem[]> = createSelector(
764
+ const selectAssets: Selector<RootReducerState, AssetItem[]> = createSelector(
808
765
  [selectAssetsByIds, selectAssetsAllIds],
809
- (byIds, allIds) => allIds.map((id) => byIds[id]),
766
+ (byIds, allIds) => allIds.map((id) => byIds[id]!),
810
767
  )
811
768
 
812
769
  export const selectAssetsLength = createSelector([selectAssets], (assets) => assets.length)
@@ -37,7 +37,7 @@ describe('assets slice', () => {
37
37
  it('pick toggles picked flag', () => {
38
38
  let state = stateWithOneAsset()
39
39
  state = assetsReducer(state, assetsActions.pick({assetId: 'img-1', picked: true}))
40
- expect(state.byIds['img-1'].picked).toBe(true)
40
+ expect(state.byIds['img-1']!.picked).toBe(true)
41
41
  expect(state.lastPicked).toBe('img-1')
42
42
  })
43
43
 
@@ -45,7 +45,7 @@ describe('assets slice', () => {
45
45
  let state = stateWithOneAsset()
46
46
  state = assetsReducer(state, assetsActions.pick({assetId: 'img-1', picked: true}))
47
47
  state = assetsReducer(state, assetsActions.pickClear())
48
- expect(state.byIds['img-1'].picked).toBe(false)
48
+ expect(state.byIds['img-1']!.picked).toBe(false)
49
49
  expect(state.lastPicked).toBeUndefined()
50
50
  })
51
51
 
@@ -86,6 +86,6 @@ describe('assets slice', () => {
86
86
  let state = stateWithOneAsset()
87
87
  const updated = {...minimalImage, title: 'New'}
88
88
  state = assetsReducer(state, assetsActions.listenerUpdateQueueComplete({assets: [updated]}))
89
- expect(state.byIds['img-1'].asset.title).toBe('New')
89
+ expect(state.byIds['img-1']!.asset.title).toBe('New')
90
90
  })
91
91
  })
@@ -159,7 +159,7 @@ describe('assets listener queue epics', () => {
159
159
  await vi.advanceTimersByTimeAsync(2000)
160
160
 
161
161
  await vi.waitFor(() => {
162
- expect(store.getState().assets.byIds.a1.asset.title).toBe('L')
162
+ expect(store.getState().assets.byIds['a1']!.asset.title).toBe('L')
163
163
  })
164
164
  })
165
165
 
@@ -179,7 +179,7 @@ describe('assets listener queue epics', () => {
179
179
  await vi.advanceTimersByTimeAsync(2000)
180
180
 
181
181
  await vi.waitFor(() => {
182
- expect(store.getState().assets.byIds.a1).toBeUndefined()
182
+ expect(store.getState().assets.byIds['a1']).toBeUndefined()
183
183
  })
184
184
  })
185
185
 
@@ -200,7 +200,7 @@ describe('assets listener queue epics', () => {
200
200
  await vi.advanceTimersByTimeAsync(2000)
201
201
 
202
202
  await vi.waitFor(() => {
203
- expect(store.getState().assets.byIds.a1.asset.title).toBe('Buffered')
203
+ expect(store.getState().assets.byIds['a1']!.asset.title).toBe('Buffered')
204
204
  })
205
205
  })
206
206
  })
@@ -116,7 +116,7 @@ describe('dialogTagCreateEpic', () => {
116
116
  await vi.waitFor(() => {
117
117
  const item = store.getState().dialog.items[0]
118
118
  expect(item?.type).toBe('assetEdit')
119
- expect('lastCreatedTag' in item && item.lastCreatedTag).toEqual({
119
+ expect('lastCreatedTag' in item! && item.lastCreatedTag).toEqual({
120
120
  label: 'alpha',
121
121
  value: 't1',
122
122
  })
@@ -209,7 +209,7 @@ export const dialogTagCreateEpic: MyEpic = (action$) =>
209
209
  action$.pipe(
210
210
  filter(tagsActions.createComplete.match),
211
211
  mergeMap((action) => {
212
- const {assetId, tag} = action?.payload
212
+ const {assetId, tag} = action?.payload || {}
213
213
 
214
214
  if (assetId) {
215
215
  return of(dialogSlice.actions.inlineTagCreate({tag, assetId}))
@@ -227,7 +227,7 @@ export const dialogTagDeleteEpic: MyEpic = (action$) =>
227
227
  action$.pipe(
228
228
  filter(tagsActions.listenerDeleteQueueComplete.match),
229
229
  mergeMap((action) => {
230
- const {tagIds} = action?.payload
230
+ const {tagIds} = action?.payload || {}
231
231
 
232
232
  return of(dialogSlice.actions.inlineTagRemove({tagIds}))
233
233
  }),
@@ -1,9 +1,4 @@
1
- import {
2
- type ActionFromReducersMapObject,
3
- type Reducer,
4
- type StateFromReducersMapObject,
5
- combineReducers,
6
- } from '@reduxjs/toolkit'
1
+ import {type Reducer, type StateFromReducersMapObject, combineReducers} from '@reduxjs/toolkit'
7
2
  import {combineEpics} from 'redux-observable'
8
3
 
9
4
  import assetsReducer, {
@@ -118,7 +113,5 @@ type ReducersMapObject = typeof reducers
118
113
  // Workaround to avoid `$CombinedState` ts errors
119
114
  // source: https://github.com/reduxjs/redux-toolkit/issues/2068#issuecomment-1130796500
120
115
  // TODO: remove once we use `redux-toolkit` v2
121
- export const rootReducer: Reducer<
122
- StateFromReducersMapObject<ReducersMapObject>,
123
- ActionFromReducersMapObject<ReducersMapObject>
124
- > = combineReducers(reducers)
116
+ export const rootReducer: Reducer<StateFromReducersMapObject<ReducersMapObject>> =
117
+ combineReducers(reducers)
@@ -94,8 +94,8 @@ describe('notificationsAssetsDeleteErrorEpic', () => {
94
94
  store.dispatch(assetsActions.deleteError({assetIds: ['a1'], error: {} as any}))
95
95
  await vi.waitFor(() => {
96
96
  const [n] = store.getState().notifications.items
97
- expect(n.status).toBe('error')
98
- expect(n.title).toBe(
97
+ expect(n!.status).toBe('error')
98
+ expect(n!.title).toBe(
99
99
  'Unable to delete 1 asset. Please review any asset errors and try again.',
100
100
  )
101
101
  })
@@ -271,7 +271,7 @@ describe('notificationsGenericErrorEpic', () => {
271
271
  }),
272
272
  )
273
273
  await vi.waitFor(() => {
274
- expect(store.getState().notifications.items[0].title).toBe('An error occurred: fetch failed')
274
+ expect(store.getState().notifications.items[0]!.title).toBe('An error occurred: fetch failed')
275
275
  })
276
276
  })
277
277
 
@@ -294,7 +294,7 @@ describe('notificationsGenericErrorEpic', () => {
294
294
  }),
295
295
  )
296
296
  await vi.waitFor(() => {
297
- expect(store.getState().notifications.items[0].title).toBe('An error occurred: tag create')
297
+ expect(store.getState().notifications.items[0]!.title).toBe('An error occurred: tag create')
298
298
  })
299
299
  })
300
300
 
@@ -309,7 +309,7 @@ describe('notificationsGenericErrorEpic', () => {
309
309
  }),
310
310
  )
311
311
  await vi.waitFor(() => {
312
- expect(store.getState().notifications.items[0].title).toBe('An error occurred: upload bad')
312
+ expect(store.getState().notifications.items[0]!.title).toBe('An error occurred: upload bad')
313
313
  })
314
314
  })
315
315
  })
@@ -166,7 +166,7 @@ export const notificationsGenericErrorEpic: MyEpic = (action$) =>
166
166
  uploadsActions.uploadError.type,
167
167
  ),
168
168
  mergeMap((action: AnyAction) => {
169
- const title = `An error occurred: ${messageFromGenericErrorPayload(action.payload)}`
169
+ const title = `An error occurred: ${messageFromGenericErrorPayload(action['payload'])}`
170
170
  return of(
171
171
  notificationsSlice.actions.add({
172
172
  status: 'error',
@@ -10,8 +10,8 @@ describe('search slice', () => {
10
10
  let state = searchReducer(undefined, {type: '@@INIT'} as never)
11
11
  state = searchReducer(state, searchActions.facetsAdd({facet: {...inputs.title}}))
12
12
  expect(state.facets).toHaveLength(1)
13
- expect(state.facets[0].name).toBe('title')
14
- expect(state.facets[0].id).toBeDefined()
13
+ expect(state.facets[0]!.name).toBe('title')
14
+ expect(state.facets[0]!.id).toBeDefined()
15
15
  })
16
16
 
17
17
  it('querySet updates search string', () => {
@@ -103,7 +103,7 @@ const searchSlice = createSlice({
103
103
  facet.operatorType = operatorType
104
104
  }
105
105
  if (typeof value !== 'undefined') {
106
- state.facets[index].value = value
106
+ state.facets[index]!.value = value
107
107
  }
108
108
  }
109
109
  })
@@ -33,7 +33,7 @@ describe('tagsCreateEpic', () => {
33
33
  store.dispatch(tagsActions.createRequest({name: 'alpha'}))
34
34
 
35
35
  await vi.waitFor(() => {
36
- expect(store.getState().tags.byIds.t1?.tag).toEqual(sampleTag)
36
+ expect(store.getState().tags.byIds['t1']?.tag).toEqual(sampleTag)
37
37
  expect(client.observable.create).toHaveBeenCalled()
38
38
  })
39
39
  })
@@ -90,7 +90,7 @@ describe('tagsDeleteEpic', () => {
90
90
  expect(tx.patch).toHaveBeenCalled()
91
91
  expect(tx.delete).toHaveBeenCalledWith('t1')
92
92
  expect(tx.commit).toHaveBeenCalled()
93
- expect(store.getState().tags.byIds.t1).toBeUndefined()
93
+ expect(store.getState().tags.byIds['t1']).toBeUndefined()
94
94
  })
95
95
  })
96
96
  })
@@ -19,7 +19,7 @@ describe('tags slice', () => {
19
19
  let state = tagsReducer(undefined, {type: '@@INIT'} as never)
20
20
  state = tagsReducer(state, tagsActions.createComplete({tag: sampleTag}))
21
21
  expect(state.allIds).toContain('tag-1')
22
- expect(state.byIds['tag-1'].tag).toEqual(sampleTag)
22
+ expect(state.byIds['tag-1']!.tag).toEqual(sampleTag)
23
23
  expect(state.creating).toBe(false)
24
24
  })
25
25
 
@@ -37,6 +37,6 @@ describe('tags slice', () => {
37
37
  expect(state.fetching).toBe(true)
38
38
  state = tagsReducer(state, tagsActions.fetchComplete({tags: [sampleTag]}))
39
39
  expect(state.fetching).toBe(false)
40
- expect(state.byIds['tag-1'].tag).toEqual(sampleTag)
40
+ expect(state.byIds['tag-1']!.tag).toEqual(sampleTag)
41
41
  })
42
42
  })
@@ -48,7 +48,7 @@ const tagsSlice = createSlice({
48
48
  })
49
49
  .addCase(DIALOG_ACTIONS.showTagEdit, (state, action) => {
50
50
  const {tagId} = action.payload
51
- delete state.byIds[tagId].error
51
+ delete state.byIds[tagId]!.error
52
52
  })
53
53
  .addMatcher(
54
54
  isAnyOf(
@@ -59,14 +59,14 @@ const tagsSlice = createSlice({
59
59
  ),
60
60
  (state, action) => {
61
61
  const {tag} = action.payload
62
- state.byIds[tag._id].updating = false
62
+ state.byIds[tag._id]!.updating = false
63
63
  },
64
64
  )
65
65
  .addMatcher(
66
66
  isAnyOf(ASSETS_ACTIONS.tagsAddRequest, ASSETS_ACTIONS.tagsRemoveRequest),
67
67
  (state, action) => {
68
68
  const {tag} = action.payload
69
- state.byIds[tag._id].updating = true
69
+ state.byIds[tag._id]!.updating = true
70
70
  },
71
71
  )
72
72
  },
@@ -104,16 +104,16 @@ const tagsSlice = createSlice({
104
104
  const {error, tag} = action.payload
105
105
 
106
106
  const tagId = tag?._id
107
- state.byIds[tagId].error = error
108
- state.byIds[tagId].updating = false
107
+ state.byIds[tagId]!.error = error
108
+ state.byIds[tagId]!.updating = false
109
109
  },
110
110
  deleteRequest(state, action: PayloadAction<{tag: Tag}>) {
111
111
  const tagId = action.payload?.tag?._id
112
- state.byIds[tagId].picked = false
113
- state.byIds[tagId].updating = true
112
+ state.byIds[tagId]!.picked = false
113
+ state.byIds[tagId]!.updating = true
114
114
 
115
115
  Object.keys(state.byIds).forEach((key) => {
116
- delete state.byIds[key].error
116
+ delete state.byIds[key]!.error
117
117
  })
118
118
  },
119
119
  fetchComplete(state, action: PayloadAction<{tags: Tag[]}>) {
@@ -209,7 +209,7 @@ const tagsSlice = createSlice({
209
209
 
210
210
  tags?.forEach((tag) => {
211
211
  if (state.byIds[tag._id]) {
212
- state.byIds[tag._id].tag = tag
212
+ state.byIds[tag._id]!.tag = tag
213
213
  }
214
214
  })
215
215
  },
@@ -221,8 +221,8 @@ const tagsSlice = createSlice({
221
221
  // Sort all tags by name
222
222
  sort(state) {
223
223
  state.allIds.sort((a, b) => {
224
- const tagA = state.byIds[a].tag.name.current
225
- const tagB = state.byIds[b].tag.name.current
224
+ const tagA = state.byIds[a]!.tag.name.current
225
+ const tagB = state.byIds[b]!.tag.name.current
226
226
 
227
227
  if (tagA < tagB) {
228
228
  return -1
@@ -234,14 +234,14 @@ const tagsSlice = createSlice({
234
234
  },
235
235
  updateComplete(state, action: PayloadAction<{closeDialogId?: string; tag: Tag}>) {
236
236
  const {tag} = action.payload
237
- state.byIds[tag._id].tag = tag
238
- state.byIds[tag._id].updating = false
237
+ state.byIds[tag._id]!.tag = tag
238
+ state.byIds[tag._id]!.updating = false
239
239
  },
240
240
  updateError(state, action: PayloadAction<{tag: Tag; error: HttpError}>) {
241
241
  const {error, tag} = action.payload
242
242
  const tagId = tag?._id
243
- state.byIds[tagId].error = error
244
- state.byIds[tagId].updating = false
243
+ state.byIds[tagId]!.error = error
244
+ state.byIds[tagId]!.updating = false
245
245
  },
246
246
  updateRequest(
247
247
  state,
@@ -252,7 +252,7 @@ const tagsSlice = createSlice({
252
252
  }>,
253
253
  ) {
254
254
  const {tag} = action.payload
255
- state.byIds[tag?._id].updating = true
255
+ state.byIds[tag?._id]!.updating = true
256
256
  },
257
257
  },
258
258
  })
@@ -464,14 +464,14 @@ export const tagsUpdateEpic: MyEpic = (action$, state$, {client}) =>
464
464
  // Optionally throttle
465
465
  debugThrottle(state.debug.badConnection),
466
466
  // Check if tag name is available, throw early if not
467
- checkTagName(client, formData?.name?.current),
467
+ checkTagName(client, formData?.['name']?.current),
468
468
  // Patch document (Update tag)
469
469
  mergeMap(
470
470
  () =>
471
471
  from(
472
472
  client
473
473
  .patch(tag._id)
474
- .set({name: {_type: 'slug', current: formData?.name.current}})
474
+ .set({name: {_type: 'slug', current: formData?.['name'].current}})
475
475
  .commit(),
476
476
  ) as Observable<Tag>,
477
477
  ),
@@ -507,7 +507,7 @@ const selectTagsAllIds = (state: RootReducerState) => state.tags.allIds
507
507
 
508
508
  export const selectTags: Selector<RootReducerState, TagItem[]> = createSelector(
509
509
  [selectTagsByIds, selectTagsAllIds],
510
- (byIds, allIds) => allIds.map((id) => byIds[id]),
510
+ (byIds, allIds) => allIds.map((id) => byIds[id]!),
511
511
  )
512
512
 
513
513
  export const selectTagById = createSelector(
@@ -55,7 +55,7 @@ describe('uploadsAssetStartEpic', () => {
55
55
  store.dispatch(uploadsActions.uploadStart({file, uploadItem}))
56
56
 
57
57
  await vi.waitFor(() => {
58
- expect(store.getState().uploads.byIds.deadbeef?.objectUrl).toBe('blob:http://preview')
58
+ expect(store.getState().uploads.byIds['deadbeef']?.objectUrl).toBe('blob:http://preview')
59
59
  })
60
60
 
61
61
  await vi.waitFor(() => {
@@ -103,7 +103,7 @@ describe('uploadsCheckRequestEpic', () => {
103
103
 
104
104
  await vi.waitFor(() => {
105
105
  expect(client.observable.fetch).toHaveBeenCalled()
106
- expect(store.getState().uploads.byIds.hh).toBeUndefined()
106
+ expect(store.getState().uploads.byIds['hh']).toBeUndefined()
107
107
  })
108
108
  })
109
109
  })
@@ -26,7 +26,7 @@ describe('uploads slice', () => {
26
26
  )
27
27
 
28
28
  expect(state.allIds).toEqual(['abc'])
29
- expect(state.byIds.abc).toMatchObject({hash: 'abc', status: 'queued'})
29
+ expect(state.byIds['abc']).toMatchObject({hash: 'abc', status: 'queued'})
30
30
  })
31
31
 
32
32
  it('uploadProgress updates percent and status', () => {
@@ -53,7 +53,7 @@ describe('uploads slice', () => {
53
53
  }),
54
54
  )
55
55
 
56
- expect(state.byIds.h1.percent).toBe(42)
57
- expect(state.byIds.h1.status).toBe('uploading')
56
+ expect(state.byIds['h1']!.percent).toBe(42)
57
+ expect(state.byIds['h1']!.status).toBe('uploading')
58
58
  })
59
59
  })
@@ -1,7 +1,6 @@
1
1
  import {createSelector, createSlice, type PayloadAction} from '@reduxjs/toolkit'
2
2
  import type {ClientError, SanityAssetDocument, SanityImageAssetDocument} from '@sanity/client'
3
3
  import groq from 'groq'
4
- import type {Selector} from 'react-redux'
5
4
  import {empty, merge, of} from 'rxjs'
6
5
  import {catchError, delay, filter, mergeMap, takeUntil, withLatestFrom} from 'rxjs/operators'
7
6
 
@@ -31,7 +30,7 @@ const uploadsSlice = createSlice({
31
30
  .addCase(UPLOADS_ACTIONS.uploadComplete, (state, action) => {
32
31
  const {asset} = action.payload
33
32
  if (state.byIds[asset.sha1hash]) {
34
- state.byIds[asset.sha1hash].status = 'complete'
33
+ state.byIds[asset.sha1hash]!.status = 'complete'
35
34
  }
36
35
  })
37
36
  },
@@ -98,8 +97,8 @@ const uploadsSlice = createSlice({
98
97
  action: PayloadAction<{event: SanityUploadProgressEvent; uploadHash: string}>,
99
98
  ) {
100
99
  const {event, uploadHash} = action.payload
101
- state.byIds[uploadHash].percent = event.percent
102
- state.byIds[uploadHash].status = 'uploading'
100
+ state.byIds[uploadHash]!.percent = event.percent
101
+ state.byIds[uploadHash]!.status = 'uploading'
103
102
  },
104
103
  uploadStart(state, action: PayloadAction<{file: File; uploadItem: UploadItem}>) {
105
104
  const {uploadItem} = action.payload
@@ -260,10 +259,6 @@ export const uploadsCheckRequestEpic: MyEpic = (action$, state$, {client}) =>
260
259
 
261
260
  // Selectors
262
261
 
263
- const selectUploadsByIds = (state: RootReducerState) => state.uploads.byIds
264
-
265
- const selectUploadsAllIds = (state: RootReducerState) => state.uploads.allIds
266
-
267
262
  export const selectUploadById = createSelector(
268
263
  [
269
264
  (state: RootReducerState) => state.uploads.byIds,
@@ -272,11 +267,6 @@ export const selectUploadById = createSelector(
272
267
  (byIds, uploadId) => byIds[uploadId],
273
268
  )
274
269
 
275
- export const selectUploads: Selector<RootReducerState, UploadItem[]> = createSelector(
276
- [selectUploadsByIds, selectUploadsAllIds],
277
- (byIds, allIds) => allIds.map((id) => byIds[id]),
278
- )
279
-
280
270
  export const uploadsActions = {...uploadsSlice.actions}
281
271
 
282
272
  export default uploadsSlice.reducer