mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: improve code readability and consistency across dashboard components
This commit is contained in:
@@ -63,7 +63,7 @@ interface MetricConfig {
|
||||
legendUnit?: string;
|
||||
}
|
||||
|
||||
function buildMetricQueryConfig(config: MetricConfig): object {
|
||||
function buildMetricQueryConfig(config: MetricConfig): Record<string, unknown> {
|
||||
return {
|
||||
metricAliasData: {
|
||||
metricVariable: "a",
|
||||
@@ -82,7 +82,7 @@ function buildMetricQueryConfig(config: MetricConfig): object {
|
||||
};
|
||||
}
|
||||
|
||||
function buildMetricQueryData(config: MetricConfig): object {
|
||||
function buildMetricQueryData(config: MetricConfig): Record<string, unknown> {
|
||||
return {
|
||||
metricQueryData: {
|
||||
filterData: {
|
||||
@@ -497,10 +497,7 @@ function createMonitorDashboardConfig(): DashboardViewConfig {
|
||||
return {
|
||||
_type: ObjectType.DashboardViewConfig,
|
||||
components,
|
||||
heightInDashboardUnits: Math.max(
|
||||
DashboardSize.heightInDashboardUnits,
|
||||
13,
|
||||
),
|
||||
heightInDashboardUnits: Math.max(DashboardSize.heightInDashboardUnits, 13),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -739,10 +736,7 @@ function createIncidentDashboardConfig(): DashboardViewConfig {
|
||||
return {
|
||||
_type: ObjectType.DashboardViewConfig,
|
||||
components,
|
||||
heightInDashboardUnits: Math.max(
|
||||
DashboardSize.heightInDashboardUnits,
|
||||
20,
|
||||
),
|
||||
heightInDashboardUnits: Math.max(DashboardSize.heightInDashboardUnits, 20),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -950,10 +944,7 @@ function createKubernetesDashboardConfig(): DashboardViewConfig {
|
||||
return {
|
||||
_type: ObjectType.DashboardViewConfig,
|
||||
components,
|
||||
heightInDashboardUnits: Math.max(
|
||||
DashboardSize.heightInDashboardUnits,
|
||||
16,
|
||||
),
|
||||
heightInDashboardUnits: Math.max(DashboardSize.heightInDashboardUnits, 16),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -978,10 +978,7 @@ const AreaChart: React.ForwardRefExoticComponent<
|
||||
);
|
||||
})}
|
||||
{props.referenceLines?.map(
|
||||
(
|
||||
refLine: ChartReferenceLineProps,
|
||||
refIndex: number,
|
||||
) => {
|
||||
(refLine: ChartReferenceLineProps, refIndex: number) => {
|
||||
return (
|
||||
<ReferenceLine
|
||||
key={`ref-${refIndex}`}
|
||||
|
||||
@@ -1014,10 +1014,7 @@ const BarChart: React.ForwardRefExoticComponent<
|
||||
);
|
||||
})}
|
||||
{props.referenceLines?.map(
|
||||
(
|
||||
refLine: ChartReferenceLineProps,
|
||||
refIndex: number,
|
||||
) => {
|
||||
(refLine: ChartReferenceLineProps, refIndex: number) => {
|
||||
return (
|
||||
<ReferenceLine
|
||||
key={`ref-${refIndex}`}
|
||||
|
||||
@@ -996,10 +996,7 @@ const LineChart: React.ForwardRefExoticComponent<
|
||||
})
|
||||
: null}
|
||||
{props.referenceLines?.map(
|
||||
(
|
||||
refLine: ChartReferenceLineProps,
|
||||
refIndex: number,
|
||||
) => {
|
||||
(refLine: ChartReferenceLineProps, refIndex: number) => {
|
||||
return (
|
||||
<ReferenceLine
|
||||
key={`ref-${refIndex}`}
|
||||
|
||||
@@ -2803,11 +2803,7 @@ const Icon: FunctionComponent<ComponentProps> = ({
|
||||
strokeLinejoin="round"
|
||||
d="M5.636 7.636l1.414 1.414"
|
||||
/>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M12 5v2"
|
||||
/>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M12 5v2" />
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Human-friendly value formatting for metric units.
|
||||
// Converts raw values like 1048576 bytes → "1 MB", 3661 seconds → "1.02 hr", etc.
|
||||
/*
|
||||
* Human-friendly value formatting for metric units.
|
||||
* Converts raw values like 1048576 bytes → "1 MB", 3661 seconds → "1.02 hr", etc.
|
||||
*/
|
||||
|
||||
export interface FormattedValue {
|
||||
value: string; // e.g. "1.5"
|
||||
@@ -135,10 +137,12 @@ function formatNumber(value: number): string {
|
||||
}
|
||||
|
||||
export default class ValueFormatter {
|
||||
// Format a value with a unit into a human-friendly string.
|
||||
// e.g. formatValue(1048576, "bytes") → "1 MB"
|
||||
// e.g. formatValue(3661, "seconds") → "1.02 hr"
|
||||
// e.g. formatValue(42, "%") → "42 %" (passthrough for unknown units)
|
||||
/*
|
||||
* Format a value with a unit into a human-friendly string.
|
||||
* e.g. formatValue(1048576, "bytes") → "1 MB"
|
||||
* e.g. formatValue(3661, "seconds") → "1.02 hr"
|
||||
* e.g. formatValue(42, "%") → "42 %" (passthrough for unknown units)
|
||||
*/
|
||||
public static formatValue(value: number, unit: string): string {
|
||||
if (!unit || unit.trim() === "") {
|
||||
return formatNumber(value);
|
||||
|
||||
Reference in New Issue
Block a user