Skip to content

Commit

Permalink
feat: add actions(register, refresh) to cluster selector (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: yaojiping <[email protected]>
  • Loading branch information
yaojp123 and yaojiping authored Dec 10, 2024
1 parent 3dd3ba9 commit ccd44c9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 38 deletions.
41 changes: 38 additions & 3 deletions web/src/components/ClusterSelect/index.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { useState } from "react";
import { getLocale } from "umi/locale";
import { getLocale, formatMessage } from "umi/locale";

import DropdownList from "@/common/src/DropdownList";
import { SearchEngineIcon } from "@/lib/search_engines";
import { HealthStatusRect } from "../infini/health_status_rect";
import { connect } from "dva";
import { hasAuthority } from "@/utils/authority";

export default (props) => {
export default connect(({ global, loading }) => ({
clusterList: global.clusterList,
clusterLoading: loading.effects["global/fetchClusterList"],
clusterStatus: global.clusterStatus,
}))((props) => {
const {
className,
popoverClassName,
Expand All @@ -17,7 +23,12 @@ export default (props) => {
clusterStatus,
onChange,
mode = "",
onRefresh,
clusterLoading,
dispatch,
showCreate = true
} = props;

const [sorter, setSorter] = useState([]);
const [filters, setFilters] = useState({
status: ["green", "yellow", "red"],
Expand All @@ -44,6 +55,16 @@ export default (props) => {
: "unavailable",
};
};

const actions = [];
if (hasAuthority("system.cluster:all") && showCreate) {
actions.push(
<a onClick={() => window.open(`/#/resource/cluster/regist`,"_blank")}>
{formatMessage({ id: "cluster.manage.btn.regist" })}
</a>
);
}

return (
<DropdownList
getPopupContainer={(triggerNode) => triggerNode.parentNode}
Expand Down Expand Up @@ -146,8 +167,22 @@ export default (props) => {
value: "opensearch",
},
]}
onRefresh={() => {
dispatch({
type: "global/fetchClusterList",
payload: {
size: 200,
name: "",
},
});
dispatch({
type: "global/fetchClusterStatus",
})
}}
loading={clusterLoading}
actions={actions}
>
{children}
</DropdownList>
);
};
});
2 changes: 0 additions & 2 deletions web/src/components/GlobalHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export default class GlobalHeader extends PureComponent {
width={300}
dropdownWidth={400}
selectedCluster={selectedCluster}
clusterList={clusterList}
clusterStatus={clusterStatus}
onChange={(item) => {
const rel = this.props
.handleSaveGlobalState({
Expand Down
2 changes: 0 additions & 2 deletions web/src/pages/Agent/Instance/components/AutoEnroll.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export default ({ onEnroll, loading }) => {
width={"100%"}
dropdownWidth={400}
selectedCluster={selectedCluster}
clusterList={clusterList}
clusterStatus={clusterStatus}
onChange={(item) => {
setSelectedCluster(item);
}}
Expand Down
2 changes: 0 additions & 2 deletions web/src/pages/Agent/Instance/components/UnknownAssociate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export default ({ onBatchEnroll, loading }) => {
width={"100%"}
dropdownWidth={400}
selectedCluster={selectedCluster}
clusterList={clusterList}
clusterStatus={clusterStatus}
onChange={(item) => {
console.log("onChange item:", item);
setSelectedCluster(item);
Expand Down
2 changes: 0 additions & 2 deletions web/src/pages/Alerting/Rule/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,6 @@ const RuleForm = (props) => {
width={300}
dropdownWidth={400}
selectedCluster={selectedCluster}
clusterList={props.clusterList}
clusterStatus={props.clusterStatus}
onChange={(item) => {
setSelectedCluster(item);
}}
Expand Down
29 changes: 7 additions & 22 deletions web/src/pages/DevTool/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { TabTitle } from "./console_tab_title";
import "@/assets/utility.scss";
import { Resizable } from "re-resizable";
import { ResizeBar } from "@/components/infini/resize_bar";
import NewTabMenu from "./NewTabMenu";

import maximizeSvg from "@/assets/window-maximize.svg";
import restoreSvg from "@/assets/window-restore.svg";
import ClusterSelect from "@/components/ClusterSelect";

const MaximizeIcon = (props = {}) => {
return <img height="14px" width="14px" {...props} src={maximizeSvg} />;
Expand Down Expand Up @@ -282,19 +282,6 @@ export const ConsoleUI = ({
[clusterList]
);

// const menu = (
// // <Menu onClick={newTabClick}>
// // {(clusterList||[]).map((cluster:any)=>{
// // return <Menu.Item key={cluster.id}>{cluster.name}</Menu.Item>
// // })}
// // </Menu>
// <NewTabMenu data={clusterList}
// onItemClick={newTabClick}
// clusterStatus={clusterStatus}
// size={10}
// width="300px"/>
// );

const rootRef = useRef(null);
const [isFullscreen, setIsFullscreen] = useState(false);
const fullscreenClick = () => {
Expand Down Expand Up @@ -340,17 +327,15 @@ export const ConsoleUI = ({
</>
),
append: (
<NewTabMenu
data={clusterList}
onItemClick={newTabClick}
clusterStatus={clusterStatus}
size={10}
width="500px"
<ClusterSelect
width={34}
dropdownWidth={400}
onChange={(item) => newTabClick(item)}
>
<div className="tabbar-icon">
<Icon type="plus" />
</div>
</NewTabMenu>
</ClusterSelect>
),
};

Expand Down Expand Up @@ -487,7 +472,7 @@ export const ConsoleUI = ({
);
};

export default connect(({ global }) => ({
export default connect(({ global, loading }) => ({
selectedCluster: global.selectedCluster,
clusterList: global.clusterList,
clusterStatus: global.clusterStatus,
Expand Down
17 changes: 12 additions & 5 deletions web/src/pages/DevTool/NewTabMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,31 @@ class NewTabMenu extends React.Component {
};
constructor(props) {
super(props);
this.state = {
data: this.props.data || [],
};
}

componentDidMount() {}


render() {
const { clusterStatus } = this.props;
const { clusterList, clusterStatus, clusterLoading, dispatch } = this.props;
return (
<div>
<ClusterSelect
width={34}
dropdownWidth={400}
clusterList={this.state.data}
clusterList={clusterList}
clusterStatus={clusterStatus}
onChange={(item) => this.handleItemClick(item)}
loading={clusterLoading}
onRefresh={() => {
dispatch({
type: "global/fetchClusterList",
payload: {
size: 200,
name: "",
},
});
}}
>
{this.props.children}
</ClusterSelect>
Expand Down

0 comments on commit ccd44c9

Please sign in to comment.