sanity-plugin-media 4.3.1 → 4.3.3

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 (147) hide show
  1. package/LICENSE +4 -4
  2. package/README.md +12 -12
  3. package/dist/{index.mjs → index.cjs} +1115 -1242
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +462 -0
  6. package/dist/index.d.ts +263 -195
  7. package/dist/index.js +1125 -1237
  8. package/dist/index.js.map +1 -1
  9. package/package.json +45 -68
  10. package/src/__tests__/fixtures/createEpicTestStore.ts +5 -4
  11. package/src/__tests__/fixtures/mockSanityClient.ts +8 -8
  12. package/src/__tests__/fixtures/renderWithProviders.tsx +8 -7
  13. package/src/__tests__/fixtures/rootState.ts +4 -4
  14. package/src/components/AssetGridVirtualized/index.tsx +8 -7
  15. package/src/components/AssetMetadata/index.tsx +6 -5
  16. package/src/components/AssetTableVirtualized/index.tsx +7 -6
  17. package/src/components/AutoTagInputWrapper/index.tsx +9 -4
  18. package/src/components/Browser/Browser.test.tsx +9 -8
  19. package/src/components/Browser/index.tsx +2 -1
  20. package/src/components/Browser/useBrowserInit.ts +9 -9
  21. package/src/components/ButtonAssetCopy/index.tsx +1 -0
  22. package/src/components/ButtonViewGroup/index.tsx +4 -3
  23. package/src/components/CardAsset/CardAsset.test.tsx +53 -52
  24. package/src/components/CardAsset/index.tsx +52 -49
  25. package/src/components/CardUpload/index.tsx +7 -6
  26. package/src/components/Controls/index.tsx +7 -6
  27. package/src/components/DebugControls/index.tsx +5 -4
  28. package/src/components/DialogAssetEdit/Details.tsx +3 -2
  29. package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +28 -27
  30. package/src/components/DialogAssetEdit/index.tsx +37 -37
  31. package/src/components/DialogConfirm/index.tsx +2 -1
  32. package/src/components/DialogSearchFacets/index.tsx +3 -2
  33. package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +16 -15
  34. package/src/components/DialogTagCreate/index.tsx +11 -10
  35. package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +28 -27
  36. package/src/components/DialogTagEdit/index.tsx +17 -16
  37. package/src/components/DialogTags/index.tsx +4 -3
  38. package/src/components/Dialogs/index.tsx +2 -3
  39. package/src/components/DocumentList/index.tsx +2 -3
  40. package/src/components/FileAssetPreview/index.tsx +2 -2
  41. package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +12 -11
  42. package/src/components/FormBuilderTool/index.tsx +2 -1
  43. package/src/components/FormFieldInputLabel/index.tsx +1 -2
  44. package/src/components/FormFieldInputTags/index.tsx +4 -3
  45. package/src/components/FormSubmitButton/index.tsx +1 -1
  46. package/src/components/Header/index.tsx +3 -3
  47. package/src/components/Image/index.tsx +10 -4
  48. package/src/components/Items/index.tsx +5 -4
  49. package/src/components/Notifications/index.tsx +3 -2
  50. package/src/components/OrderSelect/index.tsx +4 -3
  51. package/src/components/PickedBar/index.tsx +2 -1
  52. package/src/components/Progress/index.tsx +3 -3
  53. package/src/components/ReduxProvider/index.tsx +15 -12
  54. package/src/components/SearchFacet/index.tsx +3 -2
  55. package/src/components/SearchFacetNumber/index.tsx +8 -8
  56. package/src/components/SearchFacetSelect/index.tsx +7 -8
  57. package/src/components/SearchFacetString/index.tsx +1 -1
  58. package/src/components/SearchFacetTags/index.tsx +13 -12
  59. package/src/components/SearchFacets/index.tsx +2 -3
  60. package/src/components/SearchFacetsControl/index.tsx +13 -12
  61. package/src/components/TableHeader/index.tsx +18 -17
  62. package/src/components/TableHeaderItem/index.tsx +4 -4
  63. package/src/components/TableRowAsset/index.tsx +37 -36
  64. package/src/components/TableRowUpload/index.tsx +7 -6
  65. package/src/components/Tag/index.tsx +8 -7
  66. package/src/components/TagView/index.tsx +2 -2
  67. package/src/components/TagViewHeader/index.tsx +5 -4
  68. package/src/components/TagsPanel/index.tsx +3 -3
  69. package/src/components/TagsVirtualized/index.tsx +25 -24
  70. package/src/components/TextInputSearch/index.tsx +3 -2
  71. package/src/components/UploadDropzone/UploadDropzone.test.tsx +8 -7
  72. package/src/components/UploadDropzone/index.tsx +14 -13
  73. package/src/config/orders.ts +6 -6
  74. package/src/config/searchFacets.ts +56 -55
  75. package/src/constants.ts +15 -14
  76. package/src/contexts/AssetSourceDispatchContext.tsx +1 -1
  77. package/src/contexts/ToolOptionsContext.tsx +6 -5
  78. package/src/formSchema/index.test.ts +6 -5
  79. package/src/formSchema/index.ts +5 -5
  80. package/src/hooks/useBreakpointIndex.ts +6 -6
  81. package/src/hooks/useKeyPress.ts +2 -2
  82. package/src/hooks/usePortalPopoverProps.ts +1 -1
  83. package/src/modules/assets/actions.ts +8 -7
  84. package/src/modules/assets/deleteAndUpdateEpics.test.ts +18 -17
  85. package/src/modules/assets/fetchEpic.test.ts +12 -11
  86. package/src/modules/assets/index.ts +134 -133
  87. package/src/modules/assets/reducer.test.ts +9 -8
  88. package/src/modules/assets/tagsAndListenerEpics.test.ts +36 -35
  89. package/src/modules/debug/index.ts +3 -3
  90. package/src/modules/dialog/actions.ts +2 -2
  91. package/src/modules/dialog/epics.test.ts +29 -28
  92. package/src/modules/dialog/index.ts +36 -35
  93. package/src/modules/dialog/reducer.test.ts +31 -30
  94. package/src/modules/index.ts +9 -9
  95. package/src/modules/notifications/epics.test.ts +71 -70
  96. package/src/modules/notifications/index.ts +50 -49
  97. package/src/modules/notifications/reducer.test.ts +8 -7
  98. package/src/modules/search/index.test.ts +2 -1
  99. package/src/modules/search/index.ts +22 -22
  100. package/src/modules/selected/index.ts +2 -2
  101. package/src/modules/selectors.test.ts +4 -3
  102. package/src/modules/selectors.ts +5 -5
  103. package/src/modules/tags/epics.test.ts +16 -15
  104. package/src/modules/tags/index.test.ts +2 -1
  105. package/src/modules/tags/index.ts +82 -81
  106. package/src/modules/uploads/actions.ts +3 -3
  107. package/src/modules/uploads/epics.test.ts +13 -12
  108. package/src/modules/uploads/index.test.ts +8 -7
  109. package/src/modules/uploads/index.ts +48 -47
  110. package/src/operators/checkTagName.test.ts +7 -6
  111. package/src/operators/checkTagName.ts +6 -5
  112. package/src/operators/debugThrottle.ts +4 -4
  113. package/src/plugin.tsx +18 -18
  114. package/src/schemas/tag.ts +7 -7
  115. package/src/styled/react-select/creatable.tsx +40 -39
  116. package/src/styled/react-select/single.tsx +39 -38
  117. package/src/types/index.ts +4 -3
  118. package/src/utils/applyMediaTags.ts +11 -10
  119. package/src/utils/blocksToText.test.ts +5 -4
  120. package/src/utils/blocksToText.ts +2 -2
  121. package/src/utils/constructFilter.test.ts +15 -14
  122. package/src/utils/constructFilter.ts +7 -7
  123. package/src/utils/generatePreviewBlobUrl.test.ts +6 -5
  124. package/src/utils/generatePreviewBlobUrl.ts +2 -2
  125. package/src/utils/getAssetResolution.test.ts +3 -2
  126. package/src/utils/getDocumentAssetIds.test.ts +7 -6
  127. package/src/utils/getDocumentAssetIds.ts +2 -2
  128. package/src/utils/getSchemeColor.test.ts +1 -0
  129. package/src/utils/getSchemeColor.ts +9 -9
  130. package/src/utils/getTagSelectOptions.test.ts +6 -5
  131. package/src/utils/getTagSelectOptions.ts +1 -1
  132. package/src/utils/getUniqueDocuments.test.ts +4 -3
  133. package/src/utils/getUniqueDocuments.ts +2 -2
  134. package/src/utils/imageDprUrl.test.ts +4 -3
  135. package/src/utils/imageDprUrl.ts +1 -1
  136. package/src/utils/isSupportedAssetType.test.ts +1 -0
  137. package/src/utils/mediaField.ts +4 -3
  138. package/src/utils/sanitizeFormData.test.ts +14 -13
  139. package/src/utils/typeGuards.test.ts +2 -1
  140. package/src/utils/uploadSanityAsset.test.ts +5 -4
  141. package/src/utils/uploadSanityAsset.ts +17 -16
  142. package/src/utils/withMaxConcurrency.test.ts +5 -4
  143. package/src/utils/withMaxConcurrency.ts +4 -4
  144. package/src/utils/zodFormResolver.ts +17 -0
  145. package/v2-incompatible.js +2 -2
  146. package/dist/index.d.mts +0 -394
  147. package/dist/index.mjs.map +0 -1
