import * as React from "react"; import { Observable } from "rxjs"; import { IPluginQueryOptions as FilterOptions } from "@daostack/arc.js"; import { Arc as Protocol, ArcConfig as ProtocolConfig, InferredPlugin as Component, PluginEntity as Entity, PluginData as Data, DAO, DAOEntity, CProps, ComponentList, ComponentListLogs, ComponentListProps, createFilterFromScope, } from "../../"; import { CreateContextFeed } from "../../runtime/ContextFeed"; type Scopes = "DAO"; const scopeProps: Record = { DAO: "dao", }; interface RequiredProps extends ComponentListProps { from?: Scopes; } interface InferredProps extends RequiredProps { config: ProtocolConfig; dao?: string; } class InferredPlugins extends ComponentList { createObservableEntities(): Observable { 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, any> { const { config } = this.props; return ( {children} ); } public static get Entities() { return CreateContextFeed( this.EntitiesContext.Consumer, this.LogsContext.Consumer, "Plugins" ); } public static get Logs() { return CreateContextFeed( this.LogsContext.Consumer, this.LogsContext.Consumer, "Plugins" ); } protected static EntitiesContext = React.createContext( undefined ); protected static LogsContext = React.createContext< ComponentListLogs | undefined >(undefined); } class Plugins extends React.Component { render() { const { children, from, sort, filter } = this.props; return ( {(config: ProtocolConfig) => { switch (from) { case "DAO": return ( {(dao: DAOEntity) => ( {children} )} ); default: if (from) { throw Error(`Unsupported scope: ${from}`); } return ( {children} ); } }} ); } public static get Entities() { return InferredPlugins.Entities; } public static get Logs() { return InferredPlugins.Logs; } } export default Plugins; export { Plugins, InferredPlugins };