Skip to content

Commit 5fcad49

Browse files
committed
fix(settings): improve fault tolerance and fix TypeScript errors in settings components
- Fix ProfileManager.tsx: Add proper async/await for exportProfile and importProfile - Fix ProfileManager.tsx: Handle Date | number type for formatDate function - Fix ProfileManager.tsx: Correct createProfile call to match API signature (2 params, not 3) - Fix SettingsContext.tsx: Fix deepMerge function to handle PartialCortexSettings type - Fix SettingsContext.tsx: Properly cast CustomEvent handlers to EventListener via unknown - Fix SettingsContext.tsx: Remove unused destructured variables in useWorkbenchEditorSettings - Fix PolicySettingsContext.tsx: Remove unused imports (createSignal, createEffect) - Fix profiles/ProfileManager.tsx: Remove unused imports and activeProfile variable These fixes improve configuration persistence reliability and prevent 'Cannot read properties of undefined' errors.
1 parent 59aee04 commit 5fcad49

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

cortex-gui/src/components/profiles/ProfileManager.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Show, For, createSignal, createEffect, createMemo } from "solid-js";
2-
import { Portal } from "solid-js/web";
3-
import { useProfiles, type Profile, type KeyBinding } from "@/context/ProfilesContext";
1+
import { Show, For, createSignal, createEffect } from "solid-js";
2+
import { useProfiles, type Profile } from "@/context/ProfilesContext";
43
import { Button, Input, Modal, IconButton, Text, Divider, Badge } from "@/components/ui";
54
import { getProfileIcon } from "./ProfileSwitcher";
65
import { Icon } from "../ui/Icon";
@@ -11,7 +10,6 @@ type ManagerView = "list" | "edit" | "create";
1110
export function ProfileManager() {
1211
const {
1312
profiles,
14-
activeProfile,
1513
activeProfileId,
1614
showManager,
1715
closeManager,

cortex-gui/src/components/settings/ProfileManager.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export function ProfileManager() {
7676
}
7777
};
7878

79-
const handleExport = (profileId: string) => {
80-
const json = profiles.exportProfile(profileId);
79+
const handleExport = async (profileId: string) => {
80+
const json = await profiles.exportProfile(profileId);
8181
if (json) {
8282
const profile = profiles.profiles().find((p) => p.id === profileId);
8383
const filename = `profile-${profile?.name || "export"}-${Date.now()}.json`;
@@ -104,7 +104,7 @@ export function ProfileManager() {
104104

105105
try {
106106
const text = await file.text();
107-
const result = profiles.importProfile(text);
107+
const result = await profiles.importProfile(text);
108108
if (result.success && result.profile) {
109109
setImportSuccess(`Imported profile: ${result.profile.name}`);
110110
} else {
@@ -136,8 +136,10 @@ export function ProfileManager() {
136136
setShowIconPicker(null);
137137
};
138138

139-
const formatDate = (timestamp: number): string => {
140-
const date = new Date(timestamp);
139+
const formatDate = (dateOrTimestamp: Date | number): string => {
140+
const date = typeof dateOrTimestamp === 'number'
141+
? new Date(dateOrTimestamp)
142+
: dateOrTimestamp;
141143
return date.toLocaleDateString(undefined, {
142144
year: "numeric",
143145
month: "short",
@@ -437,8 +439,14 @@ export function ProfileManager() {
437439
<Show when={showCreateModal()}>
438440
<CreateProfileModal
439441
onClose={() => setShowCreateModal(false)}
440-
onCreate={(name, icon, copyFromCurrent) => {
441-
profiles.createProfile(name, icon, copyFromCurrent);
442+
onCreate={async (name, icon, copyFromCurrent) => {
443+
// Create profile (optionally copying from current active profile)
444+
const copyFromId = copyFromCurrent ? profiles.activeProfileId() : undefined;
445+
const newProfile = await profiles.createProfile(name, copyFromId ?? undefined);
446+
// Set the icon if specified
447+
if (icon && newProfile?.id) {
448+
await profiles.setProfileIcon(newProfile.id, icon);
449+
}
442450
setShowCreateModal(false);
443451
}}
444452
icons={profiles.getAvailableIcons()}

cortex-gui/src/context/PolicySettingsContext.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ import {
1919
createContext,
2020
useContext,
2121
ParentProps,
22-
createSignal,
2322
createMemo,
24-
createEffect,
2523
onMount,
2624
onCleanup,
2725
Accessor,

cortex-gui/src/context/SettingsContext.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,15 +1051,16 @@ const SettingsContext = createContext<SettingsContextValue>();
10511051
* Deep merge two objects with proper type safety.
10521052
* Source values override target values, with recursive merging for nested objects.
10531053
* @param target - The base object to merge into
1054-
* @param source - The object with values to merge (can be partial)
1054+
* @param source - The object with values to merge (can be partial or PartialCortexSettings)
10551055
* @returns A new merged object of type T
10561056
*/
1057-
function deepMerge<T extends object>(target: T, source: Partial<T>): T {
1057+
function deepMerge<T extends object>(target: T, source: Partial<T> | PartialCortexSettings): T {
10581058
const result = { ...target };
1059+
const sourceRecord = source as Record<string, unknown>;
10591060

10601061
for (const key in source) {
10611062
if (Object.prototype.hasOwnProperty.call(source, key)) {
1062-
const sourceValue = source[key as keyof T];
1063+
const sourceValue = sourceRecord[key];
10631064
const targetValue = target[key as keyof T];
10641065

10651066
// Recursively merge nested objects (excluding arrays)
@@ -1707,11 +1708,11 @@ const updateCommandPaletteSetting = async <K extends keyof CommandPaletteSetting
17071708
createEffect(() => {
17081709
const handleFolderAdded = (e: CustomEvent<{ path: string }>) => loadFolderSettings(e.detail.path);
17091710
const handleFolderRemoved = (e: CustomEvent<{ path: string }>) => clearFolderSettings(e.detail.path);
1710-
window.addEventListener("workspace:folder-added", handleFolderAdded as EventListener);
1711-
window.addEventListener("workspace:folder-removed", handleFolderRemoved as EventListener);
1711+
window.addEventListener("workspace:folder-added", handleFolderAdded as unknown as EventListener);
1712+
window.addEventListener("workspace:folder-removed", handleFolderRemoved as unknown as EventListener);
17121713
onCleanup(() => {
1713-
window.removeEventListener("workspace:folder-added", handleFolderAdded as EventListener);
1714-
window.removeEventListener("workspace:folder-removed", handleFolderRemoved as EventListener);
1714+
window.removeEventListener("workspace:folder-added", handleFolderAdded as unknown as EventListener);
1715+
window.removeEventListener("workspace:folder-removed", handleFolderRemoved as unknown as EventListener);
17151716
});
17161717
});
17171718

@@ -1741,9 +1742,9 @@ const updateCommandPaletteSetting = async <K extends keyof CommandPaletteSetting
17411742
}
17421743
}
17431744
};
1744-
window.addEventListener("settings:toggle", handleSettingsToggle as EventListener);
1745+
window.addEventListener("settings:toggle", handleSettingsToggle as unknown as EventListener);
17451746
onCleanup(() => {
1746-
window.removeEventListener("settings:toggle", handleSettingsToggle as EventListener);
1747+
window.removeEventListener("settings:toggle", handleSettingsToggle as unknown as EventListener);
17471748
});
17481749
});
17491750

@@ -2044,7 +2045,7 @@ export function useCommandPaletteSettings() {
20442045
}
20452046

20462047
export function useWorkbenchEditorSettings() {
2047-
const { effectiveSettings, updateWorkbenchEditorSetting, resetSection, getSettingSource, hasWorkspaceOverride, setWorkspaceSetting, resetWorkspaceSetting } = useSettings();
2048+
const { effectiveSettings, updateWorkbenchEditorSetting, resetSection } = useSettings();
20482049
return {
20492050
settings: () => effectiveSettings().workbench?.editor ?? DEFAULT_WORKBENCH_EDITOR,
20502051
update: updateWorkbenchEditorSetting,

0 commit comments

Comments
 (0)