-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4001 - Datatable use Datagrid - Editable borders corrections (#4230)
* 4001 - Move grid utils to DataGrid * 4001 - Correct cell border rendering when adjacent cells are non-editable * 4001 - Rename vars to lastEditableRow and lastEditableCol * 4001 - Put editable border scss vars together
- Loading branch information
Showing
6 changed files
with
112 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/client/pages/Section/DataTable/Table/hooks/useCellBorderCorrection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { MutableRefObject, useEffect } from 'react' | ||
|
||
import { Objects } from 'utils/objects' | ||
|
||
import { Row } from 'meta/assessment' | ||
|
||
import { getDataGridElementMatrix } from 'client/components/DataGrid/utils' | ||
|
||
type Props = { | ||
disabled: boolean | ||
gridRef: MutableRefObject<HTMLDivElement> | ||
rowsData: Array<Row> | ||
rowsHeader: Array<Row> | ||
} | ||
|
||
export const useCellBorderCorrection = (props: Props) => { | ||
const { disabled, gridRef, rowsData, rowsHeader } = props | ||
|
||
useEffect(() => { | ||
if (!gridRef?.current) return | ||
|
||
if (disabled) return | ||
|
||
const dataGridElementMatrix = getDataGridElementMatrix(gridRef.current) | ||
|
||
dataGridElementMatrix.forEach((row, rowIndex) => { | ||
row.forEach((cell, colIndex) => { | ||
if (Objects.isEmpty(cell)) return | ||
|
||
const isEditable = cell.classList.contains('editable') | ||
|
||
if (!isEditable) return | ||
|
||
const rightCell = row[colIndex + 1] | ||
const bottomCell = dataGridElementMatrix[rowIndex + 1]?.[colIndex] | ||
|
||
if (!Objects.isEmpty(rightCell) && !rightCell.classList.contains('editable')) { | ||
if (!rightCell.classList.contains('actions')) { | ||
cell.classList.add('lastEditableCol') | ||
} | ||
} | ||
|
||
if (!Objects.isEmpty(bottomCell) && !bottomCell.classList.contains('editable')) { | ||
if (!bottomCell.classList.contains('actions')) { | ||
cell.classList.add('lastEditableRow') | ||
} | ||
} | ||
}) | ||
}) | ||
}, [disabled, gridRef, rowsData.length, rowsHeader.length]) | ||
} |