feat: add MainContent component with Excel-like bulk editing, batch updates, and navigation tabs
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
|||||||
Save,
|
Save,
|
||||||
Undo
|
Undo
|
||||||
} from '@mui/icons-material';
|
} from '@mui/icons-material';
|
||||||
import { DataGrid, type GridPaginationModel, type GridRowModel } from '@mui/x-data-grid';
|
import { DataGrid, useGridApiRef, type GridPaginationModel, type GridRowModel } from '@mui/x-data-grid';
|
||||||
import { useAppStore } from '../store/useAppStore';
|
import { useAppStore } from '../store/useAppStore';
|
||||||
import { SchemaService } from '../services/api';
|
import { SchemaService } from '../services/api';
|
||||||
import TransferContent from './TransferContent';
|
import TransferContent from './TransferContent';
|
||||||
@@ -33,6 +33,7 @@ import type { MainNotification } from '../types/database';
|
|||||||
|
|
||||||
const MainContent: React.FC = () => {
|
const MainContent: React.FC = () => {
|
||||||
const { activeTable, activeDatabase, darkMode, dbTab, setDbTab } = useAppStore();
|
const { activeTable, activeDatabase, darkMode, dbTab, setDbTab } = useAppStore();
|
||||||
|
const apiRef = useGridApiRef();
|
||||||
|
|
||||||
const [paginationModel, setPaginationModel] = useState<GridPaginationModel>({
|
const [paginationModel, setPaginationModel] = useState<GridPaginationModel>({
|
||||||
page: 0,
|
page: 0,
|
||||||
@@ -217,6 +218,21 @@ const MainContent: React.FC = () => {
|
|||||||
return () => window.removeEventListener('mouseup', handleMouseUp);
|
return () => window.removeEventListener('mouseup', handleMouseUp);
|
||||||
}, [handleMouseUp]);
|
}, [handleMouseUp]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const api = apiRef.current;
|
||||||
|
if (!api || !api.subscribeEvent) return;
|
||||||
|
|
||||||
|
const unsubs = [
|
||||||
|
api.subscribeEvent('cellFocusIn', (params) => {
|
||||||
|
setCellFocus({ id: params.id, field: params.field });
|
||||||
|
}),
|
||||||
|
api.subscribeEvent('cellMouseDown', handleCellMouseDown),
|
||||||
|
api.subscribeEvent('cellMouseOver', handleCellMouseEnter)
|
||||||
|
];
|
||||||
|
|
||||||
|
return () => unsubs.forEach(unsub => unsub?.());
|
||||||
|
}, [apiRef, activeTable, handleCellMouseDown, handleCellMouseEnter]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPaginationModel({ page: 0, pageSize: 100 });
|
setPaginationModel({ page: 0, pageSize: 100 });
|
||||||
setPendingChanges({});
|
setPendingChanges({});
|
||||||
@@ -335,6 +351,7 @@ const MainContent: React.FC = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
) : (
|
) : (
|
||||||
<DataGrid
|
<DataGrid
|
||||||
|
apiRef={apiRef}
|
||||||
rows={rows.map(row => ({
|
rows={rows.map(row => ({
|
||||||
...row,
|
...row,
|
||||||
...(pendingChanges[row[primaryKey]] || {})
|
...(pendingChanges[row[primaryKey]] || {})
|
||||||
@@ -351,9 +368,6 @@ const MainContent: React.FC = () => {
|
|||||||
onProcessRowUpdateError={(error) => {
|
onProcessRowUpdateError={(error) => {
|
||||||
console.error('Row update error:', error);
|
console.error('Row update error:', error);
|
||||||
}}
|
}}
|
||||||
onCellFocusIn={(params) => setCellFocus({ id: params.id, field: params.field })}
|
|
||||||
onCellMouseDown={handleCellMouseDown}
|
|
||||||
onCellMouseEnter={handleCellMouseEnter}
|
|
||||||
slotProps={{
|
slotProps={{
|
||||||
root: {
|
root: {
|
||||||
onPaste: handlePaste,
|
onPaste: handlePaste,
|
||||||
|
|||||||
Reference in New Issue
Block a user