@@ -1,10 +1,11 @@
1
1
  import {type PayloadAction, createSlice} from '@reduxjs/toolkit'
2
- import type {AnyAction} from 'redux'
3
- import type {HttpError, ImageAsset, MyEpic} from '../../types'
4
2
  import pluralize from 'pluralize'
3
+ import type {AnyAction} from 'redux'
5
4
  import {ofType} from 'redux-observable'
6
5
  import {of} from 'rxjs'
7
6
  import {bufferTime, filter, mergeMap} from 'rxjs/operators'
7
+
8
+ import type {HttpError, ImageAsset, MyEpic} from '../../types'
8
9
  import {assetsActions} from '../assets'
9
10
  import {ASSETS_ACTIONS} from '../assets/actions'
10
11
  import {tagsActions} from '../tags'
@@ -40,7 +41,7 @@ function messageFromGenericErrorPayload(payload: unknown): string {
40
41
  }
41
42
 
42
43
  const initialState = {
43
- items: []
44
+ items: [],
44
45
  } as NotificationsReducerState
45
46
 
46
47
  const notificationsSlice = createSlice({
@@ -52,33 +53,33 @@ const notificationsSlice = createSlice({
52
53
  state.items.push({
53
54
  asset,
54
55
  status,
55
- title
56
+ title,
56
57
  })
57
- }
58
- }
58
+ },
59
+ },
59
60
  })
