Fixed loading local plugin, search input

pull/1344/head
ioedeveloper 3 years ago
parent d161d09c7b
commit fe94df66f0
  1. 3
      apps/remix-ide-e2e/src/tests/pluginManager.spec.ts
  2. 51
      apps/remix-ide/src/app/components/plugin-manager-component.js
  3. 11
      libs/remix-ui/plugin-manager/src/lib/components/LocalPluginForm.tsx
  4. 4
      libs/remix-ui/plugin-manager/src/types.d.ts

@ -37,7 +37,8 @@ module.exports = {
.waitForElementVisible('*[data-id="pluginManagerComponentActivateButtonZoKrates"]') .waitForElementVisible('*[data-id="pluginManagerComponentActivateButtonZoKrates"]')
.clearValue('*[data-id="pluginManagerComponentSearchInput"]') .clearValue('*[data-id="pluginManagerComponentSearchInput"]')
.click('*[data-id="pluginManagerComponentSearchInput"]') .click('*[data-id="pluginManagerComponentSearchInput"]')
.keys(browser.Keys.ENTER) .keys(browser.Keys.SPACE)
.keys(browser.Keys.BACK_SPACE)
}, },
'Should activate plugins': function (browser: NightwatchBrowser) { 'Should activate plugins': function (browser: NightwatchBrowser) {

@ -13,7 +13,7 @@ import * as packageJson from '../../../../../package.json'
const yo = require('yo-yo') const yo = require('yo-yo')
const csjs = require('csjs-inject') const csjs = require('csjs-inject')
const EventEmitter = require('events') const EventEmitter = require('events')
const LocalPlugin = require('./local-plugin') // eslint-disable-line // const LocalPlugin = require('./local-plugin') // eslint-disable-line
const addToolTip = require('../ui/tooltip') const addToolTip = require('../ui/tooltip')
const _paq = window._paq = window._paq || [] const _paq = window._paq = window._paq || []
@ -37,7 +37,7 @@ class PluginManagerComponent extends ViewPlugin {
this.appManager = appManager this.appManager = appManager
this.engine = engine this.engine = engine
this.pluginManagerSettings = new PluginManagerSettings() this.pluginManagerSettings = new PluginManagerSettings()
this.localPlugin = new LocalPlugin() // this.localPlugin = new LocalPlugin()
this.htmlElement = document.createElement('div') this.htmlElement = document.createElement('div')
this.htmlElement.setAttribute('id', 'pluginManager') this.htmlElement.setAttribute('id', 'pluginManager')
this.views = { this.views = {
@ -86,13 +86,14 @@ class PluginManagerComponent extends ViewPlugin {
* @param {Profile} pluginName * @param {Profile} pluginName
* @returns {void} * @returns {void}
*/ */
async activateAndRegisterLocalPlugin (plugin, localPlugin) { async activateAndRegisterLocalPlugin (localPlugin) {
if (plugin) { if (localPlugin) {
debugger
this.engine.register(localPlugin) this.engine.register(localPlugin)
await this.appManager.activatePlugin(plugin) this.appManager.activatePlugin(localPlugin.profile.name)
this.getAndFilterPlugins()
// this.activateP(localPlugin.profile.name)
// localStorage.setItem('targetLocalPlugin', plugin.name) // localStorage.setItem('targetLocalPlugin', plugin.name)
// localStorage.setItem('plugins/local', JSON.stringify(properPlugin)) localStorage.setItem('plugins/local', JSON.stringify(localPlugin))
} }
} }
@ -120,8 +121,6 @@ class PluginManagerComponent extends ViewPlugin {
ReactDOM.render( ReactDOM.render(
<RemixUiPluginManager <RemixUiPluginManager
pluginComponent={this} pluginComponent={this}
activePlugins={this.activePlugins}
inactivePlugins={this.inactivePlugins}
/>, />,
document.getElementById('pluginManager')) document.getElementById('pluginManager'))
} }
@ -132,29 +131,29 @@ class PluginManagerComponent extends ViewPlugin {
/** /**
* Add a local plugin to the list of plugins * Add a local plugin to the list of plugins
*/ */
async openLocalPlugin () { // async openLocalPlugin () {
try { // try {
const profile = await this.localPlugin.open(this.appManager.getAll()) // const profile = await this.localPlugin.open(this.appManager.getAll())
if (!profile) return // if (!profile) return
if (this.appManager.getIds().includes(profile.name)) { // if (this.appManager.getIds().includes(profile.name)) {
throw new Error('This name has already been used') // throw new Error('This name has already been used')
} // }
const plugin = profile.type === 'iframe' ? new IframePlugin(profile) : new WebsocketPlugin(profile) // const plugin = profile.type === 'iframe' ? new IframePlugin(profile) : new WebsocketPlugin(profile)
this.engine.register(plugin) // this.engine.register(plugin)
await this.appManager.activatePlugin(plugin.name) // await this.appManager.activatePlugin(plugin.name)
} catch (err) { // } catch (err) {
// TODO : Use an alert to handle this error instead of a console.log // // TODO : Use an alert to handle this error instead of a console.log
console.log(`Cannot create Plugin : ${err.message}`) // console.log(`Cannot create Plugin : ${err.message}`)
addToolTip(`Cannot create Plugin : ${err.message}`) // addToolTip(`Cannot create Plugin : ${err.message}`)
} // }
} // }
render () { render () {
return this.htmlElement return this.htmlElement
} }
getAndFilterPlugins (filter) { getAndFilterPlugins (filter) {
this.filter = filter ? filter.toLowerCase() : this.filter this.filter = typeof filter === 'string' ? filter.toLowerCase() : this.filter
const isFiltered = (profile) => (profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(this.filter) const isFiltered = (profile) => (profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(this.filter)
const isNotRequired = (profile) => !this.appManager.isRequired(profile.name) const isNotRequired = (profile) => !this.appManager.isRequired(profile.name)

@ -14,10 +14,9 @@ interface LocalPluginFormProps {
} }
const handleModalOkClick = async (pluginManager: PluginManagerComponent, plugin: FormStateProps, setErrorMsg: React.Dispatch<React.SetStateAction<string>>) => { const handleModalOkClick = async (pluginManager: PluginManagerComponent, plugin: FormStateProps, setErrorMsg: React.Dispatch<React.SetStateAction<string>>) => {
debugger
try { try {
const profile = JSON.parse(localStorage.getItem('plugins/local')) const profile = JSON.parse(localStorage.getItem('plugins/local'))
if (profile.profile && Object.keys(profile).length > 0) { if (profile && profile.profile && Object.keys(profile).length > 0) {
if (pluginManager.appManager.getIds().includes(profile.profile.name)) { if (pluginManager.appManager.getIds().includes(profile.profile.name)) {
throw new Error('This name has already been used') throw new Error('This name has already been used')
} }
@ -25,7 +24,9 @@ const handleModalOkClick = async (pluginManager: PluginManagerComponent, plugin:
if (!plugin.location) throw new Error('Plugin should have a location') if (!plugin.location) throw new Error('Plugin should have a location')
if (!plugin.name) throw new Error('Plugin should have a name') if (!plugin.name) throw new Error('Plugin should have a name')
if (!plugin.url) throw new Error('Plugin should have an URL') if (!plugin.url) throw new Error('Plugin should have an URL')
plugin.methods = plugin.methods.split(',').filter(val => val)
const localPlugin = plugin.type === 'iframe' ? new IframePlugin(plugin) : new WebsocketPlugin(plugin) const localPlugin = plugin.type === 'iframe' ? new IframePlugin(plugin) : new WebsocketPlugin(plugin)
localPlugin.profile.hash = `local-${plugin.name}` localPlugin.profile.hash = `local-${plugin.name}`
// <-------------------------------- Plumbing starts here ---------------------------------------> // <-------------------------------- Plumbing starts here --------------------------------------->
const targetPlugin = { const targetPlugin = {
@ -38,9 +39,11 @@ const handleModalOkClick = async (pluginManager: PluginManagerComponent, plugin:
kind: (localPlugin.profile.kind !== undefined ? localPlugin.profile.kind : ''), kind: (localPlugin.profile.kind !== undefined ? localPlugin.profile.kind : ''),
methods: localPlugin.profile.methods, methods: localPlugin.profile.methods,
type: plugin.type, type: plugin.type,
location: plugin.location location: plugin.location,
icon: 'assets/img/localPlugin.webp'
} }
pluginManager.activateAndRegisterLocalPlugin(targetPlugin, localPlugin) localPlugin.profile = { ...localPlugin.profile, ...targetPlugin }
pluginManager.activateAndRegisterLocalPlugin(localPlugin)
} catch (error) { } catch (error) {
console.error(error) console.error(error)
// setErrorMsg(error.message) // setErrorMsg(error.message)

@ -105,7 +105,7 @@ export class PluginManagerComponent extends ViewPlugin extends Plugin implements
render(): HTMLDivElement render(): HTMLDivElement
getAndFilterPlugins: (filter?: string) => void getAndFilterPlugins: (filter?: string) => void
triggerEngineEventListener: () => void triggerEngineEventListener: () => void
activateAndRegisterLocalPlugin: (plugin: Profile, localPlugin: IframePlugin | WebsocketPlugin) => Promise<void> activateAndRegisterLocalPlugin: (localPlugin: IframePlugin | WebsocketPlugin) => Promise<void>
activeProfiles: string[] activeProfiles: string[]
_paq: any _paq: any
} }
@ -155,8 +155,6 @@ export interface PluginManagerContextProviderProps {
} }
export interface RemixUiPluginManagerProps { export interface RemixUiPluginManagerProps {
inactivePlugins: Profile[]
activePlugins: Profile[]
pluginComponent: PluginManagerComponent pluginComponent: PluginManagerComponent
} }
/** @class Reference loaders. /** @class Reference loaders.

Loading…
Cancel
Save