Skip to content

Commit 6391321

Browse files
committed
Add SciDataGrid and Filters components to explore-data task flow
1 parent 4af8541 commit 6391321

File tree

8 files changed

+58
-56
lines changed

8 files changed

+58
-56
lines changed

strudel-components/lib/components/SciDataGrid.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Stack, Typography } from '@mui/material';
1+
import { Box, Typography } from '@mui/material';
22
import { DataGrid, DataGridProps, GridColDef, GridColumnHeaderParams, GridRenderCellParams } from '@mui/x-data-grid';
33
import React, { ReactNode } from 'react';
44
import { ArrayWithPopover } from './ArrayWithPopover';
@@ -40,15 +40,31 @@ const getGridColumns = (columns: SciDataGridColDef[]) => {
4040
...gridColumn
4141
} = column;
4242

43-
/** Render unit label underneath the headerName */
44-
if (units) {
45-
gridColumn.renderHeader = (params: GridColumnHeaderParams) => (
46-
<Stack>
47-
<Typography fontSize="0.875rem" fontWeight="bold">{params.colDef.headerName}</Typography>
48-
<Typography fontSize="small" color="grey.700">{units}</Typography>
49-
</Stack>
50-
)
51-
}
43+
/**
44+
* Style column header and render unit label
45+
* underneath the headerName if units supplied
46+
*/
47+
gridColumn.renderHeader = (params: GridColumnHeaderParams) => (
48+
<Box>
49+
<Typography fontSize="0.875rem" fontWeight="bold">{params.colDef.headerName}</Typography>
50+
{units && (
51+
<Typography
52+
fontSize="small"
53+
color="grey.700"
54+
sx={{
55+
position: 'absolute',
56+
bottom: '4px',
57+
left: params.colDef.type !== 'number' ? 0 : 'auto',
58+
right: params.colDef.type === 'number' ? 0 : 'auto',
59+
transform: 'translate(0, 0)',
60+
zIndex: 1000
61+
}}
62+
>
63+
{units}
64+
</Typography>
65+
)}
66+
</Box>
67+
)
5268

5369
/** Handle value transformation options */
5470
if (!gridColumn.valueFormatter) {

strudel-components/package-lock.json

Lines changed: 12 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

strudel-components/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
},
3939
"peerDependencies": {
4040
"@emotion/react": "^11.11.4",
41-
"@emotion/styled": "^11.11.5",
42-
"@mui/icons-material": "^5.15.15",
43-
"@mui/material": "^5.15.15",
44-
"@mui/x-data-grid": "^7.11.0",
45-
"@mui/x-date-pickers": "^7.11.0",
41+
"@emotion/styled": "^11.11.0",
42+
"@mui/icons-material": "^5.15.14",
43+
"@mui/material": "^5.15.14",
44+
"@mui/x-data-grid": "^7.0.0",
45+
"@mui/x-date-pickers": "^7.0.0",
4646
"dayjs": "^1.11.12",
4747
"react": "^18.0.0",
4848
"react-dom": "^18.0.0"

strudel-components/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ function App() {
1313
<LocalizationProvider dateAdapter={AdapterDayjs}>
1414
<ThemeProvider theme={createTheme()}>
1515
<CssBaseline />
16-
{/* <SciDataGridEx /> */}
16+
<SciDataGridEx />
1717
{/* <FiltersExGroups /> */}
18-
<FiltersExNoGroups />
18+
{/* <FiltersExNoGroups /> */}
1919
</ThemeProvider>
2020
</LocalizationProvider>
2121
)

strudel-taskflows/src/pages/explore-data/_components/DataTablePanel.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import FilterListIcon from '@mui/icons-material/FilterList';
22
import { Button, Paper, Stack, TextField, Typography } from '@mui/material';
33
import { GridEventListener } from '@mui/x-data-grid';
4+
import { SciDataGrid } from '@strudel-science/components';
45
import React from 'react';
5-
import { DataGrid } from '@mui/x-data-grid';
66
import { useExploreData } from '../_context/ContextProvider';
77
import { setPreviewItem, setSearch } from '../_context/actions';
88

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

21-
const handleRowClick: GridEventListener<'rowClick'> = (rowData) => {
21+
const handleRowClick: GridEventListener<"rowClick"> = (rowData) => {
2222
dispatch(setPreviewItem(rowData.row));
2323
};
2424

@@ -53,9 +53,9 @@ export const DataTablePanel: React.FC<DataTablePanelProps> = (props) => {
5353
onChange={handleSearch}
5454
/>
5555
</Stack>
56-
<DataGrid
56+
<SciDataGrid
5757
rows={state.filteredData || []}
58-
getRowId={(row) => row[state.dataIdField]}
58+
getRowId={(row: any) => row[state.dataIdField]}
5959
columns={state.columns}
6060
disableColumnSelector
6161
initialState={{
@@ -64,6 +64,7 @@ export const DataTablePanel: React.FC<DataTablePanelProps> = (props) => {
6464
{...props}
6565
onRowClick={handleRowClick}
6666
sx={{
67+
border: 'none',
6768
'& .MuiDataGrid-cell:focus-within': {
6869
outline: 'none'
6970
},

strudel-taskflows/src/pages/explore-data/_components/FiltersPanel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export const FiltersPanel: React.FC<FiltersPanelProps> = (props) => {
3434
grouped={false}
3535
onClose={props.onClose}
3636
onChange={handleFiltersChange}
37+
sx={{
38+
border: 'none'
39+
}}
3740
>
3841
{taskflow.pages.index.tableFilters.map((f, i) => (
3942
<FilterField

strudel-taskflows/src/pages/explore-data/_config/taskflow.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ export const taskflow: ExploreDataConfig = {
3030
{
3131
field: "Organism",
3232
headerName: "Organism",
33+
hasPopover: true,
34+
units: "test",
3335
width: 200
3436
},
3537
{
3638
field: "Common Name",
3739
headerName: "Common Name",
40+
units: "test",
3841
width: 200
3942
},
4043
{

strudel-taskflows/src/pages/explore-data/_config/taskflow.types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GridColDef } from "@mui/x-data-grid"
1+
import { SciDataGridColDef } from "@strudel-science/components"
22
import { FilterComponent, FilterOperator } from "@strudel-science/components/dist/components/FilterField"
33

44
/**
@@ -22,7 +22,7 @@ export interface ExploreDataConfig {
2222
index: {
2323
title: string,
2424
description: string,
25-
tableColumns: GridColDef[],
25+
tableColumns: SciDataGridColDef[],
2626
tableFilters: {
2727
field: string,
2828
label: string,

0 commit comments

Comments
 (0)