Fix export/import validation missing categories, dialog now always clears json and file selection on open/close
This commit is contained in:
@@ -112,6 +112,7 @@ const DataManagementModal: React.FC<DataManagementModalProps> = ({
|
|||||||
const [jsonValidationMessage, setJsonValidationMessage] = useState<{
|
const [jsonValidationMessage, setJsonValidationMessage] = useState<{
|
||||||
type: 'success' | 'error' | null;
|
type: 'success' | 'error' | null;
|
||||||
message: string;
|
message: string;
|
||||||
|
warnings?: string[];
|
||||||
}>({ type: null, message: '' });
|
}>({ type: null, message: '' });
|
||||||
|
|
||||||
// Clipboard feedback
|
// Clipboard feedback
|
||||||
@@ -119,23 +120,25 @@ const DataManagementModal: React.FC<DataManagementModalProps> = ({
|
|||||||
|
|
||||||
// Reset editor when modal opens/closes
|
// Reset editor when modal opens/closes
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (isOpen) {
|
// TODO nice to have: use can decide behavior via checkbox (near editor)
|
||||||
// Load current app data into editor when opening
|
// if (isOpen) {
|
||||||
const appState = {
|
// // Load current app data into editor when opening
|
||||||
pkParams,
|
// const appState = {
|
||||||
days,
|
// pkParams,
|
||||||
therapeuticRange,
|
// days,
|
||||||
doseIncrement,
|
// therapeuticRange,
|
||||||
uiSettings,
|
// doseIncrement,
|
||||||
steadyStateConfig: { daysOnMedication: pkParams.advanced.steadyStateDays },
|
// uiSettings,
|
||||||
};
|
// steadyStateConfig: { daysOnMedication: pkParams.advanced.steadyStateDays },
|
||||||
const exportData = exportSettings(appState, exportOptions, APP_VERSION);
|
// };
|
||||||
const jsonString = JSON.stringify(exportData, null, 2);
|
// const exportData = exportSettings(appState, exportOptions, APP_VERSION);
|
||||||
setJsonEditorContent(jsonString);
|
// const jsonString = JSON.stringify(exportData, null, 2);
|
||||||
setJsonEditorExpanded(true);
|
// setJsonEditorContent(jsonString);
|
||||||
validateJsonContent(jsonString);
|
// setJsonEditorExpanded(true);
|
||||||
} else {
|
// validateJsonContent(jsonString);
|
||||||
// Clear editor when closing
|
// } else {
|
||||||
|
|
||||||
|
// Clear/collapse editor and clear upload file ref when opening/closing
|
||||||
setJsonEditorContent('');
|
setJsonEditorContent('');
|
||||||
setJsonEditorExpanded(false);
|
setJsonEditorExpanded(false);
|
||||||
setJsonValidationMessage({ type: null, message: '' });
|
setJsonValidationMessage({ type: null, message: '' });
|
||||||
@@ -143,7 +146,6 @@ const DataManagementModal: React.FC<DataManagementModalProps> = ({
|
|||||||
if (fileInputRef.current) {
|
if (fileInputRef.current) {
|
||||||
fileInputRef.current.value = '';
|
fileInputRef.current.value = '';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
|
||||||
if (!isOpen) return null;
|
if (!isOpen) return null;
|
||||||
@@ -300,9 +302,11 @@ const DataManagementModal: React.FC<DataManagementModalProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (validation.warnings.length > 0) {
|
if (validation.warnings.length > 0) {
|
||||||
|
// Show success with warnings - warnings will be displayed separately
|
||||||
setJsonValidationMessage({
|
setJsonValidationMessage({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('jsonValidationSuccess') + ' ⚠️ ' + validation.warnings.length + ' warnings',
|
message: t('jsonValidationSuccess'),
|
||||||
|
warnings: validation.warnings,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -734,6 +738,7 @@ const DataManagementModal: React.FC<DataManagementModalProps> = ({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
{jsonValidationMessage.type && (
|
{jsonValidationMessage.type && (
|
||||||
|
<div className="space-y-2">
|
||||||
<div
|
<div
|
||||||
className={`flex items-center gap-2 text-sm ${
|
className={`flex items-center gap-2 text-sm ${
|
||||||
jsonValidationMessage.type === 'success'
|
jsonValidationMessage.type === 'success'
|
||||||
@@ -742,12 +747,25 @@ const DataManagementModal: React.FC<DataManagementModalProps> = ({
|
|||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{jsonValidationMessage.type === 'success' ? (
|
{jsonValidationMessage.type === 'success' ? (
|
||||||
<Check className="h-4 w-4" />
|
<Check className="h-4 w-4 flex-shrink-0" />
|
||||||
) : (
|
) : (
|
||||||
<X className="h-4 w-4" />
|
<X className="h-4 w-4 flex-shrink-0" />
|
||||||
)}
|
)}
|
||||||
<span>{jsonValidationMessage.message}</span>
|
<span>{jsonValidationMessage.message}</span>
|
||||||
</div>
|
</div>
|
||||||
|
{jsonValidationMessage.warnings && jsonValidationMessage.warnings.length > 0 && (
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
{jsonValidationMessage.warnings.map((warning, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="bg-yellow-500 text-white text-xs p-2 rounded-md"
|
||||||
|
>
|
||||||
|
{warning}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ export const validateImportData = (data: any): ImportValidationResult => {
|
|||||||
|
|
||||||
// Validate advanced settings
|
// Validate advanced settings
|
||||||
if (importData.advancedSettings !== undefined) {
|
if (importData.advancedSettings !== undefined) {
|
||||||
const validCategories = ['standardVd', 'weightBasedVd', 'foodEffect', 'urinePh', 'fOral', 'steadyStateDays'];
|
const validCategories = ['standardVd', 'weightBasedVd', 'foodEffect', 'urinePh', 'fOral', 'steadyStateDays', 'ageGroup', 'renalFunction'];
|
||||||
const importedCategories = Object.keys(importData.advancedSettings);
|
const importedCategories = Object.keys(importData.advancedSettings);
|
||||||
const unknownCategories = importedCategories.filter(c => !validCategories.includes(c));
|
const unknownCategories = importedCategories.filter(c => !validCategories.includes(c));
|
||||||
if (unknownCategories.length > 0) {
|
if (unknownCategories.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user