1- import * as React from 'react' ;
1+ import React , { createRef } from 'react' ;
22import { connect } from 'react-redux' ;
3- import { RecoilRoot } from 'recoil' ;
4- import { ApolloClient , ApolloLink , ApolloProvider } from '@apollo/client' ;
3+ import { ApolloClient , ApolloLink } from '@apollo/client' ;
54import { createUploadLink } from 'apollo-upload-client' ;
6- import { $get , $transform } from 'plow-js' ;
75
86// Neos dependencies are provided by the UI
97// @ts -ignore
108import { neos } from '@neos-project/neos-ui-decorators' ;
119// @ts -ignore
1210import { actions } from '@neos-project/neos-ui-redux-store' ;
1311
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' ;
3412import NewAssetUpload from './NewAssetUpload' ;
3513
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+
3619let apolloClient = null ;
3720
3821interface AssetUploadScreenProps {
3922 i18nRegistry : I18nRegistry ;
40- frontendConfiguration : {
41- queryAssetUsage : boolean ;
42- } ;
23+ frontendConfiguration : FeatureFlags ;
4324 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'
4526 onComplete : ( result : { object : { __identity : string } } ) => void ;
4627 isLeftSideBarHidden : boolean ;
4728 isNodeCreationDialogOpen : boolean ;
@@ -55,23 +36,22 @@ interface AssetUploadScreenState {
5536 initialNodeCreationDialogOpenState : boolean ;
5637}
5738
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- } ) )
7239export class AssetUploadScreen extends React . PureComponent < AssetUploadScreenProps , AssetUploadScreenState > {
40+ notificationHandler : NeosNotification ;
41+
7342 constructor ( props ) {
7443 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+ } ;
7555 }
7656
7757 getConfig ( ) {
@@ -90,22 +70,17 @@ export class AssetUploadScreen extends React.PureComponent<AssetUploadScreenProp
9070 if ( ! apolloClient ) {
9171 const { endpoints } = this . getConfig ( ) ;
9272 const cache = CacheFactory . createCache ( this . props . frontendConfiguration as FeatureFlags ) ;
93- PersistentStateManager . restoreLocalState ( cache , this . props . constraints ) ;
9473
9574 apolloClient = new ApolloClient ( {
9675 cache,
9776 link : ApolloLink . from ( [
98- ApolloErrorHandler ,
77+ createErrorHandler ( this . notificationHandler ) ,
9978 createUploadLink ( {
10079 uri : endpoints . graphql ,
10180 credentials : 'same-origin' ,
10281 } ) ,
10382 ] ) ,
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 ] ,
10984 } ) ;
11085 }
11186 return apolloClient ;
@@ -121,45 +96,58 @@ export class AssetUploadScreen extends React.PureComponent<AssetUploadScreenProp
12196 return this . props . i18nRegistry . translate ( id , fallback , params , packageKey , sourceName ) ;
12297 } ;
12398
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+
124112 render ( ) {
125- const { addFlashMessage, onComplete, constraints, type } = this . props ;
126- const client = this . getApolloClient ( ) ;
113+ const { onComplete } = this . props ;
127114 const { dummyImage } = this . getConfig ( ) ;
128115 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 ;
140117
141118 return (
142119 < 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 >
162135 </ div >
163136 ) ;
164137 }
165138}
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