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

yongjiezhao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 67535bb  refactor: reorganize dateFilterUtils.tx (#14309)
67535bb is described below

commit 67535bb320d73e3693e273f90d1321ea6065a3a3
Author: Yongjie Zhao <[email protected]>
AuthorDate: Fri Apr 23 16:05:50 2021 +0800

    refactor: reorganize dateFilterUtils.tx (#14309)
    
    * refactor: reorganize dateFilterUtils.tx
    
    * move spec to src dirctory
---
 .../spec/javascripts/explore/utils_spec.jsx        | 38 ----------------------
 .../controls/DateFilterControl/DateFilterLabel.tsx | 13 ++++----
 .../DateFilterControl/components/AdvancedFrame.tsx |  2 +-
 .../DateFilterControl/utils}/dateFilterUtils.ts    |  0
 .../controls/DateFilterControl/utils/dateParser.ts |  2 +-
 .../controls/DateFilterControl/utils/index.ts      |  1 +
 .../DateFilterControl/utils/utils.test.ts}         | 36 ++++++++++++++++++++
 7 files changed, 45 insertions(+), 47 deletions(-)

diff --git a/superset-frontend/spec/javascripts/explore/utils_spec.jsx 
b/superset-frontend/spec/javascripts/explore/utils_spec.jsx
index d416fc0..2c1eb03 100644
--- a/superset-frontend/spec/javascripts/explore/utils_spec.jsx
+++ b/superset-frontend/spec/javascripts/explore/utils_spec.jsx
@@ -26,10 +26,6 @@ import {
   shouldUseLegacyApi,
   getSimpleSQLExpression,
 } from 'src/explore/exploreUtils';
-import {
-  buildTimeRangeString,
-  formatTimeRange,
-} from 'src/explore/dateFilterUtils';
 import { DashboardStandaloneMode } from 'src/dashboard/util/constants';
 import * as hostNamesConfig from 'src/utils/hostNamesConfig';
 import { getChartMetadataRegistry } from '@superset-ui/core';
@@ -264,40 +260,6 @@ describe('exploreUtils', () => {
     });
   });
 
