From 6b0b3dd8b53774342afba1bbd7db3284ecdb9652 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Wed, 25 May 2022 14:20:58 -0300 Subject: [PATCH] chore: Moves date utils to utils folder --- .../src/SqlLab/actions/sqlLab.js | 2 +- .../SqlLab/components/QuerySearch/index.tsx | 2 +- .../SqlLab/components/QueryTable/index.tsx | 2 +- .../src/SqlLab/reducers/sqlLab.js | 2 +- .../src/SqlLab/reducers/sqlLab.test.js | 2 +- .../src/components/Chart/chartReducer.ts | 2 +- .../src/components/Timer/Timer.test.tsx | 2 +- .../src/components/Timer/index.tsx | 2 +- .../src/dashboard/actions/sliceEntities.js | 5 ++- .../src/explore/controlPanels/Separator.js | 2 +- .../src/explore/controlPanels/sections.tsx | 2 +- superset-frontend/src/explore/controls.jsx | 2 +- .../src/explore/exploreUtils/index.js | 4 ++ superset-frontend/src/modules/utils.js | 43 ------------------- superset-frontend/src/modules/utils.test.jsx | 40 ----------------- .../src/{modules => utils}/dates.js | 0 .../src/{modules => utils}/dates.test.js | 2 +- .../src/views/CRUD/alert/ExecutionLog.tsx | 2 +- 18 files changed, 21 insertions(+), 97 deletions(-) delete mode 100644 superset-frontend/src/modules/utils.js delete mode 100644 superset-frontend/src/modules/utils.test.jsx rename superset-frontend/src/{modules => utils}/dates.js (100%) rename superset-frontend/src/{modules => utils}/dates.test.js (98%) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index b950d0e37737f..15e41fada5533 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -23,7 +23,7 @@ import invert from 'lodash/invert'; import mapKeys from 'lodash/mapKeys'; import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags'; -import { now } from 'src/modules/dates'; +import { now } from 'src/utils/dates'; import { addDangerToast as addDangerToastAction, addInfoToast as addInfoToastAction, diff --git a/superset-frontend/src/SqlLab/components/QuerySearch/index.tsx b/superset-frontend/src/SqlLab/components/QuerySearch/index.tsx index 762f35e89880e..67d25c48b3cdc 100644 --- a/superset-frontend/src/SqlLab/components/QuerySearch/index.tsx +++ b/superset-frontend/src/SqlLab/components/QuerySearch/index.tsx @@ -27,7 +27,7 @@ import { epochTimeXHoursAgo, epochTimeXDaysAgo, epochTimeXYearsAgo, -} from 'src/modules/dates'; +} from 'src/utils/dates'; import AsyncSelect from 'src/components/AsyncSelect'; import { Query } from 'src/SqlLab/types'; import { STATUS_OPTIONS, TIME_OPTIONS } from 'src/SqlLab/constants'; diff --git a/superset-frontend/src/SqlLab/components/QueryTable/index.tsx b/superset-frontend/src/SqlLab/components/QueryTable/index.tsx index a50779d6eb9c1..e533477c47614 100644 --- a/superset-frontend/src/SqlLab/components/QueryTable/index.tsx +++ b/superset-frontend/src/SqlLab/components/QueryTable/index.tsx @@ -25,7 +25,7 @@ import { t, useTheme } from '@superset-ui/core'; import { useSelector } from 'react-redux'; import TableView from 'src/components/TableView'; import Button from 'src/components/Button'; -import { fDuration } from 'src/modules/dates'; +import { fDuration } from 'src/utils/dates'; import Icons from 'src/components/Icons'; import { Tooltip } from 'src/components/Tooltip'; import { Query, RootState } from 'src/SqlLab/types'; diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.js b/superset-frontend/src/SqlLab/reducers/sqlLab.js index 923caaf96152d..b68199270e7fb 100644 --- a/superset-frontend/src/SqlLab/reducers/sqlLab.js +++ b/superset-frontend/src/SqlLab/reducers/sqlLab.js @@ -20,7 +20,7 @@ import { t } from '@superset-ui/core'; import getInitialState from './getInitialState'; import * as actions from '../actions/sqlLab'; -import { now } from '../../modules/dates'; +import { now } from '../../utils/dates'; import { addToObject, alterInObject, diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.test.js b/superset-frontend/src/SqlLab/reducers/sqlLab.test.js index cac9376ef52cc..067cba3070ac9 100644 --- a/superset-frontend/src/SqlLab/reducers/sqlLab.test.js +++ b/superset-frontend/src/SqlLab/reducers/sqlLab.test.js @@ -18,7 +18,7 @@ */ import sqlLabReducer from 'src/SqlLab/reducers/sqlLab'; import * as actions from 'src/SqlLab/actions/sqlLab'; -import { now } from 'src/modules/dates'; +import { now } from 'src/utils/dates'; import { table, initialState as mockState } from '../fixtures'; const initialState = mockState.sqlLab; diff --git a/superset-frontend/src/components/Chart/chartReducer.ts b/superset-frontend/src/components/Chart/chartReducer.ts index d6d612fbfaf25..010140584c2b1 100644 --- a/superset-frontend/src/components/Chart/chartReducer.ts +++ b/superset-frontend/src/components/Chart/chartReducer.ts @@ -22,7 +22,7 @@ import { HYDRATE_DASHBOARD } from 'src/dashboard/actions/hydrate'; import { DatasourcesAction } from 'src/dashboard/actions/datasources'; import { ChartState } from 'src/explore/types'; import { getFormDataFromControls } from 'src/explore/controlUtils'; -import { now } from 'src/modules/dates'; +import { now } from 'src/utils/dates'; import * as actions from './chartAction'; export const chart: ChartState = { diff --git a/superset-frontend/src/components/Timer/Timer.test.tsx b/superset-frontend/src/components/Timer/Timer.test.tsx index f37004af838f8..a71d0f292fcca 100644 --- a/superset-frontend/src/components/Timer/Timer.test.tsx +++ b/superset-frontend/src/components/Timer/Timer.test.tsx @@ -22,7 +22,7 @@ import React from 'react'; import { render, sleep, waitFor } from 'spec/helpers/testing-library'; import Timer, { TimerProps } from 'src/components/Timer'; -import { now } from 'src/modules/dates'; +import { now } from 'src/utils/dates'; function parseTime(text?: string | null) { return !!text && Number(text.replace(/:/g, '')); diff --git a/superset-frontend/src/components/Timer/index.tsx b/superset-frontend/src/components/Timer/index.tsx index 612c78d12dfc6..b03e1a831f8e8 100644 --- a/superset-frontend/src/components/Timer/index.tsx +++ b/superset-frontend/src/components/Timer/index.tsx @@ -20,7 +20,7 @@ import React, { useEffect, useRef, useState } from 'react'; import { styled } from '@superset-ui/core'; import Label, { Type } from 'src/components/Label'; -import { now, fDuration } from 'src/modules/dates'; +import { now, fDuration } from 'src/utils/dates'; export interface TimerProps { endTime?: number; diff --git a/superset-frontend/src/dashboard/actions/sliceEntities.js b/superset-frontend/src/dashboard/actions/sliceEntities.js index 8fc85c9161ffd..be111605202cd 100644 --- a/superset-frontend/src/dashboard/actions/sliceEntities.js +++ b/superset-frontend/src/dashboard/actions/sliceEntities.js @@ -21,7 +21,6 @@ import { t, SupersetClient } from '@superset-ui/core'; import rison from 'rison'; import { addDangerToast } from 'src/components/MessageToasts/actions'; -import { getDatasourceParameter } from 'src/modules/utils'; import { getClientErrorObject } from 'src/utils/getClientErrorObject'; export const SET_ALL_SLICES = 'SET_ALL_SLICES'; @@ -39,6 +38,10 @@ export function fetchAllSlicesFailed(error) { return { type: FETCH_ALL_SLICES_FAILED, payload: { error } }; } +export function getDatasourceParameter(datasourceId, datasourceType) { + return `${datasourceId}__${datasourceType}`; +} + const FETCH_SLICES_PAGE_SIZE = 200; export function fetchAllSlices(userId, excludeFilterBox = false) { return (dispatch, getState) => { diff --git a/superset-frontend/src/explore/controlPanels/Separator.js b/superset-frontend/src/explore/controlPanels/Separator.js index 588adea2aae7c..2be8594690d05 100644 --- a/superset-frontend/src/explore/controlPanels/Separator.js +++ b/superset-frontend/src/explore/controlPanels/Separator.js @@ -17,7 +17,7 @@ * under the License. */ import { t, validateNonEmpty } from '@superset-ui/core'; -import { formatSelectOptions } from 'src/modules/utils'; +import { formatSelectOptions } from 'src/explore/exploreUtils'; export default { controlPanelSections: [ diff --git a/superset-frontend/src/explore/controlPanels/sections.tsx b/superset-frontend/src/explore/controlPanels/sections.tsx index a6adbf3af23c3..be21747ed63e6 100644 --- a/superset-frontend/src/explore/controlPanels/sections.tsx +++ b/superset-frontend/src/explore/controlPanels/sections.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { t } from '@superset-ui/core'; import { ControlPanelSectionConfig } from '@superset-ui/chart-controls'; -import { formatSelectOptions } from 'src/modules/utils'; +import { formatSelectOptions } from 'src/explore/exploreUtils'; export const druidTimeSeries: ControlPanelSectionConfig = { label: t('Time'), diff --git a/superset-frontend/src/explore/controls.jsx b/superset-frontend/src/explore/controls.jsx index daba78ca6d243..21134d48f3178 100644 --- a/superset-frontend/src/explore/controls.jsx +++ b/superset-frontend/src/explore/controls.jsx @@ -64,7 +64,7 @@ import { legacyValidateInteger, validateNonEmpty, } from '@superset-ui/core'; -import { formatSelectOptions } from 'src/modules/utils'; +import { formatSelectOptions } from 'src/explore/exploreUtils'; import { TIME_FILTER_LABELS } from './constants'; import { StyledColumnOption } from './components/optionRenderers'; diff --git a/superset-frontend/src/explore/exploreUtils/index.js b/superset-frontend/src/explore/exploreUtils/index.js index 79bcb1a36241e..d5c3d06d5f6b6 100644 --- a/superset-frontend/src/explore/exploreUtils/index.js +++ b/superset-frontend/src/explore/exploreUtils/index.js @@ -348,3 +348,7 @@ export const getSimpleSQLExpression = (subject, operator, comparator) => { } return expression; }; + +export function formatSelectOptions(options) { + return options.map(opt => [opt, opt.toString()]); +} diff --git a/superset-frontend/src/modules/utils.js b/superset-frontend/src/modules/utils.js deleted file mode 100644 index 07dc43856e522..0000000000000 --- a/superset-frontend/src/modules/utils.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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. - */ -/* eslint camelcase: 0 */ - -export function formatSelectOptions(options) { - return options.map(opt => [opt, opt.toString()]); -} - -export function getDatasourceParameter(datasourceId, datasourceType) { - return `${datasourceId}__${datasourceType}`; -} - -export function mainMetric(savedMetrics) { - // Using 'count' as default metric if it exists, otherwise using whatever one shows up first - let metric; - if (savedMetrics && savedMetrics.length > 0) { - savedMetrics.forEach(m => { - if (m.metric_name === 'count') { - metric = 'count'; - } - }); - if (!metric) { - metric = savedMetrics[0].metric_name; - } - } - return metric; -} diff --git a/superset-frontend/src/modules/utils.test.jsx b/superset-frontend/src/modules/utils.test.jsx deleted file mode 100644 index 0c8515f8ae0b4..0000000000000 --- a/superset-frontend/src/modules/utils.test.jsx +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 { mainMetric } from 'src/modules/utils'; - -describe('utils', () => { - describe('mainMetric', () => { - it('is null when no options', () => { - expect(mainMetric([])).toBeUndefined(); - expect(mainMetric(null)).toBeUndefined(); - }); - it('prefers the "count" metric when first', () => { - const metrics = [{ metric_name: 'count' }, { metric_name: 'foo' }]; - expect(mainMetric(metrics)).toBe('count'); - }); - it('prefers the "count" metric when not first', () => { - const metrics = [{ metric_name: 'foo' }, { metric_name: 'count' }]; - expect(mainMetric(metrics)).toBe('count'); - }); - it('selects the first metric when "count" is not an option', () => { - const metrics = [{ metric_name: 'foo' }, { metric_name: 'not_count' }]; - expect(mainMetric(metrics)).toBe('foo'); - }); - }); -}); diff --git a/superset-frontend/src/modules/dates.js b/superset-frontend/src/utils/dates.js similarity index 100% rename from superset-frontend/src/modules/dates.js rename to superset-frontend/src/utils/dates.js diff --git a/superset-frontend/src/modules/dates.test.js b/superset-frontend/src/utils/dates.test.js similarity index 98% rename from superset-frontend/src/modules/dates.test.js rename to superset-frontend/src/utils/dates.test.js index 49325f64f48bf..62973693ea572 100644 --- a/superset-frontend/src/modules/dates.test.js +++ b/superset-frontend/src/utils/dates.test.js @@ -22,7 +22,7 @@ import { epochTimeXHoursAgo, epochTimeXDaysAgo, epochTimeXYearsAgo, -} from 'src/modules/dates'; +} from 'src/utils/dates'; describe('fDuration', () => { it('is a function', () => { diff --git a/superset-frontend/src/views/CRUD/alert/ExecutionLog.tsx b/superset-frontend/src/views/CRUD/alert/ExecutionLog.tsx index 8bdae92eb53d0..37f3e7c2add6d 100644 --- a/superset-frontend/src/views/CRUD/alert/ExecutionLog.tsx +++ b/superset-frontend/src/views/CRUD/alert/ExecutionLog.tsx @@ -25,7 +25,7 @@ import ListView from 'src/components/ListView'; import { Tooltip } from 'src/components/Tooltip'; import SubMenu from 'src/views/components/SubMenu'; import withToasts from 'src/components/MessageToasts/withToasts'; -import { fDuration } from 'src/modules/dates'; +import { fDuration } from 'src/utils/dates'; import AlertStatusIcon from 'src/views/CRUD/alert/components/AlertStatusIcon'; import { useListViewResource,