Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where sometimes plugin could not be removed from UI #2115

Merged
merged 1 commit into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import CloseIcon from '@material-ui/icons/Close'
import LockIcon from '@material-ui/icons/Lock'

import PluginManager from '@jbrowse/core/PluginManager'
import { getSession } from '@jbrowse/core/util'
import { BasePlugin } from '@jbrowse/core/util/types'
import { isSessionWithSessionPlugins } from '@jbrowse/core/util/types'
Expand Down Expand Up @@ -99,9 +100,11 @@ function PluginDialog({
function InstalledPlugin({
plugin,
model,
pluginManager,
}: {
plugin: BasePlugin
model: PluginStoreModel
pluginManager: PluginManager
}) {
const [dialogPlugin, setDialogPlugin] = useState<string>()

Expand All @@ -110,7 +113,7 @@ function InstalledPlugin({
// @ts-ignore
const { sessionPlugins } = session
const isSessionPlugin = sessionPlugins?.some(
(p: BasePlugin) => `${p.name}Plugin` === plugin.name,
(p: BasePlugin) => pluginManager.pluginMetadata[plugin.name].url === p.url,
)

const rootModel = getParent(model, 3)
Expand All @@ -123,10 +126,12 @@ function InstalledPlugin({
plugin={dialogPlugin}
onClose={name => {
if (name) {
const pluginMetadata = pluginManager.pluginMetadata[plugin.name]
const pluginUrl = pluginMetadata.url
if (adminMode) {
jbrowse.removePlugin(plugin.name)
jbrowse.removePlugin(pluginUrl)
} else if (isSessionWithSessionPlugins(session)) {
session.removeSessionPlugin(plugin.name)
session.removeSessionPlugin(pluginUrl)
}
}
setDialogPlugin(undefined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ function InstalledPluginsList({
plugin.name.toLowerCase().includes(model.filterText.toLowerCase()),
)
.map(plugin => (
<InstalledPlugin key={plugin.name} plugin={plugin} model={model} />
<InstalledPlugin
key={plugin.name}
plugin={plugin}
model={model}
pluginManager={pluginManager}
/>
))
) : (
<Typography>No plugins currently installed</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import PersonIcon from '@material-ui/icons/Person'
import AddIcon from '@material-ui/icons/Add'
import CheckIcon from '@material-ui/icons/Check'

import PluginManager from '@jbrowse/core/PluginManager'
import { getSession } from '@jbrowse/core/util'
import type { JBrowsePlugin } from '@jbrowse/core/util/types'
import { isSessionWithSessionPlugins } from '@jbrowse/core/util/types'
Expand Down Expand Up @@ -51,8 +52,12 @@ function PluginCard({
}) {
const classes = useStyles()
const session = getSession(model)
const { pluginManager } = getEnv(model)
const isInstalled = pluginManager.hasPlugin(`${plugin.name}Plugin`)
const { pluginManager } = getEnv(model) as { pluginManager: PluginManager }
const isInstalled = Boolean(
pluginManager.runtimePluginDefinitions.find(
pluginDefinition => pluginDefinition.url === plugin.url,
),
)
const [tempDisabled, setTempDisabled] = useState(false)
const disableButton = isInstalled || tempDisabled

Expand Down
1 change: 1 addition & 0 deletions products/jbrowse-desktop/src/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default function Loader({
...runtimePlugins.map(({ plugin: P, definition }) => ({
plugin: new P(),
definition,
metadata: { url: definition.url },
})),
])
} catch (e) {
Expand Down
6 changes: 2 additions & 4 deletions products/jbrowse-desktop/src/jbrowseModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,8 @@ export default function JBrowseDesktop(
const rootModel = getParent(self)
rootModel.setPluginsUpdated(true)
},
removePlugin(pluginName) {
self.plugins = self.plugins.filter(
plugin => `${plugin.name}Plugin` !== pluginName,
)
removePlugin(pluginUrl) {
self.plugins = self.plugins.filter(plugin => plugin.url !== pluginUrl)
const rootModel = getParent(self)
rootModel.setPluginsUpdated(true)
},
Expand Down
2 changes: 2 additions & 0 deletions products/jbrowse-web/src/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,12 @@ const Renderer = observer(
...runtimePlugins.map(({ plugin: P, definition }) => ({
plugin: new P(),
definition,
metadata: { url: definition.url },
})),
...sessionPlugins.map(({ plugin: P, definition }) => ({
plugin: new P(),
definition,
metadata: { url: definition.url },
})),
])
pluginManager.createPluggableElements()
Expand Down
6 changes: 2 additions & 4 deletions products/jbrowse-web/src/jbrowseModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,8 @@ export default function JBrowseWeb(
const rootModel = getRoot(self)
rootModel.setPluginsUpdated(true)
},
removePlugin(pluginName) {
self.plugins = self.plugins.filter(
plugin => `${plugin.name}Plugin` !== pluginName,
)
removePlugin(pluginUrl) {
self.plugins = self.plugins.filter(plugin => plugin.url !== pluginUrl)
const rootModel = getRoot(self)
rootModel.setPluginsUpdated(true)
},
Expand Down
4 changes: 2 additions & 2 deletions products/jbrowse-web/src/sessionModelFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ export default function sessionModelFactory(
self.sessionAssemblies.splice(index, 1)
}
},
removeSessionPlugin(pluginName: string) {
removeSessionPlugin(pluginUrl: string) {
const index = self.sessionPlugins.findIndex(
plugin => `${plugin.name}Plugin` === pluginName,
plugin => plugin.url === pluginUrl,
)
if (index !== -1) {
self.sessionPlugins.splice(index, 1)
Expand Down