Skip to content

Commit

Permalink
stripIds on variant breakend dialog too
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 19, 2024
1 parent f936022 commit 8c45005
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const BreakendOptionDialog = observer(function ({
try {
const viewSnapshot = getBreakpointSplitView({ view, f1, f2 })
const [view1, view2] = viewSnapshot.views
const viewTracks = getSnapshot(view.tracks) as Track[]
const viewTracks = getSnapshot(view.tracks)

session.addView('BreakpointSplitView', {
...viewSnapshot,
Expand Down
87 changes: 51 additions & 36 deletions plugins/variants/src/VariantFeatureWidget/BreakendOptionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,37 @@ const useStyles = makeStyles()({
})

interface Track {
trackId: string
id: string
displays: { id: string; [key: string]: unknown }[]
[key: string]: unknown
}

function remapIds(arr: Track[]) {
return arr.map(v => ({
...v,
id: `${v.trackId}-${Math.random()}`,
function stripIds(arr: Track[]) {
return arr.map(({ id, displays, ...rest }) => ({
...rest,
displays: displays.map(({ id, ...rest }) => rest),
}))
}

function Checkbox2({
checked,
label,
onChange,
}: {
checked: boolean
label: string
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void
}) {
const { classes } = useStyles()
return (
<FormControlLabel
className={classes.block}
control={<Checkbox checked={checked} onChange={onChange} />}
label={label}
/>
)
}

const BreakendOptionDialog = observer(function ({
model,
handleClose,
Expand All @@ -44,32 +64,20 @@ const BreakendOptionDialog = observer(function ({
feature: Feature
viewType: ViewType
}) {
const { classes } = useStyles()
const [copyTracks, setCopyTracks] = useState(true)
const [mirrorTracks, setMirrorTracks] = useState(true)
const [mirror, setMirror] = useState(true)

return (
<Dialog open onClose={handleClose} title="Breakpoint split view options">
<DialogContent>
<FormControlLabel
className={classes.block}
control={
<Checkbox
checked={copyTracks}
onChange={event => setCopyTracks(event.target.checked)}
/>
}
<Checkbox2
checked={copyTracks}
onChange={event => setCopyTracks(event.target.checked)}
label="Copy tracks into the new view"
/>

<FormControlLabel
className={classes.block}
control={
<Checkbox
checked={mirrorTracks}
onChange={event => setMirrorTracks(event.target.checked)}
/>
}
<Checkbox2
checked={mirror}
onChange={event => setMirror(event.target.checked)}
label="Mirror tracks vertically in vertically stacked view"
/>
</DialogContent>
Expand All @@ -84,19 +92,26 @@ const BreakendOptionDialog = observer(function ({
feature,
view,
)
const [view1, view2] = viewSnapshot.views
const viewTracks = getSnapshot(view.tracks)

viewSnapshot.views[0].offsetPx -= view.width / 2 + 100
viewSnapshot.views[1].offsetPx -= view.width / 2 + 100
viewSnapshot.featureData = feature
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const viewTracks = getSnapshot(view.tracks) as Track[]
viewSnapshot.views[0].tracks = remapIds(viewTracks)
viewSnapshot.views[1].tracks = remapIds(
mirrorTracks ? [...viewTracks].reverse() : viewTracks,
)
console.log({ viewSnapshot })

session.addView('BreakpointSplitView', viewSnapshot)
session.addView('BreakpointSplitView', {
...viewSnapshot,
views: [
{
...view1,
tracks: stripIds(viewTracks),

Check failure on line 103 in plugins/variants/src/VariantFeatureWidget/BreakendOptionDialog.tsx

View workflow job for this annotation

GitHub Actions / Test and typecheck on node 20.x and ubuntu-latest

Argument of type 'unknown' is not assignable to parameter of type 'Track[]'.
offsetPx: view1.offsetPx - view.width / 2 + 100,
},
{
...view2,
tracks: stripIds(
mirror ? [...viewTracks].reverse() : viewTracks,

Check failure on line 109 in plugins/variants/src/VariantFeatureWidget/BreakendOptionDialog.tsx

View workflow job for this annotation

GitHub Actions / Test and typecheck on node 20.x and ubuntu-latest

Argument of type 'unknown' is not assignable to parameter of type 'Track[]'.

Check failure on line 109 in plugins/variants/src/VariantFeatureWidget/BreakendOptionDialog.tsx

View workflow job for this annotation

GitHub Actions / Test and typecheck on node 20.x and ubuntu-latest

Type 'unknown' must have a '[Symbol.iterator]()' method that returns an iterator.
),
offsetPx: view2.offsetPx - view.width / 2 + 100,
},
],
})
} catch (e) {
console.error(e)
session.notify(`${e}`)
Expand Down

0 comments on commit 8c45005

Please sign in to comment.