Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable metrics for analysis page #673

Merged
merged 5 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/scripts/components/analysis/define/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

const findParentDataset = (layerId: string) => {
const parentDataset = Object.values(datasets).find((dataset) =>
(dataset as VedaDatum<DatasetData>).data.layers.find(

Check warning on line 105 in app/scripts/components/analysis/define/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Use a ! assertion to more succinctly remove null and undefined from the type
(l) => l.id === layerId
)
);
Expand All @@ -112,9 +112,9 @@
export const allAvailableDatasetsLayers: DatasetLayer[] = Object.values(
datasets
)
.map((dataset) => (dataset as VedaDatum<DatasetData>).data.layers)

Check warning on line 115 in app/scripts/components/analysis/define/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Use a ! assertion to more succinctly remove null and undefined from the type
.flat()
.filter((d) => d.type !== 'vector');
.filter((d) => d.type !== 'vector' && !d.analysis?.exclude);

export default function Analysis() {
const { params, setAnalysisParam } = useAnalysisParams();
Expand Down Expand Up @@ -167,7 +167,7 @@
const onDatasetLayerChange = useCallback(
(e) => {
const id = e.target.id;
let newDatasetsLayers = [...(datasetsLayers || [])];

Check warning on line 170 in app/scripts/components/analysis/define/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
if (e.target.checked) {
const newDatasetLayer = allAvailableDatasetsLayers.find(
(l) => l.id === id
Expand Down Expand Up @@ -197,14 +197,14 @@
const selectableDatasetLayersIds = selectableDatasetLayers.map(
(layer) => layer.id
);
const cleanedDatasetsLayers = datasetsLayers?.filter((l) =>

Check warning on line 200 in app/scripts/components/analysis/define/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Unnecessary optional chain on a non-nullish value
selectableDatasetLayersIds.includes(l.id)
);

setAnalysisParam('datasetsLayers', cleanedDatasetsLayers);
// Only update when stac search gets updated to avoid triggering an infinite
// read/set state loop
}, [selectableDatasetLayers, setAnalysisParam]);

Check warning on line 207 in app/scripts/components/analysis/define/index.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'datasetsLayers'. Either include it or remove the dependency array

const showTip = !readyToLoadDatasets || !datasetsLayers?.length;

Expand Down
199 changes: 0 additions & 199 deletions app/scripts/components/analysis/results/analysis-head-actions.tsx

This file was deleted.

79 changes: 79 additions & 0 deletions app/scripts/components/analysis/results/analysis-head.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, { Fragment } from 'react';
import styled, { useTheme } from 'styled-components';
import { media } from '@devseed-ui/theme-provider';
import { Button } from '@devseed-ui/button';

import { DATA_METRICS } from './analysis-metrics-dropdown';

import { FoldHeadActions } from '$components/common/fold';
import {
Legend,
LegendTitle,
LegendList,
LegendSwatch,
LegendLabel
} from '$styles/infographics';

const AnalysisFoldHeadActions = styled(FoldHeadActions)`
width: 100%;

${media.mediumUp`
width: auto;
`}

${Button} {
margin-left: auto;
}
`;

const AnalysisLegend = styled(Legend)`
flex-flow: column nowrap;
align-items: flex-start;

${media.smallUp`
flex-flow: row nowrap;
align-items: center;
`};
`;

const AnalysisLegendList = styled(LegendList)`
display: grid;
grid-template-columns: repeat(6, auto);

${media.smallUp`
display: flex;
flex-flow: row nowrap;
`};
`;

export default function AnalysisHead() {
const theme = useTheme();

return (
<AnalysisFoldHeadActions>
<AnalysisLegend>
<LegendTitle>Legend</LegendTitle>
<AnalysisLegendList>
{DATA_METRICS.map((metric) => {
return (
<Fragment key={metric.id}>
<LegendSwatch>
<svg height='8' width='8'>
<title>{theme.color?.[metric.themeColor]}</title>
<circle
cx='4'
cy='4'
r='4'
fill={theme.color?.[metric.themeColor]}
/>
</svg>
</LegendSwatch>
<LegendLabel>{metric.label}</LegendLabel>
</Fragment>
);
})}
</AnalysisLegendList>
</AnalysisLegend>
</AnalysisFoldHeadActions>
);
}
Loading
Loading