sanity-plugin-media 4.3.1 → 4.3.2

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 (145) hide show
  1. package/LICENSE +4 -4
  2. package/README.md +12 -12
  3. package/dist/index.d.mts +263 -195
  4. package/dist/index.d.ts +263 -195
  5. package/dist/index.js +83 -203
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +84 -203
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +41 -63
  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
@@ -1,6 +1,7 @@
1
1
  // @vitest-environment node
2
2
 
3
3
  import {describe, expect, it} from 'vitest'
4
+
4
5
  import type {AssetType, ImageAsset} from '../../types'
5
6
  import assetsReducer, {assetsActions, initialState, type AssetsReducerState} from './index'
6
7
 
@@ -13,7 +14,7 @@ const minimalImage = {
13
14
  originalFilename: 'a.png',
14
15
  size: 1,
15
16
  mimeType: 'image/png',
16
- url: 'https://example.com/a.png'
17
+ url: 'https://example.com/a.png',
17
18
  } as ImageAsset
18
19
 
19
20
  describe('assets slice', () => {
@@ -27,9 +28,9 @@ describe('assets slice', () => {
27
28
  _type: 'asset',
28
29
  asset: minimalImage,
29
30
  picked: false,
30
- updating: false
31
- }
32
- }
31
+ updating: false,
32
+ },
33
+ },
33
34
  }
34
35
  }
35
36
 
