Skip to content

Commit 39b9fd2

Browse files
committed
chore: clean up Plate component
1 parent ea80428 commit 39b9fd2

File tree

6 files changed

+91
-95
lines changed

6 files changed

+91
-95
lines changed

src/Plate/ColumnLabel.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
3+
export function ColumnLabel({ column }: { column: number }) {
4+
return (
5+
<span
6+
style={{
7+
display: 'flex',
8+
justifyContent: 'center',
9+
padding: 4,
10+
}}
11+
>
12+
<strong>{column}</strong>
13+
</span>
14+
);
15+
}

src/Plate/EmptyWell.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,18 @@ import { CoordinateSystem } from './types';
88
import { columnForPosition, rowForPosition } from './utils';
99
import { GENERAL_WELL_STYLE } from './wellUtils';
1010

11-
export function EmptyWell<TCoordinateSystem extends CoordinateSystem>(props: {
11+
export function EmptyWell<TCoordinateSystem extends CoordinateSystem>({
12+
coordinateSystem,
13+
position,
14+
}: {
1215
position: number;
1316
coordinateSystem: TCoordinateSystem;
1417
}) {
15-
const row = rowForPosition(
16-
props.position,
17-
PLATE_FLOW,
18-
props.coordinateSystem,
19-
);
20-
const column = columnForPosition(
21-
props.position,
22-
PLATE_FLOW,
23-
props.coordinateSystem,
24-
);
18+
const row = rowForPosition(position, PLATE_FLOW, coordinateSystem);
19+
const column = columnForPosition(position, PLATE_FLOW, coordinateSystem);
2520

2621
const { setNodeRef, isOver } = useDroppable({
27-
id: props.position,
22+
id: position,
2823
data: {
2924
coordinates: {
3025
row,

src/Plate/FilledWell.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,28 @@ import { CoordinateSystem, PlateWell } from './types';
99
import { columnForPosition, rowForPosition } from './utils';
1010
import { GENERAL_WELL_STYLE } from './wellUtils';
1111

12-
export function FilledWell<TCoordinateSystem extends CoordinateSystem>(props: {
12+
export function FilledWell<TCoordinateSystem extends CoordinateSystem>({
13+
isDraggable,
14+
well,
15+
coordinateSystem,
16+
position,
17+
}: {
1318
well: PlateWell<TCoordinateSystem>;
1419
coordinateSystem: TCoordinateSystem;
1520
position: number;
1621
isDraggable: boolean;
1722
}) {
1823
const data = {
1924
coordinates: {
20-
row: rowForPosition(props.position, PLATE_FLOW, props.coordinateSystem),
21-
column: columnForPosition(
22-
props.position,
23-
PLATE_FLOW,
24-
props.coordinateSystem,
25-
),
25+
row: rowForPosition(position, PLATE_FLOW, coordinateSystem),
26+
column: columnForPosition(position, PLATE_FLOW, coordinateSystem),
2627
},
2728
};
2829

2930
const { attributes, listeners, setNodeRef, transform } = useDraggable({
30-
id: props.position,
31+
id: position,
3132
data,
32-
disabled: !props.isDraggable,
33+
disabled: !isDraggable,
3334
});
3435

3536
return (
@@ -40,10 +41,10 @@ export function FilledWell<TCoordinateSystem extends CoordinateSystem>(props: {
4041
style={{
4142
...GENERAL_WELL_STYLE,
4243
transform: CSS.Translate.toString(transform),
43-
backgroundColor: props.well.color ?? PALETTE.gray3,
44+
backgroundColor: well.color ?? PALETTE.gray3,
4445
}}
4546
>
46-
{props.well.content}
47+
{well.content}
4748
</div>
4849
);
4950
}

src/Plate/RowLabel.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import React from 'react';
22

3-
import { PLATE_FLOW } from './constants';
4-
import { CoordinateSystem } from './types';
5-
import { rowForPosition } from './utils';
6-
7-
export function RowLabel(props: {
8-
position: number;
9-
coordinateSystem: CoordinateSystem;
10-
}) {
3+
export function RowLabel({ row }: { row: string }) {
114
return (
125
<span
136
style={{
@@ -16,9 +9,7 @@ export function RowLabel(props: {
169
alignItems: 'center',
1710
}}
1811
>
19-
<strong>
20-
{rowForPosition(props.position, PLATE_FLOW, props.coordinateSystem)}
21-
</strong>
12+
<strong>{row}</strong>
2213
</span>
2314
);
2415
}

src/Plate/Well.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@ import { EmptyWell } from './EmptyWell';
55
import { FilledWell } from './FilledWell';
66
import { CoordinateSystem, PlateWell } from './types';
77

8-
export function Well<TCoordinateSystem extends CoordinateSystem>(props: {
8+
export function Well<TCoordinateSystem extends CoordinateSystem>({
9+
coordinateSystem,
10+
isDraggable,
11+
position,
12+
well,
13+
}: {
914
position: number;
1015
well: Maybe<PlateWell<TCoordinateSystem>>;
1116
coordinateSystem: TCoordinateSystem;
1217
isDraggable: boolean;
1318
}) {
14-
return props.well?.content ? (
19+
return well?.content ? (
1520
<FilledWell
16-
well={props.well}
17-
coordinateSystem={props.coordinateSystem}
18-
position={props.position}
19-
isDraggable={props.isDraggable}
21+
well={well}
22+
coordinateSystem={coordinateSystem}
23+
position={position}
24+
isDraggable={isDraggable}
2025
/>
2126
) : (
22-
<EmptyWell
23-
position={props.position}
24-
coordinateSystem={props.coordinateSystem}
25-
/>
27+
<EmptyWell position={position} coordinateSystem={coordinateSystem} />
2628
);
2729
}

src/Plate/index.tsx

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, { Fragment } from 'react';
44

55
import { MllSpinnerIcon } from '../Spinner';
66

7+
import { ColumnLabel } from './ColumnLabel';
78
import { RowLabel } from './RowLabel';
89
import { Well } from './Well';
910
import { PLATE_FLOW } from './constants';
@@ -12,6 +13,7 @@ import {
1213
allCoordinateSystemPositions,
1314
assertUniquePositions,
1415
columnForPosition,
16+
rowForPosition,
1517
wellAtPosition,
1618
} from './utils';
1719

@@ -22,17 +24,21 @@ export * from './types';
2224
export * from './utils';
2325
export { GENERAL_WELL_STYLE } from './wellUtils';
2426

25-
export function Plate<TCoordinateSystem extends CoordinateSystem>(
26-
props: PlateProps<TCoordinateSystem>,
27-
) {
28-
if (props.data) {
29-
assertUniquePositions(props.data);
27+
export function Plate<TCoordinateSystem extends CoordinateSystem>({
28+
coordinateSystem,
29+
data,
30+
dndContextProps,
31+
isDraggable,
32+
loading,
33+
}: PlateProps<TCoordinateSystem>) {
34+
if (data) {
35+
assertUniquePositions(data);
3036
}
3137

3238
return (
33-
<DndContext {...props.dndContextProps}>
39+
<DndContext {...dndContextProps}>
3440
<Spin
35-
spinning={props.loading ?? false}
41+
spinning={loading ?? false}
3642
indicator={
3743
<MllSpinnerIcon
3844
style={{
@@ -44,59 +50,45 @@ export function Plate<TCoordinateSystem extends CoordinateSystem>(
4450
<div
4551
style={{
4652
display: 'grid',
47-
gridTemplateColumns: `1fr ${'4fr '.repeat(
48-
props.coordinateSystem.columns.length,
53+
gridTemplateColumns: `1fr${' 4fr'.repeat(
54+
coordinateSystem.columns.length,
4955
)}`,
5056
gridGap: '3px',
5157
}}
5258
>
59+
{/* takes up the space in the upper left corner between A and 1 */}
5360
<span />
5461

55-
{props.coordinateSystem.columns.map((column) => (
56-
<span
57-
style={{
58-
display: 'flex',
59-
justifyContent: 'center',
60-
padding: 4,
61-
}}
62-
key={column}
63-
>
64-
<strong>{column}</strong>
65-
</span>
62+
{coordinateSystem.columns.map((column) => (
63+
<ColumnLabel key={column} column={column} />
6664
))}
6765

68-
{allCoordinateSystemPositions(props.coordinateSystem).map(
69-
(position) => (
70-
<Fragment key={position}>
71-
{columnForPosition(
72-
position,
73-
PLATE_FLOW,
74-
props.coordinateSystem,
75-
) === 1 && (
76-
<RowLabel
77-
position={position}
78-
coordinateSystem={props.coordinateSystem}
79-
/>
80-
)}
81-
82-
<Well
83-
position={position}
84-
coordinateSystem={props.coordinateSystem}
85-
well={
86-
props.data
87-
? wellAtPosition(
88-
position,
89-
props.data,
90-
PLATE_FLOW,
91-
props.coordinateSystem,
92-
)
93-
: null
94-
}
95-
isDraggable={props.isDraggable ?? false}
66+
{allCoordinateSystemPositions(coordinateSystem).map((position) => (
67+
<Fragment key={position}>
68+
{columnForPosition(position, PLATE_FLOW, coordinateSystem) ===
69+
1 && (
70+
<RowLabel
71+
row={rowForPosition(position, PLATE_FLOW, coordinateSystem)}
9672
/>
97-
</Fragment>
98-
),
99-
)}
73+
)}
74+
75+
<Well
76+
position={position}
77+
coordinateSystem={coordinateSystem}
78+
well={
79+
data
80+
? wellAtPosition(
81+
position,
82+
data,
83+
PLATE_FLOW,
84+
coordinateSystem,
85+
)
86+
: null
87+
}
88+
isDraggable={isDraggable ?? false}
89+
/>
90+
</Fragment>
91+
))}
10092
</div>
10193
</Spin>
10294
</DndContext>

0 commit comments

Comments
 (0)