Skip to content

Commit

Permalink
[Improve] Rule and MetaData module adaptation namespace (#479)
Browse files Browse the repository at this point in the history
* [Improve] hide namespace for some page

* [Improve] data permission support namespace

* [Fix] fix data permission namespace change problem
  • Loading branch information
VampireAchao authored Sep 25, 2024
1 parent 57fef23 commit f60aad7
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 42 deletions.
88 changes: 50 additions & 38 deletions src/components/GlobalHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
Modal,
} from "antd";
import { connect } from "dva";
import { withRouter } from "dva/router";
import AddModal from "./AddModal";
import ImportResultModal from "./ImportResultModal";
import styles from "./index.less";
Expand Down Expand Up @@ -236,8 +237,17 @@ class GlobalHeader extends PureComponent {
loading,
namespaces,
currentNamespaceId,
location: { pathname },
} = this.props;
const { popup, userName, visible } = this.state;
const showNamespaces = !~[
"/config/dict",
"/config/namespace",
"/config/pluginhandle",
"/system/resource",
"/system/role",
"/system/manage",
].indexOf(pathname);
const menu = (
<Menu>
<Menu.Item
Expand Down Expand Up @@ -270,43 +280,45 @@ class GlobalHeader extends PureComponent {
Apache ShenYu Gateway Management System
</span>
<div>
<div className={styles.item}>
<Dropdown
placement="bottomCenter"
overlay={
<Menu onClick={this.handleNamespacesValueChange}>
{namespaces.map((namespace) => {
let isCurrentNamespace =
currentNamespaceId === namespace.namespaceId;
return (
<Menu.Item
key={namespace.namespaceId}
disabled={isCurrentNamespace}
>
<span>{namespace.name}</span>
</Menu.Item>
);
})}
</Menu>
}
>
<Button>
<a
className="ant-dropdown-link"
style={{ fontWeight: "bold" }}
onClick={(e) => e.preventDefault()}
>
{`${getIntlContent("SHENYU.SYSTEM.NAMESPACE")} / ${
namespaces.find(
(namespace) =>
currentNamespaceId === namespace.namespaceId,
)?.name
} `}
</a>
<Icon type="down" />
</Button>
</Dropdown>
</div>
{showNamespaces && (
<div className={styles.item}>
<Dropdown
placement="bottomCenter"
overlay={
<Menu onClick={this.handleNamespacesValueChange}>
{namespaces.map((namespace) => {
let isCurrentNamespace =
currentNamespaceId === namespace.namespaceId;
return (
<Menu.Item
key={namespace.namespaceId}
disabled={isCurrentNamespace}
>
<span>{namespace.name}</span>
</Menu.Item>
);
})}
</Menu>
}
>
<Button>
<a
className="ant-dropdown-link"
style={{ fontWeight: "bold" }}
onClick={(e) => e.preventDefault()}
>
{`${getIntlContent("SHENYU.SYSTEM.NAMESPACE")} / ${
namespaces.find(
(namespace) =>
currentNamespaceId === namespace.namespaceId,
)?.name
} `}
</a>
<Icon type="down" />
</Button>
</Dropdown>
</div>
)}
<div className={styles.item}>
<Dropdown placement="bottomCenter" overlay={this.state.help}>
<Button>
Expand Down Expand Up @@ -472,4 +484,4 @@ class GlobalHeader extends PureComponent {
}
}

export default GlobalHeader;
export default withRouter(GlobalHeader);
89 changes: 85 additions & 4 deletions src/routes/System/User/DataPermModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
Col,
Input,
Empty,
Dropdown,
Menu,
} from "antd";
import { connect } from "dva";
import { getIntlContent } from "../../../utils/IntlUtils";
Expand All @@ -39,6 +41,7 @@ const { Search } = Input;
dataPermission,
resource,
global,
namespaces: global.namespaces,
selectorPermisionLoading:
loading.effects["dataPermission/fetchDataPermisionSelectors"],
rulePermisionLoading:
Expand All @@ -54,6 +57,8 @@ export default class DataPermModal extends Component {
pageSize: 12,
ruleListMap: {},
searchValue: "",
currentNamespaceId: "649330b6-c2d7-4edc-be8e-8a54df9eb385",
selectorExpandedRowKeys: [],
};
}

