-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from andrewisen-tikab/feature
Add `DataGrid`
- Loading branch information
Showing
3 changed files
with
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,58 @@ | ||
import React from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import Button from '@mui/material/Button'; | ||
|
||
import { DataGrid, GridColDef } from '@mui/x-data-grid'; | ||
import { styled } from '@mui/material/styles'; | ||
|
||
import BCFViewer from '../../viewer/BCFViewer'; | ||
import { RootState } from '../state/store'; | ||
import { selectTopic } from '../state/bcfSlice'; | ||
import * as BCF from '../../../src'; | ||
|
||
type IssueItemProps = { | ||
isSelected?: boolean; | ||
topic: BCF.THREE.Topic_Three; | ||
children: React.ReactNode; | ||
}; | ||
function IssueItem({ children, topic, isSelected }: IssueItemProps) { | ||
const dispatch = useDispatch(); | ||
const onClick = () => { | ||
BCFViewer.setTopicCameraState(topic); | ||
const columns: GridColDef[] = [ | ||
{ field: 'index', headerName: 'No.', type: 'number', width: 80 }, | ||
{ field: 'title', headerName: 'Title', width: 200 }, | ||
{ field: 'description', headerName: 'Description', flex: 1 }, | ||
]; | ||
|
||
dispatch(selectTopic(topic.index)); | ||
}; | ||
return ( | ||
<Button variant={isSelected ? 'outlined' : 'text'} onClick={onClick}> | ||
{children} | ||
</Button> | ||
); | ||
} | ||
const StyledDataGrid = styled(DataGrid)(({ theme }) => ({ | ||
'.selected-row': { backgroundColor: theme.palette.action.selected }, | ||
})); | ||
|
||
export default function IssueList() { | ||
const topics = useSelector((state: RootState) => state.bcf.topics); | ||
const selected = useSelector((state: RootState) => state.bcf.selectedTopic); | ||
const dispatch = useDispatch(); | ||
|
||
const topicList = topics.map((input) => { | ||
const topic = new BCF.THREE.Topic_Three(); | ||
topic.fromJSON(input); | ||
const { uuid } = topic; | ||
return ( | ||
<div style={{ height: '100%', width: '100%' }}> | ||
<StyledDataGrid | ||
rows={topics} | ||
columns={columns} | ||
initialState={{ | ||
pagination: { | ||
paginationModel: { page: 0, pageSize: 5 }, | ||
}, | ||
}} | ||
pageSizeOptions={[5, 10]} | ||
getRowId={(row) => row.uuid} | ||
onRowClick={(params) => { | ||
// Find the topic from the state | ||
const topic = topics.filter((topic) => topic.uuid === params.id)[0]; | ||
if (!topic) return; | ||
|
||
return ( | ||
<IssueItem key={uuid} topic={topic} isSelected={selected?.uuid === uuid}> | ||
{topic.direction} | ||
</IssueItem> | ||
); | ||
}); | ||
// Convert the topic to the THREE.js version | ||
const topic3 = new BCF.THREE.Topic_Three(); | ||
topic3.fromJSON(topic); | ||
BCFViewer.setTopicCameraState(topic3); | ||
|
||
return <div>{topicList}</div>; | ||
// Finally, update the state | ||
dispatch(selectTopic(topic.index)); | ||
}} | ||
getCellClassName={(params: any) => { | ||
return params.id === selected?.uuid ? 'selected-row' : ''; | ||
}} | ||
/> | ||
</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