Skip to content

Commit 27e1aff

Browse files
authored
Merge pull request #1781 from emlys/bugfix/1692
Close any open plugin tabs before removing it
2 parents 2959368 + 76d5920 commit 27e1aff

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

workbench/src/renderer/app.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ export default class App extends React.Component {
379379
}
380380
<PluginModal
381381
updateInvestList={this.updateInvestList}
382+
closeInvestModel={this.closeInvestModel}
383+
openJobs={openJobs}
382384
/>
383385
<SettingsModal
384386
className="mx-3"

workbench/src/renderer/components/PluginModal/index.jsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ipcMainChannels } from '../../../main/ipcMainChannels';
1313
const { ipcRenderer } = window.Workbench.electron;
1414

1515
export default function PluginModal(props) {
16-
const { updateInvestList } = props;
16+
const { updateInvestList, closeInvestModel, openJobs } = props;
1717
const [showPluginModal, setShowPluginModal] = useState(false);
1818
const [url, setURL] = useState(undefined);
1919
const [revision, setRevision] = useState(undefined);
@@ -52,6 +52,11 @@ export default function PluginModal(props) {
5252

5353
const removePlugin = () => {
5454
setLoading(true);
55+
Object.keys(openJobs).forEach((tabID) => {
56+
if (openJobs[tabID].modelRunName === pluginToRemove) {
57+
closeInvestModel(tabID);
58+
}
59+
});
5560
ipcRenderer.invoke(ipcMainChannels.REMOVE_PLUGIN, pluginToRemove).then(() => {
5661
updateInvestList();
5762
setLoading(false);
@@ -212,4 +217,8 @@ export default function PluginModal(props) {
212217

213218
PluginModal.propTypes = {
214219
updateInvestList: PropTypes.func.isRequired,
220+
closeInvestModel: PropTypes.func.isRequired,
221+
openJobs: PropTypes.shape({
222+
modelRunName: PropTypes.string,
223+
}).isRequired,
215224
};

workbench/tests/renderer/plugin.test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,14 @@ describe('Add plugin modal', () => {
142142
return Promise.resolve();
143143
});
144144
const {
145-
findByText, getByRole, findByLabelText, queryByRole,
145+
findByText, findByRole, getByRole, findByLabelText, queryByRole,
146146
} = render(<App />);
147147

148+
// open the plugin first, to make sure it doesn't cause a crash when removing
149+
const pluginButton = await findByRole('button', { name: /Foo/ });
150+
await act(async () => {
151+
userEvent.click(pluginButton);
152+
});
148153
const managePluginsButton = await findByText('Manage plugins');
149154
userEvent.click(managePluginsButton);
150155

0 commit comments

Comments
 (0)