1
1
import React , { useState , useEffect } from 'react' ;
2
2
import { batch , useDispatch } from 'react-redux' ;
3
3
4
- import { DashLayoutPath } from '../types/component' ;
4
+ import { DashComponent , DashLayoutPath } from '../types/component' ;
5
5
import DashWrapper from './DashWrapper' ;
6
6
import {
7
7
addComponentToLayout ,
@@ -11,21 +11,14 @@ import {
11
11
} from '../actions' ;
12
12
13
13
type Props = {
14
+ component : DashComponent ;
14
15
componentPath : DashLayoutPath ;
15
- componentType : string ;
16
- componentNamespace : string ;
17
- [ k : string ] : any ;
18
16
} ;
19
17
20
18
/**
21
19
* For rendering components that are out of the regular layout tree.
22
20
*/
23
- function ExternalWrapper ( {
24
- componentType,
25
- componentNamespace,
26
- componentPath,
27
- ...props
28
- } : Props ) {
21
+ function ExternalWrapper ( { component, componentPath} : Props ) {
29
22
const dispatch : any = useDispatch ( ) ;
30
23
const [ inserted , setInserted ] = useState ( false ) ;
31
24
@@ -34,11 +27,7 @@ function ExternalWrapper({
34
27
// The props will come from the parent so they can be updated.
35
28
dispatch (
36
29
addComponentToLayout ( {
37
- component : {
38
- type : componentType ,
39
- namespace : componentNamespace ,
40
- props : props
41
- } ,
30
+ component,
42
31
componentPath
43
32
} )
44
33
) ;
@@ -50,12 +39,19 @@ function ExternalWrapper({
50
39
51
40
useEffect ( ( ) => {
52
41
batch ( ( ) => {
53
- dispatch ( updateProps ( { itempath : componentPath , props} ) ) ;
54
- if ( props . id ) {
55
- dispatch ( notifyObservers ( { id : props . id , props} ) ) ;
42
+ dispatch (
43
+ updateProps ( { itempath : componentPath , props : component . props } )
44
+ ) ;
45
+ if ( component . props . id ) {
46
+ dispatch (
47
+ notifyObservers ( {
48
+ id : component . props . id ,
49
+ props : component . props
50
+ } )
51
+ ) ;
56
52
}
57
53
} ) ;
58
- } , [ props ] ) ;
54
+ } , [ component . props ] ) ;
59
55
60
56
if ( ! inserted ) {
61
57
return null ;
0 commit comments