diff --git a/plugins/cost-insights/src/api/CostInsightsApi.ts b/plugins/cost-insights/src/api/CostInsightsApi.ts index be5cd54fdb..8e165ba72a 100644 --- a/plugins/cost-insights/src/api/CostInsightsApi.ts +++ b/plugins/cost-insights/src/api/CostInsightsApi.ts @@ -18,13 +18,13 @@ import { createApiRef } from '@backstage/core'; import { Alert, Cost, - Duration, Group, Project, ProductCost, Maybe, MetricData, } from '../types'; +import { Duration } from '../utils/duration'; export type CostInsightsApi = { /** diff --git a/plugins/cost-insights/src/api/ExampleCostInsightsClient.ts b/plugins/cost-insights/src/api/ExampleCostInsightsClient.ts index 35bff86f7f..8f116afb65 100644 --- a/plugins/cost-insights/src/api/ExampleCostInsightsClient.ts +++ b/plugins/cost-insights/src/api/ExampleCostInsightsClient.ts @@ -23,11 +23,7 @@ import { ChangeStatistic, Cost, DateAggregation, - DEFAULT_DATE_FORMAT, - Duration, - exclusiveEndDateOf, Group, - inclusiveStartDateOf, Maybe, MetricData, ProductCost, @@ -38,6 +34,7 @@ import { UnlabeledDataflowAlert, UnlabeledDataflowData, } from '../types'; +import { DEFAULT_DATE_FORMAT, Duration, exclusiveEndDateOf, inclusiveStartDateOf } from '../utils/duration'; type IntervalFields = { duration: Duration; diff --git a/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx b/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx index 9dff164fdf..8744c5c6e7 100644 --- a/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx +++ b/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx @@ -17,7 +17,8 @@ import React, { PropsWithChildren } from 'react'; import { renderInTestApp } from '@backstage/test-utils'; import { CostGrowth } from './CostGrowth'; -import { Currency, Duration } from '../../types'; +import { Currency } from '../../types'; +import { Duration } from '../../utils/duration'; import { findAlways } from '../../utils/assert'; import { MockConfigProvider, MockCurrencyProvider } from '../../utils/tests'; import { defaultCurrencies, CurrencyType } from '../../utils/currency'; diff --git a/plugins/cost-insights/src/components/CostGrowth/CostGrowth.tsx b/plugins/cost-insights/src/components/CostGrowth/CostGrowth.tsx index 3dad0e780a..bdb4e00394 100644 --- a/plugins/cost-insights/src/components/CostGrowth/CostGrowth.tsx +++ b/plugins/cost-insights/src/components/CostGrowth/CostGrowth.tsx @@ -16,8 +16,9 @@ import React from 'react'; import classnames from 'classnames'; -import { ChangeStatistic, Duration } from '../../types'; +import { ChangeStatistic } from '../../types'; import { rateOf, CurrencyType } from '../../utils/currency'; +import { Duration } from '../../utils/duration'; import { growthOf, GrowthType, EngineerThreshold } from '../../utils/change'; import { useCostGrowthStyles as useStyles } from '../../utils/styles'; import { formatPercent, formatCurrency } from '../../utils/formatters'; diff --git a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewTooltip.tsx b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewTooltip.tsx index e0a9b9a9ea..51f2f12bdb 100644 --- a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewTooltip.tsx +++ b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewTooltip.tsx @@ -17,7 +17,7 @@ import React from 'react'; import moment from 'moment'; import { TooltipPayload, TooltipProps } from 'recharts'; import { Tooltip, TooltipItemProps } from '../../components/Tooltip'; -import { DEFAULT_DATE_FORMAT } from '../../types'; +import { DEFAULT_DATE_FORMAT } from '../../utils/duration'; export type CostOverviewTooltipProps = TooltipProps & { dataKeys: Array; diff --git a/plugins/cost-insights/src/components/CostOverviewCard/selector.tsx b/plugins/cost-insights/src/components/CostOverviewCard/selector.tsx index ef65f38dbb..3440500215 100644 --- a/plugins/cost-insights/src/components/CostOverviewCard/selector.tsx +++ b/plugins/cost-insights/src/components/CostOverviewCard/selector.tsx @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Duration, Maybe, PageFilters } from '../../types'; +import { Maybe, PageFilters } from '../../types'; +import { Duration } from '../../utils/duration'; import { MapFiltersToProps } from '../../hooks/useFilters'; type CostOverviewFilterProps = PageFilters & { diff --git a/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx b/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx index e2cf1b7480..628046f921 100644 --- a/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx +++ b/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx @@ -19,7 +19,8 @@ import { getByRole, waitFor } from '@testing-library/react'; import { renderInTestApp } from '@backstage/test-utils'; import UserEvent from '@testing-library/user-event'; import { PeriodSelect, getDefaultOptions } from './PeriodSelect'; -import { Duration, getDefaultPageFilters, Group } from '../../types'; +import { getDefaultPageFilters, Group } from '../../types'; +import { Duration } from '../../utils/duration'; import { MockBillingDateProvider } from '../../utils/tests'; const DefaultPageFilters = getDefaultPageFilters([{ id: 'tools' }] as Group[]); diff --git a/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.tsx b/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.tsx index 918200471f..f1a80a55f5 100644 --- a/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.tsx +++ b/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.tsx @@ -20,7 +20,7 @@ import { formatLastTwoLookaheadQuarters, formatLastTwoMonths, } from '../../utils/formatters'; -import { Duration } from '../../types'; +import { Duration } from '../../utils/duration'; import { findAlways } from '../../utils/assert'; import { useSelectStyles as useStyles } from '../../utils/styles'; import { useLastCompleteBillingDate } from '../../hooks'; diff --git a/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.test.tsx b/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.test.tsx index 9d1610e298..f27d7349a3 100644 --- a/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.test.tsx +++ b/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.test.tsx @@ -35,7 +35,8 @@ import { MockScrollProvider, MockLoadingProvider, } from '../../utils/tests'; -import { Duration, Product, ProductCost, ProductPeriod } from '../../types'; +import { Duration } from '../../utils/duration'; +import { Product, ProductCost, ProductPeriod } from '../../types'; const costInsightsApi = ( productCost: ProductCost, diff --git a/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.tsx b/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.tsx index 840c99522a..fec73f0c06 100644 --- a/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.tsx +++ b/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.tsx @@ -28,9 +28,10 @@ import { useLoading, useScroll, } from '../../hooks'; +import { Duration } from '../../utils/duration'; import { useProductInsightsCardStyles as useStyles } from '../../utils/styles'; import { mapFiltersToProps, mapLoadingToProps } from './selector'; -import { Duration, Maybe, Product, ProductCost } from '../../types'; +import { Maybe, Product, ProductCost } from '../../types'; import { pluralOf } from '../../utils/grammar'; import { formatPeriod } from '../../utils/formatters'; diff --git a/plugins/cost-insights/src/components/ProductInsightsCard/selector.ts b/plugins/cost-insights/src/components/ProductInsightsCard/selector.ts index efc8448034..6007070707 100644 --- a/plugins/cost-insights/src/components/ProductInsightsCard/selector.ts +++ b/plugins/cost-insights/src/components/ProductInsightsCard/selector.ts @@ -16,7 +16,8 @@ import { MapFiltersToProps } from '../../hooks/useFilters'; import { MapLoadingToProps } from '../../hooks/useLoading'; -import { Duration, PageFilters, ProductPeriod } from '../../types'; +import { PageFilters, ProductPeriod } from '../../types'; +import { Duration } from '../../utils/duration'; import { findAlways } from '../../utils/assert'; type ProductInsightsCardFilterProps = PageFilters & { diff --git a/plugins/cost-insights/src/components/ProjectGrowthAlertCard/ProjectGrowthAlertCard.tsx b/plugins/cost-insights/src/components/ProjectGrowthAlertCard/ProjectGrowthAlertCard.tsx index 4311bcc1bf..28e7948ca4 100644 --- a/plugins/cost-insights/src/components/ProjectGrowthAlertCard/ProjectGrowthAlertCard.tsx +++ b/plugins/cost-insights/src/components/ProjectGrowthAlertCard/ProjectGrowthAlertCard.tsx @@ -20,7 +20,8 @@ import { Box } from '@material-ui/core'; import { InfoCard } from '@backstage/core'; import { ResourceGrowthBarChart } from '../ResourceGrowthBarChart'; import { ResourceGrowthBarChartLegend } from '../ResourceGrowthBarChartLegend'; -import { Duration, ProjectGrowthData } from '../../types'; +import { ProjectGrowthData } from '../../types'; +import { Duration } from '../../utils/duration'; import { pluralOf } from '../../utils/grammar'; type ProjectGrowthAlertProps = { @@ -31,9 +32,8 @@ export const ProjectGrowthAlertCard = ({ alert }: ProjectGrowthAlertProps) => { const [costStart, costEnd] = alert.aggregation; const subheader = ` - ${alert.products.length} ${pluralOf(alert.products.length, 'product')}${ - alert.products.length > 1 ? ', sorted by cost' : '' - }`; + ${alert.products.length} ${pluralOf(alert.products.length, 'product')}${alert.products.length > 1 ? ', sorted by cost' : '' + }`; const previousName = moment(alert.periodStart, 'YYYY-[Q]Q').format( '[Q]Q YYYY', ); diff --git a/plugins/cost-insights/src/components/ProjectGrowthInstructionsPage/ProjectGrowthInstructionsPage.tsx b/plugins/cost-insights/src/components/ProjectGrowthInstructionsPage/ProjectGrowthInstructionsPage.tsx index 3c2d241222..074d3e2b92 100644 --- a/plugins/cost-insights/src/components/ProjectGrowthInstructionsPage/ProjectGrowthInstructionsPage.tsx +++ b/plugins/cost-insights/src/components/ProjectGrowthInstructionsPage/ProjectGrowthInstructionsPage.tsx @@ -18,9 +18,9 @@ import React from 'react'; import { Box, Typography } from '@material-ui/core'; import { InfoCard } from '@backstage/core'; import { AlertInstructionsLayout } from '../AlertInstructionsLayout'; +import { Duration } from '../../utils/duration'; import { Alert, - Duration, Entity, Product, ProjectGrowthAlert, diff --git a/plugins/cost-insights/src/components/ResourceGrowthBarChartLegend/ResourceGrowthBarChartLegend.test.tsx b/plugins/cost-insights/src/components/ResourceGrowthBarChartLegend/ResourceGrowthBarChartLegend.test.tsx index 9599b3cca1..bf5c1021cc 100644 --- a/plugins/cost-insights/src/components/ResourceGrowthBarChartLegend/ResourceGrowthBarChartLegend.test.tsx +++ b/plugins/cost-insights/src/components/ResourceGrowthBarChartLegend/ResourceGrowthBarChartLegend.test.tsx @@ -17,7 +17,7 @@ import React, { PropsWithChildren } from 'react'; import { renderInTestApp } from '@backstage/test-utils'; import { ResourceGrowthBarChartLegend } from './ResourceGrowthBarChartLegend'; -import { Duration } from '../../types'; +import { Duration } from '../../utils/duration'; import { defaultCurrencies } from '../../utils/currency'; import { findAlways } from '../../utils/assert'; import { MockConfigProvider, MockCurrencyProvider } from '../../utils/tests'; diff --git a/plugins/cost-insights/src/components/ResourceGrowthBarChartLegend/ResourceGrowthBarChartLegend.tsx b/plugins/cost-insights/src/components/ResourceGrowthBarChartLegend/ResourceGrowthBarChartLegend.tsx index 6b5ce17c95..0c281e6266 100644 --- a/plugins/cost-insights/src/components/ResourceGrowthBarChartLegend/ResourceGrowthBarChartLegend.tsx +++ b/plugins/cost-insights/src/components/ResourceGrowthBarChartLegend/ResourceGrowthBarChartLegend.tsx @@ -19,7 +19,8 @@ import { Box, useTheme } from '@material-ui/core'; import { LegendItem } from '../LegendItem'; import { CostGrowth } from '../CostGrowth'; import { currencyFormatter } from '../../utils/formatters'; -import { ChangeStatistic, CostInsightsTheme, Duration } from '../../types'; +import { Duration } from '../../utils/duration'; +import { ChangeStatistic, CostInsightsTheme } from '../../types'; export type ResourceGrowthBarChartLegendProps = { change: ChangeStatistic; diff --git a/plugins/cost-insights/src/index.ts b/plugins/cost-insights/src/index.ts index 71cc66dba6..661aa01db3 100644 --- a/plugins/cost-insights/src/index.ts +++ b/plugins/cost-insights/src/index.ts @@ -19,4 +19,5 @@ export * from './api'; export * from './components'; export { useCurrency } from './hooks'; export * from './types'; +export { Duration } from './utils/duration'; export * from './utils/tests'; diff --git a/plugins/cost-insights/src/types/Filters.ts b/plugins/cost-insights/src/types/Filters.ts index b1fbbb2848..e72e850c61 100644 --- a/plugins/cost-insights/src/types/Filters.ts +++ b/plugins/cost-insights/src/types/Filters.ts @@ -15,8 +15,8 @@ */ import { Maybe } from './Maybe'; -import { Duration } from './Duration'; import { Group } from './Group'; +import { Duration } from '../utils/duration'; export interface PageFilters { group: Maybe; diff --git a/plugins/cost-insights/src/types/index.ts b/plugins/cost-insights/src/types/index.ts index 398110ec80..cced505f86 100644 --- a/plugins/cost-insights/src/types/index.ts +++ b/plugins/cost-insights/src/types/index.ts @@ -19,7 +19,6 @@ export * from './ChangeStatistic'; export * from './ChartData'; export * from './Cost'; export * from './DateAggregation'; -export * from './Duration'; export * from './Currency'; export * from './Entity'; export * from './Icon'; diff --git a/plugins/cost-insights/src/utils/currency.ts b/plugins/cost-insights/src/utils/currency.ts index 439dbb70c3..7f43acc66b 100644 --- a/plugins/cost-insights/src/utils/currency.ts +++ b/plugins/cost-insights/src/utils/currency.ts @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Currency, Duration } from '../types'; +import { Currency } from '../types'; +import { Duration } from '../utils/duration'; import { assertNever } from '../utils/assert'; export enum CurrencyType { diff --git a/plugins/cost-insights/src/types/Duration.test.ts b/plugins/cost-insights/src/utils/duration.test.ts similarity index 98% rename from plugins/cost-insights/src/types/Duration.test.ts rename to plugins/cost-insights/src/utils/duration.test.ts index 4ab84de974..675a90b54a 100644 --- a/plugins/cost-insights/src/types/Duration.test.ts +++ b/plugins/cost-insights/src/utils/duration.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Duration, inclusiveEndDateOf, inclusiveStartDateOf } from './Duration'; +import { Duration, inclusiveEndDateOf, inclusiveStartDateOf } from './duration'; const lastCompleteBillingDate = '2020-06-05'; diff --git a/plugins/cost-insights/src/types/Duration.ts b/plugins/cost-insights/src/utils/duration.ts similarity index 100% rename from plugins/cost-insights/src/types/Duration.ts rename to plugins/cost-insights/src/utils/duration.ts diff --git a/plugins/cost-insights/src/utils/formatters.test.ts b/plugins/cost-insights/src/utils/formatters.test.ts index 69e9086be1..7be6e1dffb 100644 --- a/plugins/cost-insights/src/utils/formatters.test.ts +++ b/plugins/cost-insights/src/utils/formatters.test.ts @@ -19,7 +19,7 @@ import { lengthyCurrencyFormatter, quarterOf, } from './formatters'; -import { Duration } from '../types'; +import { Duration } from '../utils/duration'; Date.now = jest.fn(() => new Date(Date.parse('2019-12-07')).valueOf()); diff --git a/plugins/cost-insights/src/utils/formatters.ts b/plugins/cost-insights/src/utils/formatters.ts index 44c7517351..48b0b77188 100644 --- a/plugins/cost-insights/src/utils/formatters.ts +++ b/plugins/cost-insights/src/utils/formatters.ts @@ -19,7 +19,7 @@ import { Duration, inclusiveEndDateOf, inclusiveStartDateOf, -} from '../types/Duration'; +} from '../utils/duration'; import { pluralOf } from '../utils/grammar'; export type Period = { diff --git a/plugins/cost-insights/src/utils/history.ts b/plugins/cost-insights/src/utils/history.ts index 90df574acf..3b55aeebce 100644 --- a/plugins/cost-insights/src/utils/history.ts +++ b/plugins/cost-insights/src/utils/history.ts @@ -16,7 +16,8 @@ import qs from 'qs'; import * as yup from 'yup'; -import { Group, PageFilters, getDefaultPageFilters, Duration } from '../types'; +import { Group, PageFilters, getDefaultPageFilters } from '../types'; +import { Duration } from '../utils/duration'; import { ConfigContextProps } from '../hooks/useConfig'; const schema = yup diff --git a/plugins/cost-insights/src/utils/mockData.ts b/plugins/cost-insights/src/utils/mockData.ts index 9609da6ce8..91cd2f8ad2 100644 --- a/plugins/cost-insights/src/utils/mockData.ts +++ b/plugins/cost-insights/src/utils/mockData.ts @@ -14,8 +14,9 @@ * limitations under the License. */ +import { Config } from '@backstage/config'; +import { ConfigApi } from '@backstage/core'; import { - Duration, Entity, Product, ProductCost, @@ -29,8 +30,7 @@ import { getDefaultState as getDefaultLoadingState, } from '../utils/loading'; import { findAlways } from '../utils/assert'; -import { Config } from '@backstage/config'; -import { ConfigApi } from '@backstage/core'; +import { Duration } from '../utils/duration'; type mockAlertRenderer = (alert: T) => T; type mockEntityRenderer = (entity: T) => T; diff --git a/plugins/cost-insights/src/utils/tests.tsx b/plugins/cost-insights/src/utils/tests.tsx index db47bd72bd..09eab89139 100644 --- a/plugins/cost-insights/src/utils/tests.tsx +++ b/plugins/cost-insights/src/utils/tests.tsx @@ -32,7 +32,8 @@ import { BillingDateContextProps, } from '../hooks/useLastCompleteBillingDate'; import { ScrollContext, ScrollContextProps } from '../hooks/useScroll'; -import { Duration, Group } from '../types'; +import { Duration } from '../utils/duration'; +import { Group } from '../types'; /* Mock Providers and types are exposed publicly to allow users to test custom implementations