Skip to content

Commit 72b7728

Browse files
authored
Merge pull request #1931 from ethereum/vicons
vertical icon fixes
2 parents 33385cf + dc90c7e commit 72b7728

35 files changed

+364
-913
lines changed

apps/remix-ide-e2e/src/tests/generalSettings.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]', 5000)
2020
.waitForElementVisible('*[data-id="settingsTabGenerateContractMetadataLabel"]', 5000)
2121
.verify.elementPresent('[data-id="settingsTabGenerateContractMetadata"]:checked')
22-
.click('*[data-id="verticalIconsFileExplorerIcons"]')
22+
.click('*[data-id="verticalIconsKindfilePanel"]')
2323
.click('[data-id="treeViewLitreeViewItemcontracts"]')
2424
.openFile('contracts/3_Ballot.sol')
2525
.click('*[data-id="verticalIconsKindsolidity"]')

apps/remix-ide/src/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ class AppComponent {
225225
self.engine.register([appPanel, tabProxy])
226226

227227
// those views depend on app_manager
228-
self.menuicons = new VerticalIcons(appManager)
229-
self.sidePanel = new SidePanel(appManager, self.menuicons)
228+
self.menuicons = new VerticalIcons()
229+
self.sidePanel = new SidePanel()
230230
self.hiddenPanel = new HiddenPanel()
231231

232232
const pluginManagerComponent = new PluginManagerComponent(

apps/remix-ide/src/app/components/panel.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ export class AbstractPanel extends HostPlugin {
4949
* @param {String} name The name of the plugin to display the content
5050
*/
5151
showContent (name) {
52-
if (!this.plugins[name]) throw new Error(`Plugin ${name} is not yet activated`)
53-
52+
if (!this.plugins[name]) throw new Error(`Plugin ${name} is not yet activated`)
5453
Object.values(this.plugins).forEach(plugin => {
5554
plugin.active = false
5655
})

apps/remix-ide/src/app/components/side-panel.tsx

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import ReactDOM from 'react-dom'
44
import { AbstractPanel } from './panel'
55
import { RemixPluginPanel } from '@remix-ui/panel'
66
import packageJson from '../../../../../package.json'
7-
import { RemixAppManager } from '../../remixAppManager'
8-
import { VerticalIcons } from 'libs/remix-ui/vertical-icons-panel/types/vertical-icons-panel'
97
import RemixUIPanelHeader from 'libs/remix-ui/panel/src/lib/plugins/panel-header'
108
// const csjs = require('csjs-inject')
119

@@ -17,20 +15,18 @@ const sidePanel = {
1715
methods: ['addView', 'removeView']
1816
}
1917

20-
// TODO merge with vertical-icons.js
2118
export class SidePanel extends AbstractPanel {
22-
appManager: RemixAppManager
2319
sideelement: any
24-
verticalIcons: VerticalIcons;
25-
constructor (appManager: RemixAppManager, verticalIcons: VerticalIcons) {
20+
constructor() {
2621
super(sidePanel)
27-
this.appManager = appManager
2822
this.sideelement = document.createElement('section')
2923
this.sideelement.setAttribute('class', 'panel plugin-manager')
30-
this.verticalIcons = verticalIcons
24+
}
3125

26+
onActivation() {
27+
this.renderComponent()
3228
// Toggle content
33-
verticalIcons.events.on('toggleContent', (name) => {
29+
this.on('menuicons', 'toggleContent', (name) => {
3430
if (!this.plugins[name]) return
3531
if (this.plugins[name].active) {
3632
// TODO: Only keep `this.emit` (issue#2210)
@@ -44,7 +40,7 @@ export class SidePanel extends AbstractPanel {
4440
this.events.emit('showing', name)
4541
})
4642
// Force opening
47-
verticalIcons.events.on('showContent', (name) => {
43+
this.on('menuicons', 'showContent', (name) => {
4844
if (!this.plugins[name]) return
4945
this.showContent(name)
5046
// TODO: Only keep `this.emit` (issue#2210)
@@ -53,43 +49,40 @@ export class SidePanel extends AbstractPanel {
5349
})
5450
}
5551

56-
onActivation () {
57-
this.renderComponent()
58-
}
59-
60-
focus (name) {
52+
focus(name) {
6153
this.emit('focusChanged', name)
6254
super.focus(name)
6355
}
6456

65-
removeView (profile) {
57+
removeView(profile) {
58+
if (this.plugins[profile.name].active) this.call('menuicons', 'select', 'filePanel')
6659
super.removeView(profile)
6760
this.emit('pluginDisabled', profile.name)
6861
this.call('menuicons', 'unlinkContent', profile)
6962
this.renderComponent()
7063
}
7164

72-
addView (profile, view) {
65+
addView(profile, view) {
7366
super.addView(profile, view)
74-
this.verticalIcons.linkContent(profile)
67+
this.call('menuicons', 'linkContent', profile)
7568
this.renderComponent()
7669
}
7770

7871
/**
7972
* Display content and update the header
8073
* @param {String} name The name of the plugin to display
8174
*/
82-
async showContent (name) {
75+
async showContent(name) {
8376
super.showContent(name)
8477
this.emit('focusChanged', name)
8578
this.renderComponent()
8679
}
8780

88-
render () {
81+
render() {
8982
return this.sideelement
9083
}
9184

92-
renderComponent () {
93-
ReactDOM.render(<RemixPluginPanel header={<RemixUIPanelHeader plugins={this.plugins}></RemixUIPanelHeader>} plugins={this.plugins}/>, this.sideelement)
85+
renderComponent() {
86+
ReactDOM.render(<RemixPluginPanel header={<RemixUIPanelHeader plugins={this.plugins}></RemixUIPanelHeader>} plugins={this.plugins} />, this.sideelement)
9487
}
9588
}

apps/remix-ide/src/app/components/vertical-icons.js

Lines changed: 0 additions & 110 deletions
This file was deleted.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// eslint-disable-next-line no-use-before-define
2+
import React from 'react'
3+
import ReactDOM from 'react-dom'
4+
import Registry from '../state/registry'
5+
import packageJson from '../../../../../package.json'
6+
import { Plugin } from '@remixproject/engine'
7+
import { EventEmitter } from 'events'
8+
import { IconRecord, RemixUiVerticalIconsPanel } from '@remix-ui/vertical-icons-panel'
9+
import { Profile } from '@remixproject/plugin-utils'
10+
import { timeStamp } from 'console'
11+
12+
const profile = {
13+
name: 'menuicons',
14+
displayName: 'Vertical Icons',
15+
description: '',
16+
version: packageJson.version,
17+
methods: ['select', 'unlinkContent', 'linkContent'],
18+
events: ['toggleContent', 'showContent']
19+
}
20+
21+
export class VerticalIcons extends Plugin {
22+
events: EventEmitter
23+
htmlElement: HTMLDivElement
24+
icons: Record<string, IconRecord> = {}
25+
constructor () {
26+
super(profile)
27+
this.events = new EventEmitter()
28+
this.htmlElement = document.createElement('div')
29+
this.htmlElement.setAttribute('id', 'icon-panel')
30+
}
31+
32+
renderComponent () {
33+
const fixedOrder = ['filePanel', 'solidity','udapp', 'debugger', 'solidityStaticAnalysis', 'solidityUnitTesting', 'pluginManager']
34+
35+
const divived = Object.values(this.icons).map((value) => { return {
36+
...value,
37+
isRequired: fixedOrder.indexOf(value.profile.name) > -1
38+
}}).sort((a,b) => {
39+
return a.timestamp - b.timestamp
40+
})
41+
42+
const required = divived.filter((value) => value.isRequired).sort((a,b) => {
43+
return fixedOrder.indexOf(a.profile.name) - fixedOrder.indexOf(b.profile.name)
44+
})
45+
46+
const sorted: IconRecord[] = [
47+
...required,
48+
...divived.filter((value) => { return !value.isRequired })
49+
]
50+
51+
ReactDOM.render(
52+
<RemixUiVerticalIconsPanel
53+
verticalIconsPlugin={this}
54+
icons={sorted}
55+
/>,
56+
this.htmlElement)
57+
}
58+
59+
onActivation () {
60+
this.renderComponent()
61+
this.on('sidePanel', 'focusChanged', (name: string) => {
62+
Object.keys(this.icons).map((o) => {
63+
this.icons[o].active = false
64+
})
65+
this.icons[name].active = true
66+
this.renderComponent()
67+
})
68+
}
69+
70+
async linkContent (profile: Profile) {
71+
if (!profile.icon) return
72+
if (!profile.kind) profile.kind = 'none'
73+
this.icons[profile.name] = {
74+
profile: profile,
75+
active: false,
76+
canbeDeactivated: await this.call('manager', 'canDeactivate', this.profile, profile),
77+
timestamp: Date.now()
78+
}
79+
this.renderComponent()
80+
}
81+
82+
unlinkContent (profile: Profile) {
83+
delete this.icons[profile.name]
84+
this.renderComponent()
85+
}
86+
87+
async activateHome() {
88+
await this.call('manager', 'activatePlugin', 'home')
89+
await this.call('tabs', 'focus', 'home')
90+
}
91+
92+
/**
93+
* Set an icon as active
94+
* @param {string} name Name of profile of the module to activate
95+
*/
96+
select (name: string) {
97+
// TODO: Only keep `this.emit` (issue#2210)
98+
console.log(name, this)
99+
this.emit('showContent', name)
100+
this.events.emit('showContent', name)
101+
}
102+
103+
/**
104+
* Toggles the side panel for plugin
105+
* @param {string} name Name of profile of the module to activate
106+
*/
107+
toggle (name: string) {
108+
// TODO: Only keep `this.emit` (issue#2210)
109+
this.emit('toggleContent', name)
110+
this.events.emit('toggleContent', name)
111+
}
112+
113+
render () {
114+
return this.htmlElement
115+
}
116+
}

apps/remix-ide/src/remixAppManager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export class RemixAppManager extends PluginManager {
5050
return isNative(from.name)
5151
}
5252

53+
async canDeactivate(from,to) {
54+
return this.canDeactivatePlugin(from, to)
55+
}
56+
5357
async deactivatePlugin (name) {
5458
const [to, from] = [
5559
await this.getProfile(name),

apps/remix-ide/src/walkthroughService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class WalkthroughService extends Plugin {
3131
position: 'right'
3232
},
3333
{
34-
element: document.querySelector('#compileIcons'),
34+
element: document.querySelector('#verticalIconsKindsolidity'),
3535
title: 'Solidity Compiler',
3636
intro: 'Having selected a .sol file in the File Explorers (the icon above), compile it with the Solidity Compiler.',
3737
tooltipClass: 'bg-light text-dark',

libs/remix-ui/panel/src/lib/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export type PluginRecord = {
66
active: boolean
77
class?: string
88
minimized?: boolean
9-
}
9+
}

0 commit comments

Comments
 (0)