diff --git a/apps/remix-ide/src/app/components/plugin-manager-component.js b/apps/remix-ide/src/app/components/plugin-manager-component.js index 799e841088..a37232e5f8 100644 --- a/apps/remix-ide/src/app/components/plugin-manager-component.js +++ b/apps/remix-ide/src/app/components/plugin-manager-component.js @@ -92,11 +92,12 @@ const profile = { class PluginManagerComponent extends ViewPlugin { constructor (appManager, engine) { super(profile) - // this.event = new EventEmitter() //already exists in engine so not needed here - // this.appManager = appManager - // this.engine = engine + // this.event = new EventEmitter() // already exists in engine so not needed here + this.appManager = appManager + this.engine = engine this.htmlElement = document.createElement('div') this.htmlElement.setAttribute('id', 'pluginManager') + this.props = {} // this.views = { // root: null, // items: {} @@ -106,6 +107,22 @@ class PluginManagerComponent extends ViewPlugin { // this.appManager.event.on('activate', () => { this.reRender() }) // this.appManager.event.on('deactivate', () => { this.reRender() }) // this.engine.event.on('onRegistration', () => { this.reRender() }) + // const { actives, inactives } = this.getAllPlugins() + } + + reactProps () { + return { + views: this.views, + filter: this.filter, + localPlugin: this.localPlugin, + isActive: this.isActive, + activatePlugin: this.activateP, + deactivePlugin: this.deactivateP, + openLocalPlugin: this.openLocalPlugin, + profile: this.profile + // actives: actives, + // inactives: inactives + } } onActivation () { @@ -113,22 +130,46 @@ class PluginManagerComponent extends ViewPlugin { } renderComponent () { - ReactDOM.render(, document.getElementById('pluginManager')) + // const props = this.reactProps() + ReactDOM.render( + // , + , + document.getElementById('pluginManager')) } - isActive (name) { - return this.appManager.actives.includes(name) - } + // isActive (name) { + // return this.appManager.actives.includes(name) + // } - activateP (name) { - this.appManager.activatePlugin(name) - _paq.push(['trackEvent', 'manager', 'activate', name]) - } + // activateP (name) { + // this.appManager.activatePlugin(name) + // _paq.push(['trackEvent', 'manager', 'activate', name]) + // } - deactivateP (name) { - this.call('manager', 'deactivatePlugin', name) - _paq.push(['trackEvent', 'manager', 'deactivate', name]) - } + // deactivateP (name) { + // this.call('manager', 'deactivatePlugin', name) + // _paq.push(['trackEvent', 'manager', 'deactivate', name]) + // } // renderItem (profile) { // const displayName = (profile.displayName) ? profile.displayName : profile.name @@ -189,47 +230,55 @@ class PluginManagerComponent extends ViewPlugin { /** * Add a local plugin to the list of plugins */ - async openLocalPlugin () { - try { - const profile = await this.localPlugin.open(this.appManager.getAll()) - if (!profile) return - if (this.appManager.getIds().includes(profile.name)) { - throw new Error('This name has already been used') - } - const plugin = profile.type === 'iframe' ? new IframePlugin(profile) : new WebsocketPlugin(profile) - this.engine.register(plugin) - await this.appManager.activatePlugin(plugin.name) - } catch (err) { - // TODO : Use an alert to handle this error instead of a console.log - console.log(`Cannot create Plugin : ${err.message}`) - addToolTip(`Cannot create Plugin : ${err.message}`) - } - } + // async openLocalPlugin () { + // try { + // const profile = await this.localPlugin.open(this.appManager.getAll()) + // if (!profile) return + // if (this.appManager.getIds().includes(profile.name)) { + // throw new Error('This name has already been used') + // } + // const plugin = profile.type === 'iframe' ? new IframePlugin(profile) : new WebsocketPlugin(profile) + // this.engine.register(plugin) + // await this.appManager.activatePlugin(plugin.name) + // } catch (err) { + // // TODO : Use an alert to handle this error instead of a console.log + // console.log(`Cannot create Plugin : ${err.message}`) + // addToolTip(`Cannot create Plugin : ${err.message}`) + // } + // } + + // filterHelper () { + // const isFiltered = (profile) => (profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(this.filter) + // const isNotRequired = (profile) => !this.appManager.isRequired(profile.name) + // const isNotDependent = (profile) => !this.appManager.isDependent(profile.name) + // const isNotHome = (profile) => profile.name !== 'home' + // const sortByName = (profileA, profileB) => { + // const nameA = ((profileA.displayName) ? profileA.displayName : profileA.name).toUpperCase() + // const nameB = ((profileB.displayName) ? profileB.displayName : profileB.name).toUpperCase() + // return (nameA < nameB) ? -1 : (nameA > nameB) ? 1 : 0 + // } + // return (isFiltered, isNotRequired, isNotDependent, isNotHome, sortByName) + // } + + // getAllPlugins () { + // // // Filter all active and inactive modules that are not required + // const [isFiltered, isNotRequired, isNotDependent, isNotHome, sortByName] = this.filterHelper() + // const { actives, inactives } = this.appManager.getAll() + // .filter(isFiltered) + // .filter(isNotRequired) + // .filter(isNotDependent) + // .filter(isNotHome) + // .sort(sortByName) + // .reduce(({ actives, inactives }, profile) => { + // return this.isActive(profile.name) + // ? { actives: [...actives, profile], inactives } + // : { inactives: [...inactives, profile], actives } + // }, { actives: [], inactives: [] }) + // return (actives, inactives) + // } render () { // Filtering helpers - const isFiltered = (profile) => (profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(this.filter) - const isNotRequired = (profile) => !this.appManager.isRequired(profile.name) - const isNotDependent = (profile) => !this.appManager.isDependent(profile.name) - const isNotHome = (profile) => profile.name !== 'home' - const sortByName = (profileA, profileB) => { - const nameA = ((profileA.displayName) ? profileA.displayName : profileA.name).toUpperCase() - const nameB = ((profileB.displayName) ? profileB.displayName : profileB.name).toUpperCase() - return (nameA < nameB) ? -1 : (nameA > nameB) ? 1 : 0 - } - - // // Filter all active and inactive modules that are not required - const { actives, inactives } = this.appManager.getAll() - .filter(isFiltered) - .filter(isNotRequired) - .filter(isNotDependent) - .filter(isNotHome) - .sort(sortByName) - .reduce(({ actives, inactives }, profile) => { - return this.isActive(profile.name) - ? { actives: [...actives, profile], inactives } - : { inactives: [...inactives, profile], actives } - }, { actives: [], inactives: [] }) // const activeTile = actives.length !== 0 // ? yo` @@ -275,7 +324,7 @@ class PluginManagerComponent extends ViewPlugin { return this.htmlElement } - // reRender () { --> no needed possibly + // reRender () { // if (this.views.root) { // yo.update(this.views.root, this.render()) // } diff --git a/libs/remix-ui/plugin-manager/src/lib/components/activeTile.tsx b/libs/remix-ui/plugin-manager/src/lib/components/activeTile.tsx index 7bb42ca5ad..8067a42a4e 100644 --- a/libs/remix-ui/plugin-manager/src/lib/components/activeTile.tsx +++ b/libs/remix-ui/plugin-manager/src/lib/components/activeTile.tsx @@ -1,21 +1,20 @@ -import React from 'react' -import { TileLabel } from '../../customTypes' +import React, { useContext } from 'react' +import { PluginManagerContext } from '../contexts/pluginmanagercontext' -interface ActiveTileProps { - inactivesCount?: number - activesCount?: number - tileLabel?: TileLabel +interface ModuleHeadingProps { + headingLabel: string } -function ActiveTile ({ inactivesCount, activesCount, tileLabel }: ActiveTileProps) { +function ModuleHeading ({ headingLabel }: ModuleHeadingProps) { + const { inactivesCount, activesCount } = useContext(PluginManagerContext) return ( ) } -export default ActiveTile +export default ModuleHeading diff --git a/libs/remix-ui/plugin-manager/src/lib/components/listGroupItem.tsx b/libs/remix-ui/plugin-manager/src/lib/components/listGroupItem.tsx index cc92302409..e767c2cb02 100644 --- a/libs/remix-ui/plugin-manager/src/lib/components/listGroupItem.tsx +++ b/libs/remix-ui/plugin-manager/src/lib/components/listGroupItem.tsx @@ -3,21 +3,23 @@ import { Profile } from '../../customTypes' import RenderItem from './renderItem' interface ListGroupItemProps { - activeProfiles: Profile[] - inactiveProfiles: Profile[] + activeProfiles?: Profile[] + inactiveProfiles?: Profile[] } -function ListGroupItem ({ activeProfiles, inactiveProfiles }: ListGroupItemProps) { +function ListGroupItem () { return (
- { activeProfiles.length > 0 + {/* { activeProfiles.length > 0 ? activeProfiles.map(profile => ( )) : inactiveProfiles.map(profile => ( )) - } + } */} + +
List Group Item Component
) } diff --git a/libs/remix-ui/plugin-manager/src/lib/components/pluginCard.tsx b/libs/remix-ui/plugin-manager/src/lib/components/pluginCard.tsx index da9bca617e..f5f5b62d47 100644 --- a/libs/remix-ui/plugin-manager/src/lib/components/pluginCard.tsx +++ b/libs/remix-ui/plugin-manager/src/lib/components/pluginCard.tsx @@ -1,4 +1,5 @@ -import React from 'react' +import React, { useContext } from 'react' +import { PluginManagerContext } from '../contexts/pluginmanagercontext' import '../remix-ui-plugin-manager.css' import Button from './button' interface PluginCardProps { @@ -10,32 +11,27 @@ interface PluginCardProps { profileDescription: string } -function PluginCard ({ - profileName, - displayName, - docLink, - versionWarning, - profileIcon, - profileDescription -}: PluginCardProps) { +// eslint-disable-next-line no-empty-pattern +function PluginCard () { + const { profile } = useContext(PluginManagerContext) return ( -
+
- {displayName} - {docLink} - {versionWarning} + {profile.displayName} + {profile.docLink} + {profile.versionWarning}
- profile icon - {profileDescription} + profile icon + {profile.description}
) diff --git a/libs/remix-ui/plugin-manager/src/lib/components/renderItem.tsx b/libs/remix-ui/plugin-manager/src/lib/components/renderItem.tsx index f976357f24..efe554a140 100644 --- a/libs/remix-ui/plugin-manager/src/lib/components/renderItem.tsx +++ b/libs/remix-ui/plugin-manager/src/lib/components/renderItem.tsx @@ -1,52 +1,55 @@ -import React, { useEffect, useState } from 'react' +import React, { useContext } from 'react' import { Profile } from '../../customTypes' +import { PluginManagerContext } from '../contexts/pluginmanagercontext' import PluginCard from './pluginCard' interface RenderItemProps { profile: Profile } -function RenderItem ({ profile }: RenderItemProps) { - const [displayName, setDisplayName] = useState('') - const [docLink, setDocLink] = useState() - const [versionWarning, setVersionWarning] = useState, HTMLElement>>() +function RenderItem () { + const { profile } = useContext(PluginManagerContext) + // const [displayName, setDisplayName] = useState('') + // const [docLink, setDocLink] = useState() + // const [versionWarning, setVersionWarning] = useState, HTMLElement>>() - useEffect(() => { - const checkPluginVersion = (version: string) => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let versionWarning: React.DetailedHTMLProps, HTMLElement> - if (version && version.match(/\b(\w*alpha\w*)\b/g)) { - versionWarning = alpha - } - // Beta - if (version && version.match(/\b(\w*beta\w*)\b/g)) { - versionWarning = beta - } - return versionWarning - } + // useEffect(() => { + // const checkPluginVersion = (version: string) => { + // // eslint-disable-next-line @typescript-eslint/no-unused-vars + // let versionWarning: React.DetailedHTMLProps, HTMLElement> + // if (version && version.match(/\b(\w*alpha\w*)\b/g)) { + // versionWarning = alpha + // } + // // Beta + // if (version && version.match(/\b(\w*beta\w*)\b/g)) { + // versionWarning = beta + // } + // return versionWarning + // } - setDisplayName((profile.displayName) ? profile.displayName : profile.name) - setDocLink( - profile.documentation ? ( - - - - ) : '') - setVersionWarning(checkPluginVersion(profile.version)) - }, [profile.displayName, profile.documentation, profile.name, profile.version, versionWarning]) + // setDisplayName((profile.displayName) ? profile.displayName : profile.name) + // setDocLink( + // profile.documentation ? ( + // + // + // + // ) : '') + // setVersionWarning(checkPluginVersion(profile.version)) + // }, [profile.displayName, profile.documentation, profile.name, profile.version, versionWarning]) + console.log('Profile object from render item component', profile) return ( ) } diff --git a/libs/remix-ui/plugin-manager/src/lib/components/rootView.tsx b/libs/remix-ui/plugin-manager/src/lib/components/rootView.tsx index 28c822d1df..9cda87e04e 100644 --- a/libs/remix-ui/plugin-manager/src/lib/components/rootView.tsx +++ b/libs/remix-ui/plugin-manager/src/lib/components/rootView.tsx @@ -1,5 +1,4 @@ -import React, { useContext } from 'react' -import { PluginManagerContext } from '../remix-ui-plugin-manager' +import React from 'react' import ActiveTile from './activeTile' import ListGroupItem from './listGroupItem' @@ -8,23 +7,35 @@ interface RootViewProps { } function RootView ({ localPluginButtonText }: RootViewProps) { - const { actives, inactives, tileLabel } = useContext(PluginManagerContext) + // const { actives, inactives, tileLabel } = useContext(PluginManagerContext) return ( + //
+ //
+ // + // + //
+ //
+ // + // + //
+ //
+
- +
- - + + +
) diff --git a/libs/remix-ui/plugin-manager/src/lib/contexts/pluginmanagercontext.tsx b/libs/remix-ui/plugin-manager/src/lib/contexts/pluginmanagercontext.tsx new file mode 100644 index 0000000000..4e853458c8 --- /dev/null +++ b/libs/remix-ui/plugin-manager/src/lib/contexts/pluginmanagercontext.tsx @@ -0,0 +1,14 @@ +import React, { createContext } from 'react' +import { PluginManagerContextProviderProps } from '../../types' + +export const PluginManagerContext = createContext>({}) + +function PluginManagerContextProvider ({ children, props }) { + return ( + + {children} + + ) +} + +export default PluginManagerContextProvider diff --git a/libs/remix-ui/plugin-manager/src/lib/remix-ui-plugin-manager.tsx b/libs/remix-ui/plugin-manager/src/lib/remix-ui-plugin-manager.tsx index 9c7fd7be6a..cd0ad8e4ee 100644 --- a/libs/remix-ui/plugin-manager/src/lib/remix-ui-plugin-manager.tsx +++ b/libs/remix-ui/plugin-manager/src/lib/remix-ui-plugin-manager.tsx @@ -1,91 +1,20 @@ -import React, { createContext, useEffect, useState } from 'react' -import { Profile, TileLabel } from '../customTypes' -import { RemixAppManager, RemixEngine, _Paq } from '../types' +import React from 'react' +import { RemixUiPluginManagerProps } from '../types' import RootView from './components/rootView' +import PluginManagerContextProvider from './contexts/pluginmanagercontext' import './remix-ui-plugin-manager.css' -/* eslint-disable-next-line */ -export interface PluginManagerContextProviderProps { - appManager: RemixAppManager - engine: RemixEngine - _paq: _Paq - filter: string - actives: Profile[] - inactives: Profile[] - activatePlugin: (name: string) => void - deActivatePlugin: (name: string) => void - isActive: (name: string) => any - openLocalPlugin: () => Promise - filterPlugins: () => void - profile: Profile - tileLabel: TileLabel -} - -export interface RemixUiPluginManagerProps { - appManager: RemixAppManager - engine: RemixEngine - _paq: _Paq - filter: string - actives: Profile[] - inactives: Profile[] - activatePlugin: (name: string) => void - deActivatePlugin: (name: string) => void - isActive: (name: string) => any - openLocalPlugin: () => Promise - filterPlugins: () => void - profile: Profile - tileLabel: TileLabel -} - -export const PluginManagerContext = createContext>({}) - -function PluginManagerContextProvider ({ children, props }) { - const [isFiltered] = useState((profile) => - (profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(props.filter)) - const [isNotRequired, setIsNotRequired] = useState() - const [isNotDependent, setIsNotDependent] = useState() - const [isNotHome, setIsNotHome] = useState() - const [sortByName, setSortByName] = useState() - const { actives, inactives } = props.appManager.getAll() - .filter(isFiltered) - .filter(isNotRequired) - .filter(isNotDependent) - .filter(isNotHome) - .sort(sortByName) - .reduce(({ actives, inactives }, profile) => { - return props.isActive(profile.name) - ? { actives: [...actives, profile], inactives } - : { inactives: [...inactives, profile], actives } - }, { actives: [], inactives: [] }) - props.actives = actives - props.inactives = inactives - useEffect(() => { - const notRequired = (profile: Profile) => !props.appManager.isRequired(profile.name) - const notDependent = (profile) => !props.appManager.isDependent(profile.name) - const notHome = (profile) => profile.name !== 'home' - const sortedByName = (profileA: Profile, profileB: Profile) => { - const nameA = ((profileA.displayName) ? profileA.displayName : profileA.name).toUpperCase() - const nameB = ((profileB.displayName) ? profileB.displayName : profileB.name).toUpperCase() - return (nameA < nameB) ? -1 : (nameA > nameB) ? 1 : 0 - } - setIsNotRequired(notRequired(props.profile)) - setIsNotDependent(notDependent(notDependent)) - setIsNotHome(notHome) - setSortByName(sortedByName) - }, [props.appManager, props.profile]) - return ( - - {children} - - ) -} - export const RemixUiPluginManager = (props: RemixUiPluginManagerProps) => { + console.log('current state of appmanager', props.appManager) return ( - - + // + // + // + +

Remix UI Plugin Manager React

+
) } diff --git a/libs/remix-ui/plugin-manager/src/types.d.ts b/libs/remix-ui/plugin-manager/src/types.d.ts index 4167ddc17b..0ee4d6ca44 100644 --- a/libs/remix-ui/plugin-manager/src/types.d.ts +++ b/libs/remix-ui/plugin-manager/src/types.d.ts @@ -60,6 +60,42 @@ export class RemixAppManager extends PluginManager { isRequired(name: any): any; registeredPlugins(): Promise; } + +export interface PluginManagerContextProviderProps { + appManager: RemixAppManager + engine: RemixEngine + _paq: _Paq + filter: string + actives: Profile[] + inactives: Profile[] + activatePlugin: (name: string) => void + deActivatePlugin: (name: string) => void + isActive: (name: string) => any + openLocalPlugin: () => Promise + filterPlugins: () => void + profile: Profile + inactivesCount: number + activesCount: number + headingLabel: string +} + +export interface RemixUiPluginManagerProps { + appManager: RemixAppManager + engine: RemixEngine + _paq: _Paq + filter: string + actives: Profile[] + inactives: Profile[] + activatePlugin: (name: string) => void + deActivatePlugin: (name: string) => void + isActive: (name: string) => any + openLocalPlugin: () => Promise + filterPlugins: () => void + profile: Profile + inactivesCount: number + activesCount: number + headingLabel: string +} /** @class Reference loaders. * A loader is a get,set based object which load a workspace from a defined sources. * (localStorage, queryParams)