Expand All @@ -73,14 +78,15 @@ export default class DataPermModal extends Component {

getPermissionSelectorList = (page) => {
const { dispatch, userId } = this.props;
const { currentPlugin, pageSize } = this.state;
const { currentPlugin, pageSize, currentNamespaceId } = this.state;
dispatch({
type: "dataPermission/fetchDataPermisionSelectors",
payload: {
currentPage: page,
pageSize,
userId,
pluginId: currentPlugin.pluginId,
namespaceId: currentNamespaceId,
},
callback: (res) => {
this.setState({
Expand Down Expand Up @@ -178,6 +184,20 @@ export default class DataPermModal extends Component {
};

handleExpandRuleTable = (expanded, record) => {
let { selectorExpandedRowKeys } = this.state;
if (expanded) {
selectorExpandedRowKeys.push(record.dataId);
this.setState({
selectorExpandedRowKeys,
});
} else {
selectorExpandedRowKeys = selectorExpandedRowKeys.filter(
(e) => e !== record.dataId,
);
this.setState({
selectorExpandedRowKeys,
});
}
this.getPermissionRuleList(record.dataId, 1);
};

Expand Down Expand Up @@ -315,7 +335,7 @@ export default class DataPermModal extends Component {

renderSelectorRuleTable = () => {
const { currentPermissionSelectorPage, pageSize } = this.state;
const { selectorData, ruleListMap } = this.state;
const { selectorData, ruleListMap, selectorExpandedRowKeys } = this.state;
const ruleColumns = [
{
title: getIntlContent("SHENYU.SYSTEM.DATA.PERMISSION.CHECKED"),
Expand Down Expand Up @@ -388,6 +408,8 @@ export default class DataPermModal extends Component {
columns={columns}
expandedRowRender={expandedRowRender}
dataSource={selectorData && selectorData.dataList}
rowKey="dataId"
expandedRowKeys={selectorExpandedRowKeys}
onExpand={this.handleExpandRuleTable}
pagination={{
total: selectorData && selectorData.total,
Expand All @@ -399,13 +421,72 @@ export default class DataPermModal extends Component {
);
};

handleNamespacesValueChange = (value) => {
const { currentPlugin } = this.state;
this.setState({ currentNamespaceId: value.key }, () => {
if (currentPlugin) {
this.setState({ selectorExpandedRowKeys: [] });
this.getPermissionSelectorList(1);
}
});
};

render() {
let { handleCancel } = this.props;
let { handleCancel, namespaces } = this.props;
let { currentNamespaceId } = this.state;
return (
<Modal
width={800}
centered
title={getIntlContent("SHENYU.SYSTEM.DATA.PERMISSION.CONFIG")}
title={
<div
style={{
height: 24,
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}}
>
<div>{getIntlContent("SHENYU.SYSTEM.DATA.PERMISSION.CONFIG")}</div>
<div style={{ marginRight: 30 }}>
<Dropdown
placement="bottomCenter"
overlay={
<Menu onClick={this.handleNamespacesValueChange}>
{namespaces.map((namespace) => {
let isCurrentNamespace =
currentNamespaceId === namespace.namespaceId;
return (
<Menu.Item
key={namespace.namespaceId}
disabled={isCurrentNamespace}
>
<span>{namespace.name}</span>
</Menu.Item>
);
})}
</Menu>
}
>
<Button>
<a
className="ant-dropdown-link"
style={{ fontWeight: "bold" }}
onClick={(e) => e.preventDefault()}
>
{`${getIntlContent("SHENYU.SYSTEM.NAMESPACE")} / ${
namespaces.find(
(namespace) =>
currentNamespaceId === namespace.namespaceId,
)?.name
} `}
</a>
<Icon type="down" />
</Button>
</Dropdown>
</div>
</div>
}
visible
cancelText={getIntlContent("SHENYU.COMMON.CLOSE")}
onCancel={handleCancel}
Expand Down

0 comments on commit f60aad7

Please sign in to comment.