Skip to content

Commit 33cdebf

Browse files
CopilotPDowney
andauthored
refactor: extract constants, use this.pendingChanges, simplify log messages in external-services.js
Agent-Logs-Url: https://github.com/EngineScript/EngineScript/sessions/6d0647df-8d96-4a24-ae31-5b2055a4fd58 Co-authored-by: PDowney <[email protected]>
1 parent 4986402 commit 33cdebf

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ Changes are organized by date, with the most recent changes listed first.
66

77
## 2026-04-11
88

9+
### 🧹 EXTERNAL SERVICES JS CODE QUALITY IMPROVEMENTS
10+
11+
- Extracted the "Failed to fetch external service status" error message into a `ERROR_LOADING_EXTERNAL_SERVICES_MESSAGE` constant in `external-services.js` for easier maintenance and potential localization.
12+
- Extracted the settings panel instruction text into a `SETTINGS_INSTRUCTION_TEXT` constant in `external-services.js` for easier updates and potential internationalization support.
13+
- Refactored `pendingChanges` in `renderServiceSettings` from a local variable to an instance property (`this.pendingChanges`) to reduce deep parameter passing through nested function calls.
14+
- Simplified the `console.error` message in `getServiceCardElement` to focus on actionable information: `Service card not found: ${name}. Status updates will be skipped.`
15+
- Simplified the `console.warn` message in `getSheetRules` to: `Error accessing stylesheet rules:` followed by the error object.
16+
17+
## 2026-04-11
18+
919
### 🔧 VHOST IMPORT BUG FIXES & IMPROVEMENTS
1020

1121
- Updated the single-zip database file detection in `scripts/functions/vhost/vhost-import.sh` to search for both `*.sql` and `*.sql.gz` patterns, so compressed database dumps are correctly found and imported instead of failing silently.

config/var/www/admin/control-panel/external-services/external-services.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const CATEGORY_ORDER = [
1818
'Security'
1919
];
2020

21+
const ERROR_LOADING_EXTERNAL_SERVICES_MESSAGE = "Failed to fetch external service status. Check your internet connection and refresh the page. If the problem continues, check the browser console for details or contact your administrator.";
22+
23+
const SETTINGS_INSTRUCTION_TEXT = 'Toggle services to show/hide on the dashboard. Drag service cards to reorder them, or use the keyboard: press Enter to activate reorder mode and use arrow keys to move cards. Click "Save Changes" to apply. Services are organized by category.';
24+
2125
const DND_MOVE_TOKEN = 'moving';
2226

2327
const DEFAULT_ICON_SUFFIX = 'question';
@@ -245,7 +249,7 @@ export class ExternalServicesManager {
245249
h3.textContent = "Error Loading External Services";
246250

247251
const p = document.createElement("p");
248-
p.textContent = "Failed to fetch external service status. Check your internet connection and refresh the page. If the problem continues, check the browser console for details or contact your administrator.";
252+
p.textContent = ERROR_LOADING_EXTERNAL_SERVICES_MESSAGE;
249253

250254
errorDiv.appendChild(iconDiv);
251255
errorDiv.appendChild(h3);
@@ -436,8 +440,8 @@ export class ExternalServicesManager {
436440
renderServiceSettings(settingsContainer, services, serviceDefinitions, preferences) {
437441
settingsContainer.replaceChildren();
438442

439-
// Track pending changes (shared across components)
440-
const pendingChanges = {};
443+
// Track pending changes as instance state (shared across components)
444+
this.pendingChanges = {};
441445

442446
// Create main UI structure
443447
const { settingsToggle, settingsContent } = this.createSettingsStructure();
@@ -451,13 +455,13 @@ export class ExternalServicesManager {
451455
for (const category of categoryOrder) {
452456
if (!categories[category]) continue;
453457
const categorySection = this.createSettingsCategorySection(
454-
category, categories[category], services, serviceDefinitions, preferences, pendingChanges
458+
category, categories[category], services, serviceDefinitions, preferences, this.pendingChanges
455459
);
456460
settingsContent.appendChild(categorySection);
457461
}
458462

459463
// Create and append save button
460-
const saveButton = this.createSaveButton(settingsContent, services, pendingChanges);
464+
const saveButton = this.createSaveButton(settingsContent, services, this.pendingChanges);
461465
settingsContent.appendChild(saveButton);
462466
}
463467

@@ -489,7 +493,7 @@ export class ExternalServicesManager {
489493
const settingsHeader = document.createElement("div");
490494
settingsHeader.className = "settings-header";
491495
const headerP = document.createElement("p");
492-
headerP.textContent = 'Toggle services to show/hide on the dashboard. Drag service cards to reorder them, or use the keyboard: press Enter to activate reorder mode and use arrow keys to move cards. Click "Save Changes" to apply. Services are organized by category.';
496+
headerP.textContent = SETTINGS_INSTRUCTION_TEXT;
493497
settingsHeader.appendChild(headerP);
494498
settingsContent.appendChild(settingsHeader);
495499

@@ -1095,7 +1099,7 @@ export class ExternalServicesManager {
10951099
const serviceCard = document.querySelector(`[data-service-key="${serviceKey}"]`);
10961100
if (!serviceCard) {
10971101
const name = serviceDef && serviceDef.name ? serviceDef.name : serviceKey;
1098-
console.error(`Card not found for service: ${serviceKey} (${name}). This may occur if the service is disabled in preferences or the DOM has not finished rendering. Status updates for this service will be skipped.`);
1102+
console.error(`Service card not found: ${name}. Status updates will be skipped.`);
10991103
return null;
11001104
}
11011105
return serviceCard;
@@ -1715,7 +1719,7 @@ export class ExternalServicesManager {
17151719
if (e.name === 'SecurityError') {
17161720
return null;
17171721
}
1718-
console.warn('Unexpected error while accessing stylesheet rules (non-CORS related). Check for malformed stylesheets or browser compatibility issues:', e);
1722+
console.warn('Error accessing stylesheet rules:', e);
17191723
return null;
17201724
}
17211725
}

0 commit comments

Comments
 (0)