@@ -50,7 +51,7 @@ describe('assets slice', () => {
50
51
 
51
52
  it('fetchComplete merges assets', () => {
52
53
  let state = assetsReducer({...initialState, assetTypes: ['image'] as AssetType[]}, {
53
- type: '@@INIT'
54
+ type: '@@INIT',
54
55
  } as never)
55
56
  state = assetsReducer(state, assetsActions.fetchComplete({assets: [minimalImage]}))
56
57
  expect(state.allIds).toContain('img-1')
@@ -62,13 +63,13 @@ describe('assets slice', () => {
62
63
  let state: AssetsReducerState = {
63
64
  ...initialState,
64
65
  assetTypes: ['image'] as AssetType[],
65
- pageIndex: 3
66
+ pageIndex: 3,
66
67
  }
67
68
  state = assetsReducer(
68
69
  state,
69
70
  assetsActions.orderSet({
70
- order: {field: 'size', direction: 'asc'}
71
- })
71
+ order: {field: 'size', direction: 'asc'},
72
+ }),
72
73
  )
73
74
  expect(state.pageIndex).toBe(0)
74
75
  expect(state.order.field).toBe('size')
@@ -1,22 +1,23 @@
1
1
  // @vitest-environment node
2
2
 
3
3
  import {describe, expect, it, vi, beforeEach, afterEach} from 'vitest'
4
+
5
+ import {createEpicTestStore} from '../../__tests__/fixtures/createEpicTestStore'
6
+ import {
7
+ createMockSanityClient,
8
+ mockTransactionCommit,
9
+ } from '../../__tests__/fixtures/mockSanityClient'
10
+ import type {ImageAsset, Tag} from '../../types'
11
+ import {ASSETS_ACTIONS} from './actions'
4
12
  import {
5
13
  assetsActions,
6
14
  assetsListenerCreateQueueEpic,
7
15
  assetsListenerDeleteQueueEpic,
8
16
  assetsListenerUpdateQueueEpic,
9
17
  assetsTagsAddEpic,
10
- assetsTagsRemoveEpic
18
+ assetsTagsRemoveEpic,
11
19
  } from './index'
12
- import {ASSETS_ACTIONS} from './actions'
13
- import {createEpicTestStore} from '../../__tests__/fixtures/createEpicTestStore'
14
- import {
15
- createMockSanityClient,
16
- mockTransactionCommit
17
- } from '../../__tests__/fixtures/mockSanityClient'
18
20
  import {initialState as assetsInitialState} from './index'
19
- import type {ImageAsset, Tag} from '../../types'
20
21
 
21
22
  const sampleAsset = {
22
23
  _id: 'a1',
@@ -27,7 +28,7 @@ const sampleAsset = {
27
28
  originalFilename: 'x.png',
28
29
  size: 1,
29
30
  mimeType: 'image/png',
30
- url: ''
31
+ url: '',
31
32
  } as ImageAsset
32
33
 
33
34
  const sampleTag: Tag = {
@@ -36,21 +37,21 @@ const sampleTag: Tag = {
36
37
  _createdAt: '',
37
38
  _updatedAt: '',
38
39
  _rev: 'tr',
39
- name: {_type: 'slug', current: 'tag-a'}
40
+ name: {_type: 'slug', current: 'tag-a'},
40
41
  }
41
42
 
42
43
  describe('assetsTagsAddEpic', () => {
43
44
  it('runs transaction.commit when adding tag to picked assets', async () => {
44
45
  const tx = mockTransactionCommit(undefined)
45
46
  const client = createMockSanityClient({
46
- transaction: vi.fn(() => tx)
47
+ transaction: vi.fn(() => tx),
47
48
  })
48
49
 
49
50
  const assetItem = {
50
51
  _type: 'asset' as const,
51
52
  asset: sampleAsset,
52
53
  picked: true,
53
- updating: false
54
+ updating: false,
54
55
  }
55
56
 
56
57
  const store = createEpicTestStore(assetsTagsAddEpic, client, {
@@ -58,25 +59,25 @@ describe('assetsTagsAddEpic', () => {
58
59
  ...assetsInitialState,
59
60
  assetTypes: ['image'],
60
61
  allIds: ['a1'],
61
- byIds: {a1: assetItem}
62
+ byIds: {a1: assetItem},
62
63
  },
63
64
  tags: {
64
65
  allIds: ['t1'],
65
66
  byIds: {
66
- t1: {_type: 'tag', tag: sampleTag, picked: false, updating: false}
67
+ t1: {_type: 'tag', tag: sampleTag, picked: false, updating: false},
67
68
  },
68
69
  creating: false,
69
70
  fetchCount: -1,
70
71
  fetching: false,
71
- panelVisible: true
72
- }
72
+ panelVisible: true,
73
+ },
73
74
  })
74
75
 
75
76
  store.dispatch(
76
77
  ASSETS_ACTIONS.tagsAddRequest({
77
78
  assets: [assetItem],
78
- tag: sampleTag
79
- })
79
+ tag: sampleTag,
80
+ }),
80
81
  )
81
82
 
82
83
  await vi.waitFor(() => {
@@ -89,14 +90,14 @@ describe('assetsTagsRemoveEpic', () => {
89
90
  it('runs transaction.commit for tag removal', async () => {
90
91
  const tx = mockTransactionCommit(undefined)
91
92
  const client = createMockSanityClient({
92
- transaction: vi.fn(() => tx)
93
+ transaction: vi.fn(() => tx),
93
94
  })
94
95
 
95
96
  const assetItem = {
96
97
  _type: 'asset' as const,
97
98
  asset: sampleAsset,
98
99
  picked: true,
99
- updating: false
100
+ updating: false,
100
101
  }
101
102
 
102
103
  const store = createEpicTestStore(assetsTagsRemoveEpic, client, {
@@ -104,25 +105,25 @@ describe('assetsTagsRemoveEpic', () => {
104
105
  ...assetsInitialState,
105
106
  assetTypes: ['image'],
106
107
  allIds: ['a1'],
107
- byIds: {a1: assetItem}
108
+ byIds: {a1: assetItem},
108
109
  },
109
110
  tags: {
110
111
  allIds: ['t1'],
111
112
  byIds: {
112
- t1: {_type: 'tag', tag: sampleTag, picked: false, updating: false}
113
+ t1: {_type: 'tag', tag: sampleTag, picked: false, updating: false},
113
114
  },
114
115
  creating: false,
115
116
  fetchCount: -1,
116
117
  fetching: false,
117
- panelVisible: true
118
- }
118
+ panelVisible: true,
119
+ },
119
120
  })
120
121
 
121
122
  store.dispatch(
122
123
  ASSETS_ACTIONS.tagsRemoveRequest({
123
124
  assets: [assetItem],
124
- tag: sampleTag
125
- })
125
+ tag: sampleTag,
126
+ }),
126
127
  )
127
128
 
128
129
  await vi.waitFor(() => {
@@ -147,9 +148,9 @@ describe('assets listener queue epics', () => {
147
148
  assetTypes: ['image'],
148
149
  allIds: ['a1'],
149
150
  byIds: {
150
- a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false}
151
- }
152
- }
151
+ a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false},
152
+ },
153
+ },
153
154
  })
154
155
 
155
156
  const updated = {...sampleAsset, title: 'L'}
@@ -169,9 +170,9 @@ describe('assets listener queue epics', () => {
169
170
  assetTypes: ['image'],
170
171
  allIds: ['a1'],
171
172
  byIds: {
172
- a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false}
173
- }
174
- }
173
+ a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false},
174
+ },
175
+ },
175
176
  })
176
177
 
177
178
  store.dispatch(assetsActions.listenerDeleteQueue({assetId: 'a1'}))
@@ -189,9 +190,9 @@ describe('assets listener queue epics', () => {
189
190
  assetTypes: ['image'],
190
191
  allIds: ['a1'],
191
192
  byIds: {
192
- a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false}
193
- }
194
- }
193
+ a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false},
194
+ },
195
+ },
195
196
  })
