Skip to content

Commit

Permalink
Lint and add GH Action to check linting (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Dec 1, 2020
1 parent bb62a49 commit 3e0871d
Show file tree
Hide file tree
Showing 12 changed files with 407 additions and 380 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Node CI

on: push

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Linting (prettier)
uses: actions/setup-node@v1
with:
node-version: '15.x'
- run: npm install
- run: npm run lint

# TODO: add tests
73 changes: 33 additions & 40 deletions src/components/LayerController/AcquisitionController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,39 @@ import type { Acquisition } from '../../state';

import { sourceInfoState } from '../../state';


function AcquisitionController({ layerId }: {layerId: string,}): JSX.Element | null {

const sourceInfo = useRecoilValue(sourceInfoState);
const { acquisitionId, acquisitions, source } = sourceInfo[layerId];

if (!acquisitions) {
return null;
}

const handleSelectionChange = (event: ChangeEvent<HTMLSelectElement>) => {
let value = event.target.value;
let acquisition = value === '-1' ? '' : `&acquisition=${value}`
window.location.href = window.location.origin + window.location.pathname + `?source=${source}${acquisition}`;
};

return (
<>
<Grid>
<NativeSelect
fullWidth
style={{ fontSize: '0.7em' }}
onChange={handleSelectionChange}
value={acquisitionId}
>
<option value="-1" key="-1">
Filter by Acquisition
</option>
{acquisitions.map(acq => {
acq = acq as Acquisition;
return(
<option value={acq.id} key={acq.id}>
Acquisition: {acq.name}
</option>
)
})}
</NativeSelect>
</Grid>
</>
)
function AcquisitionController({ layerId }: { layerId: string }): JSX.Element | null {
const sourceInfo = useRecoilValue(sourceInfoState);
const { acquisitionId, acquisitions, source } = sourceInfo[layerId];

if (!acquisitions) {
return null;
}

const handleSelectionChange = (event: ChangeEvent<HTMLSelectElement>) => {
let value = event.target.value;
let acquisition = value === '-1' ? '' : `&acquisition=${value}`;
window.location.href = window.location.origin + window.location.pathname + `?source=${source}${acquisition}`;
};

return (
<>
<Grid>
<NativeSelect fullWidth style={{ fontSize: '0.7em' }} onChange={handleSelectionChange} value={acquisitionId}>
<option value="-1" key="-1">
Filter by Acquisition
</option>
{acquisitions.map((acq) => {
acq = acq as Acquisition;
return (
<option value={acq.id} key={acq.id}>
Acquisition: {acq.name}
</option>
);
})}
</NativeSelect>
</Grid>
</>
);
}

export default AcquisitionController;
142 changes: 69 additions & 73 deletions src/components/LayerController/AxisOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,88 +8,84 @@ import { MoreHoriz } from '@material-ui/icons';
import { layerStateFamily } from '../../state';

const DenseInput = withStyles({
root: {
width: '5.5em',
fontSize: '0.7em',
},
root: {
width: '5.5em',
fontSize: '0.7em',
},
})(Input);

function AxisOptions({ layerId, axisIndex, max }: {
layerId: string,
axisIndex: number,
max: number
}): JSX.Element {
const [layer, setLayer] = useRecoilState(layerStateFamily(layerId));
const [anchorEl, setAnchorEl] = useState<null | Element>(null);
function AxisOptions({ layerId, axisIndex, max }: { layerId: string; axisIndex: number; max: number }): JSX.Element {
const [layer, setLayer] = useRecoilState(layerStateFamily(layerId));
const [anchorEl, setAnchorEl] = useState<null | Element>(null);

const handleClick = (event: MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClick = (event: MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};

const handleClose = () => {
setAnchorEl(null);
};
const handleClose = () => {
setAnchorEl(null);
};

const handleIndexChange = (event: ChangeEvent<HTMLInputElement>) => {
let value = +event.target.value;
// Restrict value to valid range
if (value < 0) value = 0;
if (value > max) value = max;
const handleIndexChange = (event: ChangeEvent<HTMLInputElement>) => {
let value = +event.target.value;
// Restrict value to valid range
if (value < 0) value = 0;
if (value > max) value = max;

setLayer((prev) => {
let layerProps = { ...prev.layerProps }
// for each channel, update index
layerProps.loaderSelection = layerProps.loaderSelection.map(ch => {
let new_ch = [...ch]
new_ch[axisIndex] = value;
return new_ch;
});
setLayer((prev) => {
let layerProps = { ...prev.layerProps };
// for each channel, update index
layerProps.loaderSelection = layerProps.loaderSelection.map((ch) => {
let new_ch = [...ch];
new_ch[axisIndex] = value;
return new_ch;
});

return { ...prev, layerProps };
});
};
return { ...prev, layerProps };
});
};

const open = Boolean(anchorEl);
const id = open ? `${axisIndex}-index-${layerId}-options` : undefined;
const value = layer.layerProps.loaderSelection[0] ? layer.layerProps.loaderSelection[0][axisIndex] : 1;
const open = Boolean(anchorEl);
const id = open ? `${axisIndex}-index-${layerId}-options` : undefined;
const value = layer.layerProps.loaderSelection[0] ? layer.layerProps.loaderSelection[0][axisIndex] : 1;

return (
<>
<IconButton
onClick={handleClick}
aria-describedby={id}
style={{
backgroundColor: 'transparent',
padding: 0,
zIndex: 2,
cursor: 'pointer',
}}
>
<MoreHoriz />
</IconButton>
<Popover
id={id}
open={open}
anchorEl={anchorEl}
onClose={handleClose}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'left',
}}
>
<Paper style={{ padding: '0px 4px', marginBottom: 4 }}>
<Typography variant="caption">Index:</Typography>
<Divider />
<DenseInput value={value} onChange={handleIndexChange} type="number" id="max" fullWidth={false} />
<Divider />
</Paper>
</Popover>
</>
);
return (
<>
<IconButton
onClick={handleClick}
aria-describedby={id}
style={{
backgroundColor: 'transparent',
padding: 0,
zIndex: 2,
cursor: 'pointer',
}}
>
<MoreHoriz />
</IconButton>
<Popover
id={id}
open={open}
anchorEl={anchorEl}
onClose={handleClose}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'left',
}}
>
<Paper style={{ padding: '0px 4px', marginBottom: 4 }}>
<Typography variant="caption">Index:</Typography>
<Divider />
<DenseInput value={value} onChange={handleIndexChange} type="number" id="max" fullWidth={false} />
<Divider />
</Paper>
</Popover>
</>
);
}

