8000 Delete function for loaded plugins, minor fixes · corner4world/rclone-webui-react@41dfd76 · GitHub
[go: up one dir, main page]

Skip to content

Commit 41dfd76

Browse files
committed
Delete function for loaded plugins, minor fixes
1 parent bbd7593 commit 41dfd76

File tree

6 files changed

+37
-13
lines changed

6 files changed

+37
-13
lines changed

Utils/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import checkPropTypes from 'check-prop-types';
22
import {applyMiddleware, createStore} from 'redux';
33
import rootReducer from './../src/reducers';
4-
import {middleware} from './../src/store';
4+
import {middleware} from '../src/store';
55

66
export const findByTestAttr = (component, attr) => {
77
const wrapper = component.find(`[data-test='${attr}']`);

src/actions/pluginActions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const addTestPlugin = (pluginName, pluginUrl) => (dispatch) => {
3939
}
4040

4141
export const getPlugins = () => (dispatch) => {
42-
axiosInstance.post("pluginsctl/getPlugins").then(res => {
42+
axiosInstance.post("pluginsctl/listPlugins").then(res => {
4343
dispatch({
4444
type: LOAD_PLUGINS,
4545
status: REQUEST_SUCCESS,

src/views/PluginDashboard/PluginDashboard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PluginDashboard extends React.Component {
3939
</tr>
4040
</thead>
4141
<tbody>
42-
<PluginRowEntries loadedPlugins={loadedPlugins}/>
42+
<PluginRowEntries loadedPlugins={loadedPlugins} getPlugins={getPlugins}/>
4343
</tbody>
4444
</Table>
4545
</div>);
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import React from "react";
22
import * as PropTypes from "prop-types";
33
import {Button} from "reactstrap";
4+
import axiosInstance from "../../utils/API/API";
5+
import {toast} from "react-toastify";
46

57
const deactivatePlugin = (item) => {
68

79
}
810

9-
const removePlugin = (item) => {
1011

11-
}
12-
13-
function PluginRowEntries({loadedPlugins}) {
12+
function PluginRowEntries({loadedPlugins, getPlugins}) {
1413

14+
const removePlugin = (key) => {
15+
axiosInstance.post("pluginsctl/removePlugin", {
16+
name: key
17+
}).then(res => {
18+
toast.info(`Plugin ${key} removed successfully`);
19+
}, err => {
20+
toast.error(`Error removing plugin ${key} : ${err}`);
21+
})
22+
getPlugins();
1523

24+
}
1625
let entries = [];
1726
for (const [key, value] of Object.entries(loadedPlugins)) {
1827
entries.push(
@@ -21,7 +30,7 @@ function PluginRowEntries({loadedPlugins}) {
2130
<td>{value.description}</td>
2231
<td>
2332
<Button color="primary">Deactivate</Button>
24-
<Button color={"danger"} className="ml-2">Delete</Button>
33+
<Button color={"danger"} className="ml-2" onClick={() => removePlugin(key)}>Delete</Button>
2534
</td>
2635
</tr>
2736
)
@@ -31,6 +40,7 @@ function PluginRowEntries({loadedPlugins}) {
3140

3241
PluginRowEntries.propTypes = {
3342
loadedPlugins: PropTypes.object.isRequired,
43+
getPlugins: PropTypes.func.isRequired
3444
}
3545

3646
export default PluginRowEntries;

src/views/StoreDashboard/PluginPlaceHolderCard.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@ import {Button, Card, CardBody, Col, Row} from "reactstrap";
22
import React from "react";
33
import * as PropTypes from "prop-types";
44
import {toast} from "react-toastify";
5+
import axiosInstance from "../../utils/API/API";
56

67

78
function PluginPlaceHolderCard({plugin}) {
89
const {
9-
name, description, author, longDescription, icon, url
10+
name, description, author, longDescription, icon, url, repo
1011
} = plugin;
1112

13+
const activatePlugin = (e) => {
14+
axiosInstance.post("pluginsctl/addPlugin", {
15+
url: repo
16+
}).then(res => {
17+
toast.info(`Plugin ${name} added`);
18+
}, err => {
19+
toast.error(`An error occurred: ${err}`)
20+
})
21+
}
22+
1223
return (
1324
<Card>
1425
<CardBody>
@@ -30,7 +41,7 @@ function PluginPlaceHolderCard({plugin}) {
3041
<p>By {author}</p>
3142
</Col>
3243
<Col lg={3} md={3}>
33-
<Button color={"primary mb-2"}>Activate</Button>
44+
<Button color={"primary mb-2"} onClick={activatePlugin}>Activate</Button>
3445
<Button color={"link p-sm-2 p-lg-0"}
3546
onClick={(e) => url ? window.open(url) : toast.error("Url not specified for details")}>More
3647
Details</Button>

src/views/StoreDashboard/StoreDashboard.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import axios from "axios";
77
import PluginPlaceHolderCard from "./PluginPlaceHolderCard";
88
import {toast} from "react-toastify";
99

10-
class PluginDashboard extends React.Component {
10+
class StoreDashboard extends React.Component {
1111

1212
constructor(props, context) {
1313
super(props, context);
@@ -35,6 +35,9 @@ class PluginDashboard extends React.Component {
3535

3636
render() {
3737
const {pluginsList} = this.state;
38+
if (pluginsList.length <= 0) {
39+
return (<p>Loading</p>)
40+
}
3841
return (
3942
<div data-test="storeDashboardComponent">
4043
<Row>
@@ -60,12 +63,12 @@ const mapStateToProps = state => ({
6063
loadedPlugins: state.plugins.loadedPlugins,
6164
});
6265

63-
PluginDashboard.propTypes = {
66+
StoreDashboard.propTypes = {
6467
loadedPlugins: PropTypes.object.isRequired,
6568

6669
getPlugins: PropTypes.func.isRequired,
6770

6871
addPlugin: PropTypes.func.isRequired,
6972
};
7073

71-
export default connect(mapStateToProps, {getPlugins, addPlugin})(PluginDashboard);
74+
export default connect(mapStateToProps, {getPlugins, addPlugin})(StoreDashboard);

0 commit comments

Comments
 (0)
0