sanity-plugin-media 4.3.6 → 5.0.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.
- package/package.json +6 -15
- package/dist/index.cjs +0 -4721
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -239
- package/dist/index.d.cts.map +0 -1
- package/sanity.json +0 -8
- package/src/__tests__/fixtures/createEpicTestStore.ts +0 -28
- package/src/__tests__/fixtures/listenMock.ts +0 -9
- package/src/__tests__/fixtures/mockSanityClient.ts +0 -84
- package/src/__tests__/fixtures/renderWithProviders.tsx +0 -55
- package/src/__tests__/fixtures/rootState.ts +0 -27
- package/src/__tests__/fixtures/withinDialog.ts +0 -28
- package/src/components/AssetGridVirtualized/index.tsx +0 -94
- package/src/components/AssetMetadata/index.tsx +0 -122
- package/src/components/AssetTableVirtualized/index.tsx +0 -73
- package/src/components/AutoTagInputWrapper/index.tsx +0 -85
- package/src/components/Browser/Browser.test.tsx +0 -45
- package/src/components/Browser/index.tsx +0 -90
- package/src/components/Browser/useBrowserInit.ts +0 -126
- package/src/components/ButtonAssetCopy/index.tsx +0 -65
- package/src/components/ButtonViewGroup/index.tsx +0 -39
- package/src/components/CardAsset/CardAsset.test.tsx +0 -323
- package/src/components/CardAsset/index.tsx +0 -290
- package/src/components/CardUpload/index.tsx +0 -161
- package/src/components/Controls/index.tsx +0 -136
- package/src/components/DebugControls/index.tsx +0 -80
- package/src/components/Dialog/index.tsx +0 -11
- package/src/components/DialogAssetEdit/Details.tsx +0 -181
- package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +0 -216
- package/src/components/DialogAssetEdit/index.tsx +0 -493
- package/src/components/DialogConfirm/index.tsx +0 -90
- package/src/components/DialogSearchFacets/index.tsx +0 -42
- package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +0 -121
- package/src/components/DialogTagCreate/index.tsx +0 -111
- package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +0 -165
- package/src/components/DialogTagEdit/index.tsx +0 -201
- package/src/components/DialogTags/index.tsx +0 -45
- package/src/components/Dialogs/index.tsx +0 -76
- package/src/components/DocumentList/index.tsx +0 -62
- package/src/components/FileAssetPreview/index.tsx +0 -37
- package/src/components/FileIcon/index.tsx +0 -43
- package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +0 -63
- package/src/components/FormBuilderTool/index.tsx +0 -69
- package/src/components/FormFieldInputLabel/index.tsx +0 -66
- package/src/components/FormFieldInputTags/index.tsx +0 -98
- package/src/components/FormFieldInputText/index.tsx +0 -41
- package/src/components/FormFieldInputTextarea/index.tsx +0 -43
- package/src/components/FormSubmitButton/index.tsx +0 -59
- package/src/components/Header/index.tsx +0 -80
- package/src/components/Image/index.tsx +0 -41
- package/src/components/Items/index.tsx +0 -68
- package/src/components/Notifications/index.tsx +0 -24
- package/src/components/OrderSelect/index.tsx +0 -66
- package/src/components/PickedBar/index.tsx +0 -77
- package/src/components/Progress/index.tsx +0 -38
- package/src/components/ReduxProvider/index.tsx +0 -96
- package/src/components/SearchFacet/index.tsx +0 -66
- package/src/components/SearchFacetNumber/index.tsx +0 -133
- package/src/components/SearchFacetSelect/index.tsx +0 -110
- package/src/components/SearchFacetString/index.tsx +0 -88
- package/src/components/SearchFacetTags/index.tsx +0 -121
- package/src/components/SearchFacets/index.tsx +0 -72
- package/src/components/SearchFacetsControl/index.tsx +0 -140
- package/src/components/TableHeader/index.tsx +0 -110
- package/src/components/TableHeaderItem/index.tsx +0 -61
- package/src/components/TableRowAsset/index.tsx +0 -419
- package/src/components/TableRowUpload/index.tsx +0 -164
- package/src/components/Tag/index.tsx +0 -200
- package/src/components/TagIcon/index.tsx +0 -22
- package/src/components/TagView/index.tsx +0 -39
- package/src/components/TagViewHeader/index.tsx +0 -70
- package/src/components/TagsPanel/index.tsx +0 -40
- package/src/components/TagsVirtualized/index.tsx +0 -160
- package/src/components/TextInputNumber/index.tsx +0 -32
- package/src/components/TextInputSearch/index.tsx +0 -60
- package/src/components/Tool/index.tsx +0 -13
- package/src/components/UploadDropzone/UploadDropzone.test.tsx +0 -40
- package/src/components/UploadDropzone/index.tsx +0 -173
- package/src/config/orders.ts +0 -28
- package/src/config/searchFacets.ts +0 -312
- package/src/constants.ts +0 -87
- package/src/contexts/AssetSourceDispatchContext.tsx +0 -38
- package/src/contexts/DropzoneDispatchContext.tsx +0 -32
- package/src/contexts/ToolOptionsContext.tsx +0 -66
- package/src/formSchema/index.test.ts +0 -56
- package/src/formSchema/index.ts +0 -39
- package/src/hooks/useBreakpointIndex.ts +0 -50
- package/src/hooks/useKeyPress.ts +0 -39
- package/src/hooks/usePortalPopoverProps.ts +0 -13
- package/src/hooks/useTypedSelector.ts +0 -7
- package/src/hooks/useVersionedClient.ts +0 -6
- package/src/index.ts +0 -5
- package/src/modules/assets/actions.ts +0 -42
- package/src/modules/assets/deleteAndUpdateEpics.test.ts +0 -87
- package/src/modules/assets/fetchEpic.test.ts +0 -73
- package/src/modules/assets/index.ts +0 -782
- package/src/modules/assets/reducer.test.ts +0 -91
- package/src/modules/assets/tagsAndListenerEpics.test.ts +0 -206
- package/src/modules/debug/index.ts +0 -28
- package/src/modules/dialog/actions.ts +0 -10
- package/src/modules/dialog/epics.test.ts +0 -168
- package/src/modules/dialog/index.ts +0 -238
- package/src/modules/dialog/reducer.test.ts +0 -185
- package/src/modules/index.ts +0 -117
- package/src/modules/notifications/epics.test.ts +0 -374
- package/src/modules/notifications/index.ts +0 -199
- package/src/modules/notifications/reducer.test.ts +0 -54
- package/src/modules/search/index.test.ts +0 -36
- package/src/modules/search/index.ts +0 -167
- package/src/modules/selected/index.ts +0 -22
- package/src/modules/selectors.test.ts +0 -21
- package/src/modules/selectors.ts +0 -17
- package/src/modules/tags/epics.test.ts +0 -96
- package/src/modules/tags/index.test.ts +0 -42
- package/src/modules/tags/index.ts +0 -540
- package/src/modules/types.ts +0 -3
- package/src/modules/uploads/actions.ts +0 -13
- package/src/modules/uploads/epics.test.ts +0 -109
- package/src/modules/uploads/index.test.ts +0 -59
- package/src/modules/uploads/index.ts +0 -272
- package/src/operators/checkTagName.test.ts +0 -29
- package/src/operators/checkTagName.ts +0 -33
- package/src/operators/debugThrottle.ts +0 -25
- package/src/plugin.tsx +0 -54
- package/src/schemas/tag.ts +0 -28
- package/src/styled/GlobalStyles/index.tsx +0 -40
- package/src/styled/react-select/creatable.tsx +0 -184
- package/src/styled/react-select/single.tsx +0 -184
- package/src/types/index.ts +0 -346
- package/src/types/sanity-ui.d.ts +0 -5
- package/src/utils/applyMediaTags.ts +0 -87
- package/src/utils/blocksToText.test.ts +0 -43
- package/src/utils/blocksToText.ts +0 -27
- package/src/utils/constructFilter.test.ts +0 -120
- package/src/utils/constructFilter.ts +0 -98
- package/src/utils/generatePreviewBlobUrl.test.ts +0 -68
- package/src/utils/generatePreviewBlobUrl.ts +0 -53
- package/src/utils/getAssetResolution.test.ts +0 -13
- package/src/utils/getAssetResolution.ts +0 -7
- package/src/utils/getDocumentAssetIds.test.ts +0 -50
- package/src/utils/getDocumentAssetIds.ts +0 -35
- package/src/utils/getSchemeColor.test.ts +0 -12
- package/src/utils/getSchemeColor.ts +0 -43
- package/src/utils/getTagSelectOptions.test.ts +0 -44
- package/src/utils/getTagSelectOptions.ts +0 -16
- package/src/utils/getUniqueDocuments.test.ts +0 -26
- package/src/utils/getUniqueDocuments.ts +0 -15
- package/src/utils/imageDprUrl.test.ts +0 -46
- package/src/utils/imageDprUrl.ts +0 -27
- package/src/utils/isSupportedAssetType.test.ts +0 -16
- package/src/utils/isSupportedAssetType.ts +0 -15
- package/src/utils/mediaField.ts +0 -73
- package/src/utils/sanitizeFormData.test.ts +0 -59
- package/src/utils/sanitizeFormData.ts +0 -26
- package/src/utils/typeGuards.test.ts +0 -18
- package/src/utils/typeGuards.ts +0 -9
- package/src/utils/uploadSanityAsset.test.ts +0 -29
- package/src/utils/uploadSanityAsset.ts +0 -97
- package/src/utils/withMaxConcurrency.test.ts +0 -43
- package/src/utils/withMaxConcurrency.ts +0 -55
- package/src/utils/zodFormResolver.ts +0 -17
- package/v2-incompatible.js +0 -11
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import {createSlice, type PayloadAction} from '@reduxjs/toolkit'
|
|
2
|
-
import pluralize from 'pluralize'
|
|
3
|
-
import {ofType} from 'redux-observable'
|
|
4
|
-
import {EMPTY, of} from 'rxjs'
|
|
5
|
-
import {filter, mergeMap} from 'rxjs/operators'
|
|
6
|
-
|
|
7
|
-
import type {AssetItem, Dialog, MyEpic, Tag} from '../../types'
|
|
8
|
-
import {assetsActions} from '../assets'
|
|
9
|
-
import {ASSETS_ACTIONS} from '../assets/actions'
|
|
10
|
-
import {tagsActions} from '../tags'
|
|
11
|
-
import {DIALOG_ACTIONS} from './actions'
|
|
12
|
-
|
|
13
|
-
type DialogReducerState = {
|
|
14
|
-
items: Dialog[]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const initialState = {
|
|
18
|
-
items: [],
|
|
19
|
-
} as DialogReducerState
|
|
20
|
-
|
|
21
|
-
const dialogSlice = createSlice({
|
|
22
|
-
name: 'dialog',
|
|
23
|
-
initialState,
|
|
24
|
-
extraReducers: (builder) => {
|
|
25
|
-
builder.addCase(DIALOG_ACTIONS.showTagCreate, (state) => {
|
|
26
|
-
state.items.push({
|
|
27
|
-
id: 'tagCreate',
|
|
28
|
-
type: 'tagCreate',
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
builder.addCase(DIALOG_ACTIONS.showTagEdit, (state, action) => {
|
|
32
|
-
const {tagId} = action.payload
|
|
33
|
-
state.items.push({
|
|
34
|
-
id: tagId,
|
|
35
|
-
tagId,
|
|
36
|
-
type: 'tagEdit',
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
},
|
|
40
|
-
reducers: {
|
|
41
|
-
// Clear all dialogs
|
|
42
|
-
clear(state) {
|
|
43
|
-
state.items = []
|
|
44
|
-
},
|
|
45
|
-
// Add newly created inline tag to assetEdit dialog
|
|
46
|
-
inlineTagCreate(state, action: PayloadAction<{assetId: string; tag: Tag}>) {
|
|
47
|
-
const {assetId, tag} = action.payload
|
|
48
|
-
|
|
49
|
-
state.items.forEach((item) => {
|
|
50
|
-
if (item.type === 'assetEdit' && item.assetId === assetId) {
|
|
51
|
-
item.lastCreatedTag = {
|
|
52
|
-
label: tag.name.current,
|
|
53
|
-
value: tag._id,
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
},
|
|
58
|
-
// Remove inline tags from assetEdit dialog
|
|
59
|
-
inlineTagRemove(state, action: PayloadAction<{tagIds: string[]}>) {
|
|
60
|
-
const {tagIds} = action.payload
|
|
61
|
-
|
|
62
|
-
state.items.forEach((item) => {
|
|
63
|
-
if (item.type === 'assetEdit') {
|
|
64
|
-
item.lastRemovedTagIds = tagIds
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
},
|
|
68
|
-
// Remove dialog by id
|
|
69
|
-
remove(state, action: PayloadAction<{id: string}>) {
|
|
70
|
-
const id = action.payload?.id
|
|
71
|
-
state.items = state.items.filter((item) => item.id !== id)
|
|
72
|
-
},
|
|
73
|
-
showConfirmAssetsTagAdd(
|
|
74
|
-
state,
|
|
75
|
-
action: PayloadAction<{
|
|
76
|
-
assetsPicked: AssetItem[]
|
|
77
|
-
closeDialogId?: string
|
|
78
|
-
tag: Tag
|
|
79
|
-
}>,
|
|
80
|
-
) {
|
|
81
|
-
const {assetsPicked, closeDialogId, tag} = action.payload
|
|
82
|
-
|
|
83
|
-
const suffix = `${assetsPicked.length} ${pluralize('asset', assetsPicked.length)}`
|
|
84
|
-
|
|
85
|
-
state.items.push({
|
|
86
|
-
closeDialogId,
|
|
87
|
-
confirmCallbackAction: ASSETS_ACTIONS.tagsAddRequest({
|
|
88
|
-
assets: assetsPicked,
|
|
89
|
-
tag,
|
|
90
|
-
}),
|
|
91
|
-
confirmText: `Yes, add tag to ${suffix}`,
|
|
92
|
-
title: `Add tag ${tag.name.current} to ${suffix}?`,
|
|
93
|
-
id: 'confirm',
|
|
94
|
-
headerTitle: 'Confirm tag addition',
|
|
95
|
-
tone: 'primary',
|
|
96
|
-
type: 'confirm',
|
|
97
|
-
})
|
|
98
|
-
},
|
|
99
|
-
showConfirmAssetsTagRemove(
|
|
100
|
-
state,
|
|
101
|
-
action: PayloadAction<{
|
|
102
|
-
assetsPicked: AssetItem[]
|
|
103
|
-
closeDialogId?: string
|
|
104
|
-
tag: Tag
|
|
105
|
-
}>,
|
|
106
|
-
) {
|
|
107
|
-
const {assetsPicked, closeDialogId, tag} = action.payload
|
|
108
|
-
|
|
109
|
-
const suffix = `${assetsPicked.length} ${pluralize('asset', assetsPicked.length)}`
|
|
110
|
-
|
|
111
|
-
state.items.push({
|
|
112
|
-
closeDialogId,
|
|
113
|
-
confirmCallbackAction: ASSETS_ACTIONS.tagsRemoveRequest({assets: assetsPicked, tag}),
|
|
114
|
-
confirmText: `Yes, remove tag from ${suffix}`,
|
|
115
|
-
headerTitle: 'Confirm tag removal',
|
|
116
|
-
id: 'confirm',
|
|
117
|
-
title: `Remove tag ${tag.name.current} from ${suffix}?`,
|
|
118
|
-
tone: 'critical',
|
|
119
|
-
type: 'confirm',
|
|
120
|
-
})
|
|
121
|
-
},
|
|
122
|
-
showConfirmDeleteAssets(
|
|
123
|
-
state,
|
|
124
|
-
action: PayloadAction<{assets: AssetItem[]; closeDialogId?: string}>,
|
|
125
|
-
) {
|
|
126
|
-
const {assets, closeDialogId} = action.payload
|
|
127
|
-
|
|
128
|
-
const suffix = `${assets.length} ${pluralize('asset', assets.length)}`
|
|
129
|
-
|
|
130
|
-
state.items.push({
|
|
131
|
-
closeDialogId,
|
|
132
|
-
confirmCallbackAction: assetsActions.deleteRequest({
|
|
133
|
-
assets: assets.map((assetItem) => assetItem.asset),
|
|
134
|
-
}),
|
|
135
|
-
confirmText: `Yes, delete ${suffix}`,
|
|
136
|
-
description: 'This operation cannot be reversed. Are you sure you want to continue?',
|
|
137
|
-
title: `Permanently delete ${suffix}?`,
|
|
138
|
-
id: 'confirm',
|
|
139
|
-
headerTitle: 'Confirm deletion',
|
|
140
|
-
tone: 'critical',
|
|
141
|
-
type: 'confirm',
|
|
142
|
-
})
|
|
143
|
-
},
|
|
144
|
-
showConfirmDeleteTag(state, action: PayloadAction<{closeDialogId?: string; tag: Tag}>) {
|
|
145
|
-
const {closeDialogId, tag} = action.payload
|
|
146
|
-
|
|
147
|
-
const suffix = 'tag'
|
|
148
|
-
|
|
149
|
-
state.items.push({
|
|
150
|
-
closeDialogId,
|
|
151
|
-
confirmCallbackAction: tagsActions.deleteRequest({tag}),
|
|
152
|
-
confirmText: `Yes, delete ${suffix}`,
|
|
153
|
-
description: 'This operation cannot be reversed. Are you sure you want to continue?',
|
|
154
|
-
title: `Permanently delete ${suffix}?`,
|
|
155
|
-
id: 'confirm',
|
|
156
|
-
headerTitle: 'Confirm deletion',
|
|
157
|
-
tone: 'critical',
|
|
158
|
-
type: 'confirm',
|
|
159
|
-
})
|
|
160
|
-
},
|
|
161
|
-
showAssetEdit(state, action: PayloadAction<{assetId: string}>) {
|
|
162
|
-
const {assetId} = action.payload
|
|
163
|
-
state.items.push({
|
|
164
|
-
assetId,
|
|
165
|
-
id: assetId,
|
|
166
|
-
type: 'assetEdit',
|
|
167
|
-
})
|
|
168
|
-
},
|
|
169
|
-
showSearchFacets(state) {
|
|
170
|
-
state.items.push({
|
|
171
|
-
id: 'searchFacets',
|
|
172
|
-
type: 'searchFacets',
|
|
173
|
-
})
|
|
174
|
-
},
|
|
175
|
-
showTags(state) {
|
|
176
|
-
state.items.push({
|
|
177
|
-
id: 'tags',
|
|
178
|
-
type: 'tags',
|
|
179
|
-
})
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
// Epics
|
|
185
|
-
|
|
186
|
-
export const dialogClearOnAssetUpdateEpic: MyEpic = (action$) =>
|
|
187
|
-
action$.pipe(
|
|
188
|
-
ofType(
|
|
189
|
-
assetsActions.deleteComplete.type,
|
|
190
|
-
assetsActions.updateComplete.type,
|
|
191
|
-
tagsActions.deleteComplete.type,
|
|
192
|
-
tagsActions.updateComplete.type,
|
|
193
|
-
),
|
|
194
|
-
filter(
|
|
195
|
-
(action: {
|
|
196
|
-
payload: {closeDialogId?: string}
|
|
197
|
-
}): action is PayloadAction<{closeDialogId?: string}> => !!action?.payload?.closeDialogId,
|
|
198
|
-
),
|
|
199
|
-
mergeMap((action) => {
|
|
200
|
-
const dialogId = action?.payload?.closeDialogId
|
|
201
|
-
if (dialogId) {
|
|
202
|
-
return of(dialogSlice.actions.remove({id: dialogId}))
|
|
203
|
-
}
|
|
204
|
-
return EMPTY
|
|
205
|
-
}),
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
export const dialogTagCreateEpic: MyEpic = (action$) =>
|
|
209
|
-
action$.pipe(
|
|
210
|
-
filter(tagsActions.createComplete.match),
|
|
211
|
-
mergeMap((action) => {
|
|
212
|
-
const {assetId, tag} = action?.payload || {}
|
|
213
|
-
|
|
214
|
-
if (assetId) {
|
|
215
|
-
return of(dialogSlice.actions.inlineTagCreate({tag, assetId}))
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (tag._id) {
|
|
219
|
-
return of(dialogSlice.actions.remove({id: 'tagCreate'}))
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return EMPTY
|
|
223
|
-
}),
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
export const dialogTagDeleteEpic: MyEpic = (action$) =>
|
|
227
|
-
action$.pipe(
|
|
228
|
-
filter(tagsActions.listenerDeleteQueueComplete.match),
|
|
229
|
-
mergeMap((action) => {
|
|
230
|
-
const {tagIds} = action?.payload || {}
|
|
231
|
-
|
|
232
|
-
return of(dialogSlice.actions.inlineTagRemove({tagIds}))
|
|
233
|
-
}),
|
|
234
|
-
)
|
|
235
|
-
|
|
236
|
-
export const dialogActions = {...dialogSlice.actions}
|
|
237
|
-
|
|
238
|
-
export default dialogSlice.reducer
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
// @vitest-environment node
|
|
2
|
-
|
|
3
|
-
import {describe, expect, it} from 'vitest'
|
|
4
|
-
|
|
5
|
-
import {createTestRootState} from '../../__tests__/fixtures/rootState'
|
|
6
|
-
import type {AssetItem, ImageAsset, Tag} from '../../types'
|
|
7
|
-
import {assetsActions} from '../assets'
|
|
8
|
-
import {ASSETS_ACTIONS} from '../assets/actions'
|
|
9
|
-
import {tagsActions} from '../tags'
|
|
10
|
-
import {DIALOG_ACTIONS} from './actions'
|
|
11
|
-
import dialogReducer, {dialogActions} from './index'
|
|
12
|
-
|
|
13
|
-
const sampleAsset = {
|
|
14
|
-
_id: 'a1',
|
|
15
|
-
_type: 'sanity.imageAsset',
|
|
16
|
-
_createdAt: '',
|
|
17
|
-
_updatedAt: '',
|
|
18
|
-
_rev: 'r1',
|
|
19
|
-
originalFilename: 'x.png',
|
|
20
|
-
size: 1,
|
|
21
|
-
mimeType: 'image/png',
|
|
22
|
-
url: 'https://example.com/x.png',
|
|
23
|
-
} as ImageAsset
|
|
24
|
-
|
|
25
|
-
const sampleTag: Tag = {
|
|
26
|
-
_id: 't1',
|
|
27
|
-
_type: 'media.tag',
|
|
28
|
-
_createdAt: '',
|
|
29
|
-
_updatedAt: '',
|
|
30
|
-
_rev: 'tr',
|
|
31
|
-
name: {_type: 'slug', current: 'alpha'},
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const assetItem = (asset: ImageAsset = sampleAsset): AssetItem => ({
|
|
35
|
-
_type: 'asset',
|
|
36
|
-
asset,
|
|
37
|
-
picked: false,
|
|
38
|
-
updating: false,
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
function dialogState() {
|
|
42
|
-
return createTestRootState().dialog
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
describe('dialog slice reducers', () => {
|
|
46
|
-
it('clear removes all items', () => {
|
|
47
|
-
const state = dialogReducer(
|
|
48
|
-
{...dialogState(), items: [{id: 'x', type: 'tags'}]},
|
|
49
|
-
dialogActions.clear(),
|
|
50
|
-
)
|
|
51
|
-
expect(state.items).toEqual([])
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('remove filters out the dialog with the given id', () => {
|
|
55
|
-
const state = dialogReducer(
|
|
56
|
-
{
|
|
57
|
-
...dialogState(),
|
|
58
|
-
items: [
|
|
59
|
-
{id: 'a', type: 'tags'},
|
|
60
|
-
{id: 'b', type: 'searchFacets'},
|
|
61
|
-
],
|
|
62
|
-
},
|
|
63
|
-
dialogActions.remove({id: 'a'}),
|
|
64
|
-
)
|
|
65
|
-
expect(state.items).toEqual([{id: 'b', type: 'searchFacets'}])
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('showAssetEdit appends an asset edit dialog', () => {
|
|
69
|
-
const state = dialogReducer(dialogState(), dialogActions.showAssetEdit({assetId: 'a1'}))
|
|
70
|
-
expect(state.items).toEqual([{assetId: 'a1', id: 'a1', type: 'assetEdit'}])
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('showSearchFacets and showTags append the expected dialogs', () => {
|
|
74
|
-
let state = dialogReducer(dialogState(), dialogActions.showSearchFacets())
|
|
75
|
-
state = dialogReducer(state, dialogActions.showTags())
|
|
76
|
-
expect(state.items).toEqual([
|
|
77
|
-
{id: 'searchFacets', type: 'searchFacets'},
|
|
78
|
-
{id: 'tags', type: 'tags'},
|
|
79
|
-
])
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('inlineTagCreate sets lastCreatedTag on matching assetEdit items', () => {
|
|
83
|
-
const state = dialogReducer(
|
|
84
|
-
{
|
|
85
|
-
...dialogState(),
|
|
86
|
-
items: [
|
|
87
|
-
{id: 'a1', type: 'assetEdit', assetId: 'a1'},
|
|
88
|
-
{id: 'a2', type: 'assetEdit', assetId: 'a2'},
|
|
89
|
-
],
|
|
90
|
-
},
|
|
91
|
-
dialogActions.inlineTagCreate({assetId: 'a1', tag: sampleTag}),
|
|
92
|
-
)
|
|
93
|
-
const a1 = state.items.find((i) => i.type === 'assetEdit' && i.assetId === 'a1')
|
|
94
|
-
const a2 = state.items.find((i) => i.type === 'assetEdit' && i.assetId === 'a2')
|
|
95
|
-
expect(a1 && 'lastCreatedTag' in a1 && a1.lastCreatedTag).toEqual({
|
|
96
|
-
label: 'alpha',
|
|
97
|
-
value: 't1',
|
|
98
|
-
})
|
|
99
|
-
expect(a2).toBeDefined()
|
|
100
|
-
expect(Object.prototype.hasOwnProperty.call(a2, 'lastCreatedTag')).toBe(false)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('inlineTagRemove sets lastRemovedTagIds on all assetEdit items', () => {
|
|
104
|
-
const state = dialogReducer(
|
|
105
|
-
{
|
|
106
|
-
...dialogState(),
|
|
107
|
-
items: [
|
|
108
|
-
{id: 'a1', type: 'assetEdit', assetId: 'a1'},
|
|
109
|
-
{id: 'tags', type: 'tags'},
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
dialogActions.inlineTagRemove({tagIds: ['x', 'y']}),
|
|
113
|
-
)
|
|
114
|
-
const edit = state.items.find((i) => i.type === 'assetEdit')
|
|
115
|
-
expect(edit && 'lastRemovedTagIds' in edit && edit.lastRemovedTagIds).toEqual(['x', 'y'])
|
|
116
|
-
const tagsPanel = state.items.find((i) => i.type === 'tags')
|
|
117
|
-
expect(tagsPanel && 'lastRemovedTagIds' in tagsPanel).toBeFalsy()
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('showConfirmDeleteAssets pushes a confirm dialog wired to assets deleteRequest', () => {
|
|
121
|
-
const item = assetItem()
|
|
122
|
-
const state = dialogReducer(
|
|
123
|
-
dialogState(),
|
|
124
|
-
dialogActions.showConfirmDeleteAssets({assets: [item], closeDialogId: 'a1'}),
|
|
125
|
-
)
|
|
126
|
-
const confirm = state.items[0]
|
|
127
|
-
expect(confirm?.type).toBe('confirm')
|
|
128
|
-
expect(confirm && 'title' in confirm && confirm.title).toBe('Permanently delete 1 asset?')
|
|
129
|
-
const cb = confirm && 'confirmCallbackAction' in confirm ? confirm.confirmCallbackAction : null
|
|
130
|
-
expect(cb).toEqual(assetsActions.deleteRequest({assets: [sampleAsset]}))
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('showConfirmDeleteTag pushes a confirm dialog wired to tags deleteRequest', () => {
|
|
134
|
-
const state = dialogReducer(
|
|
135
|
-
dialogState(),
|
|
136
|
-
dialogActions.showConfirmDeleteTag({closeDialogId: 't1', tag: sampleTag}),
|
|
137
|
-
)
|
|
138
|
-
const confirm = state.items[0]
|
|
139
|
-
expect(confirm?.type).toBe('confirm')
|
|
140
|
-
expect(confirm && 'title' in confirm && confirm.title).toMatch(/permanently delete/i)
|
|
141
|
-
const cb = confirm && 'confirmCallbackAction' in confirm ? confirm.confirmCallbackAction : null
|
|
142
|
-
expect(cb).toEqual(tagsActions.deleteRequest({tag: sampleTag}))
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('showConfirmAssetsTagAdd uses plural copy for multiple assets', () => {
|
|
146
|
-
const a2 = {...sampleAsset, _id: 'a2', originalFilename: 'y.png'} as ImageAsset
|
|
147
|
-
const state = dialogReducer(
|
|
148
|
-
dialogState(),
|
|
149
|
-
dialogActions.showConfirmAssetsTagAdd({
|
|
150
|
-
assetsPicked: [assetItem(), assetItem(a2)],
|
|
151
|
-
tag: sampleTag,
|
|
152
|
-
}),
|
|
153
|
-
)
|
|
154
|
-
const confirm = state.items[0]
|
|
155
|
-
expect(confirm && 'title' in confirm && confirm.title).toContain('2 assets')
|
|
156
|
-
const cb = confirm && 'confirmCallbackAction' in confirm ? confirm.confirmCallbackAction : null
|
|
157
|
-
expect(cb).toEqual(
|
|
158
|
-
ASSETS_ACTIONS.tagsAddRequest({assets: [assetItem(), assetItem(a2)], tag: sampleTag}),
|
|
159
|
-
)
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
it('showConfirmAssetsTagRemove pushes removal confirm with tagsRemoveRequest', () => {
|
|
163
|
-
const state = dialogReducer(
|
|
164
|
-
dialogState(),
|
|
165
|
-
dialogActions.showConfirmAssetsTagRemove({
|
|
166
|
-
assetsPicked: [assetItem()],
|
|
167
|
-
tag: sampleTag,
|
|
168
|
-
}),
|
|
169
|
-
)
|
|
170
|
-
const confirm = state.items[0]
|
|
171
|
-
expect(confirm && 'tone' in confirm && confirm.tone).toBe('critical')
|
|
172
|
-
const cb = confirm && 'confirmCallbackAction' in confirm ? confirm.confirmCallbackAction : null
|
|
173
|
-
expect(cb).toEqual(ASSETS_ACTIONS.tagsRemoveRequest({assets: [assetItem()], tag: sampleTag}))
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
it('DIALOG_ACTIONS.showTagCreate appends tag create dialog', () => {
|
|
177
|
-
const state = dialogReducer(dialogState(), DIALOG_ACTIONS.showTagCreate())
|
|
178
|
-
expect(state.items).toEqual([{id: 'tagCreate', type: 'tagCreate'}])
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
it('DIALOG_ACTIONS.showTagEdit appends tag edit dialog with tag id', () => {
|
|
182
|
-
const state = dialogReducer(dialogState(), DIALOG_ACTIONS.showTagEdit({tagId: 't9'}))
|
|
183
|
-
expect(state.items).toEqual([{id: 't9', tagId: 't9', type: 'tagEdit'}])
|
|
184
|
-
})
|
|
185
|
-
})
|
package/src/modules/index.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import {type Reducer, type StateFromReducersMapObject, combineReducers} from '@reduxjs/toolkit'
|
|
2
|
-
import {combineEpics} from 'redux-observable'
|
|
3
|
-
|
|
4
|
-
import assetsReducer, {
|
|
5
|
-
assetsDeleteEpic,
|
|
6
|
-
assetsFetchAfterDeleteAllEpic,
|
|
7
|
-
assetsFetchEpic,
|
|
8
|
-
assetsFetchNextPageEpic,
|
|
9
|
-
assetsFetchPageIndexEpic,
|
|
10
|
-
assetsListenerCreateQueueEpic,
|
|
11
|
-
assetsListenerDeleteQueueEpic,
|
|
12
|
-
assetsListenerUpdateQueueEpic,
|
|
13
|
-
assetsOrderSetEpic,
|
|
14
|
-
assetsSearchEpic,
|
|
15
|
-
assetsSortEpic,
|
|
16
|
-
assetsTagsAddEpic,
|
|
17
|
-
assetsTagsRemoveEpic,
|
|
18
|
-
assetsUnpickEpic,
|
|
19
|
-
assetsUpdateEpic,
|
|
20
|
-
} from './assets'
|
|
21
|
-
import debugReducer from './debug'
|
|
22
|
-
import dialogReducer, {
|
|
23
|
-
dialogClearOnAssetUpdateEpic,
|
|
24
|
-
dialogTagCreateEpic,
|
|
25
|
-
dialogTagDeleteEpic,
|
|
26
|
-
} from './dialog'
|
|
27
|
-
import notificationsReducer, {
|
|
28
|
-
notificationsAssetsDeleteErrorEpic,
|
|
29
|
-
notificationsAssetsDeleteCompleteEpic,
|
|
30
|
-
notificationsAssetsTagsAddCompleteEpic,
|
|
31
|
-
notificationsAssetsTagsRemoveCompleteEpic,
|
|
32
|
-
notificationsAssetsUpdateCompleteEpic,
|
|
33
|
-
notificationsGenericErrorEpic,
|
|
34
|
-
notificationsTagCreateCompleteEpic,
|
|
35
|
-
notificationsTagDeleteCompleteEpic,
|
|
36
|
-
notificationsTagUpdateCompleteEpic,
|
|
37
|
-
} from './notifications'
|
|
38
|
-
import searchReducer, {searchFacetTagUpdateEpic} from './search'
|
|
39
|
-
import selectedReducer from './selected'
|
|
40
|
-
import tagsReducer, {
|
|
41
|
-
tagsCreateEpic,
|
|
42
|
-
tagsDeleteEpic,
|
|
43
|
-
tagsFetchEpic,
|
|
44
|
-
tagsListenerCreateQueueEpic,
|
|
45
|
-
tagsListenerDeleteQueueEpic,
|
|
46
|
-
tagsListenerUpdateQueueEpic,
|
|
47
|
-
tagsSortEpic,
|
|
48
|
-
tagsUpdateEpic,
|
|
49
|
-
} from './tags'
|
|
50
|
-
import uploadsReducer, {
|
|
51
|
-
uploadsAssetStartEpic,
|
|
52
|
-
uploadsAssetUploadEpic,
|
|
53
|
-
uploadsCheckRequestEpic,
|
|
54
|
-
uploadsCompleteQueueEpic,
|
|
55
|
-
} from './uploads'
|
|
56
|
-
|
|
57
|
-
export const rootEpic = combineEpics(
|
|
58
|
-
assetsDeleteEpic,
|
|
59
|
-
assetsFetchEpic,
|
|
60
|
-
assetsFetchAfterDeleteAllEpic,
|
|
61
|
-
assetsFetchNextPageEpic,
|
|
62
|
-
assetsFetchPageIndexEpic,
|
|
63
|
-
assetsListenerCreateQueueEpic,
|
|
64
|
-
assetsListenerDeleteQueueEpic,
|
|
65
|
-
assetsListenerUpdateQueueEpic,
|
|
66
|
-
assetsOrderSetEpic,
|
|
67
|
-
assetsSearchEpic,
|
|
68
|
-
assetsSortEpic,
|
|
69
|
-
assetsTagsAddEpic,
|
|
70
|
-
assetsTagsRemoveEpic,
|
|
71
|
-
assetsUnpickEpic,
|
|
72
|
-
assetsUpdateEpic,
|
|
73
|
-
dialogClearOnAssetUpdateEpic,
|
|
74
|
-
dialogTagCreateEpic,
|
|
75
|
-
dialogTagDeleteEpic,
|
|
76
|
-
notificationsAssetsDeleteErrorEpic,
|
|
77
|
-
notificationsAssetsDeleteCompleteEpic,
|
|
78
|
-
notificationsAssetsTagsAddCompleteEpic,
|
|
79
|
-
notificationsAssetsTagsRemoveCompleteEpic,
|
|
80
|
-
notificationsAssetsUpdateCompleteEpic,
|
|
81
|
-
notificationsGenericErrorEpic,
|
|
82
|
-
notificationsTagCreateCompleteEpic,
|
|
83
|
-
notificationsTagDeleteCompleteEpic,
|
|
84
|
-
notificationsTagUpdateCompleteEpic,
|
|
85
|
-
searchFacetTagUpdateEpic,
|
|
86
|
-
tagsCreateEpic,
|
|
87
|
-
tagsDeleteEpic,
|
|
88
|
-
tagsFetchEpic,
|
|
89
|
-
tagsListenerCreateQueueEpic,
|
|
90
|
-
tagsListenerDeleteQueueEpic,
|
|
91
|
-
tagsListenerUpdateQueueEpic,
|
|
92
|
-
tagsSortEpic,
|
|
93
|
-
tagsUpdateEpic,
|
|
94
|
-
uploadsAssetStartEpic,
|
|
95
|
-
uploadsAssetUploadEpic,
|
|
96
|
-
uploadsCheckRequestEpic,
|
|
97
|
-
uploadsCompleteQueueEpic,
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
const reducers = {
|
|
101
|
-
assets: assetsReducer,
|
|
102
|
-
debug: debugReducer,
|
|
103
|
-
dialog: dialogReducer,
|
|
104
|
-
notifications: notificationsReducer,
|
|
105
|
-
search: searchReducer,
|
|
106
|
-
selected: selectedReducer,
|
|
107
|
-
tags: tagsReducer,
|
|
108
|
-
uploads: uploadsReducer,
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
type ReducersMapObject = typeof reducers
|
|
112
|
-
|
|
113
|
-
// Workaround to avoid `$CombinedState` ts errors
|
|
114
|
-
// source: https://github.com/reduxjs/redux-toolkit/issues/2068#issuecomment-1130796500
|
|
115
|
-
// TODO: remove once we use `redux-toolkit` v2
|
|
116
|
-
export const rootReducer: Reducer<StateFromReducersMapObject<ReducersMapObject>> =
|
|
117
|
-
combineReducers(reducers)
|