refactor: optimize connector status hook and update class name for deprecated status

- Refactored `useConnectorStatus` hook to utilize `useCallback` for improved performance.
- Updated class name for the deprecated status badge to maintain consistency in styling.
This commit is contained in:
Anish Sarkar 2026-01-15 16:56:58 +05:30
parent 9ddcd4f99b
commit 351f6eb23d
2 changed files with 28 additions and 17 deletions

View file

@ -44,7 +44,7 @@ export const ConnectorStatusBadge: FC<ConnectorStatusBadgeProps> = ({
case "deprecated": case "deprecated":
return { return {
icon: AlertTriangle, icon: AlertTriangle,
className: "ext-slate-500 dark:text-slate-400", className: "text-slate-500 dark:text-slate-400",
defaultTitle: "Deprecated", defaultTitle: "Deprecated",
}; };
default: default:

View file

@ -1,6 +1,6 @@
"use client"; "use client";
import { useMemo } from "react"; import { useCallback, useMemo } from "react";
import { import {
type ConnectorStatusConfig, type ConnectorStatusConfig,
connectorStatusConfig, connectorStatusConfig,
@ -14,34 +14,45 @@ export function useConnectorStatus() {
/** /**
* Get status configuration for a specific connector type * Get status configuration for a specific connector type
*/ */
const getConnectorStatus = (connectorType: string | undefined): ConnectorStatusConfig => { const getConnectorStatus = useCallback(
if (!connectorType) { (connectorType: string | undefined): ConnectorStatusConfig => {
return getDefaultConnectorStatus(); if (!connectorType) {
} return getDefaultConnectorStatus();
}
return connectorStatusConfig.connectorStatuses[connectorType] || getDefaultConnectorStatus(); return (
}; connectorStatusConfig.connectorStatuses[connectorType] || getDefaultConnectorStatus()
);
},
[]
);
/** /**
* Check if a connector is enabled * Check if a connector is enabled
*/ */
const isConnectorEnabled = (connectorType: string | undefined): boolean => { const isConnectorEnabled = useCallback(
return getConnectorStatus(connectorType).enabled; (connectorType: string | undefined): boolean => {
}; return getConnectorStatus(connectorType).enabled;
},
[getConnectorStatus]
);
/** /**
* Get status message for a connector * Get status message for a connector
*/ */
const getConnectorStatusMessage = (connectorType: string | undefined): string | null => { const getConnectorStatusMessage = useCallback(
return getConnectorStatus(connectorType).statusMessage || null; (connectorType: string | undefined): string | null => {
}; return getConnectorStatus(connectorType).statusMessage || null;
},
[getConnectorStatus]
);
/** /**
* Check if warnings should be shown globally * Check if warnings should be shown globally
*/ */
const shouldShowWarnings = (): boolean => { const shouldShowWarnings = useCallback((): boolean => {
return connectorStatusConfig.globalSettings.showWarnings; return connectorStatusConfig.globalSettings.showWarnings;
}; }, []);
return useMemo( return useMemo(
() => ({ () => ({
@ -50,6 +61,6 @@ export function useConnectorStatus() {
getConnectorStatusMessage, getConnectorStatusMessage,
shouldShowWarnings, shouldShowWarnings,
}), }),
[] [getConnectorStatus, isConnectorEnabled, getConnectorStatusMessage, shouldShowWarnings]
); );
} }