Skip to content

Commit

Permalink
Add SciDataGrid and Filters components to explore-data task flow
Browse files Browse the repository at this point in the history
  • Loading branch information
codytodonnell committed Aug 16, 2024
1 parent 4af8541 commit 6391321
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 56 deletions.
36 changes: 26 additions & 10 deletions strudel-components/lib/components/SciDataGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Stack, Typography } from '@mui/material';
import { Box, Typography } from '@mui/material';
import { DataGrid, DataGridProps, GridColDef, GridColumnHeaderParams, GridRenderCellParams } from '@mui/x-data-grid';
import React, { ReactNode } from 'react';
import { ArrayWithPopover } from './ArrayWithPopover';
Expand Down Expand Up @@ -40,15 +40,31 @@ const getGridColumns = (columns: SciDataGridColDef[]) => {
...gridColumn
} = column;

/** Render unit label underneath the headerName */
if (units) {
gridColumn.renderHeader = (params: GridColumnHeaderParams) => (
<Stack>
<Typography fontSize="0.875rem" fontWeight="bold">{params.colDef.headerName}</Typography>
<Typography fontSize="small" color="grey.700">{units}</Typography>
</Stack>
)
}
/**
* Style column header and render unit label
* underneath the headerName if units supplied
*/
gridColumn.renderHeader = (params: GridColumnHeaderParams) => (
<Box>
<Typography fontSize="0.875rem" fontWeight="bold">{params.colDef.headerName}</Typography>
{units && (
<Typography
fontSize="small"
color="grey.700"
sx={{
position: 'absolute',
bottom: '4px',
left: params.colDef.type !== 'number' ? 0 : 'auto',
right: params.colDef.type === 'number' ? 0 : 'auto',
transform: 'translate(0, 0)',
zIndex: 1000
}}
>
{units}
</Typography>
)}
</Box>
)

/** Handle value transformation options */
if (!gridColumn.valueFormatter) {
Expand Down
45 changes: 12 additions & 33 deletions strudel-components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions strudel-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
},
"peerDependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@mui/icons-material": "^5.15.15",
"@mui/material": "^5.15.15",
"@mui/x-data-grid": "^7.11.0",
"@mui/x-date-pickers": "^7.11.0",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.15.14",
"@mui/material": "^5.15.14",
"@mui/x-data-grid": "^7.0.0",
"@mui/x-date-pickers": "^7.0.0",
"dayjs": "^1.11.12",
"react": "^18.0.0",
"react-dom": "^18.0.0"
Expand Down
4 changes: 2 additions & 2 deletions strudel-components/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function App() {
<LocalizationProvider dateAdapter={AdapterDayjs}>
<ThemeProvider theme={createTheme()}>
<CssBaseline />
{/* <SciDataGridEx /> */}
<SciDataGridEx />
{/* <FiltersExGroups /> */}
<FiltersExNoGroups />
{/* <FiltersExNoGroups /> */}
</ThemeProvider>
</LocalizationProvider>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import FilterListIcon from '@mui/icons-material/FilterList';
import { Button, Paper, Stack, TextField, Typography } from '@mui/material';
import { GridEventListener } from '@mui/x-data-grid';
import { SciDataGrid } from '@strudel-science/components';
import React from 'react';
import { DataGrid } from '@mui/x-data-grid';
import { useExploreData } from '../_context/ContextProvider';
import { setPreviewItem, setSearch } from '../_context/actions';

Expand All @@ -18,7 +18,7 @@ interface DataTablePanelProps {
export const DataTablePanel: React.FC<DataTablePanelProps> = (props) => {
const {state, dispatch} = useExploreData();

const handleRowClick: GridEventListener<'rowClick'> = (rowData) => {
const handleRowClick: GridEventListener<"rowClick"> = (rowData) => {
dispatch(setPreviewItem(rowData.row));
};

Expand Down Expand Up @@ -53,9 +53,9 @@ export const DataTablePanel: React.FC<DataTablePanelProps> = (props) => {
onChange={handleSearch}
/>
</Stack>
<DataGrid
<SciDataGrid
rows={state.filteredData || []}
getRowId={(row) => row[state.dataIdField]}
getRowId={(row: any) => row[state.dataIdField]}
columns={state.columns}
disableColumnSelector
initialState={{
Expand All @@ -64,6 +64,7 @@ export const DataTablePanel: React.FC<DataTablePanelProps> = (props) => {
{...props}
onRowClick={handleRowClick}
sx={{
border: 'none',
'& .MuiDataGrid-cell:focus-within': {
outline: 'none'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const FiltersPanel: React.FC<FiltersPanelProps> = (props) => {
grouped={false}
onClose={props.onClose}
onChange={handleFiltersChange}
sx={{
border: 'none'
}}
>
{taskflow.pages.index.tableFilters.map((f, i) => (
<FilterField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ export const taskflow: ExploreDataConfig = {
{
field: "Organism",
headerName: "Organism",
hasPopover: true,
units: "test",
width: 200
},
{
field: "Common Name",
headerName: "Common Name",
units: "test",
width: 200
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GridColDef } from "@mui/x-data-grid"
import { SciDataGridColDef } from "@strudel-science/components"
import { FilterComponent, FilterOperator } from "@strudel-science/components/dist/components/FilterField"

/**
Expand All @@ -22,7 +22,7 @@ export interface ExploreDataConfig {
index: {
title: string,
description: string,
tableColumns: GridColDef[],
tableColumns: SciDataGridColDef[],
tableFilters: {
field: string,
label: string,
Expand Down

0 comments on commit 6391321

Please sign in to comment.