From commits-return-1071-archive-asf-public=cust-asf.ponee.io@zipkin.apache.org Fri May 10 04:26:20 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id D6EC2180763 for ; Fri, 10 May 2019 06:26:19 +0200 (CEST) Received: (qmail 30715 invoked by uid 500); 10 May 2019 04:26:19 -0000 Mailing-List: contact commits-help@zipkin.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zipkin.apache.org Delivered-To: mailing list commits@zipkin.apache.org Received: (qmail 30682 invoked by uid 99); 10 May 2019 04:26:19 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 May 2019 04:26:19 +0000 From: GitBox To: commits@zipkin.apache.org Subject: [GitHub] [incubator-zipkin] tacigar commented on a change in pull request #2577: Change file suffix .js to .jsx Message-ID: <155746237922.17655.12881370079206554356.gitbox@gitbox.apache.org> Date: Fri, 10 May 2019 04:26:19 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit tacigar commented on a change in pull request #2577: Change file suffix .js to .jsx URL: https://github.com/apache/incubator-zipkin/pull/2577#discussion_r282742366 ########## File path: zipkin-lens/src/components/Dependencies/Dependencies.jsx ########## @@ -0,0 +1,228 @@ +/* + * 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 PropTypes from 'prop-types'; +import React from 'react'; +import { withRouter } from 'react-router'; +import ReactSelect from 'react-select'; +import queryString from 'query-string'; +import moment from 'moment'; + +import DependenciesGraph from './DependenciesGraph'; +import DependenciesSidebar from './DependenciesSidebar'; +import DatePicker from '../Common/DatePicker'; +import LoadingOverlay from '../Common/LoadingOverlay'; +import { buildQueryParameters } from '../../util/api'; + +const propTypes = { + location: PropTypes.shape({}).isRequired, + isLoading: PropTypes.bool.isRequired, + graph: PropTypes.shape({}).isRequired, + fetchDependencies: PropTypes.func.isRequired, + clearDependencies: PropTypes.func.isRequired, + history: PropTypes.shape({ + push: PropTypes.func.isRequired, + }).isRequired, +}; + +export class Dependencies extends React.Component { // export for testing without withRouter + constructor(props) { + super(props); + + this.state = { + startTs: moment().subtract(1, 'days'), + endTs: moment(), + selectedServiceName: '', + filter: '', + }; + + this.handleStartTsChange = this.handleStartTsChange.bind(this); + this.handleEndTsChange = this.handleEndTsChange.bind(this); + this.handleServiceSelect = this.handleServiceSelect.bind(this); + this.handleFilterChange = this.handleFilterChange.bind(this); + this.handleAnalyzeButtonClick = this.handleAnalyzeButtonClick.bind(this); + } + + componentDidMount() { + const { location } = this.props; + + const queryParams = queryString.parse(location.search); + const endTs = queryParams.endTs ? moment(parseInt(queryParams.endTs, 10)) : moment(); + const lookback = queryParams.lookback + ? moment.duration(parseInt(queryParams.lookback, 10)) + : moment.duration(1, 'days'); + const startTs = endTs.clone().subtract(lookback); // subtract is not immutable. + this.setState({ + startTs, + endTs, + }); + this.fetchDependencies(location); + } + + componentWillUnmount() { + const { clearDependencies } = this.props; + clearDependencies(); + } + + fetchDependencies(location) { + const { fetchDependencies } = this.props; + if (location.search !== '' && location.search !== '?') { + const queryParameters = queryString.parse(location.search); + fetchDependencies(queryParameters); + } + } + + handleStartTsChange(startTs) { + this.setState({ startTs }); + } + + handleEndTsChange(endTs) { + this.setState({ endTs }); + } + + handleServiceSelect(selectedServiceName) { + this.setState({ selectedServiceName }); + } + + handleFilterChange(filter) { + this.setState({ filter }); + } + + handleAnalyzeButtonClick() { + const { startTs, endTs } = this.state; + const { history } = this.props; + const queryParameters = buildQueryParameters({ + endTs: endTs.valueOf(), + lookback: endTs.valueOf() - startTs.valueOf(), + }); + const location = { + pathname: '/zipkin/dependency', + search: queryParameters, + }; + history.push(location); + this.fetchDependencies(location); + } + + renderSearch() { + const { startTs, endTs } = this.state; + return ( +
+
+ +
+
+ - +
+
+ +
+
+
+ Analyze Dependencies +
+
+
+ ); + } + + renderFilter() { + const { filter } = this.state; + const { graph } = this.props; + const options = graph.allNodeNames().map( + nodeName => ({ value: nodeName, label: nodeName }), + ); + const value = !filter ? undefined : { value: filter, label: filter }; + return ( + { this.handleFilterChange(selected.value); }} + options={options} + value={value} + styles={{ + control: provided => ({ + ...provided, + width: '240px', + }), + }} + placeholder="Filter by ..." + /> + ); + } + + render() { + const { isLoading, graph } = this.props; + const { selectedServiceName, filter } = this.state; + const isSidebarOpened = !!selectedServiceName; + + return ( +
+ +
+
+ {this.renderSearch()} +
+ { + graph.allNodes().length === 0 + ? null + : ( +
+
+ {this.renderFilter()} +
+
+ +
+
+ ) + } +
+
+ +
+
+ ); + } +} + +Dependencies.propTypes = propTypes; + +export default withRouter(Dependencies); Review comment: The above code is moved from `index.js` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services