refactor: simplify DashboardLogsComponent arguments and default values

This commit is contained in:
Nawaz Dhandala 2025-11-28 14:41:08 +00:00
parent 196c4ae42d
commit a4e64c88d9
No known key found for this signature in database
GPG key ID: 96C5DCA24769DBCA
3 changed files with 5 additions and 74 deletions

View file

@ -7,12 +7,7 @@ export default interface DashboardLogsComponent extends BaseComponent {
componentId: ObjectID;
arguments: {
title?: string | undefined;
showFilters?: boolean | undefined;
enableRealtime?: boolean | undefined;
limit?: number | undefined;
telemetryServiceIdsCsv?: string | undefined;
logQueryJson?: string | undefined;
noLogsMessage?: string | undefined;
respectDashboardTimeRange?: boolean | undefined;
};
}

View file

@ -22,13 +22,8 @@ export default class DashboardLogsComponentUtil extends DashboardBaseComponentUt
minWidthInDashboardUnits: 6,
arguments: {
title: "Logs",
showFilters: false,
enableRealtime: false,
limit: 100,
telemetryServiceIdsCsv: "",
logQueryJson: "",
noLogsMessage: "No logs found.",
respectDashboardTimeRange: true,
},
};
}
@ -48,31 +43,6 @@ export default class DashboardLogsComponentUtil extends DashboardBaseComponentUt
id: "title",
});
componentArguments.push({
name: "Show Filters",
description:
"Display the interactive filter builder inside the logs widget.",
required: false,
type: ComponentInputType.Boolean,
id: "showFilters",
});
componentArguments.push({
name: "Enable Realtime Refresh",
description: "Automatically refresh logs every few seconds.",
required: false,
type: ComponentInputType.Boolean,
id: "enableRealtime",
});
componentArguments.push({
name: "Results Limit",
description: "Maximum number of rows to fetch per page (default 100).",
required: false,
type: ComponentInputType.Number,
id: "limit",
});
componentArguments.push({
name: "Telemetry Service IDs",
description:
@ -83,15 +53,6 @@ export default class DashboardLogsComponentUtil extends DashboardBaseComponentUt
placeholder: "service-id-1, service-id-2",
});
componentArguments.push({
name: "Respect Dashboard Time Range",
description:
"When enabled the widget constrains results to the dashboard time selection.",
required: false,
type: ComponentInputType.Boolean,
id: "respectDashboardTimeRange",
});
componentArguments.push({
name: "Advanced Log Query (JSON)",
description:
@ -102,14 +63,6 @@ export default class DashboardLogsComponentUtil extends DashboardBaseComponentUt
placeholder: '{ "attributes.environment": "prod" }',
});
componentArguments.push({
name: "Empty State Message",
description: "Message shown when no logs are found.",
required: false,
type: ComponentInputType.Text,
id: "noLogsMessage",
});
return componentArguments;
}
}

View file

@ -48,20 +48,7 @@ const DashboardLogsComponent: FunctionComponent<ComponentProps> = (
);
}, [args.telemetryServiceIdsCsv]);
const limit: number = useMemo(() => {
const parsedLimit: number = Number(args.limit);
if (!isNaN(parsedLimit) && parsedLimit > 0) {
return parsedLimit;
}
return 100;
}, [args.limit]);
const respectDashboardTimeRange: boolean =
args.respectDashboardTimeRange !== undefined
? Boolean(args.respectDashboardTimeRange)
: true;
const limit: number = 100;
const logQueryResult: {
query: Query<Log>;
@ -83,10 +70,7 @@ const DashboardLogsComponent: FunctionComponent<ComponentProps> = (
}
}
if (
respectDashboardTimeRange &&
!(mergedQuery as Record<string, unknown>)["time"]
) {
if (!(mergedQuery as Record<string, unknown>)["time"]) {
const range: InBetween<Date> =
RangeStartAndEndDateTimeUtil.getStartAndEndDate(
props.dashboardStartAndEndDate,
@ -104,16 +88,15 @@ const DashboardLogsComponent: FunctionComponent<ComponentProps> = (
}, [
args.logQueryJson,
props.dashboardStartAndEndDate,
respectDashboardTimeRange,
]);
if (logQueryResult.error) {
return <ErrorMessage message={logQueryResult.error} />;
}
const showFilters: boolean = Boolean(args.showFilters);
const enableRealtime: boolean = Boolean(args.enableRealtime);
const noLogsMessage: string = args.noLogsMessage || "No logs found.";
const showFilters: boolean = true;
const enableRealtime: boolean = true;
const noLogsMessage: string = "No logs found.";
const title: string = args.title || "Logs";
return (