move example data to separate dir

Signed-off-by: Ryan Vazquez <ryanv@spotify.com>
This commit is contained in:
Ryan Vazquez
2021-03-03 10:30:01 -05:00
parent ae30b916df
commit ea7cd031bb
15 changed files with 122 additions and 55 deletions
+1 -1
View File
@@ -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()
@@ -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';
@@ -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<Entity>;
}
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 (
<MigrationAlertCard
<KubernetesMigrationAlertCard
data={this.data}
title="Migrate to Kubernetes"
subheader={subheader}
@@ -110,7 +110,7 @@ export class KubernetesMigrationAlert implements MigrationAlert {
/* Fires when the onSubmit event is raised on a Dismiss form. Displays custom dismiss form. */
async onDismissed(
options: AlertOptions<MigrationDismissFormData>,
options: AlertOptions<KubernetesMigrationDismissFormData>,
): Promise<Alert[]> {
const alerts = await this.api.getAlerts(options.group);
return new Promise(resolve =>
@@ -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';
@@ -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<any> {
@@ -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 (
<InfoCard title={title} subheader={subheader}>
<Box display="flex" flexDirection="column">
<Box paddingY={1}>
<MigrationBarChartLegend
<KubernetesMigrationBarChartLegend
startDate={data.startDate}
change={data.change}
currentProduct={currentProduct}
@@ -48,7 +48,7 @@ export const MigrationAlertCard = ({
/>
</Box>
<Box paddingY={1}>
<MigrationBarChart
<KubernetesMigrationBarChart
services={data.services}
currentProduct={currentProduct}
comparedProduct={comparedProduct}
@@ -15,13 +15,13 @@
*/
import React from 'react';
import { BarChart } from '../BarChart';
import { BarChart } from '../../../components';
import {
BarChartOptions,
CostInsightsTheme,
Entity,
ResourceData,
} from '../../types';
} from '../../../types';
import { useTheme } from '@material-ui/core';
type MigrationBarChartProps = {
@@ -30,7 +30,7 @@ type MigrationBarChartProps = {
services: Array<Entity>;
};
export const MigrationBarChart = ({
export const KubernetesMigrationBarChart = ({
currentProduct,
comparedProduct,
services,
@@ -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,
@@ -14,4 +14,4 @@
* limitations under the License.
*/
export { MigrationAlertCard } from './MigrationAlertCard';
export * from './KubernetesMigrationAlertCard';
@@ -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';
@@ -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<Entity[]>(alert.data.services);
@@ -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';
@@ -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';
-2
View File
@@ -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';
+2 -2
View File
@@ -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';