Incorporated the feedback

Signed-off-by: bogdannechyporenko <bogdannechiporenko@gmail.com>
This commit is contained in:
bogdannechyporenko
2022-11-16 21:17:12 +01:00
parent 68d9733e54
commit 9e824cfd4a
6 changed files with 25 additions and 39 deletions
@@ -28,9 +28,9 @@ import {
MockConfigProvider,
MockFilterProvider,
MockScrollProvider,
MockPluginProvider,
} from '../../testUtils';
import { CostInsightsThemeProvider } from '../CostInsightsPage/CostInsightsThemeProvider';
import { createPlugin, PluginProvider } from '@backstage/core-plugin-api';
const mockGroupDailyCost: Cost = {
id: 'test-group',
@@ -39,21 +39,6 @@ const mockGroupDailyCost: Cost = {
trendline: trendlineOf(MockAggregatedDailyCosts),
};
type TestInputPluginOptions = {
showTrendLine: boolean;
};
type TestPluginOptions = {
showTrendLine: boolean;
};
const plugin = createPlugin({
id: 'my-plugin',
__experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions {
return { showTrendLine: false };
},
});
function renderInContext(children: JSX.Element) {
return renderInTestApp(
<CostInsightsThemeProvider>
@@ -61,7 +46,7 @@ function renderInContext(children: JSX.Element) {
<MockFilterProvider>
<MockBillingDateProvider>
<MockScrollProvider>
<PluginProvider plugin={plugin}>{children}</PluginProvider>
<MockPluginProvider>{children}</MockPluginProvider>
</MockScrollProvider>
</MockBillingDateProvider>
</MockFilterProvider>
@@ -133,7 +133,7 @@ export const CostOverviewChart = ({
);
};
const { showTrendLine } = useCostInsightsOptions();
const { hideTrendLine } = useCostInsightsOptions();
return (
<Box display="flex" flexDirection="column">
@@ -180,7 +180,7 @@ export const CostOverviewChart = ({
stroke="none"
yAxisId={data.dailyCost.dataKey}
/>
{showTrendLine && (
{!hideTrendLine && (
<Line
activeDot={false}
dataKey="trend"
@@ -21,6 +21,7 @@ import {
MockBillingDateProvider,
MockConfigProvider,
MockFilterProvider,
MockPluginProvider,
MockScrollProvider,
trendlineOf,
} from '../../testUtils';
@@ -32,7 +33,6 @@ import { EntityProvider } from '@backstage/plugin-catalog-react';
import { Entity } from '@backstage/catalog-model';
import { LoadingProvider } from '../../hooks';
import { Cost } from '@backstage/plugin-cost-insights-common';
import { createPlugin, PluginProvider } from '@backstage/core-plugin-api';
function renderInContext(children: JSX.Element) {
const mockEntity = {
@@ -57,21 +57,6 @@ function renderInContext(children: JSX.Element) {
getAlerts: jest.fn().mockResolvedValue({}),
};
type TestInputPluginOptions = {
showTrendLine: boolean;
};
type TestPluginOptions = {
showTrendLine: boolean;
};
const plugin = createPlugin({
id: 'my-plugin',
__experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions {
return { showTrendLine: false };
},
});
return renderInTestApp(
<TestApiProvider apis={[[costInsightsApiRef, mockApi]]}>
<EntityProvider entity={mockEntity}>
@@ -81,7 +66,9 @@ function renderInContext(children: JSX.Element) {
<MockFilterProvider>
<MockBillingDateProvider>
<MockScrollProvider>
<PluginProvider plugin={plugin}>{children}</PluginProvider>
<MockScrollProvider>
<MockPluginProvider>{children}</MockPluginProvider>
</MockScrollProvider>
</MockScrollProvider>
</MockBillingDateProvider>
</MockFilterProvider>
+2 -2
View File
@@ -17,12 +17,12 @@
import { usePluginOptions } from '@backstage/core-plugin-api';
export type CostInsightsPluginOptions = {
showTrendLine: boolean;
hideTrendLine?: boolean;
};
/** @ignore */
export type CostInsightsInputPluginOptions = {
showTrendLine: boolean;
hideTrendLine?: boolean;
};
export const useCostInsightsOptions = () =>
+1 -1
View File
@@ -49,7 +49,7 @@ export const costInsightsPlugin = createPlugin({
options?: CostInsightsInputPluginOptions,
): CostInsightsPluginOptions {
const defaultOptions = {
showTrendLine: true,
hideTrendLine: false,
};
return { ...defaultOptions, ...options };
},
@@ -26,6 +26,7 @@ import {
} from '../hooks/useLastCompleteBillingDate';
import { ScrollContext, ScrollContextProps } from '../hooks/useScroll';
import { Group, Duration } from '../types';
import { createPlugin, PluginProvider } from '@backstage/core-plugin-api';
export const MockGroups: Group[] = [{ id: 'tech' }, { id: 'mock-group' }];
@@ -144,6 +145,19 @@ export const MockBillingDateProvider = ({
export type MockScrollProviderProps = PropsWithChildren<{}>;
export const MockPluginProvider = ({ children }: PropsWithChildren<{}>) => {
type TestInputPluginOptions = {};
type TestPluginOptions = {};
const plugin = createPlugin({
id: 'my-plugin',
__experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions {
return {};
},
});
return <PluginProvider plugin={plugin}>{children}</PluginProvider>;
};
export const MockScrollProvider = ({ children }: MockScrollProviderProps) => {
const defaultContext: ScrollContextProps = {
scroll: null,