funky-eyes commented on code in PR #7857:
URL: https://github.com/apache/incubator-seata/pull/7857#discussion_r2618102892


##########
console/src/main/resources/static/console-fe/src/pages/ClusterManager/ClusterManager.tsx:
##########
@@ -0,0 +1,314 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import React from 'react';
+import { ConfigProvider, Table, Button, Form, Icon, Dialog, Input, Select, 
Message } from '@alicloud/console-components';
+import Actions from '@alicloud/console-components-actions';
+import { withRouter } from 'react-router-dom';
+import { connect } from 'react-redux';
+import Page from '@/components/Page';
+import { GlobalProps } from '@/module';
+import { fetchNamespaceV2, fetchClusterData } from '@/service/clusterManager';
+import PropTypes from 'prop-types';
+
+import './index.scss';
+
+const FormItem = Form.Item;
+
+type ClusterManagerLocale = {
+  title?: string;
+  subTitle?: string;
+  selectNamespaceFilerPlaceholder?: string;
+  selectClusterFilerPlaceholder?: string;
+  searchButtonLabel?: string;
+  unitName?: string;
+  members?: string;
+  clusterType?: string;
+  view?: string;
+  unitDialogTitle?: string;
+  control?: string;
+  transaction?: string;
+  weight?: string;
+  healthy?: string;
+  term?: string;
+  unit?: string;
+  operations?: string;
+  internal?: string;
+  version?: string;
+  metadata?: string;
+  controlEndpoint?: string;
+  transactionEndpoint?: string;
+  metadataDialogTitle?: string;
+};
+
+type ClusterManagerState = {
+  namespaceOptions: Map<string, { clusters: string[], clusterVgroups: {[key: 
string]: string[]} }>;
+  clusters: Array<string>;
+  namespace?: string;
+  cluster?: string;
+  clusterData: any; // ClusterData
+  loading: boolean;
+  unitDialogVisible: boolean;
+  selectedUnit: any; // Unit
+  selectedUnitName: string;
+  metadataDialogVisible: boolean;
+  selectedMetadata: any;
+};
+
+class ClusterManager extends React.Component<GlobalProps, ClusterManagerState> 
{
+  static displayName = 'ClusterManager';
+
+  static propTypes = {
+    locale: PropTypes.object,
+  };
+
+  state: ClusterManagerState = {
+    namespaceOptions: new Map<string, { clusters: string[], clusterVgroups: 
{[key: string]: string[]} }>(),
+    clusters: [],
+    clusterData: null,
+    loading: false,
+    unitDialogVisible: false,
+    selectedUnit: null,
+    selectedUnitName: '',
+    metadataDialogVisible: false,
+    selectedMetadata: null,
+  };
+
+  componentDidMount = () => {
+    this.loadNamespaces();
+  };
+
+  loadNamespaces = async () => {
+    try {
+      const namespaces = await fetchNamespaceV2();
+      const namespaceOptions = new Map<string, { clusters: string[], 
clusterVgroups: {[key: string]: string[]} }>();
+      Object.keys(namespaces).forEach(namespaceKey => {
+        const namespaceData = namespaces[namespaceKey];
+        const clusterVgroups: {[key: string]: string[]} = 
namespaceData.clusterVgroups || {};
+        const clusters = Object.keys(clusterVgroups);
+        namespaceOptions.set(namespaceKey, {
+          clusters,
+          clusterVgroups,
+        });
+      });
+      if (namespaceOptions.size > 0) {
+        const firstNamespace = Array.from(namespaceOptions.keys())[0];
+        const selectedNamespace = namespaceOptions.get(firstNamespace);
+        const firstCluster = selectedNamespace ? selectedNamespace.clusters[0] 
: undefined;
+        this.setState(prevState => ({
+          ...prevState,
+          namespaceOptions,
+          namespace: firstNamespace,
+          cluster: firstCluster,
+          clusters: selectedNamespace ? selectedNamespace.clusters : [],
+        }), () => {
+          this.search();
+        });
+      } else {
+        this.setState(prevState => ({
+          ...prevState,
+          namespaceOptions,
+        }));
+      }
+    } catch (error) {
+      console.error('Failed to fetch namespaces:', error);
+    }
+  };
+
+  searchFilterOnChange = (key: string, val: string) => {
+    if (key === 'namespace') {
+      const selectedNamespace = this.state.namespaceOptions.get(val);
+      const clusters = selectedNamespace ? selectedNamespace.clusters : [];
+      const firstCluster = clusters.length > 0 ? clusters[0] : undefined;
+      this.setState(prevState => ({
+        ...prevState,
+        namespace: val,
+        cluster: firstCluster,
+        clusters,
+      }));
+    } else if (key === 'cluster') {
+      this.setState(prevState => ({
+        ...prevState,
+        cluster: val,
+      }));
+    }
+  };
+
+  search = () => {
+    const { namespace, cluster } = this.state;
+    if (!namespace || !cluster) {
+      Message.error('Please select namespace and cluster');
+      return;
+    }
+    this.setState(prevState => ({
+      ...prevState,
+      loading: true,
+    }));
+    fetchClusterData(namespace, cluster).then(data => {
+      if (data.success) {
+        this.setState(prevState => ({
+          ...prevState,
+          clusterData: data.data,
+          loading: false,
+        }));
+      } else {
+        Message.error(data.message || 'Failed to fetch cluster data');
+        this.setState(prevState => ({
+          ...prevState,
+          loading: false,
+        }));
+      }
+    }).catch(err => {
+      Message.error('Failed to fetch cluster data');
+      this.setState(prevState => ({
+        ...prevState,
+        loading: false,
+      }));
+    });
+  };
+
+  showUnitDialog = (unitName: string, unit: any) => {
+    this.setState(prevState => ({
+      ...prevState,
+      unitDialogVisible: true,
+      selectedUnit: unit,
+      selectedUnitName: unitName,
+    }));
+  };
+
+  closeUnitDialog = () => {
+    this.setState(prevState => ({
+      ...prevState,
+      unitDialogVisible: false,
+      selectedUnit: null,
+      selectedUnitName: '',
+    }));
+  };
+
+  showMetadataDialog = (metadata: any) => {
+    this.setState(prevState => ({
+      ...prevState,
+      metadataDialogVisible: true,
+      selectedMetadata: metadata,
+    }));
+  };
+
+  closeMetadataDialog = () => {
+    this.setState(prevState => ({
+      ...prevState,
+      metadataDialogVisible: false,
+      selectedMetadata: null,
+    }));
+  };
+
+  render() {
+    const { locale = {} } = this.props;
+    const rawLocale = locale.ClusterManager;
+    const clusterManagerLocale: ClusterManagerLocale = typeof rawLocale === 
'object' && rawLocale !== null ? rawLocale : {};
+    const { title, subTitle, selectNamespaceFilerPlaceholder, 
selectClusterFilerPlaceholder, searchButtonLabel, unitName, members, 
clusterType, view, unitDialogTitle, control, transaction, weight, healthy, 
term, unit, operations, internal, version, metadata, controlEndpoint, 
transactionEndpoint, metadataDialogTitle } = clusterManagerLocale;

Review Comment:
   That response is incorrect — unitName does exist; it just isn't being used 
right now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to