196
197
 
197
198
  const updated = {...sampleAsset, title: 'Buffered'}
@@ -7,7 +7,7 @@ type DebugReducerState = {
7
7
 
8
8
  const initialState = {
9
9
  badConnection: false,
10
- enabled: false
10
+ enabled: false,
11
11
  } as DebugReducerState
12
12
 
13
13
  const debugSlice = createSlice({
@@ -19,8 +19,8 @@ const debugSlice = createSlice({
19
19
  },
20
20
  toggleEnabled(state) {
21
21
  state.enabled = !state.enabled
22
- }
23
- }
22
+ },
23
+ },
24
24
  })
25
25
 
26
26
  export const debugActions = {...debugSlice.actions}
@@ -4,7 +4,7 @@ export const DIALOG_ACTIONS = {
4
4
  showTagCreate: createAction('dialog/showTagCreate'),
5
5
  showTagEdit: createAction('dialog/showTagEdit', function prepare({tagId}: {tagId: string}) {
6
6
  return {
7
- payload: {tagId}
7
+ payload: {tagId},
8
8
  }
9
- })
9
+ }),
10
10
  }
@@ -1,12 +1,13 @@
1
1
  // @vitest-environment node
2
2
 
3
3
  import {describe, expect, it, vi} from 'vitest'
4
- import {dialogClearOnAssetUpdateEpic, dialogTagCreateEpic, dialogTagDeleteEpic} from './index'
5
- import {assetsActions, initialState as assetsInitialState} from '../assets'
6
- import {tagsActions} from '../tags'
4
+
7
5
  import {createEpicTestStore} from '../../__tests__/fixtures/createEpicTestStore'
8
6
  import {createMockSanityClient} from '../../__tests__/fixtures/mockSanityClient'
9
7
  import type {ImageAsset, Tag} from '../../types'
8
+ import {assetsActions, initialState as assetsInitialState} from '../assets'
9
+ import {tagsActions} from '../tags'
10
+ import {dialogClearOnAssetUpdateEpic, dialogTagCreateEpic, dialogTagDeleteEpic} from './index'
10
11
 
