-
Notifications
You must be signed in to change notification settings - Fork 10
/
Members.tsx
143 lines (125 loc) · 3.44 KB
/
Members.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import * as React from "react";
import { Observable } from "rxjs";
import { IMemberQueryOptions as FilterOptions } from "@daostack/arc.js";
import {
Arc as Protocol,
ArcConfig as ProtocolConfig,
DAO,
DAOEntity,
InferredMember as Component,
MemberEntity as Entity,
MemberData as Data,
CProps,
ComponentList,
ComponentListLogs,
ComponentListProps,
createFilterFromScope,
} from "../";
import { CreateContextFeed } from "../runtime/ContextFeed";
type Scopes = "DAO";
const scopeProps: Record<Scopes, string> = {
DAO: "dao",
};
interface RequiredProps extends ComponentListProps<Entity, FilterOptions> {
from?: Scopes;
}
interface InferredProps extends RequiredProps {
config: ProtocolConfig;
dao?: string;
}
class InferredMembers extends ComponentList<InferredProps, Component> {
createObservableEntities(): Observable<Entity[]> {
const { config, from, filter } = this.props;
if (!config) {
throw Error(
"Arc Config Missing: Please provide this field as a prop, or use the inference component."
);
}
const f = createFilterFromScope(filter, from, scopeProps, this.props);
return Entity.search(config.connection, f);
}
renderComponent(
entity: Entity,
children: any,
index: number
): React.ComponentElement<CProps<Component>, any> {
const { config } = this.props;
// TODO: support creating Components with just an Entity, it makes no sense to recreate the Member entity here...
return (
<Component
key={`${entity.id}_${index}`}
address={entity.coreState!.address}
dao={entity.coreState!.dao.entity}
config={config}
entity={entity}
>
{children}
</Component>
);
}
public static get Entities() {
return CreateContextFeed(
this.EntitiesContext.Consumer,
this.LogsContext.Consumer,
"Members"
);
}
public static get Logs() {
return CreateContextFeed(
this.LogsContext.Consumer,
this.LogsContext.Consumer,
"Members"
);
}
protected static EntitiesContext = React.createContext<Entity[] | undefined>(
undefined
);
protected static LogsContext = React.createContext<
ComponentListLogs | undefined
>(undefined);
}
class Members extends React.Component<RequiredProps> {
render() {
const { children, from, sort, filter } = this.props;
return (
<Protocol.Config>
{(config: ProtocolConfig) => {
switch (from) {
case "DAO":
return (
<DAO.Entity>
{(dao: DAOEntity) => (
<InferredMembers
dao={dao.id}
config={config}
sort={sort}
filter={filter}
>
{children}
</InferredMembers>
)}
</DAO.Entity>
);
default:
if (from) {
throw Error(`Unsupported scope: ${from}`);
}
return (
<InferredMembers config={config} sort={sort} filter={filter}>
{children}
</InferredMembers>
);
}
}}
</Protocol.Config>
);
}
public static get Entities() {
return InferredMembers.Entities;
}
public static get Logs() {
return InferredMembers.Logs;
}
}
export default Members;
export { Members, InferredMembers };