From 6ac026913af2bee86e8854381a301a6baeeb2be9 Mon Sep 17 00:00:00 2001 From: joseph izang Date: Tue, 13 Jul 2021 14:43:14 +0100 Subject: [PATCH] Refactor and clean up rootView component --- .../components/plugin-manager-component.js | 31 ------------------- .../src/lib/components/rootView.tsx | 29 +++-------------- 2 files changed, 5 insertions(+), 55 deletions(-) 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 be83edac72..2eb7382c43 100644 --- a/apps/remix-ide/src/app/components/plugin-manager-component.js +++ b/apps/remix-ide/src/app/components/plugin-manager-component.js @@ -167,37 +167,6 @@ class PluginManagerComponent extends ViewPlugin { } } - 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: [] }) - this.activePlugins = actives - this.inactivePlugins = inactives - } - render () { // Filtering helpers const isFiltered = (profile) => (profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(this.filter) 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 55de3eaf60..7f4fc3de50 100644 --- a/libs/remix-ui/plugin-manager/src/lib/components/rootView.tsx +++ b/libs/remix-ui/plugin-manager/src/lib/components/rootView.tsx @@ -21,18 +21,9 @@ const initialState: FormStateProps = { interface ShowInactivesProps { inactives: Partial[] - appManager?: RemixAppManager headinglabel: string } -function ShowInactives ({ inactives, appManager, headinglabel }: ShowInactivesProps) { - const [plugins] = useState[]>(appManager.getAll()) - const [litUpProfiles] = useState[]>(appManager.getActiveProfiles()) - const pluginNames = litUpProfiles.map(p => p.name) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let temp: Profile[] - pluginNames.forEach(x => { - temp = plugins.filter(plugin => plugin.name === x) - }) +function ShowInactives ({ inactives, headinglabel }: ShowInactivesProps) { return ( @@ -43,7 +34,7 @@ function ShowInactives ({ inactives, appManager, headinglabel }: ShowInactivesPr ) } -function ShowActives ({ inactives, appManager, headinglabel }: ShowInactivesProps) { +function ShowActives ({ inactives, headinglabel }: ShowInactivesProps) { const [plugins] = useState([]) if (inactives.length === 0) { plugins.map(plugin => inactives.push(plugin)) @@ -62,11 +53,6 @@ function RootView () { const { appManager, actives, engine, inactives, localPlugin, filter } = useContext(PluginManagerContext) const [visible, setVisible] = useState(true) const [plugin, setPlugin] = useState(initialState) - const [allPlugins] = useState(appManager.getAll()) - const [activePlugins, setActivePlugins] = useState([]) - const [inactivePlugins, setInactivePlugins] = useState([]) - - console.log(`allPlugins state has ${allPlugins.length} plugins ready to be filtered`) function pluginChangeHandler

(formProps: P, value: FormStateProps[P]) { setPlugin({ ...plugin, [formProps]: value }) @@ -77,11 +63,6 @@ function RootView () { const closeModal = () => setVisible(true) - const activatePlugin = async (name: string) => { - await appManager.activatePlugin(name) - } - - console.log('active plugins', activePlugins) return (

@@ -203,10 +184,10 @@ function RootView () {
{actives !== undefined - ? () - : () + ? () + : () } - {inactives !== undefined ? () : } + {inactives !== undefined ? () : }