mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-02-14 12:47:33 +00:00
refactor(SidebarModals): move normalizeProjectForSettings into utils file
This commit is contained in:
@@ -58,3 +58,5 @@ export type MCPServerStatus = {
|
||||
export type TouchHandlerFactory = (
|
||||
callback: () => void,
|
||||
) => (event: React.TouchEvent<HTMLElement>) => void;
|
||||
|
||||
export type SettingsProject = Pick<Project, 'name' | 'displayName' | 'fullPath' | 'path'>;
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Project } from '../../../types/app';
|
||||
import type {
|
||||
AdditionalSessionsByProject,
|
||||
ProjectSortOrder,
|
||||
SettingsProject,
|
||||
SessionViewModel,
|
||||
SessionWithProvider,
|
||||
} from '../types/types';
|
||||
@@ -198,3 +199,25 @@ export const getTaskIndicatorStatus = (
|
||||
|
||||
return 'not-configured';
|
||||
};
|
||||
|
||||
export const normalizeProjectForSettings = (project: Project): SettingsProject => {
|
||||
const fallbackPath =
|
||||
typeof project.fullPath === 'string' && project.fullPath.length > 0
|
||||
? project.fullPath
|
||||
: typeof project.path === 'string'
|
||||
? project.path
|
||||
: '';
|
||||
|
||||
return {
|
||||
name: project.name,
|
||||
displayName:
|
||||
typeof project.displayName === 'string' && project.displayName.trim().length > 0
|
||||
? project.displayName
|
||||
: project.name,
|
||||
fullPath: fallbackPath,
|
||||
path:
|
||||
typeof project.path === 'string' && project.path.length > 0
|
||||
? project.path
|
||||
: fallbackPath,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useMemo } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { AlertTriangle, Trash2 } from 'lucide-react';
|
||||
import type { TFunction } from 'i18next';
|
||||
@@ -7,7 +8,8 @@ import Settings from '../../../Settings';
|
||||
import VersionUpgradeModal from '../../../modals/VersionUpgradeModal';
|
||||
import type { Project } from '../../../../types/app';
|
||||
import type { ReleaseInfo } from '../../../../types/sharedTypes';
|
||||
import type { DeleteProjectConfirmation, SessionDeleteConfirmation } from '../../types/types';
|
||||
import { normalizeProjectForSettings } from '../../utils/utils';
|
||||
import type { DeleteProjectConfirmation, SessionDeleteConfirmation, SettingsProject } from '../../types/types';
|
||||
|
||||
type SidebarModalsProps = {
|
||||
projects: Project[];
|
||||
@@ -31,6 +33,19 @@ type SidebarModalsProps = {
|
||||
t: TFunction;
|
||||
};
|
||||
|
||||
type TypedSettingsProps = {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
projects: SettingsProject[];
|
||||
initialTab: string;
|
||||
};
|
||||
|
||||
const SettingsComponent = Settings as (props: TypedSettingsProps) => JSX.Element;
|
||||
|
||||
function TypedSettings(props: TypedSettingsProps) {
|
||||
return <SettingsComponent {...props} />;
|
||||
}
|
||||
|
||||
export default function SidebarModals({
|
||||
projects,
|
||||
showSettings,
|
||||
@@ -52,6 +67,12 @@ export default function SidebarModals({
|
||||
latestVersion,
|
||||
t,
|
||||
}: SidebarModalsProps) {
|
||||
// Settings expects project identity/path fields to be present for dropdown labels and local-scope MCP config.
|
||||
const settingsProjects = useMemo(
|
||||
() => projects.map(normalizeProjectForSettings),
|
||||
[projects],
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{showNewProject &&
|
||||
@@ -63,10 +84,10 @@ export default function SidebarModals({
|
||||
document.body,
|
||||
)}
|
||||
|
||||
<Settings
|
||||
<TypedSettings
|
||||
isOpen={showSettings}
|
||||
onClose={onCloseSettings}
|
||||
projects={projects as any}
|
||||
projects={settingsProjects}
|
||||
initialTab={settingsInitialTab}
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user