60
61
 
61
62
  // Epics
62
63
 
63
- export const notificationsAssetsDeleteCompleteEpic: MyEpic = action$ =>
64
+ export const notificationsAssetsDeleteCompleteEpic: MyEpic = (action$) =>
64
65
  action$.pipe(
65
66
  filter(assetsActions.deleteComplete.match),
66
- mergeMap(action => {
67
+ mergeMap((action) => {
67
68
  const {assetIds} = action.payload
68
69
  const deletedCount = assetIds.length
69
70
  return of(
70
71
  notificationsSlice.actions.add({
71
72
  status: 'info',
72
- title: `${deletedCount} ${pluralize('asset', deletedCount)} deleted`
73
- })
73
+ title: `${deletedCount} ${pluralize('asset', deletedCount)} deleted`,
74
+ }),
74
75
  )
75
- })
76
+ }),
76
77
  )
77
78
 
78
- export const notificationsAssetsDeleteErrorEpic: MyEpic = action$ =>
79
+ export const notificationsAssetsDeleteErrorEpic: MyEpic = (action$) =>
79
80
  action$.pipe(
80
81
  filter(assetsActions.deleteError.match),
81
- mergeMap(action => {
82
+ mergeMap((action) => {
82
83
  const {assetIds} = action.payload
83
84
  const count = assetIds.length
84
85
  return of(
@@ -86,74 +87,74 @@ export const notificationsAssetsDeleteErrorEpic: MyEpic = action$ =>
86
87
  status: 'error',
87
88
  title: `Unable to delete ${count} ${pluralize(
88
89
  'asset',
89
- count
90
- )}. Please review any asset errors and try again.`
91
- })
90
+ count,
91
+ )}. Please review any asset errors and try again.`,
92
+ }),
92
93
  )
93
- })
94
+ }),
94
95
  )
95
96
 
96
- export const notificationsAssetsUploadCompleteEpic: MyEpic = action$ =>
97
+ export const notificationsAssetsUploadCompleteEpic: MyEpic = (action$) =>
97
98
  action$.pipe(
98
99
  filter(uploadsActions.checkComplete.match),
99
- mergeMap(action => {
100
+ mergeMap((action) => {
100
101
  const {results} = action.payload
101
102
 
102
103
  const count = Object.keys(results).length
103
104
  return of(
104
105
  notificationsSlice.actions.add({
105
106
  status: 'info',
106
- title: `Uploaded ${count} ${pluralize('asset', count)}`
107
- })
107
+ title: `Uploaded ${count} ${pluralize('asset', count)}`,
108
+ }),
108
109
  )
109
- })
110
+ }),
110
111
  )
111
112
 
112
- export const notificationsAssetsTagsAddCompleteEpic: MyEpic = action$ =>
113
+ export const notificationsAssetsTagsAddCompleteEpic: MyEpic = (action$) =>
113
114
  action$.pipe(
114
115
  filter(ASSETS_ACTIONS.tagsAddComplete.match),
115
- mergeMap(action => {
116
+ mergeMap((action) => {
116
117
  const count = action?.payload?.assets?.length
117
118
  return of(
118
119
  notificationsSlice.actions.add({
119
120
  status: 'info',
120
- title: `Tag added to ${count} ${pluralize('asset', count)}`
121
- })
121
+ title: `Tag added to ${count} ${pluralize('asset', count)}`,
122
+ }),
122
123
  )
123
- })
124
+ }),
124
125
  )
125
126
 
126
- export const notificationsAssetsTagsRemoveCompleteEpic: MyEpic = action$ =>
127
+ export const notificationsAssetsTagsRemoveCompleteEpic: MyEpic = (action$) =>
127
128
  action$.pipe(
128
129
  filter(ASSETS_ACTIONS.tagsRemoveComplete.match),
129
- mergeMap(action => {
130
+ mergeMap((action) => {
130
131
  const count = action?.payload?.assets?.length
131
132
  return of(
132
133
  notificationsSlice.actions.add({
133
134
  status: 'info',
134
- title: `Tag removed from ${count} ${pluralize('asset', count)}`
135
- })
135
+ title: `Tag removed from ${count} ${pluralize('asset', count)}`,
136
+ }),
136
137
  )
137
- })
138
+ }),
138
139
  )
139
140
 
140
- export const notificationsAssetsUpdateCompleteEpic: MyEpic = action$ =>
141
+ export const notificationsAssetsUpdateCompleteEpic: MyEpic = (action$) =>
141
142
  action$.pipe(
142
143
  filter(assetsActions.updateComplete.match),
143
144
  bufferTime(2000),
144
- filter(actions => actions.length > 0),
145
- mergeMap(actions => {
145
+ filter((actions) => actions.length > 0),
146
+ mergeMap((actions) => {
146
147
  const updatedCount = actions.length
147
148
  return of(
148
149
  notificationsSlice.actions.add({
149
150
  status: 'info',
150
- title: `${updatedCount} ${pluralize('asset', updatedCount)} updated`
151
- })
151
+ title: `${updatedCount} ${pluralize('asset', updatedCount)} updated`,
152
+ }),
152
153
  )
153
- })
154
+ }),
154
155
  )
155
156
 
156
- export const notificationsGenericErrorEpic: MyEpic = action$ =>
157
+ export const notificationsGenericErrorEpic: MyEpic = (action$) =>
157
158
  action$.pipe(
158
159
  ofType(
159
160
  assetsActions.fetchError.type,
@@ -162,35 +163,35 @@ export const notificationsGenericErrorEpic: MyEpic = action$ =>
162
163
  tagsActions.deleteError.type,
163
164
  tagsActions.fetchError.type,
164
165
  tagsActions.updateError.type,
165
- uploadsActions.uploadError.type
166
+ uploadsActions.uploadError.type,
166
167
  ),
167
168
  mergeMap((action: AnyAction) => {
168
169
  const title = `An error occurred: ${messageFromGenericErrorPayload(action.payload)}`
169
170
  return of(
170
171
  notificationsSlice.actions.add({
171
172
  status: 'error',
172
- title
173
- })
173
+ title,
174
+ }),
174
175
  )
175
- })
176
+ }),
176
177
  )
177
178
 
178
- export const notificationsTagCreateCompleteEpic: MyEpic = action$ =>
179
+ export const notificationsTagCreateCompleteEpic: MyEpic = (action$) =>
179
180
  action$.pipe(
180
181
  filter(tagsActions.createComplete.match),
181
- mergeMap(() => of(notificationsSlice.actions.add({status: 'info', title: `Tag created`})))
182
+ mergeMap(() => of(notificationsSlice.actions.add({status: 'info', title: `Tag created`}))),
182
183
  )
183
184
 
184
- export const notificationsTagDeleteCompleteEpic: MyEpic = action$ =>
185
+ export const notificationsTagDeleteCompleteEpic: MyEpic = (action$) =>
185
186
  action$.pipe(
186
187
  filter(tagsActions.deleteComplete.match),
187
- mergeMap(() => of(notificationsSlice.actions.add({status: 'info', title: `Tag deleted`})))
188
+ mergeMap(() => of(notificationsSlice.actions.add({status: 'info', title: `Tag deleted`}))),
188
189
  )
189
190
 
190
- export const notificationsTagUpdateCompleteEpic: MyEpic = action$ =>
191
+ export const notificationsTagUpdateCompleteEpic: MyEpic = (action$) =>
191
192
  action$.pipe(
192
193
  filter(tagsActions.updateComplete.match),
193
- mergeMap(() => of(notificationsSlice.actions.add({status: 'info', title: `Tag updated`})))
194
+ mergeMap(() => of(notificationsSlice.actions.add({status: 'info', title: `Tag updated`}))),
194
195
  )
195
196
 
196
197
  export const notificationsActions = {...notificationsSlice.actions}
@@ -1,9 +1,10 @@
1
1
  // @vitest-environment node
2
2
 
3
3
  import {describe, expect, it} from 'vitest'
4
- import notificationsReducer, {notificationsActions} from './index'
5
- import type {ImageAsset} from '../../types'
4
+
6
5
  import {createTestRootState} from '../../__tests__/fixtures/rootState'
6
+ import type {ImageAsset} from '../../types'
7
+ import notificationsReducer, {notificationsActions} from './index'
7
8
 
8
9
  const sampleAsset = {
9
10
  _id: 'a1',
@@ -14,7 +15,7 @@ const sampleAsset = {
14
15
  originalFilename: 'x.png',
15
16
  size: 1,
16
17
  mimeType: 'image/png',
17
- url: 'https://example.com/x.png'
18
+ url: 'https://example.com/x.png',
18
19
  } as ImageAsset
19
20
 
20
21
  describe('notificationsReducer', () => {
@@ -30,14 +31,14 @@ describe('notificationsReducer', () => {
30
31
  notificationsActions.add({
31
32
  asset: sampleAsset,
32
33
  status: 'success',
33
- title: 'Done'
34
- })
34
+ title: 'Done',
35
+ }),
35
36
  )
36
37
  expect(next.items).toHaveLength(1)
37
38
  expect(next.items[0]).toEqual({
38
39
  asset: sampleAsset,
39
40
  status: 'success',
40
- title: 'Done'
41
+ title: 'Done',
41
42
  })
42
43
  })
43
44
 
@@ -47,7 +48,7 @@ describe('notificationsReducer', () => {
47
48
  state = notificationsReducer(state, notificationsActions.add({title: 'Y'}))
48
49
  expect(state.items).toEqual([
49
50
  {asset: undefined, status: 'error', title: 'X'},
50
- {asset: undefined, status: undefined, title: 'Y'}
51
+ {asset: undefined, status: undefined, title: 'Y'},
51
52
  ])
52
53
  })
53
54
  })
@@ -1,8 +1,9 @@
1
1
  // @vitest-environment node
2
2
 
3
3
  import {describe, expect, it} from 'vitest'
4
- import searchReducer, {searchActions} from './index'
4
+
5
5
  import {inputs} from '../../config/searchFacets'
6
+ import searchReducer, {searchActions} from './index'
6
7
 
7
8
  describe('search slice', () => {
8
9
  it('facetsAdd assigns an id and appends facet', () => {
@@ -1,9 +1,9 @@
1
1
  import {type PayloadAction, createSelector, createSlice} from '@reduxjs/toolkit'
2
- import type {MyEpic, SearchFacetInputProps, SearchFacetOperatorType, WithId} from '../../types'
2
+ import {uuid} from '@sanity/uuid'
3
3
  import {EMPTY, of} from 'rxjs'
4
4
  import {filter, mergeMap, withLatestFrom} from 'rxjs/operators'
5
- import {uuid} from '@sanity/uuid'
6
5
 
6
+ import type {MyEpic, SearchFacetInputProps, SearchFacetOperatorType, WithId} from '../../types'
7
7
  import {tagsActions} from '../tags'
8
8
  import type {RootReducerState} from '../types'
9
9
 
@@ -17,7 +17,7 @@ type SearchState = {
17
17
 
18
18
  const initialState = {
19
19
  facets: [],
20
- query: ''
20
+ query: '',
21
21
  } as SearchState
22
22
 
23
23
  const searchSlice = createSlice({
@@ -34,23 +34,23 @@ const searchSlice = createSlice({
34
34
  },
35
35
  // Remove search facet by name
36
36
  facetsRemoveByName(state, action: PayloadAction<{facetName: string}>) {
37
- state.facets = state.facets.filter(facet => facet.name !== action.payload.facetName)
37
+ state.facets = state.facets.filter((facet) => facet.name !== action.payload.facetName)
38
38
  },
39
39
  // Remove search facet by name
40
40
  facetsRemoveByTag(state, action: PayloadAction<{tagId: string}>) {
41
41
  state.facets = state.facets.filter(
42
- facet =>
42
+ (facet) =>
43
43
  !(
44
44
  facet.name === 'tag' &&
45
45
  facet.type === 'searchable' &&
46
46
  (facet.operatorType === 'references' || facet.operatorType === 'doesNotReference') &&
47
47
  facet.value?.value === action.payload.tagId
48
- )
48
+ ),
49
49
  )
50
50
  },
51
51
  // Remove search facet by name
52
52
  facetsRemoveById(state, action: PayloadAction<{facetId: string}>) {
53
- state.facets = state.facets.filter(facet => facet.id !== action.payload.facetId)
53
+ state.facets = state.facets.filter((facet) => facet.id !== action.payload.facetId)
54
54
  },
55
55
  // Update an existing search facet
56
56
  facetsUpdate(
@@ -60,11 +60,11 @@ const searchSlice = createSlice({
60
60
  name: string
61
61
  operatorType?: SearchFacetOperatorType
62
62
  value?: any // TODO: type correctly
63
- }>
63
+ }>,
64
64
  ) {
65
65
  const {modifier, name, operatorType, value} = action.payload
66
66
 
67
- const facet = state.facets.find(f => f.name === name)
67
+ const facet = state.facets.find((f) => f.name === name)
68
68
 
69
69
  if (!facet) {
70
70
  return
@@ -80,7 +80,7 @@ const searchSlice = createSlice({
80
80
  facet.value = value
81
81
  }
82
82
 
83
- state.facets = state.facets.filter(f => f.name !== facet.name || f.id === facet.id)
83
+ state.facets = state.facets.filter((f) => f.name !== facet.name || f.id === facet.id)
84
84
  },
85
85
  // Update an existing search facet
86
86
  facetsUpdateById(
@@ -90,7 +90,7 @@ const searchSlice = createSlice({
90
90
  id: string
91
91
  operatorType?: SearchFacetOperatorType
92
92
  value?: any // TODO: type correctly
93
- }>
93
+ }>,
94
94
  ) {
95
95
  const {modifier, id, operatorType, value} = action.payload
96
96
 
@@ -111,8 +111,8 @@ const searchSlice = createSlice({
111
111
  // Update existing search query
112
112
  querySet(state, action: PayloadAction<{searchQuery: string}>) {
113
113
  state.query = action.payload?.searchQuery
114
- }
115
- }
114
+ },
115
+ },
116
116
  })
117
117
 
118
118
  // Epics
@@ -125,7 +125,7 @@ export const searchFacetTagUpdateEpic: MyEpic = (action$, state$) =>
125
125
  mergeMap(([action, state]) => {
126
126
  const {tag} = action.payload
127
127
 
128
- const currentSearchFacetTag = state.search.facets?.find(facet => facet.name === 'tag')
128
+ const currentSearchFacetTag = state.search.facets?.find((facet) => facet.name === 'tag')
129
129
  const tagItem = state.tags.byIds[tag._id]
130
130
 
131
131
  if (currentSearchFacetTag?.type === 'searchable') {
@@ -135,31 +135,31 @@ export const searchFacetTagUpdateEpic: MyEpic = (action$, state$) =>
135
135
  name: 'tag',
136
136
  value: {
137
137
  label: tagItem?.tag?.name?.current,
138
- value: tagItem?.tag?._id
139
- }
140
- })
138
+ value: tagItem?.tag?._id,
139
+ },
140
+ }),
141
141
  )
142
142
  }
143
143
  }
144
144
 
145
145
  return EMPTY
146
- })
146
+ }),
147
147
  )
148
148
 
149
149
  // Selectors
150
150
  export const selectIsSearchFacetTag = createSelector(
151
151
  [
152
152
  (state: RootReducerState) => state.search.facets,
153
- (_state: RootReducerState, tagId: string) => tagId
153
+ (_state: RootReducerState, tagId: string) => tagId,
154
154
  ],
155
155
  (searchFacets, tagId) =>
156
156
  searchFacets.some(
157
- facet =>
157
+ (facet) =>
158
158
  facet.name === 'tag' &&
159
159
  facet.type === 'searchable' &&
160
160
  (facet.operatorType === 'references' || facet.operatorType === 'doesNotReference') &&
161
- facet.value?.value === tagId
162
- )
161
+ facet.value?.value === tagId,
162
+ ),
163
163
  )
164
164
 
165
165
  export const searchActions = {...searchSlice.actions}
@@ -10,13 +10,13 @@ type SelectedReducerState = {
10
10
  const initialState = {
11
11
  assets: [],
12
12
  document: undefined,
13
- documentAssetIds: []
13
+ documentAssetIds: [],
14
14
  } as SelectedReducerState
15
15
 
16
16
  const selectedSlice = createSlice({
17
17
  name: 'selected',
18
18
  initialState,
19
- reducers: {}
19
+ reducers: {},
20
20
  })
21
21
 
22
22
  export default selectedSlice.reducer
@@ -1,20 +1,21 @@
1
1
  // @vitest-environment node
2
2
 
3
3
  import {describe, expect, it} from 'vitest'
4
- import type {RootReducerState} from './types'
4
+
5
5
  import {selectCombinedItems} from './selectors'
6
+ import type {RootReducerState} from './types'
6
7
 
7
8
  describe('selectCombinedItems', () => {
8
9
  it('places upload items before asset items', () => {
9
10
  const state = {
10
11
  assets: {allIds: ['a1', 'a2']},
11
- uploads: {allIds: ['u1']}
12
+ uploads: {allIds: ['u1']},
12
13
  } as RootReducerState
13
14
 
14
15
  expect(selectCombinedItems(state)).toEqual([
15
16
  {id: 'u1', type: 'upload'},
16
17
  {id: 'a1', type: 'asset'},
17
- {id: 'a2', type: 'asset'}
18
+ {id: 'a2', type: 'asset'},
18
19
  ])
19
20
  })
20
21
  })
@@ -1,17 +1,17 @@
1
1
  import {createSelector} from '@reduxjs/toolkit'
2
- import type {CardAssetData, CardUploadData} from '../types'
3
2
 
3
+ import type {CardAssetData, CardUploadData} from '../types'
4
4
  import type {RootReducerState} from './types'
5
5
 
6
6
  export const selectCombinedItems = createSelector(
7
7
  [
8
8
  (state: RootReducerState) => state.assets.allIds,
9
- (state: RootReducerState) => state.uploads.allIds
9
+ (state: RootReducerState) => state.uploads.allIds,
10
10
  ],
11
11
  (assetIds, uploadIds) => {
12
- const assetItems = assetIds.map(id => ({id, type: 'asset'} as CardAssetData))
13
- const uploadItems = uploadIds.map(id => ({id, type: 'upload'} as CardUploadData))
12
+ const assetItems = assetIds.map((id) => ({id, type: 'asset'}) as CardAssetData)
13
+ const uploadItems = uploadIds.map((id) => ({id, type: 'upload'}) as CardUploadData)
14
14
  const combinedItems: (CardAssetData | CardUploadData)[] = [...uploadItems, ...assetItems]
15
15
  return combinedItems
16
- }
16
+ },
17
17
  )
@@ -1,14 +1,15 @@
1
1
  // @vitest-environment node
2
2
 
3
- import {describe, expect, it, vi} from 'vitest'
4
3
  import {of} from 'rxjs'
5
- import {tagsCreateEpic, tagsDeleteEpic, tagsActions} from './index'
4
+ import {describe, expect, it, vi} from 'vitest'
5
+
6
6
  import {createEpicTestStore} from '../../__tests__/fixtures/createEpicTestStore'
7
7
  import {
8
8
  createMockSanityClient,
9
- mockTransactionCommit
9
+ mockTransactionCommit,
10
10
  } from '../../__tests__/fixtures/mockSanityClient'
11
11
  import type {Tag} from '../../types'
12
+ import {tagsCreateEpic, tagsDeleteEpic, tagsActions} from './index'
12
13
 
13
14
  const sampleTag: Tag = {
14
15
  _id: 't1',
@@ -16,7 +17,7 @@ const sampleTag: Tag = {
16
17
  _createdAt: '',
17
18
  _updatedAt: '',
18
19
  _rev: 'tr',
19
- name: {_type: 'slug', current: 'alpha'}
20
+ name: {_type: 'slug', current: 'alpha'},
20
21
  }
21
22
 
22
23
  describe('tagsCreateEpic', () => {
@@ -24,8 +25,8 @@ describe('tagsCreateEpic', () => {
24
25
  const client = createMockSanityClient({
25
26
  fetch: vi.fn().mockResolvedValue(0),
26
27
  observable: {
27
- create: vi.fn(() => of(sampleTag))
28
- }
28
+ create: vi.fn(() => of(sampleTag)),
29
+ },
29
30
  })
30
31
 
31
32
  const store = createEpicTestStore(tagsCreateEpic, client)
@@ -41,8 +42,8 @@ describe('tagsCreateEpic', () => {
41
42
  const client = createMockSanityClient({
42
43
  fetch: vi.fn().mockResolvedValue(1),
43
44
  observable: {
44
- create: vi.fn(() => of(sampleTag))
45
- }
45
+ create: vi.fn(() => of(sampleTag)),
46
+ },
46
47
  })
47
48
 
48
49
  const store = createEpicTestStore(tagsCreateEpic, client)
@@ -63,24 +64,24 @@ describe('tagsDeleteEpic', () => {
63
64
  fetch: vi.fn(() =>
64
65
  of([
65
66
  {_id: 'a1', _rev: 'r1', opt: {}},
66
- {_id: 'a2', _rev: 'r2', opt: {}}
67
- ])
68
- )
67
+ {_id: 'a2', _rev: 'r2', opt: {}},
68
+ ]),
69
+ ),
69
70
  },
70
- transaction: vi.fn(() => tx)
71
+ transaction: vi.fn(() => tx),
71
72
  })
72
73
 
73
74
  const store = createEpicTestStore(tagsDeleteEpic, client, {
74
75
  tags: {
75
76
  allIds: ['t1'],
76
77
  byIds: {
77
- t1: {_type: 'tag', tag: sampleTag, picked: false, updating: false}
78
+ t1: {_type: 'tag', tag: sampleTag, picked: false, updating: false},
78
79
  },
79
80
  creating: false,
80
81
  fetchCount: -1,
81
82
  fetching: false,
82
- panelVisible: true
83
- }
83
+ panelVisible: true,
84
+ },
84
85
  })
85
86
 
86
87
  store.dispatch(tagsActions.deleteRequest({tag: sampleTag}))
@@ -1,6 +1,7 @@
1
1
  // @vitest-environment node
2
2
 
3
3
  import {describe, expect, it} from 'vitest'
4
+
4
5
  import type {Tag} from '../../types'
5
6
  import tagsReducer, {tagsActions} from './index'
6
7
 
@@ -10,7 +11,7 @@ const sampleTag: Tag = {
10
11
  _createdAt: '2020-01-01',
11
12
  _updatedAt: '2020-01-01',
12
13
  _rev: 'r1',
13
- name: {_type: 'slug', current: 'alpha'}
14
+ name: {_type: 'slug', current: 'alpha'},
14
15
  }
15
16
 
16
17
  describe('tags slice', () => {