-  describe('buildTimeRangeString', () => {
-    it('generates proper time range string', () => {
-      expect(
-        buildTimeRangeString('2010-07-30T00:00:00', '2020-07-30T00:00:00'),
-      ).toBe('2010-07-30T00:00:00 : 2020-07-30T00:00:00');
-      expect(buildTimeRangeString('', '2020-07-30T00:00:00')).toBe(
-        ' : 2020-07-30T00:00:00',
-      );
-      expect(buildTimeRangeString('', '')).toBe(' : ');
-    });
-  });
-
-  describe('formatTimeRange', () => {
-    it('generates a readable time range', () => {
-      expect(formatTimeRange('Last 7 days')).toBe('Last 7 days');
-      expect(formatTimeRange('No filter')).toBe('No filter');
-      expect(formatTimeRange('Yesterday : Tomorrow')).toBe(
-        'Yesterday < col < Tomorrow',
-      );
-      expect(
-        formatTimeRange('2010-07-30T00:00:00 : 2020-07-30T00:00:00', [
-          'inclusive',
-          'exclusive',
-        ]),
-      ).toBe('2010-07-30 ≤ col < 2020-07-30');
-      expect(
-        formatTimeRange('2010-07-30T01:00:00 : ', ['exclusive', 'inclusive']),
-      ).toBe('2010-07-30T01:00:00 < col ≤ ∞');
-      expect(formatTimeRange(' : 2020-07-30T00:00:00')).toBe(
-        '-∞ < col < 2020-07-30',
-      );
-    });
-  });
-
   describe('getSimpleSQLExpression', () => {
     it('returns empty string when subject is undefined', () => {
       expect(getSimpleSQLExpression(undefined, '=', 10)).toBe('');
diff --git 
a/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx
 
b/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx
index 811d5fb..2674eca 100644
--- 
a/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx
+++ 
b/superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterLabel.tsx
@@ -28,7 +28,11 @@ import {
 import {
   buildTimeRangeString,
   formatTimeRange,
-} from 'src/explore/dateFilterUtils';
+  COMMON_RANGE_VALUES_SET,
+  CALENDAR_RANGE_VALUES_SET,
+  FRAME_OPTIONS,
+  customTimeRangeDecode,
+} from 'src/explore/components/controls/DateFilterControl/utils';
 import { getClientErrorObject } from 'src/utils/getClientErrorObject';
 import Button from 'src/components/Button';
 import ControlHeader from 'src/explore/components/ControlHeader';
@@ -43,12 +47,7 @@ import { useDebouncedEffect } from 
'src/explore/exploreUtils';
 import { SLOW_DEBOUNCE } from 'src/constants';
 import { testWithId } from 'src/utils/testUtils';
 import { SelectOptionType, FrameType } from './types';
-import {
-  COMMON_RANGE_VALUES_SET,
-  CALENDAR_RANGE_VALUES_SET,
-  FRAME_OPTIONS,
-  customTimeRangeDecode,
-} from './utils';
+
 import {
   CommonFrame,
   CalendarFrame,
diff --git 
a/superset-frontend/src/explore/components/controls/DateFilterControl/components/AdvancedFrame.tsx
 
b/superset-frontend/src/explore/components/controls/DateFilterControl/components/AdvancedFrame.tsx
index 0264da3..607cf99 100644
--- 
a/superset-frontend/src/explore/components/controls/DateFilterControl/components/AdvancedFrame.tsx
+++ 
b/superset-frontend/src/explore/components/controls/DateFilterControl/components/AdvancedFrame.tsx
@@ -18,7 +18,7 @@
  */
 import React from 'react';
 import { t } from '@superset-ui/core';
-import { SEPARATOR } from 'src/explore/dateFilterUtils';
+import { SEPARATOR } from 
'src/explore/components/controls/DateFilterControl/utils';
 import { Input } from 'src/common/components';
 import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
 import { FrameComponentProps } from 
'src/explore/components/controls/DateFilterControl/types';
diff --git a/superset-frontend/src/explore/dateFilterUtils.ts 
b/superset-frontend/src/explore/components/controls/DateFilterControl/utils/dateFilterUtils.ts
similarity index 100%
rename from superset-frontend/src/explore/dateFilterUtils.ts
rename to 
superset-frontend/src/explore/components/controls/DateFilterControl/utils/dateFilterUtils.ts
diff --git 
a/superset-frontend/src/explore/components/controls/DateFilterControl/utils/dateParser.ts
 
b/superset-frontend/src/explore/components/controls/DateFilterControl/utils/dateParser.ts
index 6dce8d4..d1be0de 100644
--- 
a/superset-frontend/src/explore/components/controls/DateFilterControl/utils/dateParser.ts
+++ 
b/superset-frontend/src/explore/components/controls/DateFilterControl/utils/dateParser.ts
@@ -17,13 +17,13 @@
  * under the License.
  */
 import moment, { Moment } from 'moment';
-import { SEPARATOR } from 'src/explore/dateFilterUtils';
 import {
   CustomRangeDecodeType,
   CustomRangeType,
   DateTimeGrainType,
   DateTimeModeType,
 } from 'src/explore/components/controls/DateFilterControl/types';
+import { SEPARATOR } from './dateFilterUtils';
 import { SEVEN_DAYS_AGO, MIDNIGHT, MOMENT_FORMAT } from './constants';
 
 /**
diff --git 
a/superset-frontend/src/explore/components/controls/DateFilterControl/utils/index.ts
 
b/superset-frontend/src/explore/components/controls/DateFilterControl/utils/index.ts
index bc555aa..542e8ee 100644
--- 
a/superset-frontend/src/explore/components/controls/DateFilterControl/utils/index.ts
+++ 
b/superset-frontend/src/explore/components/controls/DateFilterControl/utils/index.ts
@@ -18,3 +18,4 @@
  */
 export * from './dateParser';
 export * from './constants';
+export * from './dateFilterUtils';
diff --git 
a/superset-frontend/spec/javascripts/explore/components/DateFilterControl/utils_spec.ts
 
b/superset-frontend/src/explore/components/controls/DateFilterControl/utils/utils.test.ts
similarity index 88%
rename from 
superset-frontend/spec/javascripts/explore/components/DateFilterControl/utils_spec.ts
rename to 
superset-frontend/src/explore/components/controls/DateFilterControl/utils/utils.test.ts
index d44b08d..012aab6 100644
--- 
a/superset-frontend/spec/javascripts/explore/components/DateFilterControl/utils_spec.ts
+++ 
b/superset-frontend/src/explore/components/controls/DateFilterControl/utils/utils.test.ts
@@ -20,6 +20,8 @@
 import {
   customTimeRangeEncode,
   customTimeRangeDecode,
+  buildTimeRangeString,
+  formatTimeRange,
 } from 'src/explore/components/controls/DateFilterControl/utils';
 
 describe('Custom TimeRange', () => {
@@ -296,3 +298,37 @@ describe('Custom TimeRange', () => {
     });
   });
 });
+
+describe('buildTimeRangeString', () => {
+  it('generates proper time range string', () => {
+    expect(
+      buildTimeRangeString('2010-07-30T00:00:00', '2020-07-30T00:00:00'),
+    ).toBe('2010-07-30T00:00:00 : 2020-07-30T00:00:00');
+    expect(buildTimeRangeString('', '2020-07-30T00:00:00')).toBe(
+      ' : 2020-07-30T00:00:00',
+    );
+    expect(buildTimeRangeString('', '')).toBe(' : ');
+  });
+});
+
+describe('formatTimeRange', () => {
+  it('generates a readable time range', () => {
+    expect(formatTimeRange('Last 7 days')).toBe('Last 7 days');
+    expect(formatTimeRange('No filter')).toBe('No filter');
+    expect(formatTimeRange('Yesterday : Tomorrow')).toBe(
+      'Yesterday < col < Tomorrow',
+    );
+    expect(
+      formatTimeRange('2010-07-30T00:00:00 : 2020-07-30T00:00:00', [
+        'inclusive',
+        'exclusive',
+      ]),
+    ).toBe('2010-07-30 ≤ col < 2020-07-30');
+    expect(
+      formatTimeRange('2010-07-30T01:00:00 : ', ['exclusive', 'inclusive']),
+    ).toBe('2010-07-30T01:00:00 < col ≤ ∞');
+    expect(formatTimeRange(' : 2020-07-30T00:00:00')).toBe(
+      '-∞ < col < 2020-07-30',
+    );
+  });
+});

Reply via email to