From c767a1d1a2eb1a7e48f2deeeb49305e477215448 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Sun, 17 Oct 2021 00:24:34 +0200 Subject: [PATCH] refactor plugin --- .../src/local-plugin/src/app/Client.ts | 9 -- .../src/local-plugin/src/app/app.tsx | 122 ++++++++++-------- .../src/local-plugin/src/app/logger.tsx | 12 +- apps/remix-ide-e2e/src/tests/plugin_api.ts | 31 +++-- 4 files changed, 93 insertions(+), 81 deletions(-) diff --git a/apps/remix-ide-e2e/src/local-plugin/src/app/Client.ts b/apps/remix-ide-e2e/src/local-plugin/src/app/Client.ts index dea17d9292..7d03a4f8e0 100644 --- a/apps/remix-ide-e2e/src/local-plugin/src/app/Client.ts +++ b/apps/remix-ide-e2e/src/local-plugin/src/app/Client.ts @@ -66,15 +66,6 @@ export class WorkSpacePlugin extends PluginClient { console.log("comp fin",x) }) */ - await this.setCallBacks() - - this.on( - 'solidity', - 'compilationFinished', - function (target, source, version, data) { - console.log('compile finished', target, source, version, data) - } - ) }) .catch(async (e) => { console.log('ERROR CONNECTING', e) diff --git a/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx b/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx index b26a5297b2..38ee187dab 100644 --- a/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx +++ b/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx @@ -1,83 +1,99 @@ -import React, { useState } from 'react' +import React, { useEffect, useRef, useState } from 'react' import { WorkSpacePlugin } from './Client' import { Logger } from './logger' +import { useBehaviorSubject } from './usesubscribe/index' +import { filePanelProfile } from '@remixproject/plugin-api/lib/file-system/file-panel/profile' +import { filSystemProfile } from '@remixproject/plugin-api/lib/file-system/file-manager/profile' +import { dGitProfile } from '@remixproject/plugin-api/lib/dgit/profile' +import { editorProfile } from '@remixproject/plugin-api/lib/editor/profile' +import { settingsProfile } from '@remixproject/plugin-api/lib/settings/profile' +import { networkProfile } from '@remixproject/plugin-api/lib/network/profile' +import { terminalProfile } from '@remixproject/plugin-api/lib/terminal/profile' +import { udappProfile } from '@remixproject/plugin-api/lib/udapp' +import { compilerProfile } from '@remixproject/plugin-api/lib/compiler' +import { contentImportProfile } from '@remixproject/plugin-api/lib/content-import' +import { unitTestProfile } from '@remixproject/plugin-api/lib/unit-testing' +import { windowProfile } from '@remixproject/plugin-api/lib/window' +import { pluginManagerProfile } from '@remixproject/plugin-api/lib/plugin-manager' +import { IFileSystem } from '@remixproject/plugin-api' + +import { Profile } from '@remixproject/plugin-utils' export const client = new WorkSpacePlugin() function App () { const [payload, setPayload] = useState('') - const [result, setResult] = useState() const [append, setAppend] = useState(false) + const [log, setLog] = useState() + const [profiles, setProfiles] = useState([pluginManagerProfile, filePanelProfile, filSystemProfile, dGitProfile, networkProfile, settingsProfile, editorProfile, terminalProfile, compilerProfile, udappProfile, contentImportProfile, unitTestProfile, windowProfile]) const handleChange = ({ target }: any) => { setPayload(target.value) } + useEffect(() => { + client.onload(async () => { + const customProfiles = ['solidity'] + + for (const name of customProfiles) { + const p = await client.call('manager', 'getProfile', name) + setProfiles(profiles => [p, ...profiles]) + } + + profiles.map((profile: Profile) => { + if (profile.events) { + profile.events.map((event: string) => { + console.log(profile.name, event) + client.on(profile.name as any, event, (...args:any) => { + console.log(event, args) + }) + }) + } + }) + }) + }, []) + const setAppendChange = ({ target }: any) => { console.log('append', target.checked) setAppend(target.checked) } + const clientMethod = async (profile: Profile, method: string) => { + try { + let ob: any = null + try { + ob = JSON.parse(payload) + } catch (e) {} + const send = ob || [payload] + const result = await client.call(profile.name as any, method, ...send) + setLog(result) + } catch (e) { + setLog(e.message) + } + } + return ( -
-
v5
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
+
PLUGIN API TESTER
+ + + + {profiles.map((profile: Profile) => { + const methods = profile.methods.map((method: string) => { + return + }) + return


{methods}
+ })} +
) } diff --git a/apps/remix-ide-e2e/src/local-plugin/src/app/logger.tsx b/apps/remix-ide-e2e/src/local-plugin/src/app/logger.tsx index 91712ecf82..f26812206c 100644 --- a/apps/remix-ide-e2e/src/local-plugin/src/app/logger.tsx +++ b/apps/remix-ide-e2e/src/local-plugin/src/app/logger.tsx @@ -1,21 +1,21 @@ import React, { useEffect, useState } from 'react' -import { useBehaviorSubject } from './usesubscribe/index' + import { client } from './app' interface loggerProps { - append: boolean + append: boolean, + log: any } export const Logger: React.FC = (props) => { - const log = useBehaviorSubject(client.feedback) const [value, setValue] = useState('') useEffect(() => { setValue(value => { - const addValue = typeof log === 'string' ? log : JSON.stringify(log) + const addValue = typeof props.log === 'string' ? props.log : JSON.stringify(props.log) return props.append ? `${value} ${addValue}` : addValue }) - }, [log]) + }, [props]) - return (
{value}
) + return (
{value}
) } diff --git a/apps/remix-ide-e2e/src/tests/plugin_api.ts b/apps/remix-ide-e2e/src/tests/plugin_api.ts index 8ade0fec9b..f12ed84eea 100644 --- a/apps/remix-ide-e2e/src/tests/plugin_api.ts +++ b/apps/remix-ide-e2e/src/tests/plugin_api.ts @@ -18,8 +18,13 @@ const getBrowserLogs = function (browser: NightwatchBrowser) { console.log(logEntries) }) } - -const assertLog = function (browser: NightwatchBrowser, buttonText: string, msg: any, payload: string) { +/* +* PLUGINACTION +* buttonText: which button to click +* msg: what to expect from the log +* payload: extra param for the call +*/ +const pluginAction = function (browser: NightwatchBrowser, buttonText: string, msg: any, payload: string) { if (payload) { browser.clearValue('//*[@id="payload"]').setValue('//*[@id="payload"]', payload).pause(1000) } @@ -82,22 +87,22 @@ module.exports = { }, 'Should get current workspace': function (browser: NightwatchBrowser) { - assertLog(browser, 'get workspace', { name: 'default_workspace', isLocalhost: false, absolutePath: '.workspaces/default_workspace' }, null) + pluginAction(browser, 'get workspace', { name: 'default_workspace', isLocalhost: false, absolutePath: '.workspaces/default_workspace' }, null) }, 'Should get current files': function (browser: NightwatchBrowser) { - assertLog(browser, 'readdir', { contracts: { isDirectory: true }, scripts: { isDirectory: true }, tests: { isDirectory: true }, 'README.txt': { isDirectory: false } }, null) + pluginAction(browser, 'readdir', { contracts: { isDirectory: true }, scripts: { isDirectory: true }, tests: { isDirectory: true }, 'README.txt': { isDirectory: false } }, null) }, 'Should throw error on current file': function (browser: NightwatchBrowser) { - assertLog(browser, 'getcurrentfile', 'Error from IDE : Error: No such file or directory No file selected', null) + pluginAction(browser, 'getcurrentfile', 'Error from IDE : Error: No such file or directory No file selected', null) }, 'Should open readme.txt': function (browser: NightwatchBrowser) { - assertLog(browser, 'openfile', null, 'README.txt') + pluginAction(browser, 'openfile', null, 'README.txt') }, 'Should have current file': function (browser: NightwatchBrowser) { - assertLog(browser, 'getcurrentfile', 'README.txt', null) + pluginAction(browser, 'getcurrentfile', 'README.txt', null) }, 'Should activate solidityUnitTesting': function (browser: NightwatchBrowser) { - assertLog(browser, 'activate', null, 'solidityUnitTesting') + pluginAction(browser, 'activate', null, 'solidityUnitTesting') browser.frameParent() assertPluginIsActive(browser, 'solidityUnitTesting') // @ts-ignore @@ -105,13 +110,13 @@ module.exports = { }, 'Should switch to file': function (browser: NightwatchBrowser) { - assertLog(browser, 'switch to file', null, 'contracts/1_Storage.sol') - assertLog(browser, 'getcurrentfile', 'contracts/1_Storage.sol', null) - assertLog(browser, 'switch to file', null, 'README.txt') - assertLog(browser, 'getcurrentfile', 'README.txt', null) + pluginAction(browser, 'switch to file', null, 'contracts/1_Storage.sol') + pluginAction(browser, 'getcurrentfile', 'contracts/1_Storage.sol', null) + pluginAction(browser, 'switch to file', null, 'README.txt') + pluginAction(browser, 'getcurrentfile', 'README.txt', null) }, 'Should write to file': function (browser: NightwatchBrowser) { - assertLog(browser, 'write', 'README.txt', null) + pluginAction(browser, 'write', 'README.txt', null) } }