refactor(config): make EditorState/ConfirmDeleteState generic over the artifact type
Review feedback: string widening dropped the compile-time guard at the write/delete boundary right where the Codex panel (the next task) starts writing into this state. Threading <TType extends string = CcArtifactType> through EditorState/EditorModal and ConfirmDeleteState/ConfirmDeleteModal keeps CcConfig.tsx's write/delete calls checked against CcArtifactType by default while still letting a Codex-typed caller instantiate its own union later, removing the two `as CcArtifactType` casts.
This commit is contained in:
@@ -10,18 +10,19 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Pencil, X, Save, AlertCircle } from "lucide-react";
|
||||
import type { CcArtifactType } from "../../lib/api";
|
||||
|
||||
export type EditorState =
|
||||
export type EditorState<TType extends string = CcArtifactType> =
|
||||
| {
|
||||
mode: "create";
|
||||
type: string;
|
||||
type: TType;
|
||||
defaultScope: "user" | "project";
|
||||
template: string;
|
||||
project?: string; // set for type === "auto-memory"
|
||||
}
|
||||
| {
|
||||
mode: "edit";
|
||||
type: string;
|
||||
type: TType;
|
||||
scope: "user" | "project" | "auto-memory";
|
||||
name: string;
|
||||
filePath: string;
|
||||
@@ -29,12 +30,12 @@ export type EditorState =
|
||||
}
|
||||
| null;
|
||||
|
||||
interface EditorModalProps {
|
||||
state: NonNullable<EditorState>;
|
||||
interface EditorModalProps<TType extends string = CcArtifactType> {
|
||||
state: NonNullable<EditorState<TType>>;
|
||||
fetchContent: (filePath: string) => Promise<string>;
|
||||
onClose: () => void;
|
||||
onSave: (args: {
|
||||
type: string;
|
||||
type: TType;
|
||||
targetScope: "user" | "project" | "auto-memory";
|
||||
name: string | undefined;
|
||||
content: string;
|
||||
@@ -42,7 +43,12 @@ interface EditorModalProps {
|
||||
}) => Promise<void>;
|
||||
}
|
||||
|
||||
export function EditorModal({ state, fetchContent, onClose, onSave }: EditorModalProps) {
|
||||
export function EditorModal<TType extends string = CcArtifactType>({
|
||||
state,
|
||||
fetchContent,
|
||||
onClose,
|
||||
onSave,
|
||||
}: EditorModalProps<TType>) {
|
||||
const { t } = useTranslation("ccConfig");
|
||||
const isCreate = state.mode === "create";
|
||||
const isAutoMemory = state.type === "auto-memory";
|
||||
|
||||
Reference in New Issue
Block a user