1
- import * as React from 'react' ;
1
+ import React , { createRef } from 'react' ;
2
2
import { connect } from 'react-redux' ;
3
- import { RecoilRoot } from 'recoil' ;
4
- import { ApolloClient , ApolloLink , ApolloProvider } from '@apollo/client' ;
3
+ import { ApolloClient , ApolloLink } from '@apollo/client' ;
5
4
import { createUploadLink } from 'apollo-upload-client' ;
6
- import { $get , $transform } from 'plow-js' ;
7
5
8
6
// Neos dependencies are provided by the UI
9
7
// @ts -ignore
10
8
import { neos } from '@neos-project/neos-ui-decorators' ;
11
9
// @ts -ignore
12
10
import { actions } from '@neos-project/neos-ui-redux-store' ;
13
11
14
- import {
15
- I18nRegistry ,
16
- IntlProvider ,
17
- MediaUiProvider ,
18
- MediaUiThemeProvider ,
19
- Notify ,
20
- NotifyProvider ,
21
- } from '@media-ui/core/src' ;
22
- import { FeatureFlags , SelectionConstraints } from '@media-ui/core/src/interfaces' ;
23
- import { AssetMediaType } from '@media-ui/core/src/state/selectedMediaTypeState' ;
24
- import { ApolloErrorHandler , CacheFactory , PersistentStateManager } from '@media-ui/media-module/src/core' ;
25
-
26
- import TYPE_DEFS_CORE from '@media-ui/core/schema.graphql' ;
27
- import TYPE_DEFS_CLIPBOARD from '@media-ui/feature-clipboard/schema.graphql' ;
28
- import TYPE_DEFS_ASSET_USAGE from '@media-ui/feature-asset-usage/schema.graphql' ;
29
-
30
- // GraphQL local resolvers
31
- import buildClipboardResolver from '@media-ui/feature-clipboard/src/resolvers/mutation' ;
32
- import buildModuleResolver from '@media-ui/media-module/src/resolvers/mutation' ;
33
- import { createRef } from 'react' ;
34
12
import NewAssetUpload from './NewAssetUpload' ;
35
13
14
+ import { MediaUiProvider , typeDefs as TYPE_DEFS_CORE } from '@media-ui/core' ;
15
+ import MediaApplicationWrapper from '@media-ui/core/src/components/MediaApplicationWrapper' ;
16
+ import { CacheFactory , createErrorHandler } from '@media-ui/media-module/src/core' ;
17
+ import { typeDefs as TYPE_DEFS_ASSET_USAGE } from '@media-ui/feature-asset-usage' ;
18
+
36
19
let apolloClient = null ;
37
20
38
21
interface AssetUploadScreenProps {
39
22
i18nRegistry : I18nRegistry ;
40
- frontendConfiguration : {
41
- queryAssetUsage : boolean ;
42
- } ;
23
+ frontendConfiguration : FeatureFlags ;
43
24
neos : Record < string , unknown > ;
44
- type : AssetMediaType | 'images' ; // The image editor sets the type to 'images'
25
+ type : AssetType | 'images' ; // The image editor sets the type to 'images'
45
26
onComplete : ( result : { object : { __identity : string } } ) => void ;
46
27
isLeftSideBarHidden : boolean ;
47
28
isNodeCreationDialogOpen : boolean ;
@@ -55,23 +36,22 @@ interface AssetUploadScreenState {
55
36
initialNodeCreationDialogOpenState : boolean ;
56
37
}
57
38
58
- @connect (
59
- $transform ( {
60
- isLeftSideBarHidden : $get ( 'ui.leftSideBar.isHidden' ) ,
61
- isNodeCreationDialogOpen : $get ( 'ui.nodeCreationDialog.isOpen' ) ,
62
- } ) ,
63
- {
64
- addFlashMessage : actions . UI . FlashMessages . add ,
65
- toggleSidebar : actions . UI . LeftSideBar . toggle ,
66
- }
67
- )
68
- @neos ( ( globalRegistry ) => ( {
69
- i18nRegistry : globalRegistry . get ( 'i18n' ) ,
70
- frontendConfiguration : globalRegistry . get ( 'frontendConfiguration' ) . get ( 'Flowpack.Media.Ui' ) ,
71
- } ) )
72
39
export class AssetUploadScreen extends React . PureComponent < AssetUploadScreenProps , AssetUploadScreenState > {
40
+ notificationHandler : NeosNotification ;
41
+
73
42
constructor ( props ) {
74
43
super ( props ) ;
44
+ this . state = {
45
+ initialLeftSideBarHiddenState : false ,
46
+ initialNodeCreationDialogOpenState : false ,
47
+ } ;
48
+ this . notificationHandler = {
49
+ info : ( message ) => props . addFlashMessage ( message , message , 'info' ) ,
50
+ ok : ( message ) => props . addFlashMessage ( message , message , 'success' ) ,
51
+ notice : ( message ) => props . addFlashMessage ( message , message , 'info' ) ,
52
+ warning : ( title , message = '' ) => props . addFlashMessage ( title , message , 'error' ) ,
53
+ error : ( title , message = '' ) => props . addFlashMessage ( title , message , 'error' ) ,
54
+ } ;
75
55
}
76
56
77
57
getConfig ( ) {
@@ -90,22 +70,17 @@ export class AssetUploadScreen extends React.PureComponent<AssetUploadScreenProp
90
70
if ( ! apolloClient ) {
91
71
const { endpoints } = this . getConfig ( ) ;
92
72
const cache = CacheFactory . createCache ( this . props . frontendConfiguration as FeatureFlags ) ;
93
- PersistentStateManager . restoreLocalState ( cache , this . props . constraints ) ;
94
73
95
74
apolloClient = new ApolloClient ( {
96
75
cache,
97
76
link : ApolloLink . from ( [
98
- ApolloErrorHandler ,
77
+ createErrorHandler ( this . notificationHandler ) ,
99
78
createUploadLink ( {
100
79
uri : endpoints . graphql ,
101
80
credentials : 'same-origin' ,
102
81
} ) ,
103
82
] ) ,
104
- typeDefs : [ TYPE_DEFS_CORE , TYPE_DEFS_CLIPBOARD , TYPE_DEFS_ASSET_USAGE ] ,
105
- resolvers : [
106
- buildModuleResolver ( PersistentStateManager . updateLocalState ) ,
107
- buildClipboardResolver ( PersistentStateManager . updateLocalState ) ,
108
- ] ,
83
+ typeDefs : [ TYPE_DEFS_CORE , TYPE_DEFS_ASSET_USAGE ] ,
109
84
} ) ;
110
85
}
111
86
return apolloClient ;
@@ -121,45 +96,58 @@ export class AssetUploadScreen extends React.PureComponent<AssetUploadScreenProp
121
96
return this . props . i18nRegistry . translate ( id , fallback , params , packageKey , sourceName ) ;
122
97
} ;
123
98
99
+ getInitialState = ( ) => {
100
+ const { frontendConfiguration, constraints, type } = this . props ;
101
+
102
+ return {
103
+ applicationContext : 'selection' as ApplicationContext ,
104
+ featureFlags : frontendConfiguration ,
105
+ constraints : {
106
+ ...( constraints || { } ) ,
107
+ assetType : type === 'images' ? 'image' : type ,
108
+ } ,
109
+ } ;
110
+ } ;
111
+
124
112
render ( ) {
125
- const { addFlashMessage, onComplete, constraints, type } = this . props ;
126
- const client = this . getApolloClient ( ) ;
113
+ const { onComplete } = this . props ;
127
114
const { dummyImage } = this . getConfig ( ) ;
128
115
const containerRef = createRef < HTMLDivElement > ( ) ;
129
-
130
- const featureFlags : FeatureFlags = this . props . frontendConfiguration as FeatureFlags ;
131
-
132
- // The Neos.UI Flashmessages only support the levels 'success', 'error' and 'info'
133
- const Notification : Notify = {
134
- info : ( message ) => addFlashMessage ( message , message , 'info' ) ,
135
- ok : ( message ) => addFlashMessage ( message , message , 'success' ) ,
136
- notice : ( message ) => addFlashMessage ( message , message , 'info' ) ,
137
- warning : ( title , message = '' ) => addFlashMessage ( title , message , 'error' ) ,
138
- error : ( title , message = '' ) => addFlashMessage ( title , message , 'error' ) ,
139
- } ;
116
+ const isInNodeCreationDialog = this . state . initialNodeCreationDialogOpenState ;
140
117
141
118
return (
142
119
< div style = { { width : '100%' , height : '100%' , padding : '2rem' } } >
143
- < IntlProvider translate = { this . translate } >
144
- < NotifyProvider notificationApi = { Notification } >
145
- < ApolloProvider client = { client } >
146
- < RecoilRoot >
147
- < MediaUiProvider
148
- dummyImage = { dummyImage }
149
- containerRef = { containerRef }
150
- featureFlags = { featureFlags }
151
- constraints = { constraints || { } }
152
- assetType = { type === 'images' ? 'image' : type }
153
- >
154
- < MediaUiThemeProvider >
155
- < NewAssetUpload onComplete = { onComplete } />
156
- </ MediaUiThemeProvider >
157
- </ MediaUiProvider >
158
- </ RecoilRoot >
159
- </ ApolloProvider >
160
- </ NotifyProvider >
161
- </ IntlProvider >
120
+ < MediaApplicationWrapper
121
+ client = { this . getApolloClient ( ) }
122
+ translate = { this . translate }
123
+ notificationApi = { this . notificationHandler }
124
+ initialState = { this . getInitialState ( ) }
125
+ >
126
+ < MediaUiProvider
127
+ dummyImage = { dummyImage }
128
+ selectionMode
129
+ isInNodeCreationDialog = { isInNodeCreationDialog }
130
+ containerRef = { containerRef }
131
+ >
132
+ < NewAssetUpload onComplete = { onComplete } />
133
+ </ MediaUiProvider >
134
+ </ MediaApplicationWrapper >
162
135
</ div >
163
136
) ;
164
137
}
165
138
}
139
+
140
+ const mapStateToProps = ( state : any ) => ( {
141
+ isLeftSideBarHidden : state . ui . leftSideBar . isHidden ,
142
+ isNodeCreationDialogOpen : state . ui . nodeCreationDialog . isOpen ,
143
+ } ) ;
144
+
145
+ const mapGlobalRegistryToProps = neos ( ( globalRegistry : any ) => ( {
146
+ i18nRegistry : globalRegistry . get ( 'i18n' ) ,
147
+ frontendConfiguration : globalRegistry . get ( 'frontendConfiguration' ) . get ( 'Flowpack.Media.Ui' ) ,
148
+ } ) ) ;
149
+
150
+ export default connect ( ( ) => ( { } ) , {
151
+ addFlashMessage : actions . UI . FlashMessages . add ,
152
+ toggleSidebar : actions . UI . LeftSideBar . toggle ,
153
+ } ) ( connect ( mapStateToProps ) ( mapGlobalRegistryToProps ( AssetUploadScreen ) ) ) ;
0 commit comments