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

Feat/webconsole/dep #48

Merged
merged 4 commits into from
May 3, 2020
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
4 changes: 4 additions & 0 deletions packages/rocketact-web-console/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"semi": true,
"singleQuote": false
}
2 changes: 1 addition & 1 deletion packages/rocketact-web-console/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rocketact-web-console",
"version": "1.1.8",
"version": "1.1.10",
"description": "Rocketact Web Console",
"main": "index.js",
"keywords": [
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketact-web-console/src/client/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ function updateProxyRule(ruleId: string, rule: IProxyRule) {
.then(handleResponse);
}

function toggleAllProxyRuleEnable(enabled: boolean) {
return axios
.put(`${API_BASE}/api-proxy/rules/enable`, { enabled })
.then(handleResponse);
}

function toggleProxyRuleState(ruleId: string, enabled: boolean) {
return axios
.put(`${API_BASE}/api-proxy/rule/${ruleId}/enabled`, { enabled })
Expand All @@ -138,5 +144,6 @@ export {
deleteProxyRule,
updateProxyRule,
toggleProxyRuleState,
toggleAllProxyRuleEnable,
moveProxyRule
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import React from "react";

import { Table, Switch } from "antd";
Expand Down
27 changes: 27 additions & 0 deletions packages/rocketact-web-console/src/client/routes/apiProxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import ProxyRulesTabel from "../components/ProxyRulesTable";
const JSONInput = require("react-json-editor-ajrm/index").default;
import { Button, Modal, Select, Input, message } from "antd";

const ButtonGroup = Button.Group;

export interface IProxyRule {
ruleId: string;
match: string;
Expand Down Expand Up @@ -52,6 +54,7 @@ class APIProxyRoute extends React.Component<
this.modify = this.modify.bind(this);
this.toggleState = this.toggleState.bind(this);
this.move = this.move.bind(this);
this.toggleAllEnable = this.toggleAllEnable.bind(this);
}

componentDidMount() {
Expand All @@ -78,6 +81,18 @@ class APIProxyRoute extends React.Component<
});
}

toggleAllEnable(enabled: boolean) {
API.toggleAllProxyRuleEnable(enabled).then(() => {
this.setState({
rules: this.state.rules.map(rule => {
return Object.assign({}, rule, {
enabled
});
})
});
});
}

modify(ruleId: string) {
this.setState({
showRuleEditorModal: !this.state.showRuleEditorModal,
Expand Down Expand Up @@ -142,6 +157,18 @@ class APIProxyRoute extends React.Component<
>
Create new rule
</Button>
&nbsp;&nbsp;
<ButtonGroup>
<Button icon="api" onClick={() => this.toggleAllEnable(true)}>
Enable All Rules
</Button>
<Button
icon="disconnect"
onClick={() => this.toggleAllEnable(false)}
>
Disable All Rules
</Button>
</ButtonGroup>
</p>
<ProxyRulesTabel
rules={this.state.rules}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class Dependencies extends React.Component<
this.refreshOnClosePackageInstaller = false;
}

componentDidMount() {
if (this.props.store.main && this.props.store.main.length === 0) {
dependenciesStore.refresh();
}
}

remove(name: string) {
globalLoadingStore.show(`Removing ${name}...`);
API.uninstall(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ const store = observable(
}
);

store.refresh();
// store.refresh();
export default store;
13 changes: 13 additions & 0 deletions packages/rocketact-web-console/src/server/proxyAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ proxyAPI.post("/rules", (req, res) => {
});
});

/**
* modify the enabled of all rules
*/
proxyAPI.put("/rules/enable", (req, res) => {
ruleCache = ruleCache.map(rule => {
return Object.assign({}, rule, { enabled: req.body.enabled });
});

res.json({
success: true
});
});

/**
* modify detail info of specific rule
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketact-web-console/tsconfig-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// ] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true /* Generates corresponding '.map' file. */,
Expand Down