diff --git a/packages/web/src/datagrid/DataGridCore.js b/packages/web/src/datagrid/DataGridCore.js index 1146b4828..d8b225808 100644 --- a/packages/web/src/datagrid/DataGridCore.js +++ b/packages/web/src/datagrid/DataGridCore.js @@ -22,6 +22,7 @@ import { } from './selection'; import keycodes from '../utility/keycodes'; import InplaceEditor from './InplaceEditor'; +import DataGridRow from './DataGridRow'; const GridContainer = styled.div` position: absolute; @@ -54,16 +55,6 @@ const TableBody = styled.tbody` const TableHeaderRow = styled.tr` // height: 35px; `; -const TableBodyRow = styled.tr` - // height: 35px; - background-color: #ffffff; - &:nth-child(6n + 3) { - background-color: #ebebeb; - } - &:nth-child(6n + 6) { - background-color: #ebf5ff; - } -`; const TableHeaderCell = styled.td` // font-weight: bold; border: 1px solid #c0c0c0; @@ -79,40 +70,11 @@ const TableFilterCell = styled.td` margin: 0; padding: 0; `; -const TableBodyCell = styled.td` - font-weight: normal; - border: 1px solid #c0c0c0; - // border-collapse: collapse; - padding: 2px; - white-space: nowrap; - overflow: hidden; - ${props => - // @ts-ignore - props.isSelected && - ` - background: initial; - background-color: deepskyblue; - color: white;`} -`; -const HintSpan = styled.span` - color: gray; - margin-left: 5px; -`; -const NullSpan = styled.span` - color: gray; - font-style: italic; -`; const wheelRowCount = 5; -function CellFormattedValue({ value }) { - if (value == null) return (NULL); - if (_.isDate(value)) return moment(value).format('YYYY-MM-DD HH:mm:ss'); - return value; -} - /** @param props {import('./types').DataGridProps} */ export default function DataGridCore(props) { - const { conid, database, display, changeSet, tabVisible } = props; + const { conid, database, display, changeSet, setChangeSet, tabVisible } = props; const columns = display.getGridColumns(); // console.log(`GRID, conid=${conid}, database=${database}, sql=${sql}`); @@ -529,7 +491,7 @@ export default function DataGridCore(props) { const visibleRealColumnIndexes = []; const modelIndexes = {}; /** @type {(import('@dbgate/datalib').DisplayColumn & {widthPx: string; colIndex: number})[]} */ - const realColumns = []; + const visibleRealColumns = []; // frozen columns for (let colIndex = 0; colIndex < columnSizes.frozenCount; colIndex++) { @@ -552,7 +514,7 @@ export default function DataGridCore(props) { let col = columns[modelColumnIndex]; if (!col) continue; const widthNumber = columnSizes.getSizeByRealIndex(colIndex); - realColumns.push({ + visibleRealColumns.push({ ...col, colIndex, widthPx: `${widthNumber}px`, @@ -588,7 +550,7 @@ export default function DataGridCore(props) { - {realColumns.map(col => ( + {visibleRealColumns.map(col => ( )} - {realColumns.map(col => ( + {visibleRealColumns.map(col => ( ( - - - {firstVisibleRowScrollIndex + index + 1} - - {realColumns.map(col => ( - - {inplaceEditorCell && - firstVisibleRowScrollIndex + index == inplaceEditorCell[0] && - col.colIndex == inplaceEditorCell[1] ? ( - - ) : ( - <> - - {col.hintColumnName && {row[col.hintColumnName]}} - - )} - - ))} - + ))} diff --git a/packages/web/src/datagrid/DataGridRow.js b/packages/web/src/datagrid/DataGridRow.js new file mode 100644 index 000000000..57763f5ca --- /dev/null +++ b/packages/web/src/datagrid/DataGridRow.js @@ -0,0 +1,122 @@ +import moment from 'moment'; +import _ from 'lodash'; +import React from 'react'; +import useFetch from '../utility/useFetch'; +import styled from 'styled-components'; +import theme from '../theme'; +import { HorizontalScrollBar, VerticalScrollBar } from './ScrollBars'; +import useDimensions from '../utility/useDimensions'; +import { SeriesSizes } from './SeriesSizes'; +import axios from '../utility/axios'; +import ColumnLabel from './ColumnLabel'; +import DataFilterControl from './DataFilterControl'; +import { getFilterType } from '@dbgate/filterparser'; +import { + convertCellAddress, + cellFromEvent, + getCellRange, + topLeftCell, + isRegularCell, + nullCell, + emptyCellArray, +} from './selection'; +import keycodes from '../utility/keycodes'; +import InplaceEditor from './InplaceEditor'; + +const TableBodyCell = styled.td` + font-weight: normal; + border: 1px solid #c0c0c0; + // border-collapse: collapse; + padding: 2px; + white-space: nowrap; + overflow: hidden; + ${props => + // @ts-ignore + props.isSelected && + ` + background: initial; + background-color: deepskyblue; + color: white;`} +`; +const HintSpan = styled.span` + color: gray; + margin-left: 5px; +`; +const NullSpan = styled.span` + color: gray; + font-style: italic; +`; + +const TableBodyRow = styled.tr` + // height: 35px; + background-color: #ffffff; + &:nth-child(6n + 3) { + background-color: #ebebeb; + } + &:nth-child(6n + 6) { + background-color: #ebf5ff; + } +`; + +const TableHeaderCell = styled.td` + border: 1px solid #c0c0c0; + text-align: left; + padding: 2px; + background-color: #f6f7f9; + overflow: hidden; +`; + +function CellFormattedValue({ value }) { + if (value == null) return (NULL); + if (_.isDate(value)) return moment(value).format('YYYY-MM-DD HH:mm:ss'); + return value; +} + +export default function DataGridRow({ + rowHeight, + rowIndex, + visibleRealColumns, + inplaceEditorCell, + cellIsSelected, + row, + display, + changeSet, + setChangeSet, +}) { + return ( + + + {rowIndex + 1} + + {visibleRealColumns.map(col => ( + + {inplaceEditorCell && rowIndex == inplaceEditorCell[0] && col.colIndex == inplaceEditorCell[1] ? ( + + ) : ( + <> + + {col.hintColumnName && {row[col.hintColumnName]}} + + )} + + ))} + + ); +}