migration duration utils

This commit is contained in:
Ryan Vazquez
2020-10-28 11:34:40 -04:00
parent 78ffb124dc
commit cb4568f665
26 changed files with 40 additions and 32 deletions
@@ -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 = {
/**
@@ -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;
@@ -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';
@@ -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';
@@ -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<string>;
@@ -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 & {
@@ -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[]);
@@ -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';
@@ -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,
@@ -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';
@@ -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 & {
@@ -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',
);
@@ -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,
@@ -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';
@@ -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;
+1
View File
@@ -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';
+1 -1
View File
@@ -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<string>;
-1
View File
@@ -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';
+2 -1
View File
@@ -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 {
@@ -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';
@@ -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());
@@ -19,7 +19,7 @@ import {
Duration,
inclusiveEndDateOf,
inclusiveStartDateOf,
} from '../types/Duration';
} from '../utils/duration';
import { pluralOf } from '../utils/grammar';
export type Period = {
+2 -1
View File
@@ -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
+3 -3
View File
@@ -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<T> = (alert: T) => T;
type mockEntityRenderer<T> = (entity: T) => T;
+2 -1
View File
@@ -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