|
| 1 | +import React, { ReactNode } from "react"; |
| 2 | +import { ServiceFactory } from "../../factories/serviceFactory"; |
| 3 | +import { AuthService } from "../../services/authService"; |
| 4 | +import AsyncComponent from "../components/layout/AsyncComponent"; |
| 5 | +import TabPanel from "../components/layout/TabPanel"; |
| 6 | +import Participation from "../components/plugins/Participation"; |
| 7 | +import Spammer from "../components/plugins/Spammer"; |
| 8 | +import "./Plugins.scss"; |
| 9 | +import { PluginsState } from "./PluginsState"; |
| 10 | + |
| 11 | +/** |
| 12 | + * Plugins panel. |
| 13 | + */ |
| 14 | +class Plugins extends AsyncComponent<unknown, PluginsState> { |
| 15 | + /** |
| 16 | + * The auth service. |
| 17 | + */ |
| 18 | + private readonly _authService: AuthService; |
| 19 | + |
| 20 | + /** |
| 21 | + * Create a new instance of Plugins. |
| 22 | + * @param props The props. |
| 23 | + */ |
| 24 | + constructor(props: unknown) { |
| 25 | + super(props); |
| 26 | + |
| 27 | + this._authService = ServiceFactory.get<AuthService>("auth"); |
| 28 | + |
| 29 | + this.state = { |
| 30 | + plugins: [] |
| 31 | + }; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * The component did mount. |
| 36 | + */ |
| 37 | + public async componentDidMount(): Promise<void> { |
| 38 | + super.componentDidMount(); |
| 39 | + |
| 40 | + const plugins = []; |
| 41 | + |
| 42 | + if (this._authService.isLoggedIn()) { |
| 43 | + const pluginDetailsSpammer = Spammer.pluginDetails(); |
| 44 | + if (pluginDetailsSpammer) { |
| 45 | + plugins.push(pluginDetailsSpammer); |
| 46 | + } |
| 47 | + const pluginDetailsParticipation = Participation.pluginDetails(); |
| 48 | + if (pluginDetailsParticipation) { |
| 49 | + plugins.push(pluginDetailsParticipation); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + if (plugins.length > 0) { |
| 54 | + this.setState({ |
| 55 | + activeTab: plugins[0].title |
| 56 | + }); |
| 57 | + } |
| 58 | + |
| 59 | + this.setState({ |
| 60 | + plugins |
| 61 | + }); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Render the component. |
| 66 | + * @returns The node to render. |
| 67 | + */ |
| 68 | + public render(): ReactNode { |
| 69 | + return ( |
| 70 | + <div className="plugins"> |
| 71 | + <div className="content"> |
| 72 | + {this.state.plugins.length === 0 && ( |
| 73 | + <p className="margin-t-s"> |
| 74 | + No plugins enabled which are supported by the dashboard.<br /> |
| 75 | + More information about managing plugins can be found on the |
| 76 | + {" "} |
| 77 | + <a |
| 78 | + target="_blank" |
| 79 | + rel="noreferrer" |
| 80 | + href="https://wiki.iota.org/hornet/post_installation/managing_a_node#plugins" |
| 81 | + > |
| 82 | + Hornet Developer Documentation. |
| 83 | + </a> |
| 84 | + </p> |
| 85 | + )} |
| 86 | + <TabPanel |
| 87 | + tabs={this.state.plugins.map(p => p.title)} |
| 88 | + activeTab={this.state.activeTab ? this.state.activeTab : ""} |
| 89 | + onTabChanged={activeTab => { |
| 90 | + this.setState({ |
| 91 | + activeTab |
| 92 | + }); |
| 93 | + }} |
| 94 | + > |
| 95 | + {this.state.plugins.map((p, idx) => ( |
| 96 | + <div data-label={p.title} key={idx}> |
| 97 | + {p.settings} |
| 98 | + </div> |
| 99 | + ))} |
| 100 | + |
| 101 | + </TabPanel> |
| 102 | + </div> |
| 103 | + </div > |
| 104 | + ); |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +export default Plugins; |
0 commit comments