1 | import * as React from 'react';
|
2 |
|
3 | import Types from '../types';
|
4 | import { IComponent } from "../types/component";
|
5 | import { IInfrastructure } from "../types";
|
6 | import middleware, {isMiddleware} from "../middleware/middleware-component";
|
7 | import {getChildrenArray} from "../index";
|
8 | import { listMiddleware, uploadMiddleware } from './storage-libs';
|
9 |
|
10 | export const STORAGE_INSTANCE_TYPE = "StorageComponent";
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export interface IStorageArgs {
|
17 | |
18 |
|
19 |
|
20 | id: string,
|
21 |
|
22 | |
23 |
|
24 |
|
25 |
|
26 | path: string
|
27 |
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | export interface IStorageProps {
|
34 |
|
35 | |
36 |
|
37 |
|
38 | middlewares: Array<any>,
|
39 |
|
40 |
|
41 | |
42 |
|
43 |
|
44 | setDataLayerId: (dataLayerId: string) => void,
|
45 |
|
46 | |
47 |
|
48 |
|
49 |
|
50 | dataLayerId?: any,
|
51 |
|
52 | |
53 |
|
54 |
|
55 | method: string,
|
56 |
|
57 | }
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | export function isStorage(component) {
|
66 | return component !== undefined &&
|
67 | component.instanceType === STORAGE_INSTANCE_TYPE
|
68 | }
|
69 |
|
70 |
|
71 |
|
72 | export default (props: IStorageArgs | any) => {
|
73 |
|
74 | const componentProps: IInfrastructure & IComponent = {
|
75 | infrastructureType: Types.INFRASTRUCTURE_TYPE_COMPONENT,
|
76 | instanceType: STORAGE_INSTANCE_TYPE,
|
77 | instanceId: props.id,
|
78 |
|
79 | insulatesChildComponent: (child) => {
|
80 |
|
81 | return isMiddleware(child)
|
82 | }
|
83 | };
|
84 |
|
85 | const storageProps: IStorageProps = {
|
86 | middlewares: getChildrenArray(props.children)
|
87 | .filter(child => isMiddleware(child))
|
88 | .concat([
|
89 | listMiddleware(props.id),
|
90 | uploadMiddleware(props.id)
|
91 | ]),
|
92 |
|
93 | setDataLayerId: (dataLayerId: string) => {
|
94 | props.dataLayerId = dataLayerId;
|
95 | },
|
96 |
|
97 | method: "POST"
|
98 | }
|
99 |
|
100 | return Object.assign(props, componentProps, storageProps);
|
101 |
|
102 |
|
103 | }; |
\ | No newline at end of file |