Skip to content

Commit 86632e4

Browse files
Merge pull request #120 from codytodonnell/feature/detail-page
Update detail page queries
2 parents 1060655 + 5f8fd33 commit 86632e4

File tree

9 files changed

+135
-79
lines changed

9 files changed

+135
-79
lines changed

strudel-taskflows/src/components/CheckboxList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ export const CheckboxList: React.FC<CheckboxListProps> = ({
3939
};
4040

4141
useEffect(() => {
42-
console.log(checkValues)
43-
if (onChange) onChange(checkValues);
42+
if (onChange && checkValues?.length !== values?.length) {
43+
onChange(checkValues);
44+
}
4445
}, [checkValues]);
4546

4647
useEffect(() => {

strudel-taskflows/src/components/FilterContext.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,10 @@ function filterReducer(state: FilterState, action: FilterAction): FilterState {
4343
} else if (filter.value) {
4444
activeFilters.push(filter);
4545
}
46-
console.log(activeFilters);
4746
return {
4847
...state,
4948
activeFilters
5049
}
51-
// return {
52-
// ...state,
53-
// activeFilters: { ...state.activeFilters, [action.payload.field]: action.payload.value }
54-
// }
5550
}
5651
case 'SET_ACTIVE_FILTERS': {
5752
return {
@@ -95,14 +90,6 @@ export const FilterContext: React.FC<FilterContextProps> = ({
9590
if (onChange) onChange(state.activeFilters);
9691
}, [JSON.stringify(state.activeFilters)]);
9792

98-
/**
99-
* If activeFilters is changed from outside the context (e.g. filters are reset)
100-
* then the new value should be dispatched.
101-
*/
102-
// useEffect(() => {
103-
// dispatch({ type: 'SET_ACTIVE_FILTERS', payload: activeFilters });
104-
// }, [activeFilters]);
105-
10693
return (
10794
<FilterContextAPI.Provider value={value}>
10895
{children}

strudel-taskflows/src/components/PageHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PaperProps, Breadcrumbs, Link, Paper, Stack, Typography } from '@mui/ma
33
import HomeIcon from '@mui/icons-material/Home';
44

55
interface PageHeaderProps extends PaperProps {
6-
pageTitle: string;
6+
pageTitle: React.ReactNode;
77
breadcrumbTitle?: string;
88
description?: string;
99
actions?: React.ReactNode;

strudel-taskflows/src/pages/explore-data/[id].tsx

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,56 @@ import React from 'react';
33
import { useParams } from 'react-router-dom';
44
import { PageHeader } from '../../components/PageHeader';
55
import { taskflow } from './_config/taskflow.config';
6+
import { useQuery } from '@tanstack/react-query';
7+
8+
interface DataDetailPageProps {
9+
item: any
10+
}
611

712
/**
8-
* Work in Progress:
9-
*
1013
* Detail view for a selected row from the` <DataExplorer>` in the explore-data Task Flow.
1114
*/
12-
const DataDetailPage: React.FC = () => {
15+
const DataDetailPage: React.FC<DataDetailPageProps> = ({ item }) => {
1316
const params = useParams();
17+
const dataSource = taskflow.data.item.source;
1418
const dataIdField = taskflow.data.items.idField;
1519
const columns = taskflow.pages.index.tableColumns;
16-
const data: any[] = [];
17-
const entity = data?.find((d) => {
18-
if (params.id) {
19-
return d[dataIdField].toString() === params.id.toString();
20+
const queryMode = taskflow.data.items.queryMode;
21+
const staticParams = taskflow.data.items.staticParams;
22+
let queryParams = { ...staticParams };
23+
const queryString = new URLSearchParams(queryParams).toString();
24+
let queryFn;
25+
if (queryMode === 'server') {
26+
queryFn = async (): Promise<any> => {
27+
const response = await fetch(`${dataSource}/${params.id}?${queryString}`);
28+
return await response.json();
29+
}
30+
} else if (queryMode === 'client') {
31+
queryFn = async (): Promise<any> => {
32+
const response = await fetch(`${dataSource}?${queryString}`);
33+
const results = await response.json();
34+
return results?.find((d: any) => {
35+
if (params.id) {
36+
return d[dataIdField].toString() === params.id.toString();
37+
}
38+
});
2039
}
40+
}
41+
42+
43+
// Define query for this page and fetch data items
44+
const { isPending, isFetching, isError, data, error } = useQuery({
45+
queryKey: ['item', params.id, queryParams],
46+
queryFn,
2147
});
22-
const entityTitle = entity ? entity[columns[0].field] : 'Not Found';
2348

2449
/**
2550
* Content to render on the page for this component
2651
*/
2752
return (
2853
<Box>
2954
<PageHeader
30-
pageTitle={entityTitle}
55+
pageTitle={data ? data[dataIdField] : ''}
3156
breadcrumbTitle="Data Detail"
3257
sx={{
3358
marginBottom: 1,
@@ -46,17 +71,10 @@ const DataDetailPage: React.FC = () => {
4671
{columns[1].field}
4772
</Typography>
4873
<Typography>
49-
{entity && entity[columns[1].field]}
74+
{data && data[columns[1].field]}
5075
</Typography>
5176
</Stack>
5277
</Paper>
53-
<Paper
54-
sx={{
55-
padding: 2
56-
}}
57-
>
58-
More coming soon!
59-
</Paper>
6078
</Stack>
6179
</Container>
6280
</Box>

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import { ExploreDataConfig } from "./taskflow.types";
22

33
export const taskflow: ExploreDataConfig = {
44
data: {
5+
/**
6+
* Data definition for the initial items list
7+
*/
58
items: {
69
/**
7-
* Source of the data for the initial list of items on the main page.
10+
* URL or path to the data source
811
*/
912
source: "https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI",
1013
/**
@@ -15,6 +18,21 @@ export const taskflow: ExploreDataConfig = {
1518
* Method by which data should be filtered, either client or server.
1619
*/
1720
queryMode: "client",
21+
/**
22+
* Key-value object of params that should always be included in the query URL
23+
*/
24+
staticParams: {
25+
table: 'cumulative',
26+
format: 'json'
27+
}
28+
},
29+
/**
30+
* Data definition for the item detail page
31+
*/
32+
item: {
33+
source: "https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI",
34+
idField: "kepoi_name",
35+
queryMode: "client",
1836
staticParams: {
1937
table: 'cumulative',
2038
format: 'json'
@@ -42,22 +60,22 @@ export const taskflow: ExploreDataConfig = {
4260
},
4361
{
4462
field: "kepoi_name",
45-
headerName: "Name",
63+
headerName: "Kepler OI Name",
4664
width: 150
4765
},
4866
{
49-
field: "koi_disposition",
50-
headerName: "koi_disposition",
67+
field: "kepler_name",
68+
headerName: "Kepler Name",
5169
width: 150
5270
},
5371
{
54-
field: "koi_pdisposition",
55-
headerName: "koi_pdisposition",
72+
field: "koi_disposition",
73+
headerName: "Disposition",
5674
width: 150
5775
},
5876
{
5977
field: "koi_period",
60-
headerName: "koi_period",
78+
headerName: "Period",
6179
width: 150,
6280
type: 'number'
6381
}

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import { ExploreDataConfig } from "./taskflow.types";
22

33
export const taskflow: ExploreDataConfig = {
44
data: {
5+
/**
6+
* Data definition for the initial items list
7+
*/
58
items: {
69
/**
7-
* Source of the data for the initial list of items on the main page.
10+
* URL or path to the data source
811
*/
912
source: "https://api.gbif.org/v1/occurrence/search",
1013
/**
@@ -14,7 +17,20 @@ export const taskflow: ExploreDataConfig = {
1417
/**
1518
* Method by which data should be filtered, either client or server.
1619
*/
17-
queryMode: "server"
20+
queryMode: "server",
21+
/**
22+
* Key-value object of params that should always be included in the query URL
23+
*/
24+
staticParams: null
25+
},
26+
/**
27+
* Data definition for the item detail page
28+
*/
29+
item: {
30+
source: "https://api.gbif.org/v1/occurrence",
31+
idField: "key",
32+
queryMode: "server",
33+
staticParams: null
1834
}
1935
},
2036
pages: {

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import { ExploreDataConfig } from "./taskflow.types";
22

33
export const taskflow: ExploreDataConfig = {
44
data: {
5+
/**
6+
* Data definition for the initial items list
7+
*/
58
items: {
69
/**
7-
* Source of the data for the initial list of items on the main page.
10+
* URL or path to the data source
811
*/
912
source: "https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI",
1013
/**
@@ -15,6 +18,21 @@ export const taskflow: ExploreDataConfig = {
1518
* Method by which data should be filtered, either client or server.
1619
*/
1720
queryMode: "client",
21+
/**
22+
* Key-value object of params that should always be included in the query URL
23+
*/
24+
staticParams: {
25+
table: 'cumulative',
26+
format: 'json'
27+
}
28+
},
29+
/**
30+
* Data definition for the item detail page
31+
*/
32+
item: {
33+
source: "https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI",
34+
idField: "kepoi_name",
35+
queryMode: "client",
1836
staticParams: {
1937
table: 'cumulative',
2038
format: 'json'
@@ -42,22 +60,22 @@ export const taskflow: ExploreDataConfig = {
4260
},
4361
{
4462
field: "kepoi_name",
45-
headerName: "Name",
63+
headerName: "Kepler OI Name",
4664
width: 150
4765
},
4866
{
49-
field: "koi_disposition",
50-
headerName: "koi_disposition",
67+
field: "kepler_name",
68+
headerName: "Kepler Name",
5169
width: 150
5270
},
5371
{
54-
field: "koi_pdisposition",
55-
headerName: "koi_pdisposition",
72+
field: "koi_disposition",
73+
headerName: "Disposition",
5674
width: 150
5775
},
5876
{
5977
field: "koi_period",
60-
headerName: "koi_period",
78+
headerName: "Period",
6179
width: 150,
6280
type: 'number'
6381
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export interface ExploreDataConfig {
1313
source: string,
1414
idField: string,
1515
queryMode: 'client' | 'server',
16-
staticParams?: Record<string, string>
16+
staticParams?: Record<string, string> | null
1717
},
1818
[key: string]: {
1919
source: string,
2020
idField: string,
2121
queryMode: 'client' | 'server',
22-
staticParams?: Record<string, string>
22+
staticParams?: Record<string, string> | null
2323
}
2424
},
2525
pages: {

strudel-taskflows/src/pages/explore-data/index.tsx

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, Grid, Paper } from '@mui/material';
1+
import { Box, Paper, Stack } from '@mui/material';
22
import React, { useState } from 'react';
33
import { FilterContext } from '../../components/FilterContext';
44
import { PageHeader } from '../../components/PageHeader';
@@ -41,17 +41,23 @@ const DataExplorer: React.FC = () => {
4141
padding: 2,
4242
}}
4343
/>
44-
<Grid container spacing={1}>
45-
{showFiltersPanel && (
46-
<Grid item xs={2}>
47-
<FiltersPanel onClose={handleCloseFilters} />
48-
</Grid>
49-
)}
50-
<Grid item xs={getMainColumnSize(showFiltersPanel, !!previewItem)}>
44+
<Box>
45+
<Stack direction="row">
46+
{showFiltersPanel && (
47+
<Box
48+
sx={{
49+
width: '350px'
50+
}}
51+
>
52+
<FiltersPanel onClose={handleCloseFilters} />
53+
</Box>
54+
)}
5155
<Paper
5256
elevation={0}
5357
sx={{
54-
minHeight: '600px'
58+
flex: 1,
59+
minHeight: '600px',
60+
minWidth: 0,
5561
}}
5662
>
5763
<DataViewHeader
@@ -64,28 +70,20 @@ const DataExplorer: React.FC = () => {
6470
setPreviewItem={setPreviewItem}
6571
/>
6672
</Paper>
67-
</Grid>
68-
{previewItem && (
69-
<Grid item xs={4}>
70-
<PreviewPanel previewItem={previewItem} onClose={handleClosePreview} />
71-
</Grid>
72-
)}
73-
</Grid>
73+
{previewItem && (
74+
<Box
75+
sx={{
76+
minWidth: '400px'
77+
}}
78+
>
79+
<PreviewPanel previewItem={previewItem} onClose={handleClosePreview} />
80+
</Box>
81+
)}
82+
</Stack>
83+
</Box>
7484
</Box>
7585
</FilterContext>
7686
)
7787
}
7888

79-
const getMainColumnSize = (showFiltersPanel: boolean, showPreviewPanel: boolean) => {
80-
if (!showFiltersPanel && !showPreviewPanel) {
81-
return 12;
82-
} else if (showFiltersPanel && !showPreviewPanel) {
83-
return 10;
84-
} else if (!showFiltersPanel && showPreviewPanel) {
85-
return 8;
86-
} else if (showFiltersPanel && showPreviewPanel) {
87-
return 6;
88-
}
89-
}
90-
9189
export default DataExplorer;

0 commit comments

Comments
 (0)