You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zipkin.apache.org by ad...@apache.org on 2019/06/13 11:36:01 UTC

[incubator-zipkin] branch master updated: fix(ui): display user friendly span duration on reload (#2624)

This is an automated email from the ASF dual-hosted git repository.

adriancole pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-zipkin.git


The following commit(s) were added to refs/heads/master by this push:
     new 3ba146c  fix(ui): display user friendly span duration on reload (#2624)
3ba146c is described below

commit 3ba146c147fcbd76ff4cb63a9e0318683db84e62
Author: Sílvia Mur Blanch <pc...@gmail.com>
AuthorDate: Thu Jun 13 13:35:55 2019 +0200

    fix(ui): display user friendly span duration on reload (#2624)
---
 .../components/GlobalSearch/ConditionDuration.jsx  | 13 ++++++++-
 .../GlobalSearch/ConditionDuration.test.js         | 33 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/zipkin-lens/src/components/GlobalSearch/ConditionDuration.jsx b/zipkin-lens/src/components/GlobalSearch/ConditionDuration.jsx
index 2fd4f88..38809f8 100644
--- a/zipkin-lens/src/components/GlobalSearch/ConditionDuration.jsx
+++ b/zipkin-lens/src/components/GlobalSearch/ConditionDuration.jsx
@@ -33,11 +33,22 @@ const unitOptions = [
   'μs', 'ms', 's',
 ];
 
+export const getInitialUnit = (value) => {
+  if (value % (1000 * 1000) === 0) {
+    return 's'
+  }
+  if (value % (1000) === 0) {
+    return 'ms'
+  }
+  return 'μs'
+};
+
 class ConditionDuration extends React.Component {
   constructor(props) {
     super(props);
+
     this.state = {
-      unit: 'μs',
+      unit: getInitialUnit(props.value),
       isValueFocused: false,
       isUnitFocused: false,
       isUnitMenuOpened: false,
diff --git a/zipkin-lens/src/components/GlobalSearch/ConditionDuration.test.js b/zipkin-lens/src/components/GlobalSearch/ConditionDuration.test.js
new file mode 100644
index 0000000..b5fca28
--- /dev/null
+++ b/zipkin-lens/src/components/GlobalSearch/ConditionDuration.test.js
@@ -0,0 +1,33 @@
+/*
+ * 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 { getInitialUnit } from './ConditionDuration';
+
+describe('getInitialUnit', () => {
+  it('should return "s" when value is divisible by 1.000.000', () => {
+    expect(getInitialUnit(1000000)).toBe('s');
+  });
+
+  it('should return "ms" when value is divisible by 1.000', () => {
+    expect(getInitialUnit(1500000)).toBe('ms');
+    expect(getInitialUnit(1000)).toBe('ms');
+  });
+
+  it('should return "μs" otherwise', () => {
+    expect(getInitialUnit(1500)).toBe('μs');
+    expect(getInitialUnit(100)).toBe('μs');
+  });
+});