Fix #206 6.0.0/beta 207/head
authorGao Hongtao <hanahmily@gmail.com>
Mon, 10 Dec 2018 14:27:50 +0000 (22:27 +0800)
committerGao Hongtao <hanahmily@gmail.com>
Mon, 10 Dec 2018 14:27:50 +0000 (22:27 +0800)
mock/aggregation.js
src/components/Page/Search/index.js
src/models/endpoint.js
src/routes/Endpoint/Endpoint.js

index 62c96fc..8da0157 100644 (file)
@@ -31,7 +31,7 @@ export default {
     return data.array;
   },
   getAllEndpointTopN: () => {
-    const data =  mockjs.mock({ 'array|10': [{ 'id|+1': 1, name: '@name', 'value|200-1000': 1 }]});
+    const data =  mockjs.mock({ 'array|10': [{ 'id|+1': 100, name: '@name', 'value|200-1000': 1 }]});
     return data.array;
   },
 };
index 5cddb5a..9aca61a 100644 (file)
@@ -37,53 +37,61 @@ export default class Search extends Component {
   componentDidMount() {
     const {...propsData} = this.props;
     if (propsData.variables && Object.keys(propsData.variables).length > 0) {
-      this.originFetchServer('', propsData.value.key);
+      this.originFetchServer('', propsData.value);
     }
   }
 
   componentDidUpdate(prevProps) {
     const {...propsData} = this.props;
     if (prevProps.variables !== propsData.variables) {
-      this.originFetchServer('', propsData.value.key);
+      this.originFetchServer('', propsData.value);
     }
   }
 
-  fetchServer = (value, key) => {
-    if (value === undefined) {
+  fetchServer = (keyword, value) => {
+    if (keyword === undefined) {
       return;
     }
     const { url, query, variables = {}, transform } = this.props;
-    this.lastFetchId += 1;
-    const fetchId = this.lastFetchId;
+    const that = this;
+    that.lastFetchId += 1;
+    const fetchId = that.lastFetchId;
     this.setState({ data: [], fetching: true });
     request(`/api${url}`, {
       method: 'POST',
       body: {
         variables: {
           ...variables,
-          keyword: value,
+          keyword,
         },
         query,
       },
     }).then(body => {
-      if (!body.data || fetchId !== this.lastFetchId) {
+      if (!body.data || fetchId !== that.lastFetchId) {
         // for fetch callback order
         return;
       }
       const list = body.data[Object.keys(body.data)[0]];
-      const that = this;
       this.setState({ data: transform ? list.map(transform) : list, fetching: false });
       if (that.state.data.length < 1) {
         return;
       }
-      if (!key) {
+      if (!value) {
+        return;
+      }
+      const { key, label } = value;
+      if (!key || key.length < 1) {
         this.handleSelect(that.state.data[0]);
         return;
       }
       const option = that.state.data.find(_ => _.key === key);
-      if (!option) {
-        this.handleSelect(that.state.data[0]);
+      if (option) {
+        return;
       }
+      const target = {key, label};
+      const newList = [...that.state.data, target];
+      this.setState({data: newList});
+      this.handleSelect(target);
     });
   };
 
index bb617fc..cc5c472 100644 (file)
@@ -328,23 +328,6 @@ export default base({
       return history.listen(({ pathname, state }) => {
         if (pathname === '/monitor/endpoint' && state) {
           dispatch({
-            type: 'saveVariables',
-            payload: {
-              values: {
-                endpointId: state.key,
-              },
-              labels: {
-                endpointId: state.label,
-              },
-            },
-          });
-          dispatch({
-            type: 'saveData',
-            payload: {
-              endpointInfo: { key: state.key, label: state.label },
-            },
-          });
-          dispatch({
             type: 'fetchInfo',
             payload: {
               variables: {
index 49f07df..f024da4 100644 (file)
@@ -264,6 +264,12 @@ export default class Endpoint extends PureComponent {
     const { getFieldDecorator } = form;
     const { variables: { options }, data } = endpoint;
     const { showTimeline, queryTrace, currentTraceId } = data;
+    if (!this.serviceInfo) {
+      this.serviceInfo = data.serviceInfo;
+    }
+    if (data.serviceInfo && this.serviceInfo.serviceId !== data.serviceInfo.serviceId) {
+      this.serviceInfo = data.serviceInfo;
+    }
     return (
       <div>
         {showTimeline ? (
@@ -293,14 +299,14 @@ export default class Endpoint extends PureComponent {
                   </Select>
                 )}
               </FormItem>
-              {data.serviceInfo && data.serviceInfo.serviceId  ? (
+              {this.serviceInfo && this.serviceInfo.serviceId  ? (
                 <FormItem>
                   {getFieldDecorator('endpointId')(
                     <Search
                       placeholder="Search a endpoint"
                       onSelect={this.handleSelect.bind(this)}
                       url="/graphql"
-                      variables={data.serviceInfo}
+                      variables={this.serviceInfo}
                       query={`
                         query SearchEndpoint($serviceId: ID!, $keyword: String!) {
                           searchEndpoint(serviceId: $serviceId, keyword: $keyword, limit: 10) {