From 29afff1d72303e26edd3f86bb158ea22b7c4d460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tanguy=20Maz=C3=A9?= Date: Mon, 17 Nov 2025 21:56:35 +0100 Subject: [PATCH] Refactor: Extract nested ternaries into helper methods Address code review feedback from Gemini Code Assist by extracting complex nested ternary operators into dedicated helper methods: - getSourceStatusText() for status text display - getConnectionStatusTooltip() for tooltip text This improves code readability and maintainability while matching the existing patterns used throughout the RomM codebase (e.g., Personal.vue, GameInfo.vue). No functional changes - all translation logic remains identical. --- .../src/views/Settings/MetadataSources.vue | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/frontend/src/views/Settings/MetadataSources.vue b/frontend/src/views/Settings/MetadataSources.vue index 02b006c96..483fdc130 100644 --- a/frontend/src/views/Settings/MetadataSources.vue +++ b/frontend/src/views/Settings/MetadataSources.vue @@ -96,6 +96,34 @@ async function fetchAllHeartbeats() { }); } +// Helper function to get status text for a metadata source +function getSourceStatusText(source: { disabled: boolean; heartbeat?: boolean }) { + if (source.disabled) { + return t("scan.api-key-missing-short"); + } + if (source.heartbeat === true) { + return t("scan.api-key-valid"); + } + if (source.heartbeat === false) { + return t("scan.api-key-invalid"); + } + return t("scan.connection-in-progress"); +} + +// Helper function to get tooltip text for connection status +function getConnectionStatusTooltip(source: { disabled: boolean; heartbeat?: boolean }) { + if (source.disabled) { + return t("scan.api-key-missing-or-disabled"); + } + if (source.heartbeat === true) { + return t("scan.connection-successful"); + } + if (source.heartbeat === false) { + return t("scan.connection-failed"); + } + return t("scan.connection-in-progress"); +} + onMounted(() => { fetchAllHeartbeats(); }); @@ -127,15 +155,7 @@ onMounted(() => {

{{ source.name }}

- {{ - source.disabled - ? t("scan.api-key-missing-short") - : source.heartbeat === true - ? t("scan.api-key-valid") - : source.heartbeat === false - ? t("scan.api-key-invalid") - : t("scan.connection-in-progress") - }} + {{ getSourceStatusText(source) }}

@@ -161,7 +181,7 @@ onMounted(() => { : 'warning' " size="large" - :title="source.disabled ? t('scan.api-key-missing-or-disabled') : source.heartbeat === true ? t('scan.connection-successful') : source.heartbeat === false ? t('scan.connection-failed') : t('scan.connection-in-progress')" + :title="getConnectionStatusTooltip(source)" class="ml-4" >