Skip to content

Commit

Permalink
Refactor DashboardChartComponent and related components for improved …
Browse files Browse the repository at this point in the history
…code readability and maintainability; add optional title and description properties for enhanced chart configuration
  • Loading branch information
simlarsen committed Dec 2, 2024
1 parent 6113b10 commit cc62b26
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
2 changes: 0 additions & 2 deletions Common/Utils/Dashboard/Components/DashboardChartComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export default class DashboardChartComponentUtil extends DashboardBaseComponentU
ComponentArgument<DashboardChartComponent>
> = [];



componentArguments.push({
name: "Chart Configuration",
description: "Please select the metrics to display on the chart",
Expand Down
1 change: 0 additions & 1 deletion Common/Utils/Monitor/MonitorMetricType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class MonitorMetricTypeUtil {
}
}


public static getDescriptionByMonitorMetricType(
monitorMetricType: MonitorMetricType,
): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,23 @@ const DashboardChartComponentElement: FunctionComponent<ComponentProps> = (
heightOfChart = undefined;
}

// add title and description.
// add title and description.

const chartMetricViewData: MetricViewData = {
queryConfigs: props.component.arguments.metricQueryConfig
? [{
...(props.component.arguments.metricQueryConfig)!,
metricAliasData: {
title: props.component.arguments.chartTitle || undefined,
description: props.component.arguments.chartDescription || undefined,
metricVariable: undefined,
legend: props.component.arguments.legendText || undefined,
legendUnit: props.component.arguments.legendUnit || undefined,
}
}]
? [
{
...props.component.arguments.metricQueryConfig!,
metricAliasData: {
title: props.component.arguments.chartTitle || undefined,
description:
props.component.arguments.chartDescription || undefined,
metricVariable: undefined,
legend: props.component.arguments.legendText || undefined,
legendUnit: props.component.arguments.legendUnit || undefined,
},
},
]
: [],
startAndEndDate: DashboardStartAndEndDateUtil.getStartAndEndDate(
props.dashboardStartAndEndDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ const DashboardTextComponentElement: FunctionComponent<ComponentProps> = (
props: ComponentProps,
): ReactElement => {
const textClassName: string = `truncate ${props.component.arguments.isBold ? "font-medium" : ""} ${props.component.arguments.isItalic ? "italic" : ""} ${props.component.arguments.isUnderline ? "underline" : ""}`;
const textHeightInxPx: number =props.dashboardComponentHeightInPx - 20;
const textHeightInxPx: number = props.dashboardComponentHeightInPx - 20;

return (
<div>
<div className={textClassName} style={{
height: textHeightInxPx > 0 ? `${textHeightInxPx}px` : "auto",
}}>{props.component.arguments.text}</div>
<div
className={textClassName}
style={{
height: textHeightInxPx > 0 ? `${textHeightInxPx}px` : "auto",
}}
>
{props.component.arguments.text}
</div>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ const DashboardValueComponent: FunctionComponent<ComponentProps> = (
"Please select an Aggregation Type. Click here to add a Aggregation Type.",
);
return;
} else {
setAggregationType(
(metricViewData.queryConfigs[0].metricQueryData.filterData
?.aggegationType as AggregationType) || AggregationType.Avg,
);
}
setAggregationType(
(metricViewData.queryConfigs[0].metricQueryData.filterData
?.aggegationType as AggregationType) || AggregationType.Avg,
);

try {
const results: Array<AggregatedResult> = await MetricUtil.fetchResults({
Expand Down
4 changes: 2 additions & 2 deletions Dashboard/src/Components/Monitor/MonitorMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ const MonitorMetricsElement: FunctionComponent<ComponentProps> = (
MonitorMetricTypeUtil.getDescriptionByMonitorMetricType(
monitorMetricType,
),
legend:
legend:
MonitorMetricTypeUtil.getLegendByMonitorMetricType(
monitorMetricType,
),
legendUnit:
legendUnit:
MonitorMetricTypeUtil.getLegendUnitByMonitorMetricType(
monitorMetricType,
),
Expand Down

0 comments on commit cc62b26

Please sign in to comment.