export default AxisOptions;
21 changes: 8 additions & 13 deletions src/components/LayerController/AxisSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ const DenseSlider = withStyles({
},
})(Slider);


function AxisSlider({ layerId, axisIndex, max }: {
layerId: string,
axisIndex: number,
max: number
}): JSX.Element {
function AxisSlider({ layerId, axisIndex, max }: { layerId: string; axisIndex: number; max: number }): JSX.Element {
const [layer, setLayer] = useRecoilState(layerStateFamily(layerId));
const sourceInfo = useRecoilValue(sourceInfoState);
const { axis_labels } = sourceInfo[layerId];
Expand All @@ -41,19 +36,18 @@ function AxisSlider({ layerId, axisIndex, max }: {
setValue(layer.layerProps.loaderSelection[0] ? layer.layerProps.loaderSelection[0][axisIndex] : 1);
}, [layer.layerProps.loaderSelection]);


const handleRelease = () => {
setLayer((prev) => {
let layerProps = { ...prev.layerProps }
let layerProps = { ...prev.layerProps };
// for each channel, update index of this axis
layerProps.loaderSelection = layerProps.loaderSelection.map(ch => {
layerProps.loaderSelection = layerProps.loaderSelection.map((ch) => {
let new_ch = [...ch];
new_ch[axisIndex] = value;
return new_ch;
});
return { ...prev, layerProps };
})
}
});
};

const handleDrag = (_: ChangeEvent<unknown>, value: number | number[]) => {
setValue(value as number);
Expand Down Expand Up @@ -82,13 +76,14 @@ function AxisSlider({ layerId, axisIndex, max }: {
onChangeCommitted={handleRelease}
min={0}
max={max}
step={1} />
step={1}
/>
</Grid>
</Grid>
</Grid>
<Divider />
</>
)
);
}

export default AxisSlider;
13 changes: 5 additions & 8 deletions src/components/LayerController/AxisSliders.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import React from 'react'
import React from 'react';
import { Grid, Divider } from '@material-ui/core';
import { useRecoilValue } from 'recoil';
import AxisSlider from './AxisSlider';
import { sourceInfoState } from '../../state';


function AxisSliders({ layerId }: { layerId: string }): JSX.Element | null {
const sourceInfo = useRecoilValue(sourceInfoState);
const { axis_labels, channel_axis, loader } = sourceInfo[layerId];

const sliders = axis_labels
.slice(0, -2) // ignore last two axes, [y,x]
.map((name, i): [string, number, number] => ([name, i, loader.base.shape[i]])) // capture the name, index, and size of non-yx dims
.filter(d => {
.map((name, i): [string, number, number] => [name, i, loader.base.shape[i]]) // capture the name, index, and size of non-yx dims
.filter((d) => {
if (d[1] === channel_axis) return false; // ignore channel_axis (for OME-Zarr channel_axis === 1)
if (d[2] > 1) return true; // keep if size > 1
return false; // otherwise ignore as well
Expand All @@ -22,12 +21,10 @@ function AxisSliders({ layerId }: { layerId: string }): JSX.Element | null {
if (sliders.length === 0) return null;
return (
<>
<Grid>
{sliders}
</Grid>
<Grid>{sliders}</Grid>
<Divider />
</>
)
);
}

export default AxisSliders;
5 changes: 2 additions & 3 deletions src/components/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { Layer } from '@deck.gl/core';
import { viewerViewState, layersSelector } from '../state';
import type { VivLayerProps, ZarrLoader } from '@hms-dbmi/viv';


function WrappedViewStateDeck({ layers }: { layers: Layer<VivLayerProps>[] }): JSX.Element {
const [viewState, setViewState] = useRecoilState(viewerViewState);

Expand All @@ -19,8 +18,8 @@ function WrappedViewStateDeck({ layers }: { layers: Layer<VivLayerProps>[] }): J
const zoom = -loader.numLevels;
const target = [width / 2, height / 2, 0];
setViewState({ zoom, target });
};
}

const views = [new OrthographicView({ id: 'ortho', controller: true })];

return (
Expand Down

0 comments on commit 3e0871d

Please sign in to comment.