11
12
  const sampleAsset = {
12
13
  _id: 'a1',
@@ -17,7 +18,7 @@ const sampleAsset = {
17
18
  originalFilename: 'x.png',
18
19
  size: 1,
19
20
  mimeType: 'image/png',
20
- url: 'https://example.com/x.png'
21
+ url: 'https://example.com/x.png',
21
22
  } as ImageAsset
22
23
 
23
24
  const sampleTag: Tag = {
@@ -26,12 +27,12 @@ const sampleTag: Tag = {
26
27
  _createdAt: '',
27
28
  _updatedAt: '',
28
29
  _rev: 'tr',
29
- name: {_type: 'slug', current: 'alpha'}
30
+ name: {_type: 'slug', current: 'alpha'},
30
31
  }
31
32
 
32
33
  const tagWithId = (id: string): Tag => ({
33
34
  ...sampleTag,
34
- _id: id
35
+ _id: id,
35
36
  })
36
37
 
37
38
  describe('dialogClearOnAssetUpdateEpic', () => {
@@ -42,12 +43,12 @@ describe('dialogClearOnAssetUpdateEpic', () => {
42
43
  assetTypes: ['image'],
43
44
  allIds: ['a1'],
44
45
  byIds: {
45
- a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: true}
46
- }
46
+ a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: true},
47
+ },
47
48
  },
48
49
  dialog: {
49
- items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}]
50
- }
50
+ items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}],
51
+ },
51
52
  })
52
53
 
53
54
  store.dispatch(assetsActions.updateComplete({asset: sampleAsset, closeDialogId: 'a1'}))
@@ -62,16 +63,16 @@ describe('dialogClearOnAssetUpdateEpic', () => {
62
63
  tags: {
63
64
  allIds: ['t1'],
64
65
  byIds: {
65
- t1: {_type: 'tag', tag: sampleTag, picked: false, updating: true}
66
+ t1: {_type: 'tag', tag: sampleTag, picked: false, updating: true},
66
67
  },
67
68
  creating: false,
68
69
  fetchCount: -1,
69
70
  fetching: false,
70
- panelVisible: true
71
+ panelVisible: true,
71
72
  },
72
73
  dialog: {
73
- items: [{id: 't1', type: 'tagEdit', tagId: 't1'}]
74
- }
74
+ items: [{id: 't1', type: 'tagEdit', tagId: 't1'}],
75
+ },
75
76
  })
76
77
 
77
78
  store.dispatch(tagsActions.updateComplete({tag: sampleTag, closeDialogId: 't1'}))
@@ -88,12 +89,12 @@ describe('dialogClearOnAssetUpdateEpic', () => {
88
89
  assetTypes: ['image'],
89
90
  allIds: ['a1'],
90
91
  byIds: {
91
- a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: true}
92
- }
92
+ a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: true},
93
+ },
93
94
  },
94
95
  dialog: {
95
- items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}]
96
- }
96
+ items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}],
97
+ },
97
98
  })
98
99
 
99
100
  store.dispatch(assetsActions.updateComplete({asset: sampleAsset}))
@@ -106,8 +107,8 @@ describe('dialogTagCreateEpic', () => {
106
107
  it('dispatches inlineTagCreate when createComplete includes assetId', async () => {
107
108
  const store = createEpicTestStore(dialogTagCreateEpic, createMockSanityClient({}), {
108
109
  dialog: {
109
- items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}]
110
- }
110
+ items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}],
111
+ },
111
112
  })
112
113
 
113
114
  store.dispatch(tagsActions.createComplete({assetId: 'a1', tag: sampleTag}))
@@ -117,7 +118,7 @@ describe('dialogTagCreateEpic', () => {
117
118
  expect(item?.type).toBe('assetEdit')
118
119
  expect('lastCreatedTag' in item && item.lastCreatedTag).toEqual({
119
120
  label: 'alpha',
120
- value: 't1'
121
+ value: 't1',
121
122
  })
122
123
  })
123
124
  })
