diff --git a/src/reactviews/pages/SchemaCompare/components/SchemaDifferences.tsx b/src/reactviews/pages/SchemaCompare/components/SchemaDifferences.tsx index fc95c7f7de..c480c31a20 100644 --- a/src/reactviews/pages/SchemaCompare/components/SchemaDifferences.tsx +++ b/src/reactviews/pages/SchemaCompare/components/SchemaDifferences.tsx @@ -4,25 +4,24 @@ *--------------------------------------------------------------------------------------------*/ import * as React from "react"; -import { FixedSizeList as List, ListChildComponentProps } from "react-window"; import { - useScrollbarWidth, - useFluent, - TableBody, - TableCell, - TableRow, - Table, - TableHeader, - TableHeaderCell, createTableColumn, - useTableFeatures, - useTableSelection, - TableRowData as RowStateBase, TableColumnDefinition, Checkbox, makeStyles, Spinner, + DataGridHeader, + DataGridHeaderCell, + Text, + TableColumnSizingOptions, } from "@fluentui/react-components"; +import { + DataGridBody, + DataGrid, + DataGridRow, + DataGridCell, + RowRenderer, +} from "@fluentui-contrib/react-data-grid-react-window"; import { SchemaUpdateAction } from "../../../../sharedInterfaces/schemaCompare"; import { locConstants as loc } from "../../../common/locConstants"; import { DiffEntry } from "vscode-mssql"; @@ -72,19 +71,18 @@ const useStyles = makeStyles({ backgroundColor: "var(--vscode-scrollbarSlider-background)", opacity: 0.5, }, + hideTextOverflow: { + overflow: "hidden", + whiteSpace: "nowrap", + }, + alignSpinner: { + marginLeft: "8px", + }, + dataGridHeader: { + backgroundColor: "var(--vscode-keybindingTable-headerBackground)", + }, }); -interface TableRowData extends RowStateBase { - onClick: (e: React.MouseEvent) => void; - onKeyDown: (e: React.KeyboardEvent) => void; - selected: boolean; - appearance: "brand" | "none"; -} - -interface ReactWindowRenderFnProps extends ListChildComponentProps { - data: TableRowData[]; -} - interface Props { onDiffSelected: (id: number) => void; selectedDiffId: number; @@ -94,8 +92,6 @@ interface Props { export const SchemaDifferences = React.forwardRef( ({ onDiffSelected, selectedDiffId, siblingRef }, ref) => { const classes = useStyles(); - const { targetDocument } = useFluent(); - const scrollbarWidth = useScrollbarWidth({ targetDocument }); const context = React.useContext(schemaCompareContext); const compareResult = context.state.schemaCompareResult; const [diffInclusionLevel, setDiffInclusionLevel] = React.useState< @@ -114,16 +110,6 @@ export const SchemaDifferences = React.forwardRef( siblingRef, }); - // Add a reference to the List component - const listRef = React.useRef(null); - - // Use an effect to scroll to the selected row when selectedDiffId changes - React.useEffect(() => { - if (selectedDiffId >= 0 && listRef.current) { - listRef.current.scrollToItem(selectedDiffId, "center"); - } - }, [selectedDiffId]); - // Expose resizableRef via forwarded ref React.useImperativeHandle(ref, () => resizableRef.current!); @@ -196,39 +182,97 @@ export const SchemaDifferences = React.forwardRef( const columns: TableColumnDefinition[] = [ createTableColumn({ columnId: "type", + renderHeaderCell: () => loc.schemaCompare.type, renderCell: (item) => { - return {item.name}; + return ( + + + {item.name} + + + ); }, }), createTableColumn({ columnId: "sourceName", + renderHeaderCell: () => loc.schemaCompare.sourceName, renderCell: (item) => { - return {formatName(item.sourceValue)}; + return ( + + + {formatName(item.sourceValue)} + + + ); }, }), createTableColumn({ columnId: "include", + renderHeaderCell: () => { + if (context.state.isIncludeExcludeAllOperationInProgress) { + return ( +
+ +
+ ); + } + + return ( + handleIncludeExcludeAllNodes()} + onKeyDown={toggleAllKeydown} + /> + ); + }, renderCell: (item) => { return ( - + handleIncludeExcludeNode(item, !item.included)} + disabled={context.state.isIncludeExcludeAllOperationInProgress} /> - + ); }, }), createTableColumn({ columnId: "action", + renderHeaderCell: () => loc.schemaCompare.action, renderCell: (item) => { - return {getLabelForAction(item.updateAction as number)}; + return ( + + + {getLabelForAction(item.updateAction as number)} + + + ); }, }), createTableColumn({ columnId: "targetName", + renderHeaderCell: () => loc.schemaCompare.targetName, renderCell: (item) => { - return {formatName(item.targetValue)}; + return ( + + + {formatName(item.targetValue)} + + + ); }, }), ]; @@ -244,37 +288,6 @@ export const SchemaDifferences = React.forwardRef( ); } - const { - getRows, - selection: { toggleRow }, - } = useTableFeatures( - { - columns, - items, - }, - [ - useTableSelection({ - selectionMode: "multiselect", - }), - ], - ); - - const rows: TableRowData[] = getRows((row) => { - const selected = row.item.included; - return { - ...row, - onClick: (e: React.MouseEvent) => toggleRow(e, row.rowId), - onKeyDown: (e: React.KeyboardEvent) => { - if (e.key === " ") { - e.preventDefault(); - toggleRow(e, row.rowId); - } - }, - selected, - appearance: selected ? ("brand" as const) : ("none" as const), - }; - }); - const toggleAllKeydown = (e: React.KeyboardEvent) => { if (e.key === " ") { handleIncludeExcludeAllNodes(); @@ -282,113 +295,77 @@ export const SchemaDifferences = React.forwardRef( } }; - const toggleKeyDown = ( - e: React.KeyboardEvent, - diffEntry: DiffEntry, - include: boolean, - ) => { + const toggleKeyDown = (e: React.KeyboardEvent, diffEntry: DiffEntry) => { if (e.key === "Enter") { if (diffEntry.position !== undefined) { onDiffSelected(diffEntry.position); } e.preventDefault(); } - if (e.key === " ") { - handleIncludeExcludeNode(diffEntry, include); - e.preventDefault(); - } }; - const RenderRow = ({ index, style, data }: ReactWindowRenderFnProps) => { - const { item, appearance, onKeyDown } = data[index]; + const renderRow: RowRenderer = ({ item, rowId }, style) => { return ( - + key={rowId} + className={item.position === selectedDiffId ? classes.selectedRow : undefined} style={style} - key={item.position} - onKeyDown={onKeyDown} - onClick={() => onDiffSelected(index)} - appearance={appearance} - className={index === selectedDiffId ? classes.selectedRow : undefined}> - {item.name} - {formatName(item.sourceValue)} - - handleIncludeExcludeNode(item, !item.included)} - onKeyDown={(e) => toggleKeyDown(e, item, !item.included)} - disabled={context.state.isIncludeExcludeAllOperationInProgress} - /> - - {getLabelForAction(item.updateAction as number)} - {formatName(item.targetValue)} - + onClick={() => { + if (item.position !== undefined) { + onDiffSelected(item.position); + } + }} + onKeyDown={(e: React.KeyboardEvent) => toggleKeyDown(e, item)}> + {({ renderCell }) => <>{renderCell(item)}} + ); }; + const columnSizingOptions: TableColumnSizingOptions = { + type: { + minWidth: 100, + }, + sourceName: { + minWidth: 200, + defaultWidth: 350, + }, + include: { + minWidth: 60, + defaultWidth: 60, + }, + action: { + minWidth: 100, + }, + targetName: { + minWidth: 200, + }, + }; + return (
- - - - - {loc.schemaCompare.type} - - - {loc.schemaCompare.sourceName} - - - {!context.state.isIncludeExcludeAllOperationInProgress && ( - handleIncludeExcludeAllNodes()} - onKeyDown={toggleAllKeydown} - /> - )} - {context.state.isIncludeExcludeAllOperationInProgress && ( - - )} - - - {loc.schemaCompare.action} - - - {loc.schemaCompare.targetName} - - {/** Scrollbar alignment for the header */} -
- - - - - {RenderRow} - - -
+ (item as DiffEntry).position?.toString() ?? ""} + size="extra-small"> + + + {({ renderHeaderCell }) => ( + {renderHeaderCell()} + )} + + + itemSize={30} height={height - 40} width={"100%"}> + {renderRow} + + +