mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 12:35:25 +02:00
refactor(ui): remove excel export buttons
This commit is contained in:
+3
-58
@@ -10,7 +10,7 @@ import { TopBar } from './components/TopBar';
|
|||||||
import { ProductDescriptions } from './components/ProductDescriptions';
|
import { ProductDescriptions } from './components/ProductDescriptions';
|
||||||
import { MatrixView } from './components/MatrixView';
|
import { MatrixView } from './components/MatrixView';
|
||||||
import { EditPanel } from './components/EditPanel';
|
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 { getStoredSession, signOut, type AuthSession } from './lib/auth';
|
||||||
import { LoginPage } from './components/LoginPage';
|
import { LoginPage } from './components/LoginPage';
|
||||||
import { DimensionsView } from './components/DimensionsView';
|
import { DimensionsView } from './components/DimensionsView';
|
||||||
@@ -23,7 +23,7 @@ import { MissingDataView } from './components/MissingDataView';
|
|||||||
import { CosmeticItemsView } from './components/CosmeticItemsView';
|
import { CosmeticItemsView } from './components/CosmeticItemsView';
|
||||||
import { ControlDashboardView } from './components/ControlDashboardView';
|
import { ControlDashboardView } from './components/ControlDashboardView';
|
||||||
import { UserManagementView } from './components/UserManagementView';
|
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';
|
import { ControlTabId, type DashboardDrilldownRequest } from './lib/controlDashboard';
|
||||||
|
|
||||||
const FORCED_ZERO_STOCK_SKUS = new Set([
|
const FORCED_ZERO_STOCK_SKUS = new Set([
|
||||||
@@ -109,7 +109,6 @@ export default function App() {
|
|||||||
const [bcSyncQueue, setBcSyncQueue] = useState<BcSyncQueue>(() => readStoredBcSyncQueue());
|
const [bcSyncQueue, setBcSyncQueue] = useState<BcSyncQueue>(() => readStoredBcSyncQueue());
|
||||||
const [isSavingAll, setIsSavingAll] = useState(false);
|
const [isSavingAll, setIsSavingAll] = useState(false);
|
||||||
const [isSyncingBC, setIsSyncingBC] = useState(false);
|
const [isSyncingBC, setIsSyncingBC] = useState(false);
|
||||||
const [isDownloadingBCExcel, setIsDownloadingBCExcel] = useState(false);
|
|
||||||
const [refreshTrigger, setRefreshTrigger] = useState(0);
|
const [refreshTrigger, setRefreshTrigger] = useState(0);
|
||||||
const [dashboardDrilldown, setDashboardDrilldown] = useState<DashboardDrilldownRequest | null>(null);
|
const [dashboardDrilldown, setDashboardDrilldown] = useState<DashboardDrilldownRequest | null>(null);
|
||||||
|
|
||||||
@@ -507,43 +506,6 @@ export default function App() {
|
|||||||
reader.readAsBinaryString(file);
|
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 handleSaveRow = (rowIndex: number, updatedRow: ExcelRow) => {
|
||||||
const articleNo = String(updatedRow[COLUMNS.ARTICLE_NO]);
|
const articleNo = String(updatedRow[COLUMNS.ARTICLE_NO]);
|
||||||
const currentPending = pendingRows[articleNo];
|
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) => {
|
const captureState = (message: string) => {
|
||||||
setUndoHistory(prev => {
|
setUndoHistory(prev => {
|
||||||
const newState = {
|
const newState = {
|
||||||
@@ -1009,14 +959,10 @@ export default function App() {
|
|||||||
<FilterProvider>
|
<FilterProvider>
|
||||||
<div className="h-screen bg-[#040d1a] text-slate-200 flex flex-col font-sans overflow-hidden">
|
<div className="h-screen bg-[#040d1a] text-slate-200 flex flex-col font-sans overflow-hidden">
|
||||||
{!isMaximized && (
|
{!isMaximized && (
|
||||||
<TopBar
|
<TopBar
|
||||||
stats={stats}
|
stats={stats}
|
||||||
activeModule={activeModule}
|
activeModule={activeModule}
|
||||||
onExport={handleExport}
|
|
||||||
onDownloadBCExcel={handleDownloadBCExcel}
|
|
||||||
onRefresh={() => { setRefreshTrigger(t => t + 1); }}
|
onRefresh={() => { setRefreshTrigger(t => t + 1); }}
|
||||||
hasData={appState.data.length > 0}
|
|
||||||
hasUnsavedChanges={appState.hasUnsavedChanges}
|
|
||||||
userEmail={session.user.email}
|
userEmail={session.user.email}
|
||||||
onSignOut={handleSignOut}
|
onSignOut={handleSignOut}
|
||||||
canUndo={undoHistory.length > 0}
|
canUndo={undoHistory.length > 0}
|
||||||
@@ -1036,7 +982,6 @@ export default function App() {
|
|||||||
onSyncSelectedBcSync={handleSyncSelectedBcSync}
|
onSyncSelectedBcSync={handleSyncSelectedBcSync}
|
||||||
onDiscardSelectedBcQueue={handleDiscardSelectedBcQueue}
|
onDiscardSelectedBcQueue={handleDiscardSelectedBcQueue}
|
||||||
isSyncingBC={isSyncingBC}
|
isSyncingBC={isSyncingBC}
|
||||||
isDownloadingBCExcel={isDownloadingBCExcel}
|
|
||||||
isMaximized={isMaximized}
|
isMaximized={isMaximized}
|
||||||
onToggleMaximize={() => setIsMaximized(true)}
|
onToggleMaximize={() => setIsMaximized(true)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import React, { useState, useRef, useEffect } from 'react';
|
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';
|
import { cn } from '../lib/utils';
|
||||||
|
|
||||||
interface TopBarProps {
|
interface TopBarProps {
|
||||||
stats: any;
|
stats: any;
|
||||||
activeModule?: string;
|
activeModule?: string;
|
||||||
onExport: () => void;
|
|
||||||
onDownloadBCExcel: () => void;
|
|
||||||
onRefresh?: () => void;
|
onRefresh?: () => void;
|
||||||
hasData: boolean;
|
|
||||||
hasUnsavedChanges: boolean;
|
|
||||||
userEmail?: string;
|
userEmail?: string;
|
||||||
onSignOut?: () => void;
|
onSignOut?: () => void;
|
||||||
canUndo: boolean;
|
canUndo: boolean;
|
||||||
@@ -29,12 +25,11 @@ interface TopBarProps {
|
|||||||
onSyncSelectedBcSync: () => Promise<void>;
|
onSyncSelectedBcSync: () => Promise<void>;
|
||||||
onDiscardSelectedBcQueue: () => void;
|
onDiscardSelectedBcQueue: () => void;
|
||||||
isSyncingBC: boolean;
|
isSyncingBC: boolean;
|
||||||
isDownloadingBCExcel: boolean;
|
|
||||||
isMaximized: boolean;
|
isMaximized: boolean;
|
||||||
onToggleMaximize: () => void;
|
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 [showPending, setShowPending] = useState(false);
|
||||||
const [showBcQueue, setShowBcQueue] = useState(false);
|
const [showBcQueue, setShowBcQueue] = useState(false);
|
||||||
const pendingDropdownRef = useRef<HTMLDivElement>(null);
|
const pendingDropdownRef = useRef<HTMLDivElement>(null);
|
||||||
@@ -293,36 +288,6 @@ export function TopBar({ stats, activeModule, onExport, onDownloadBCExcel, onRef
|
|||||||
)}
|
)}
|
||||||
</div>
|
</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 && (
|
{onRefresh && (
|
||||||
<button
|
<button
|
||||||
onClick={onRefresh}
|
onClick={onRefresh}
|
||||||
|
|||||||
Reference in New Issue
Block a user