@@ -125,8 +126,8 @@ describe('dialogTagCreateEpic', () => {
125
126
  it('removes tag create dialog when createComplete has no assetId', async () => {
126
127
  const store = createEpicTestStore(dialogTagCreateEpic, createMockSanityClient({}), {
127
128
  dialog: {
128
- items: [{id: 'tagCreate', type: 'tagCreate'}]
129
- }
129
+ items: [{id: 'tagCreate', type: 'tagCreate'}],
130
+ },
130
131
  })
131
132
 
132
133
  store.dispatch(tagsActions.createComplete({tag: sampleTag}))
@@ -143,16 +144,16 @@ describe('dialogTagDeleteEpic', () => {
143
144
  tags: {
144
145
  allIds: ['t9'],
145
146
  byIds: {
146
- t9: {_type: 'tag', tag: tagWithId('t9'), picked: false, updating: false}
147
+ t9: {_type: 'tag', tag: tagWithId('t9'), picked: false, updating: false},
147
148
  },
148
149
  creating: false,
149
150
  fetchCount: -1,
150
151
  fetching: false,
151
- panelVisible: true
152
+ panelVisible: true,
152
153
  },
153
154
  dialog: {
154
- items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}]
155
- }
155
+ items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}],
156
+ },
156
157
  })
157
158
 
158
159
  store.dispatch(tagsActions.listenerDeleteQueueComplete({tagIds: ['t9']}))
@@ -160,7 +161,7 @@ describe('dialogTagDeleteEpic', () => {
160
161
  await vi.waitFor(() => {
161
162
  expect(store.getState().dialog.items[0]).toMatchObject({
162
163
  type: 'assetEdit',
163
- lastRemovedTagIds: ['t9']
164
+ lastRemovedTagIds: ['t9'],
164
165
  })
165
166
  })
166
167
  })
@@ -1,9 +1,10 @@
1
1
  import {createSlice, type PayloadAction} from '@reduxjs/toolkit'
2
- import type {AssetItem, Dialog, MyEpic, Tag} from '../../types'
3
2
  import pluralize from 'pluralize'
4
3
  import {ofType} from 'redux-observable'
5
4
  import {EMPTY, of} from 'rxjs'
6
5
  import {filter, mergeMap} from 'rxjs/operators'
6
+
7
+ import type {AssetItem, Dialog, MyEpic, Tag} from '../../types'
7
8
  import {assetsActions} from '../assets'
8
9
  import {ASSETS_ACTIONS} from '../assets/actions'
9
10
  import {tagsActions} from '../tags'
@@ -14,17 +15,17 @@ type DialogReducerState = {
14
15
  }
15
16
 
16
17
  const initialState = {
17
- items: []
18
+ items: [],
18
19
  } as DialogReducerState
19
20
 
