diff --git a/plugins/cost-insights/dev/index.tsx b/plugins/cost-insights/dev/index.tsx index e4732fc364..8cfa12fc18 100644 --- a/plugins/cost-insights/dev/index.tsx +++ b/plugins/cost-insights/dev/index.tsx @@ -14,8 +14,8 @@ * limitations under the License. */ import { createDevApp } from '@backstage/dev-utils'; +import { ExampleCostInsightsClient } from '../src/example'; import { costInsightsApiRef } from '../src/api'; -import { ExampleCostInsightsClient } from '../src/client'; import { costInsightsPlugin } from '../src/plugin'; createDevApp() diff --git a/plugins/cost-insights/src/alerts/index.ts b/plugins/cost-insights/src/alerts/index.ts index b55c012a60..a732083454 100644 --- a/plugins/cost-insights/src/alerts/index.ts +++ b/plugins/cost-insights/src/alerts/index.ts @@ -16,6 +16,3 @@ export { ProjectGrowthAlert } from './ProjectGrowthAlert'; export { UnlabeledDataflowAlert } from './UnlabeledDataflowAlert'; -export { KubernetesMigrationAlert } from './KubernetesMigrationAlert'; -export type { MigrationAlert } from './KubernetesMigrationAlert'; -export type { MigrationData } from './KubernetesMigrationAlert'; diff --git a/plugins/cost-insights/src/alerts/KubernetesMigrationAlert.tsx b/plugins/cost-insights/src/example/alerts/KubernetesMigrationAlert.tsx similarity index 86% rename from plugins/cost-insights/src/alerts/KubernetesMigrationAlert.tsx rename to plugins/cost-insights/src/example/alerts/KubernetesMigrationAlert.tsx index 31a4d7e0e9..61080b465b 100644 --- a/plugins/cost-insights/src/alerts/KubernetesMigrationAlert.tsx +++ b/plugins/cost-insights/src/example/alerts/KubernetesMigrationAlert.tsx @@ -16,8 +16,8 @@ import React from 'react'; import pluralize from 'pluralize'; -import { MigrationAlertCard } from '../components/MigrationAlertCard'; -import { CostInsightsApi } from '../api'; +import { KubernetesMigrationAlertCard } from '../components'; +import { CostInsightsApi } from '../../api'; import { Alert, AlertForm, @@ -26,19 +26,19 @@ import { AlertSnoozeFormData, ChangeStatistic, Entity, -} from '../types'; -import { MigrationDismissForm, MigrationDismissFormData } from '../forms'; +} from '../../types'; +import { KubernetesMigrationDismissForm, KubernetesMigrationDismissFormData } from '../forms'; -export interface MigrationData { +export interface KubernetesMigrationData { startDate: string; endDate: string; change: ChangeStatistic; services: Array; } -export interface MigrationAlert extends Alert { +export interface KubernetesMigrationApi extends Alert { api: CostInsightsApi; - data: MigrationData; + data: KubernetesMigrationData; } /** @@ -63,9 +63,9 @@ export interface MigrationAlert extends Alert { * Custom forms must implement the corresponding event hook. See /forms for example implementations. */ -export class KubernetesMigrationAlert implements MigrationAlert { +export class KubernetesMigrationAlert implements KubernetesMigrationApi { api: CostInsightsApi; - data: MigrationData; + data: KubernetesMigrationData; subtitle = 'Services running on Kubernetes are estimated to save 50% or more compared to Compute Engine.'; @@ -74,11 +74,11 @@ export class KubernetesMigrationAlert implements MigrationAlert { AcceptForm = null; // Overrides default Dismiss form with a custom form component. DismissForm: AlertForm< - MigrationAlert, - MigrationDismissFormData - > = MigrationDismissForm; + KubernetesMigrationAlert, + KubernetesMigrationDismissFormData + > = KubernetesMigrationDismissForm; - constructor(api: CostInsightsApi, data: MigrationData) { + constructor(api: CostInsightsApi, data: KubernetesMigrationData) { this.api = api; this.data = data; } @@ -98,7 +98,7 @@ export class KubernetesMigrationAlert implements MigrationAlert { true, )}, sorted by cost`; return ( - , + options: AlertOptions, ): Promise { const alerts = await this.api.getAlerts(options.group); return new Promise(resolve => diff --git a/plugins/cost-insights/src/example/alerts/index.ts b/plugins/cost-insights/src/example/alerts/index.ts new file mode 100644 index 0000000000..eadd8d7ef4 --- /dev/null +++ b/plugins/cost-insights/src/example/alerts/index.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + +export { KubernetesMigrationAlert } from './KubernetesMigrationAlert'; +export type { KubernetesMigrationApi } from './KubernetesMigrationAlert'; +export type { KubernetesMigrationData } from './KubernetesMigrationAlert'; diff --git a/plugins/cost-insights/src/client.ts b/plugins/cost-insights/src/example/client.ts similarity index 96% rename from plugins/cost-insights/src/client.ts rename to plugins/cost-insights/src/example/client.ts index 2e70170fc1..bd85e26fe8 100644 --- a/plugins/cost-insights/src/client.ts +++ b/plugins/cost-insights/src/example/client.ts @@ -16,7 +16,7 @@ /* eslint-disable no-restricted-imports */ import dayjs from 'dayjs'; -import { CostInsightsApi, ProductInsightsOptions } from '../src/api'; +import { CostInsightsApi, ProductInsightsOptions } from '../api'; import { Alert, Cost, @@ -27,12 +27,12 @@ import { Project, ProjectGrowthData, UnlabeledDataflowData, -} from '../src/types'; +} from '../types'; +import { KubernetesMigrationAlert } from './alerts'; import { ProjectGrowthAlert, UnlabeledDataflowAlert, - KubernetesMigrationAlert, -} from '../src/alerts'; +} from '../alerts'; import { aggregationFor, changeOf, @@ -40,7 +40,7 @@ import { getGroupedProducts, getGroupedProjects, trendlineOf, -} from './utils/mockData'; +} from '../utils/mockData'; export class ExampleCostInsightsClient implements CostInsightsApi { private request(_: any, res: any): Promise { diff --git a/plugins/cost-insights/src/components/MigrationAlertCard/MigrationAlertCard.tsx b/plugins/cost-insights/src/example/components/KubernetesMigrationAlertCard/KubernetesMigrationAlertCard.tsx similarity index 75% rename from plugins/cost-insights/src/components/MigrationAlertCard/MigrationAlertCard.tsx rename to plugins/cost-insights/src/example/components/KubernetesMigrationAlertCard/KubernetesMigrationAlertCard.tsx index 56d636d8aa..3cba2b7e4d 100644 --- a/plugins/cost-insights/src/components/MigrationAlertCard/MigrationAlertCard.tsx +++ b/plugins/cost-insights/src/example/components/KubernetesMigrationAlertCard/KubernetesMigrationAlertCard.tsx @@ -17,30 +17,30 @@ import React from 'react'; import { Box } from '@material-ui/core'; import { InfoCard } from '@backstage/core'; -import { MigrationBarChartLegend } from './MigrationBarChartLegend'; -import { MigrationBarChart } from './MigrationBarChart'; -import { MigrationData } from '../../alerts'; +import { KubernetesMigrationBarChartLegend } from './KubernetesMigrationBarChartLegend'; +import { KubernetesMigrationBarChart } from './KubernetesMigrationBarChart'; +import { KubernetesMigrationData } from '../../alerts'; -type MigrationAlertProps = { - data: MigrationData; +type KubernetesMigrationAlertProps = { + data: KubernetesMigrationData; title: string; subheader: string; currentProduct: string; comparedProduct: string; }; -export const MigrationAlertCard = ({ +export const KubernetesMigrationAlertCard = ({ data, title, subheader, currentProduct, comparedProduct, -}: MigrationAlertProps) => { +}: KubernetesMigrationAlertProps) => { return ( - - ; }; -export const MigrationBarChart = ({ +export const KubernetesMigrationBarChart = ({ currentProduct, comparedProduct, services, diff --git a/plugins/cost-insights/src/components/MigrationAlertCard/MigrationBarChartLegend.tsx b/plugins/cost-insights/src/example/components/KubernetesMigrationAlertCard/KubernetesMigrationBarChartLegend.tsx similarity index 89% rename from plugins/cost-insights/src/components/MigrationAlertCard/MigrationBarChartLegend.tsx rename to plugins/cost-insights/src/example/components/KubernetesMigrationAlertCard/KubernetesMigrationBarChartLegend.tsx index a84e865e28..2c74535d0d 100644 --- a/plugins/cost-insights/src/components/MigrationAlertCard/MigrationBarChartLegend.tsx +++ b/plugins/cost-insights/src/example/components/KubernetesMigrationAlertCard/KubernetesMigrationBarChartLegend.tsx @@ -16,10 +16,9 @@ import React from 'react'; import { Box, useTheme } from '@material-ui/core'; -import { CostGrowth } from '../CostGrowth'; -import { LegendItem } from '../LegendItem'; -import { ChangeStatistic, CostInsightsTheme, Duration } from '../../types'; -import { monthOf } from '../../utils/formatters'; +import { CostGrowth, LegendItem } from '../../../components'; +import { ChangeStatistic, CostInsightsTheme, Duration } from '../../../types'; +import { monthOf } from '../../../utils/formatters'; export type MigrationBarChartLegendProps = { change: ChangeStatistic; @@ -28,7 +27,7 @@ export type MigrationBarChartLegendProps = { comparedProduct: string; }; -export const MigrationBarChartLegend = ({ +export const KubernetesMigrationBarChartLegend = ({ currentProduct, comparedProduct, change, diff --git a/plugins/cost-insights/src/components/MigrationAlertCard/index.ts b/plugins/cost-insights/src/example/components/KubernetesMigrationAlertCard/index.ts similarity index 90% rename from plugins/cost-insights/src/components/MigrationAlertCard/index.ts rename to plugins/cost-insights/src/example/components/KubernetesMigrationAlertCard/index.ts index 4feb749c27..65f0c097f3 100644 --- a/plugins/cost-insights/src/components/MigrationAlertCard/index.ts +++ b/plugins/cost-insights/src/example/components/KubernetesMigrationAlertCard/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export { MigrationAlertCard } from './MigrationAlertCard'; +export * from './KubernetesMigrationAlertCard'; diff --git a/plugins/cost-insights/src/example/components/index.ts b/plugins/cost-insights/src/example/components/index.ts new file mode 100644 index 0000000000..65f0c097f3 --- /dev/null +++ b/plugins/cost-insights/src/example/components/index.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +export * from './KubernetesMigrationAlertCard'; diff --git a/plugins/cost-insights/src/forms/MigrationDismissForm.tsx b/plugins/cost-insights/src/example/forms/KubernetesMigrationDismissForm.tsx similarity index 86% rename from plugins/cost-insights/src/forms/MigrationDismissForm.tsx rename to plugins/cost-insights/src/example/forms/KubernetesMigrationDismissForm.tsx index ce71af3a37..835577787c 100644 --- a/plugins/cost-insights/src/forms/MigrationDismissForm.tsx +++ b/plugins/cost-insights/src/example/forms/KubernetesMigrationDismissForm.tsx @@ -28,22 +28,22 @@ import { FormGroup, Typography, } from '@material-ui/core'; -import { AlertFormProps, Entity } from '../types'; -import { MigrationAlert } from '../alerts'; -import { findAlways } from '../utils/assert'; +import { AlertFormProps, Entity } from '../../types'; +import { KubernetesMigrationAlert } from '../alerts'; +import { findAlways } from '../../utils/assert'; -export type MigrationDismissFormData = { +export type KubernetesMigrationDismissFormData = { services: Entity[]; }; -export type MigrationDismissFormProps = AlertFormProps< - MigrationAlert, - MigrationDismissFormData +export type KubernetesMigrationDismissFormProps = AlertFormProps< + KubernetesMigrationAlert, + KubernetesMigrationDismissFormData >; -export const MigrationDismissForm = forwardRef< +export const KubernetesMigrationDismissForm = forwardRef< HTMLFormElement, - MigrationDismissFormProps + KubernetesMigrationDismissFormProps >(({ onSubmit, disableSubmit, alert }, ref) => { const [services, setServices] = useState(alert.data.services); diff --git a/plugins/cost-insights/src/example/forms/index.ts b/plugins/cost-insights/src/example/forms/index.ts new file mode 100644 index 0000000000..2ad52201f9 --- /dev/null +++ b/plugins/cost-insights/src/example/forms/index.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +export * from './KubernetesMigrationDismissForm'; diff --git a/plugins/cost-insights/src/example/index.ts b/plugins/cost-insights/src/example/index.ts new file mode 100644 index 0000000000..c27f03bdda --- /dev/null +++ b/plugins/cost-insights/src/example/index.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +export * from './alerts'; +export * from './components'; +export * from './forms'; +export * from './client'; diff --git a/plugins/cost-insights/src/forms/index.ts b/plugins/cost-insights/src/forms/index.ts index 5b8384a293..4692bc1de3 100644 --- a/plugins/cost-insights/src/forms/index.ts +++ b/plugins/cost-insights/src/forms/index.ts @@ -17,5 +17,3 @@ export { AlertAcceptForm } from './AlertAcceptForm'; export { AlertSnoozeForm } from './AlertSnoozeForm'; export { AlertDismissForm } from './AlertDismissForm'; -export { MigrationDismissForm } from './MigrationDismissForm'; -export type { MigrationDismissFormData } from './MigrationDismissForm'; diff --git a/plugins/cost-insights/src/index.ts b/plugins/cost-insights/src/index.ts index 0ae9d05b09..4d99fd8b48 100644 --- a/plugins/cost-insights/src/index.ts +++ b/plugins/cost-insights/src/index.ts @@ -21,9 +21,9 @@ export { CostInsightsProjectGrowthInstructionsPage, CostInsightsLabelDataflowInstructionsPage, } from './plugin'; -export * from './client'; -export * from './api'; export { ProjectGrowthAlert, UnlabeledDataflowAlert } from './alerts'; +export { ExampleCostInsightsClient } from './example'; +export * from './api'; export * from './components'; export { useCurrency } from './hooks'; export * from './types';