fix: bring back proper deletion handling we lost with refactor for onRemoveHandler

This commit is contained in:
Dustin Healy 2025-09-07 01:37:48 -07:00
parent e062ed5832
commit 013c002cbb
5 changed files with 20 additions and 0 deletions

View file

@ -184,6 +184,7 @@ const CreatePromptForm = ({
onFilesChange={setFiles} onFilesChange={setFiles}
handleFileChange={handleFileChange} handleFileChange={handleFileChange}
disabled={isSubmitting} disabled={isSubmitting}
onFileChange={() => {}}
/> />
<Description <Description
onValueChange={(value) => methods.setValue('oneliner', value)} onValueChange={(value) => methods.setValue('oneliner', value)}

View file

@ -13,6 +13,7 @@ export default function PromptFile({
fileFilter, fileFilter,
isRTL = false, isRTL = false,
Wrapper, Wrapper,
onFileChange,
}: { }: {
files: Map<string, ExtendedFile> | undefined; files: Map<string, ExtendedFile> | undefined;
abortUpload?: () => void; abortUpload?: () => void;
@ -21,6 +22,7 @@ export default function PromptFile({
fileFilter?: (file: ExtendedFile) => boolean; fileFilter?: (file: ExtendedFile) => boolean;
isRTL?: boolean; isRTL?: boolean;
Wrapper?: React.FC<{ children: React.ReactNode }>; Wrapper?: React.FC<{ children: React.ReactNode }>;
onFileChange?: (files: ExtendedFile[]) => void;
}) { }) {
const localize = useLocalize(); const localize = useLocalize();
const { showToast } = useToastContext(); const { showToast } = useToastContext();
@ -101,6 +103,11 @@ export default function PromptFile({
if (file.temp_file_id) { if (file.temp_file_id) {
updatedFiles.delete(file.temp_file_id); updatedFiles.delete(file.temp_file_id);
} }
// Call onFileChange with the updated files array
const updatedFilesArray = Array.from(updatedFiles.values());
onFileChange?.(updatedFilesArray);
return updatedFiles; return updatedFiles;
}); });
}; };

View file

@ -12,11 +12,13 @@ const PromptFiles = ({
onFilesChange, onFilesChange,
handleFileChange, handleFileChange,
disabled, disabled,
onFileChange,
}: { }: {
files: ExtendedFile[]; files: ExtendedFile[];
onFilesChange?: (files: ExtendedFile[]) => void; onFilesChange?: (files: ExtendedFile[]) => void;
handleFileChange?: (event: React.ChangeEvent<HTMLInputElement>, toolResource?: string) => void; handleFileChange?: (event: React.ChangeEvent<HTMLInputElement>, toolResource?: string) => void;
disabled?: boolean; disabled?: boolean;
onFileChange?: (files: ExtendedFile[]) => void;
}) => { }) => {
const localize = useLocalize(); const localize = useLocalize();
@ -63,6 +65,7 @@ const PromptFiles = ({
onFilesChange?.(newFiles); onFilesChange?.(newFiles);
}} }}
setFilesLoading={() => {}} setFilesLoading={() => {}}
onFileChange={onFileChange}
Wrapper={({ children }) => <div className="flex flex-wrap gap-2">{children}</div>} Wrapper={({ children }) => <div className="flex flex-wrap gap-2">{children}</div>}
/> />
</div> </div>

View file

@ -544,6 +544,12 @@ const PromptForm = () => {
onFilesChange={setFiles} onFilesChange={setFiles}
handleFileChange={handleFileChange} handleFileChange={handleFileChange}
disabled={!canEdit} disabled={!canEdit}
onFileChange={(updatedFiles) => {
if (canEdit && selectedPrompt) {
const currentPromptText = getValues('prompt');
onSave(currentPromptText, updatedFiles);
}
}}
/> />
<Description <Description
initialValue={group.oneliner ?? ''} initialValue={group.oneliner ?? ''}

View file

@ -10,6 +10,7 @@ interface PromptVariablesAndFilesProps {
handleFileChange?: (event: React.ChangeEvent<HTMLInputElement>, toolResource?: string) => void; handleFileChange?: (event: React.ChangeEvent<HTMLInputElement>, toolResource?: string) => void;
disabled?: boolean; disabled?: boolean;
showVariablesInfo?: boolean; showVariablesInfo?: boolean;
onFileChange?: (files: ExtendedFile[]) => void;
} }
const PromptVariablesAndFiles: React.FC<PromptVariablesAndFilesProps> = ({ const PromptVariablesAndFiles: React.FC<PromptVariablesAndFilesProps> = ({
@ -19,6 +20,7 @@ const PromptVariablesAndFiles: React.FC<PromptVariablesAndFilesProps> = ({
handleFileChange, handleFileChange,
disabled, disabled,
showVariablesInfo = true, showVariablesInfo = true,
onFileChange,
}) => { }) => {
return ( return (
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2 lg:items-stretch"> <div className="grid grid-cols-1 gap-4 lg:grid-cols-2 lg:items-stretch">
@ -34,6 +36,7 @@ const PromptVariablesAndFiles: React.FC<PromptVariablesAndFilesProps> = ({
onFilesChange={onFilesChange} onFilesChange={onFilesChange}
handleFileChange={handleFileChange} handleFileChange={handleFileChange}
disabled={disabled} disabled={disabled}
onFileChange={onFileChange}
/> />
</div> </div>
</div> </div>