diff --git a/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx b/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx
index ed81f657c5..2cefcbba1e 100644
--- a/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx
+++ b/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx
@@ -18,13 +18,12 @@ import React, { PropsWithChildren } from 'react';
import { renderInTestApp } from '@backstage/test-utils';
import { CostGrowth } from './CostGrowth';
import {
- defaultCurrencies,
Currency,
- CurrencyType,
Duration,
findAlways,
} from '../../types';
import { MockConfigProvider, MockCurrencyProvider } from '../../utils/tests';
+import { defaultCurrencies, CurrencyType } from '../../utils/currency';
const engineers = findAlways(defaultCurrencies, c => c.kind === null);
const usd = findAlways(defaultCurrencies, c => c.kind === CurrencyType.USD);
@@ -41,10 +40,10 @@ const MockContext = ({
currency: Currency;
engineerCost: number;
}>) => (
-
- {children}
-
-);
+
+ {children}
+
+ );
describe.each`
engineerCost | ratio | amount | expected
diff --git a/plugins/cost-insights/src/components/ProjectGrowthAlertCard/ProjectGrowthAlertCard.test.tsx b/plugins/cost-insights/src/components/ProjectGrowthAlertCard/ProjectGrowthAlertCard.test.tsx
index 4b5da409a4..3e2fc8d32e 100644
--- a/plugins/cost-insights/src/components/ProjectGrowthAlertCard/ProjectGrowthAlertCard.test.tsx
+++ b/plugins/cost-insights/src/components/ProjectGrowthAlertCard/ProjectGrowthAlertCard.test.tsx
@@ -23,7 +23,8 @@ import {
MockConfigProvider,
MockBillingDateProvider,
} from '../../utils/tests';
-import { AlertCost, defaultCurrencies, findAlways } from '../../types';
+import { AlertCost, findAlways } from '../../types';
+import { defaultCurrencies } from '../../utils/currency';
const engineers = findAlways(defaultCurrencies, c => c.kind === null);
diff --git a/plugins/cost-insights/src/hooks/useConfig.tsx b/plugins/cost-insights/src/hooks/useConfig.tsx
index f63b9228a9..450ab545ac 100644
--- a/plugins/cost-insights/src/hooks/useConfig.tsx
+++ b/plugins/cost-insights/src/hooks/useConfig.tsx
@@ -23,9 +23,10 @@ import React, {
} from 'react';
import { configApiRef, useApi } from '@backstage/core';
import { Config as BackstageConfig } from '@backstage/config';
-import { Currency, defaultCurrencies, Icon, Metric, Product } from '../types';
+import { Currency, Icon, Metric, Product } from '../types';
import { getIcon } from '../utils/navigation';
import { validateMetrics } from '../utils/config';
+import { defaultCurrencies } from '../utils/currency';
/*
* Config schema 2020-10-15
diff --git a/plugins/cost-insights/src/hooks/useCurrency.tsx b/plugins/cost-insights/src/hooks/useCurrency.tsx
index 34a4f54d5f..b5079d37f1 100644
--- a/plugins/cost-insights/src/hooks/useCurrency.tsx
+++ b/plugins/cost-insights/src/hooks/useCurrency.tsx
@@ -20,7 +20,8 @@ import React, {
useContext,
PropsWithChildren,
} from 'react';
-import { Currency, defaultCurrencies, findAlways } from '../types';
+import { Currency, findAlways } from '../types';
+import { defaultCurrencies } from '../utils/currency';
export type CurrencyContextProps = {
currency: Currency;
diff --git a/plugins/cost-insights/src/hooks/useGroups.tsx b/plugins/cost-insights/src/hooks/useGroups.tsx
index 13cec25017..f7adc84a57 100644
--- a/plugins/cost-insights/src/hooks/useGroups.tsx
+++ b/plugins/cost-insights/src/hooks/useGroups.tsx
@@ -26,6 +26,8 @@ import { costInsightsApiRef } from '../api';
import { MapLoadingToProps, useLoading } from './useLoading';
import { DefaultLoadingAction, Group, Maybe } from '../types';
+console.log(DefaultLoadingAction)
+
type GroupsProviderLoadingProps = {
dispatchLoadingGroups: (isLoading: boolean) => void;
};
diff --git a/plugins/cost-insights/src/types/Currency.ts b/plugins/cost-insights/src/types/Currency.ts
index 633e405893..16ba432be8 100644
--- a/plugins/cost-insights/src/types/Currency.ts
+++ b/plugins/cost-insights/src/types/Currency.ts
@@ -13,15 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import { Duration } from './Duration';
-import { assertNever } from './Maybe';
-
-export enum CurrencyType {
- USD = 'USD',
- CarbonOffsetTons = 'CARBON_OFFSET_TONS',
- Beers = 'BEERS',
- IceCream = 'PINTS_OF_ICE_CREAM',
-}
export interface Currency {
kind: string | null;
@@ -30,49 +21,3 @@ export interface Currency {
prefix?: string;
rate?: number;
}
-
-export const rateOf = (cost: number, duration: Duration) => {
- switch (duration) {
- case Duration.P1M:
- case Duration.P30D:
- return cost / 12;
- case Duration.P90D:
- case Duration.P3M:
- return cost / 4;
- default:
- return assertNever(duration);
- }
-};
-
-export const defaultCurrencies: Currency[] = [
- {
- kind: null,
- label: 'Engineers 🛠',
- unit: 'engineer',
- },
- {
- kind: CurrencyType.USD,
- label: 'US Dollars 💵',
- unit: 'dollar',
- prefix: '$',
- rate: 1,
- },
- {
- kind: CurrencyType.CarbonOffsetTons,
- label: 'Carbon Offset Tons ♻️⚖️s',
- unit: 'carbon offset ton',
- rate: 3.5,
- },
- {
- kind: CurrencyType.Beers,
- label: 'Beers 🍺',
- unit: 'beer',
- rate: 4.5,
- },
- {
- kind: CurrencyType.IceCream,
- label: 'Pints of Ice Cream 🍦',
- unit: 'ice cream pint',
- rate: 5.5,
- },
-];
diff --git a/plugins/cost-insights/src/types/Loading.ts b/plugins/cost-insights/src/types/Loading.ts
index 8bc0c4eaef..741453369c 100644
--- a/plugins/cost-insights/src/types/Loading.ts
+++ b/plugins/cost-insights/src/types/Loading.ts
@@ -15,50 +15,3 @@
*/
export type Loading = Record;
-
-export enum DefaultLoadingAction {
- UserGroups = 'user-groups',
- LastCompleteBillingDate = 'billing-date',
- CostInsightsInitial = 'cost-insights-initial',
- CostInsightsPage = 'cost-insights-page',
-}
-
-export const INITIAL_LOADING_ACTIONS = [
- DefaultLoadingAction.UserGroups,
- DefaultLoadingAction.CostInsightsInitial,
-];
-
-export const getDefaultState = (loadingActions: string[]): Loading => {
- return loadingActions.reduce(
- (defaultState, action) => ({ ...defaultState, [action]: true }),
- {},
- );
-};
-
-export const getResetState = (loadingActions: string[]): Loading => {
- return loadingActions.reduce(
- (defaultState, action) => ({ ...defaultState, [action]: false }),
- {},
- );
-};
-
-export const getResetStateWithoutInitial = (
- loadingActions: string[],
-): Loading => {
- return loadingActions.reduce((defaultState, action) => {
- const loadingActionState = (INITIAL_LOADING_ACTIONS as string[]).includes(
- action,
- )
- ? false
- : true;
- return { ...defaultState, [action]: loadingActionState };
- }, {});
-};
-
-export function getLoadingActions(products: string[]): string[] {
- return ([
- DefaultLoadingAction.UserGroups,
- DefaultLoadingAction.CostInsightsInitial,
- DefaultLoadingAction.CostInsightsPage,
- ] as string[]).concat(products);
-}
diff --git a/plugins/cost-insights/src/utils/currency.ts b/plugins/cost-insights/src/utils/currency.ts
new file mode 100644
index 0000000000..c15af4d80d
--- /dev/null
+++ b/plugins/cost-insights/src/utils/currency.ts
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2020 Spotify AB
+ *
+ * Licensed 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 { assertNever, Currency, Duration } from '../types';
+
+export enum CurrencyType {
+ USD = 'USD',
+ CarbonOffsetTons = 'CARBON_OFFSET_TONS',
+ Beers = 'BEERS',
+ IceCream = 'PINTS_OF_ICE_CREAM',
+}
+
+export const rateOf = (cost: number, duration: Duration) => {
+ switch (duration) {
+ case Duration.P1M:
+ case Duration.P30D:
+ return cost / 12;
+ case Duration.P90D:
+ case Duration.P3M:
+ return cost / 4;
+ default:
+ return assertNever(duration);
+ }
+};
+
+export const defaultCurrencies: Currency[] = [
+ {
+ kind: null,
+ label: 'Engineers 🛠',
+ unit: 'engineer',
+ },
+ {
+ kind: CurrencyType.USD,
+ label: 'US Dollars 💵',
+ unit: 'dollar',
+ prefix: '$',
+ rate: 1,
+ },
+ {
+ kind: CurrencyType.CarbonOffsetTons,
+ label: 'Carbon Offset Tons ♻️⚖️s',
+ unit: 'carbon offset ton',
+ rate: 3.5,
+ },
+ {
+ kind: CurrencyType.Beers,
+ label: 'Beers 🍺',
+ unit: 'beer',
+ rate: 4.5,
+ },
+ {
+ kind: CurrencyType.IceCream,
+ label: 'Pints of Ice Cream 🍦',
+ unit: 'ice cream pint',
+ rate: 5.5,
+ },
+];
diff --git a/plugins/cost-insights/src/utils/loading.ts b/plugins/cost-insights/src/utils/loading.ts
new file mode 100644
index 0000000000..7a0225154f
--- /dev/null
+++ b/plugins/cost-insights/src/utils/loading.ts
@@ -0,0 +1,48 @@
+import { Loading } from '../types';
+
+export enum DefaultLoadingAction {
+ UserGroups = 'user-groups',
+ LastCompleteBillingDate = 'billing-date',
+ CostInsightsInitial = 'cost-insights-initial',
+ CostInsightsPage = 'cost-insights-page',
+}
+
+export const INITIAL_LOADING_ACTIONS = [
+ DefaultLoadingAction.UserGroups,
+ DefaultLoadingAction.CostInsightsInitial,
+];
+
+export const getDefaultState = (loadingActions: string[]): Loading => {
+ return loadingActions.reduce(
+ (defaultState, action) => ({ ...defaultState, [action]: true }),
+ {},
+ );
+};
+
+export const getResetState = (loadingActions: string[]): Loading => {
+ return loadingActions.reduce(
+ (defaultState, action) => ({ ...defaultState, [action]: false }),
+ {},
+ );
+};
+
+export const getResetStateWithoutInitial = (
+ loadingActions: string[],
+): Loading => {
+ return loadingActions.reduce((defaultState, action) => {
+ const loadingActionState = (INITIAL_LOADING_ACTIONS as string[]).includes(
+ action,
+ )
+ ? false
+ : true;
+ return { ...defaultState, [action]: loadingActionState };
+ }, {});
+};
+
+export function getLoadingActions(products: string[]): string[] {
+ return ([
+ DefaultLoadingAction.UserGroups,
+ DefaultLoadingAction.CostInsightsInitial,
+ DefaultLoadingAction.CostInsightsPage,
+ ] as string[]).concat(products);
+}