refactor(ui): remove excel export buttons

This commit is contained in:
Christian Vidal Wolf
2026-05-26 11:30:12 +02:00
parent 4037f7924a
commit 178d34bc45
2 changed files with 5 additions and 95 deletions
+3 -58
View File
@@ -10,7 +10,7 @@ import { TopBar } from './components/TopBar';
import { ProductDescriptions } from './components/ProductDescriptions';
import { MatrixView } from './components/MatrixView';
import { EditPanel } from './components/EditPanel';
import { getAllSyncedRows, saveRowToSupabase, resetAllPendingRows, saveHistoryEntry, deleteHistoryEntry, getHistoryDataForMerge } from './lib/supabase';
import { getAllSyncedRows, saveRowToSupabase, saveHistoryEntry, deleteHistoryEntry, getHistoryDataForMerge } from './lib/supabase';
import { getStoredSession, signOut, type AuthSession } from './lib/auth';
import { LoginPage } from './components/LoginPage';
import { DimensionsView } from './components/DimensionsView';
@@ -23,7 +23,7 @@ import { MissingDataView } from './components/MissingDataView';
import { CosmeticItemsView } from './components/CosmeticItemsView';
import { ControlDashboardView } from './components/ControlDashboardView';
import { UserManagementView } from './components/UserManagementView';
import { downloadBusinessCentralItemsExcel, previewBusinessCentralSync, applyBusinessCentralSync, isPreviewTokenMismatchError } from './services/businessCentral';
import { previewBusinessCentralSync, applyBusinessCentralSync, isPreviewTokenMismatchError } from './services/businessCentral';
import { ControlTabId, type DashboardDrilldownRequest } from './lib/controlDashboard';
const FORCED_ZERO_STOCK_SKUS = new Set([
@@ -109,7 +109,6 @@ export default function App() {
const [bcSyncQueue, setBcSyncQueue] = useState<BcSyncQueue>(() => readStoredBcSyncQueue());
const [isSavingAll, setIsSavingAll] = useState(false);
const [isSyncingBC, setIsSyncingBC] = useState(false);
const [isDownloadingBCExcel, setIsDownloadingBCExcel] = useState(false);
const [refreshTrigger, setRefreshTrigger] = useState(0);
const [dashboardDrilldown, setDashboardDrilldown] = useState<DashboardDrilldownRequest | null>(null);
@@ -507,43 +506,6 @@ export default function App() {
reader.readAsBinaryString(file);
};
const handleExport = () => {
if (appState.data.length === 0) return;
const wsData = [
appState.headers,
...appState.data.map(row => {
const copy = [...row];
delete copy[COLUMNS.VERIFIED_DIMS];
return copy.slice(0, appState.headers.length);
})
];
const ws = XLSX.utils.aoa_to_sheet(wsData);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Products');
const dateStr = new Date().toISOString().split('T')[0];
XLSX.writeFile(wb, `CRAZE_Products_Updated_${dateStr}.xlsx`);
// 3. Post-export: Reset pending statuses in Supabase (pending → edited to preserve on reload)
console.log('Resetting pending statuses in Supabase...');
resetAllPendingRows().then(success => {
if (success) {
console.log('Successfully reset all pending statuses');
// Only clear 'pending' statuses locally; keep 'edited'/'saved' so they remain visible
setRowStatuses((prev: Record<string, string>) => {
const next: Record<string, string> = {};
for (const [id, status] of Object.entries(prev)) {
if (status !== 'pending') next[id] = status as string;
}
return next;
});
}
});
setAppState(prev => ({ ...prev, hasUnsavedChanges: false }));
};
const handleSaveRow = (rowIndex: number, updatedRow: ExcelRow) => {
const articleNo = String(updatedRow[COLUMNS.ARTICLE_NO]);
const currentPending = pendingRows[articleNo];
@@ -915,18 +877,6 @@ export default function App() {
}
};
const handleDownloadBCExcel = async () => {
setIsDownloadingBCExcel(true);
try {
const result = await downloadBusinessCentralItemsExcel();
if (!result.success) {
alert(`Failed to download Business Central Excel:\n\n${result.error || 'Unknown error'}`);
}
} finally {
setIsDownloadingBCExcel(false);
}
};
const captureState = (message: string) => {
setUndoHistory(prev => {
const newState = {
@@ -1009,14 +959,10 @@ export default function App() {
<FilterProvider>
<div className="h-screen bg-[#040d1a] text-slate-200 flex flex-col font-sans overflow-hidden">
{!isMaximized && (
<TopBar
<TopBar
stats={stats}
activeModule={activeModule}
onExport={handleExport}
onDownloadBCExcel={handleDownloadBCExcel}
onRefresh={() => { setRefreshTrigger(t => t + 1); }}
hasData={appState.data.length > 0}
hasUnsavedChanges={appState.hasUnsavedChanges}
userEmail={session.user.email}
onSignOut={handleSignOut}
canUndo={undoHistory.length > 0}
@@ -1036,7 +982,6 @@ export default function App() {
onSyncSelectedBcSync={handleSyncSelectedBcSync}
onDiscardSelectedBcQueue={handleDiscardSelectedBcQueue}
isSyncingBC={isSyncingBC}
isDownloadingBCExcel={isDownloadingBCExcel}
isMaximized={isMaximized}
onToggleMaximize={() => setIsMaximized(true)}
/>
+2 -37
View File
@@ -1,15 +1,11 @@
import React, { useState, useRef, useEffect } from 'react';
import { Download, LogOut, Undo2, CloudUpload, Loader2, ChevronDown, RotateCcw, Maximize2, X, CloudDownload } from 'lucide-react';
import { LogOut, Undo2, CloudUpload, Loader2, ChevronDown, RotateCcw, Maximize2, X } from 'lucide-react';
import { cn } from '../lib/utils';
interface TopBarProps {
stats: any;
activeModule?: string;
onExport: () => void;
onDownloadBCExcel: () => void;
onRefresh?: () => void;
hasData: boolean;
hasUnsavedChanges: boolean;
userEmail?: string;
onSignOut?: () => void;
canUndo: boolean;
@@ -29,12 +25,11 @@ interface TopBarProps {
onSyncSelectedBcSync: () => Promise<void>;
onDiscardSelectedBcQueue: () => void;
isSyncingBC: boolean;
isDownloadingBCExcel: boolean;
isMaximized: boolean;
onToggleMaximize: () => void;
}
export function TopBar({ stats, activeModule, onExport, onDownloadBCExcel, onRefresh, hasData, hasUnsavedChanges, userEmail, onSignOut, canUndo, onUndo, undoMessage, undoSteps, pendingCount, pendingChanges, onSaveAll, onRevertRow, isSavingAll, bcQueueCount, bcQueueEntries, onToggleBcQueueSelection, onSelectAllBcQueue, onPreviewSelectedBcSync, onSyncSelectedBcSync, onDiscardSelectedBcQueue, isSyncingBC, isDownloadingBCExcel, isMaximized, onToggleMaximize }: TopBarProps) {
export function TopBar({ stats, activeModule, onRefresh, userEmail, onSignOut, canUndo, onUndo, undoMessage, undoSteps, pendingCount, pendingChanges, onSaveAll, onRevertRow, isSavingAll, bcQueueCount, bcQueueEntries, onToggleBcQueueSelection, onSelectAllBcQueue, onPreviewSelectedBcSync, onSyncSelectedBcSync, onDiscardSelectedBcQueue, isSyncingBC, isMaximized, onToggleMaximize }: TopBarProps) {
const [showPending, setShowPending] = useState(false);
const [showBcQueue, setShowBcQueue] = useState(false);
const pendingDropdownRef = useRef<HTMLDivElement>(null);
@@ -293,36 +288,6 @@ export function TopBar({ stats, activeModule, onExport, onDownloadBCExcel, onRef
)}
</div>
{hasData && (
<button
onClick={onExport}
className={`flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-colors ${
hasUnsavedChanges
? 'bg-blue-600 hover:bg-blue-700 text-white'
: 'bg-slate-700 hover:bg-slate-600 text-slate-200'
}`}
>
<Download className="w-4 h-4" />
Export Updated Excel
{hasUnsavedChanges && <span className="w-2 h-2 rounded-full bg-red-500 ml-1 animate-pulse" />}
</button>
)}
<button
onClick={onDownloadBCExcel}
disabled={isDownloadingBCExcel}
className={cn(
'flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-colors',
isDownloadingBCExcel
? 'bg-slate-700 text-slate-400 cursor-wait'
: 'bg-slate-700 hover:bg-slate-600 text-slate-200'
)}
title="Download the latest table directly from Business Central"
>
{isDownloadingBCExcel ? <Loader2 className="w-4 h-4 animate-spin" /> : <CloudDownload className="w-4 h-4" />}
Download BC Excel
</button>
{onRefresh && (
<button
onClick={onRefresh}