-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
146 additions
and
32 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
101 changes: 93 additions & 8 deletions
101
packages/geoview-core/src/core/components/data-grid/layer-data-grid.tsx
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 |
---|---|---|
@@ -1,19 +1,104 @@ | ||
import { DataGrid, DataGridProps } from '@mui/x-data-grid'; | ||
import { DataGrid, DataGridProps, gridClasses, GridToolbar, GridCellParams, frFR, enUS } from '@mui/x-data-grid'; | ||
|
||
import { TypeDisplayLanguage } from '../../../geo/map/map-schema-types'; | ||
import { Tooltip } from '../../../ui'; | ||
|
||
/** | ||
* Create a data grid (table) component for a lyer features all request | ||
* | ||
* @param {DataGridProps} props table properties | ||
* @returns {JSX.Element} returns table component | ||
*/ | ||
export function LayerDataGrid(props: DataGridProps) { | ||
|
||
// extend the DataGridProps to include the key row element | ||
interface CustomDataGridProps extends DataGridProps { | ||
rowId: string; | ||
displayLanguage: TypeDisplayLanguage; | ||
} | ||
|
||
const sxClasses = { | ||
DataGrid: { | ||
boxShadow: 2, | ||
border: 2, | ||
borderColor: 'primary.light', | ||
'& .MuiDataGrid-cell:hover': { | ||
color: 'text.primary', | ||
}, | ||
[`& div.even.${gridClasses.row}`]: { | ||
backgroundColor: 'grey.200', | ||
'&:hover, &.Mui-hovered': { | ||
backgroundColor: 'action.hoverRow', | ||
'@media (hover: none)': { | ||
backgroundColor: 'transparent', | ||
}, | ||
}, | ||
'&.Mui-selected': { | ||
backgroundColor: 'action.selectedRow', | ||
'&:hover, &.Mui-hovered': { | ||
backgroundColor: 'action.hoverRow', | ||
// Reset on touch devices, it doesn't add specificity | ||
'@media (hover: none)': { | ||
backgroundColor: 'action.selectedRow', | ||
}, | ||
}, | ||
}, | ||
}, | ||
[`& .${gridClasses.row}`]: { | ||
'&:hover, &.Mui-hovered': { | ||
backgroundColor: 'action.hoverRow', | ||
'@media (hover: none)': { | ||
backgroundColor: 'transparent', | ||
}, | ||
}, | ||
'&.Mui-selected': { | ||
backgroundColor: 'action.selectedRow', | ||
'&:hover, &.Mui-hovered': { | ||
backgroundColor: 'action.hoverRow', | ||
// Reset on touch devices, it doesn't add specificity | ||
'@media (hover: none)': { | ||
backgroundColor: 'action.selectedRow', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export function LayerDataGrid(props: CustomDataGridProps) { | ||
const { rowId, displayLanguage, columns } = props; | ||
|
||
// tooltip implementation for column content | ||
// TODO: works only with hover and add tooltips even when not needed. need improvement | ||
columns.forEach((column) => { | ||
// eslint-disable-next-line no-param-reassign | ||
column.renderCell = (params: GridCellParams) => ( | ||
<Tooltip title={params.value}> | ||
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>{params.value}</span> | ||
</Tooltip> | ||
); | ||
}); | ||
|
||
// set locale from display language | ||
const locale = | ||
displayLanguage === 'en' ? enUS.components.MuiDataGrid.defaultProps.localeText : frFR.components.MuiDataGrid.defaultProps.localeText; | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
{...props} | ||
getRowId={(row) => row.OBJECTID} | ||
getRowClassName={(params) => (params.indexRelativeToCurrentPage % 2 === 0 ? 'even' : 'odd')} | ||
/> | ||
<div style={{ display: 'flex', height: '100%' }}> | ||
<div style={{ flexGrow: 1 }}> | ||
<DataGrid | ||
localeText={locale} | ||
sx={sxClasses.DataGrid} | ||
{...props} | ||
getRowId={(row) => row[rowId]} | ||
getRowClassName={(params) => (params.indexRelativeToCurrentPage % 2 === 0 ? 'even' : 'odd')} | ||
checkboxSelection | ||
disableSelectionOnClick | ||
rowsPerPageOptions={[50]} | ||
components={{ | ||
Toolbar: GridToolbar, | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
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