20
21
  const dialogSlice = createSlice({
21
22
  name: 'dialog',
22
23
  initialState,
23
- extraReducers: builder => {
24
- builder.addCase(DIALOG_ACTIONS.showTagCreate, state => {
24
+ extraReducers: (builder) => {
25
+ builder.addCase(DIALOG_ACTIONS.showTagCreate, (state) => {
25
26
  state.items.push({
26
27
  id: 'tagCreate',
27
- type: 'tagCreate'
28
+ type: 'tagCreate',
28
29
  })
29
30
  })
30
31
  builder.addCase(DIALOG_ACTIONS.showTagEdit, (state, action) => {
@@ -32,7 +33,7 @@ const dialogSlice = createSlice({
32
33
  state.items.push({
33
34
  id: tagId,
34
35
  tagId,
35
- type: 'tagEdit'
36
+ type: 'tagEdit',
36
37
  })
37
38
  })
38
39
  },
@@ -45,11 +46,11 @@ const dialogSlice = createSlice({
45
46
  inlineTagCreate(state, action: PayloadAction<{assetId: string; tag: Tag}>) {
46
47
  const {assetId, tag} = action.payload
47
48
 
48
- state.items.forEach(item => {
49
+ state.items.forEach((item) => {
49
50
  if (item.type === 'assetEdit' && item.assetId === assetId) {
50
51
  item.lastCreatedTag = {
51
52
  label: tag.name.current,
52
- value: tag._id
53
+ value: tag._id,
53
54
  }
54
55
  }
55
56
  })
@@ -58,7 +59,7 @@ const dialogSlice = createSlice({
58
59
  inlineTagRemove(state, action: PayloadAction<{tagIds: string[]}>) {
59
60
  const {tagIds} = action.payload
60
61
 
61
- state.items.forEach(item => {
62
+ state.items.forEach((item) => {
62
63
  if (item.type === 'assetEdit') {
63
64
  item.lastRemovedTagIds = tagIds
64
65
  }
@@ -67,7 +68,7 @@ const dialogSlice = createSlice({
67
68
  // Remove dialog by id
68
69
  remove(state, action: PayloadAction<{id: string}>) {
69
70
  const id = action.payload?.id
70
- state.items = state.items.filter(item => item.id !== id)
71
+ state.items = state.items.filter((item) => item.id !== id)
71
72
  },
72
73
  showConfirmAssetsTagAdd(
73
74
  state,
@@ -75,7 +76,7 @@ const dialogSlice = createSlice({
75
76
  assetsPicked: AssetItem[]
76
77
  closeDialogId?: string
77
78
  tag: Tag
78
- }>
79
+ }>,
79
80
  ) {
80
81
  const {assetsPicked, closeDialogId, tag} = action.payload
81
82
 
@@ -85,14 +86,14 @@ const dialogSlice = createSlice({
85
86
  closeDialogId,
86
87
  confirmCallbackAction: ASSETS_ACTIONS.tagsAddRequest({
87
88
  assets: assetsPicked,
88
- tag
89
+ tag,
89
90
  }),
90
91
  confirmText: `Yes, add tag to ${suffix}`,
91
92
  title: `Add tag ${tag.name.current} to ${suffix}?`,
92
93
  id: 'confirm',
93
94
  headerTitle: 'Confirm tag addition',
94
95
  tone: 'primary',
95
- type: 'confirm'
96
+ type: 'confirm',
96
97
  })
97
98
  },
98
99
  showConfirmAssetsTagRemove(
@@ -101,7 +102,7 @@ const dialogSlice = createSlice({
101
102
  assetsPicked: AssetItem[]
102
103
  closeDialogId?: string
103
104
  tag: Tag
104
- }>
105
+ }>,
105
106
  ) {
106
107
  const {assetsPicked, closeDialogId, tag} = action.payload
107
108
 
@@ -115,12 +116,12 @@ const dialogSlice = createSlice({
115
116
  id: 'confirm',
116
117
  title: `Remove tag ${tag.name.current} from ${suffix}?`,
117
118
  tone: 'critical',
118
- type: 'confirm'
119
+ type: 'confirm',
119
120
  })
120
121
  },
121
122
  showConfirmDeleteAssets(
122
123
  state,
123
- action: PayloadAction<{assets: AssetItem[]; closeDialogId?: string}>
124
+ action: PayloadAction<{assets: AssetItem[]; closeDialogId?: string}>,
124
125
  ) {
125
126
  const {assets, closeDialogId} = action.payload
126
127
 
@@ -129,7 +130,7 @@ const dialogSlice = createSlice({
129
130
  state.items.push({
130
131
  closeDialogId,
131
132
  confirmCallbackAction: assetsActions.deleteRequest({
132
- assets: assets.map(assetItem => assetItem.asset)
133
+ assets: assets.map((assetItem) => assetItem.asset),
133
134
  }),
134
135
  confirmText: `Yes, delete ${suffix}`,
135
136
  description: 'This operation cannot be reversed. Are you sure you want to continue?',
@@ -137,7 +138,7 @@ const dialogSlice = createSlice({
137
138
  id: 'confirm',
138
139
  headerTitle: 'Confirm deletion',
139
140
  tone: 'critical',
140
- type: 'confirm'
141
+ type: 'confirm',
141
142
  })
142
143
  },
143
144
  showConfirmDeleteTag(state, action: PayloadAction<{closeDialogId?: string; tag: Tag}>) {
@@ -154,7 +155,7 @@ const dialogSlice = createSlice({
154
155
  id: 'confirm',
155
156
  headerTitle: 'Confirm deletion',
156
157
  tone: 'critical',
157
- type: 'confirm'
158
+ type: 'confirm',
158
159
  })
159
160
  },
160
161
  showAssetEdit(state, action: PayloadAction<{assetId: string}>) {
@@ -162,52 +163,52 @@ const dialogSlice = createSlice({
162
163
  state.items.push({
163
164
  assetId,
164
165
  id: assetId,
165
- type: 'assetEdit'
166
+ type: 'assetEdit',
166
167
  })
167
168
  },
168
169
  showSearchFacets(state) {
169
170
  state.items.push({
170
171
  id: 'searchFacets',
171
- type: 'searchFacets'
172
+ type: 'searchFacets',
172
173
  })
173
174
  },
174
175
  showTags(state) {
175
176
  state.items.push({
176
177
  id: 'tags',
177
- type: 'tags'
178
+ type: 'tags',
178
179
  })
179
- }
180
- }
180
+ },
181
+ },
181
182
  })
182
183
 
183
184
  // Epics
184
185
 
185
- export const dialogClearOnAssetUpdateEpic: MyEpic = action$ =>
186
+ export const dialogClearOnAssetUpdateEpic: MyEpic = (action$) =>
186
187
  action$.pipe(
187
188
  ofType(
188
189
  assetsActions.deleteComplete.type,
189
190
  assetsActions.updateComplete.type,
190
191
  tagsActions.deleteComplete.type,
191
- tagsActions.updateComplete.type
192
+ tagsActions.updateComplete.type,
192
193
  ),
193
194
  filter(
194
195
  (action: {
195
196
  payload: {closeDialogId?: string}
196
- }): action is PayloadAction<{closeDialogId?: string}> => !!action?.payload?.closeDialogId
197
+ }): action is PayloadAction<{closeDialogId?: string}> => !!action?.payload?.closeDialogId,
197
198
  ),
198
- mergeMap(action => {
199
+ mergeMap((action) => {
199
200
  const dialogId = action?.payload?.closeDialogId
200
201
  if (dialogId) {
201
202
  return of(dialogSlice.actions.remove({id: dialogId}))
202
203
  }
203
204
  return EMPTY
204
- })
205
+ }),
205
206
  )
206
207
 
207
- export const dialogTagCreateEpic: MyEpic = action$ =>
208
+ export const dialogTagCreateEpic: MyEpic = (action$) =>
208
209
  action$.pipe(
209
210
  filter(tagsActions.createComplete.match),
210
- mergeMap(action => {
211
+ mergeMap((action) => {
211
212
  const {assetId, tag} = action?.payload
212
213
 
213
214
  if (assetId) {
@@ -219,17 +220,17 @@ export const dialogTagCreateEpic: MyEpic = action$ =>
219
220
  }
220
221
 
221
222
  return EMPTY
222
- })
223
+ }),
223
224
  )
224
225
 
225
- export const dialogTagDeleteEpic: MyEpic = action$ =>
226
+ export const dialogTagDeleteEpic: MyEpic = (action$) =>
226
227
  action$.pipe(
227
228
  filter(tagsActions.listenerDeleteQueueComplete.match),
228
- mergeMap(action => {
229
+ mergeMap((action) => {
229
230
  const {tagIds} = action?.payload
230
231
 
231
232
  return of(dialogSlice.actions.inlineTagRemove({tagIds}))
232
- })
233
+ }),
233
234
  )
234
235
 
235
236
  export const dialogActions = {...dialogSlice.actions}