Skip to content
This repository has been archived by the owner on Oct 29, 2019. It is now read-only.

Commit

Permalink
Fix #206
Browse files Browse the repository at this point in the history
  • Loading branch information
hanahmily committed Dec 10, 2018
1 parent 56f2d9a commit 875eea3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion mock/aggregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
};
32 changes: 20 additions & 12 deletions src/components/Page/Search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};

Expand Down
17 changes: 0 additions & 17 deletions src/models/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,23 +327,6 @@ export default base({
setup({ history, dispatch }) {
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: {
Expand Down
10 changes: 8 additions & 2 deletions src/routes/Endpoint/Endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? (
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 875eea3

Please sign in to comment.