Skip to content

Commit 588c2b4

Browse files
committed
add delete metamodelel button in correct page
remove delete bottun in metamodel page inside the vsum
1 parent ed321fb commit 588c2b4

File tree

1 file changed

+134
-6
lines changed

1 file changed

+134
-6
lines changed

src/components/ui/ToolsPanel.tsx

Lines changed: 134 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ const createButtonActiveStyle: React.CSSProperties = {
6666
boxShadow: '0 2px 8px rgba(52, 152, 219, 0.3)',
6767
};
6868

69-
// ... existing code ...
70-
7169
const filterContainerStyle: React.CSSProperties = {
7270
position: 'fixed',
7371
top: '230px',
@@ -207,8 +205,6 @@ const fileMetaStyle: React.CSSProperties = {
207205
fontStyle: 'italic',
208206
};
209207

210-
// ... existing code ...
211-
212208
const emptyStateStyle: React.CSSProperties = {
213209
height: 'calc(100vh - 254px)',
214210
overflowY: 'auto',
@@ -320,6 +316,9 @@ export const ToolsPanel: React.FC<ToolsPanelProps> = ({ onEcoreFileUpload, onEco
320316
const itemsPerPage = 10;
321317
const [expandedCard, setExpandedCard] = useState<number | null>(null);
322318
const [parsedFilters, setParsedFilters] = useState<any[]>([]);
319+
const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
320+
const [deletingId, setDeletingId] = useState<string | null>(null);
321+
const [deleteError, setDeleteError] = useState<string>('');
323322

324323
const handleSearchKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
325324
if (e.key !== 'Tab') return;
@@ -629,6 +628,40 @@ export const ToolsPanel: React.FC<ToolsPanelProps> = ({ onEcoreFileUpload, onEco
629628

630629
const panelStyle: React.CSSProperties = { ...toolsPanelStyle, borderRight: showBorder ? toolsPanelStyle.borderRight : 'none' };
631630

631+
const handleDeleteClick = (id: string) => {
632+
setDeletingId(id);
633+
setDeleteError('');
634+
setDeleteConfirmOpen(true);
635+
};
636+
637+
const handleConfirmDelete = async () => {
638+
if (!deletingId) return;
639+
try {
640+
await apiService.deleteMetaModel(deletingId);
641+
setUploadMessage('Meta Model deleted successfully!');
642+
setUploadMessageType('success');
643+
// Refresh models
644+
const filters = buildApiFiltersFromParsedFilters(parsedFilters, true);
645+
const response = await apiService.findMetaModels(filters);
646+
setApiModels(response.data || []);
647+
setDeleteConfirmOpen(false);
648+
setDeletingId(null);
649+
setDeleteError('');
650+
setTimeout(() => setUploadMessage(''), 3000);
651+
} catch (error: any) {
652+
// Try to extract backend error message
653+
let msg = 'Failed to delete meta model';
654+
if (error?.response?.data?.message) {
655+
msg = error.response.data.message;
656+
} else if (error?.message) {
657+
msg = error.message;
658+
}
659+
setDeleteError(msg);
660+
setUploadMessage(msg);
661+
setUploadMessageType('error');
662+
}
663+
};
664+
632665
return (
633666
<div style={panelStyle}>
634667
<div style={titleStyle}>
@@ -919,8 +952,28 @@ export const ToolsPanel: React.FC<ToolsPanelProps> = ({ onEcoreFileUpload, onEco
919952
</span>
920953
</>
921954
)}
955+
{/* Delete button: always visible */}
956+
<button
957+
onClick={(e) => {
958+
e.stopPropagation();
959+
handleDeleteClick(model.id);
960+
}}
961+
style={{
962+
padding: '4px 8px',
963+
border: '1px solid #dee2e6',
964+
borderRadius: 6,
965+
background: '#fff',
966+
cursor: 'pointer',
967+
fontSize: 12,
968+
fontWeight: 600,
969+
color: '#e03131',
970+
marginLeft: 'auto'
971+
}}
972+
title="Delete this meta model"
973+
>
974+
Delete
975+
</button>
922976
</div>
923-
924977
{/* Expanded content - only show when card is expanded */}
925978
{expandedCard === model.id && (
926979
<>
@@ -1080,7 +1133,6 @@ export const ToolsPanel: React.FC<ToolsPanelProps> = ({ onEcoreFileUpload, onEco
10801133
const response = await apiService.findMetaModels(filters);
10811134
setApiModels(response.data || []);
10821135
} catch (error) {
1083-
console.error('Error fetching meta models from API:', error);
10841136
setApiError(error instanceof Error ? error.message : 'Failed to fetch meta models');
10851137
} finally {
10861138
setIsLoadingModels(false);
@@ -1089,6 +1141,82 @@ export const ToolsPanel: React.FC<ToolsPanelProps> = ({ onEcoreFileUpload, onEco
10891141
fetchData();
10901142
}}
10911143
/>
1144+
1145+
{/* Delete confirmation popup */}
1146+
{deleteConfirmOpen && (
1147+
<div style={{
1148+
position: 'fixed',
1149+
top: 0, left: 0, right: 0, bottom: 0,
1150+
background: 'rgba(0,0,0,0.25)',
1151+
zIndex: 9999,
1152+
display: 'flex',
1153+
alignItems: 'center',
1154+
justifyContent: 'center'
1155+
}}>
1156+
<div style={{
1157+
background: '#fff',
1158+
borderRadius: 8,
1159+
boxShadow: '0 4px 24px rgba(0,0,0,0.18)',
1160+
padding: '32px 24px',
1161+
minWidth: 320,
1162+
textAlign: 'center',
1163+
fontFamily: 'Georgia, serif'
1164+
}}>
1165+
<div style={{ fontSize: 16, fontWeight: 700, marginBottom: 16, color: '#e03131' }}>
1166+
Are you sure you want to delete this meta model?
1167+
</div>
1168+
<div style={{ fontSize: 13, color: '#495057', marginBottom: 24 }}>
1169+
This action cannot be undone.
1170+
</div>
1171+
{deleteError && (
1172+
<div style={{
1173+
color: '#e03131',
1174+
background: '#f8d7da',
1175+
border: '1px solid #f5c6cb',
1176+
borderRadius: 6,
1177+
padding: '8px',
1178+
marginBottom: '16px',
1179+
fontSize: 13,
1180+
fontWeight: 500,
1181+
}}>
1182+
{deleteError}
1183+
</div>
1184+
)}
1185+
<div style={{ display: 'flex', gap: 12, justifyContent: 'center' }}>
1186+
<button
1187+
style={{
1188+
padding: '8px 18px',
1189+
borderRadius: 6,
1190+
border: 'none',
1191+
background: '#e03131',
1192+
color: '#fff',
1193+
fontWeight: 600,
1194+
cursor: 'pointer',
1195+
fontSize: 14
1196+
}}
1197+
onClick={handleConfirmDelete}
1198+
>
1199+
Confirm
1200+
</button>
1201+
<button
1202+
style={{
1203+
padding: '8px 18px',
1204+
borderRadius: 6,
1205+
border: '1px solid #dee2e6',
1206+
background: '#fff',
1207+
color: '#495057',
1208+
fontWeight: 600,
1209+
cursor: 'pointer',
1210+
fontSize: 14
1211+
}}
1212+
onClick={() => { setDeleteConfirmOpen(false); setDeletingId(null); setDeleteError(''); }}
1213+
>
1214+
Cancel
1215+
</button>
1216+
</div>
1217+
</div>
1218+
</div>
1219+
)}
10921220
</div>
10931221
);
10941222
};

0 commit comments

Comments
 (0)