Skip to content

Commit

Permalink
refactor(backstage-plugin): Move hook to own file
Browse files Browse the repository at this point in the history
Move benchmark hook to it's own file.
Rename overview to benchmark for consistency.

Addresses #71
  • Loading branch information
kylejwatson committed Nov 27, 2023
1 parent dfdb676 commit 8d429ea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import { getEntityRelations, useEntity } from '@backstage/plugin-catalog-react';
import { CircularProgress, Grid } from '@material-ui/core';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useMetricBenchmark } from '../../hooks/MetricBenchmarkHook';
import { useMetricData } from '../../hooks/MetricDataHook';
import '../../i18n';
import { MetricContext } from '../../services/MetricContext';
import {
useMetricData,
useMetricOverview,
} from '../../services/MetricDataHook';
import { BarChartComponent } from '../BarChartComponent/BarChartComponent';
import { DropdownComponent } from '../DropdownComponent/DropdownComponent';
import { HighlightTextBoxComponent } from '../HighlightTextBoxComponent/HighlightTextBoxComponent';
Expand Down Expand Up @@ -51,15 +49,15 @@ const ChartGridItem = ({ type, label }: { type: string; label: string }) => {
);
};

const OverviewGridItem = ({ type }: { type: string }) => {
const BenchmarkGridItem = ({ type }: { type: string }) => {
const [t] = useTranslation();
const { overview, error } = useMetricOverview(type);
const { benchmark, error } = useMetricBenchmark(type);

const testOrProgressComponent = overview ? (
const testOrProgressComponent = benchmark ? (
<HighlightTextBoxComponent
title=""
text=""
highlight={t(`deployment_frequency.overall_labels.${overview}`)}
highlight={t(`deployment_frequency.overall_labels.${benchmark}`)}
// to do: think of text colouring for different scenarios
textColour="positiveHighlight"
/>
Expand Down Expand Up @@ -123,7 +121,7 @@ export const DashboardComponent = ({
</Grid>
</div>
</Grid>
<OverviewGridItem type="df" />
<BenchmarkGridItem type="df" />
<ChartGridItem
type="df_count"
label={t('deployment_frequency.labels.deployment_frequency')}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useApi } from '@backstage/core-plugin-api';
import { useEffect, useState } from 'react';
import { dfBenchmarkKey } from '../models/DfBenchmarkData';
import { groupDataServiceApiRef } from '../services/GroupDataService';

export const useMetricBenchmark = (type: string) => {
const groupDataService = useApi(groupDataServiceApiRef);
const [benchmark, setDfBenchmark] = useState<dfBenchmarkKey | undefined>();
const [error, setError] = useState<Error | undefined>();

useEffect(() => {
groupDataService.retrieveBenchmarkData({ type: type }).then(response => {
setDfBenchmark(response.key);
}, setError);
}, [groupDataService, type]);

return { error: error, benchmark: benchmark };
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useApi } from '@backstage/core-plugin-api';
import { useContext, useEffect, useState } from 'react';
import { dfBenchmarkKey } from '../models/DfBenchmarkData';
import { MetricData } from '../models/MetricData';
import { groupDataServiceApiRef } from './GroupDataService';
import { MetricContext } from './MetricContext';
import { groupDataServiceApiRef } from '../services/GroupDataService';
import { MetricContext } from '../services/MetricContext';

export const useMetricData = (type: string) => {
const groupDataService = useApi(groupDataServiceApiRef);
Expand All @@ -30,17 +29,3 @@ export const useMetricData = (type: string) => {

return { error: error, chartData: chartData };
};

export const useMetricOverview = (type: string) => {
const groupDataService = useApi(groupDataServiceApiRef);
const [overview, setDfOverview] = useState<dfBenchmarkKey | undefined>();
const [error, setError] = useState<Error | undefined>();

useEffect(() => {
groupDataService.retrieveBenchmarkData({ type: type }).then(response => {
setDfOverview(response.key);
}, setError);
}, [groupDataService, type]);

return { error: error, overview: overview };
};

0 comments on commit 8d429ea

Please sign in to comment.