Skip to content

Commit

Permalink
fix: handling of hidden tiles (#1630)
Browse files Browse the repository at this point in the history
  • Loading branch information
kswenson authored Nov 16, 2024
1 parent 38b4878 commit 2eb134d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
22 changes: 13 additions & 9 deletions v3/src/models/document/free-tile-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export const FreeTileLayout = types.model("FreeTileLayout", {
isHidden: types.maybe(types.boolean),
isMinimized: types.maybe(types.boolean)
})
.preProcessSnapshot(snap => {
if (snap.isHidden && snap.isMinimized) {
// can't be both minimized and hidden
const { isMinimized, ...others } = snap
return { ...others }
}
return snap
})
.views(self => ({
get position() {
return { x: self.x, y: self.y }
Expand All @@ -45,6 +53,8 @@ export const FreeTileLayout = types.model("FreeTileLayout", {
setHidden(isHidden: boolean) {
// only store it if it's true
self.isHidden = isHidden || undefined
// can't be both hidden and minimized
if (isHidden) self.isMinimized = undefined
},
setMinimized(isMinimized: boolean) {
// only store it if it's true
Expand All @@ -60,13 +70,7 @@ export function isFreeTileLayout(layout?: any): layout is IFreeTileLayout {
Number.isFinite(layout.x) && Number.isFinite(layout.y)
}

export interface IFreeTileInRowOptions extends ITileInRowOptions {
x: number
y: number
width?: number
height?: number
zIndex?: number
isMinimized?: boolean
export type IFreeTileInRowOptions = ITileInRowOptions & Omit<IFreeTileLayoutSnapshot, "tileId"> & {
animateCreation?: boolean
}
export const isFreeTileInRowOptions = (options?: ITileInRowOptions): options is IFreeTileInRowOptions =>
Expand Down Expand Up @@ -143,9 +147,9 @@ export const FreeTileRow = TileRowModel
insertTile(tileId: string, options?: ITileInRowOptions) {
const {
x = 50, y = 50, width = undefined, height = undefined, zIndex = this.nextZIndex(),
isMinimized = undefined, animateCreation = false
isHidden = undefined, isMinimized = undefined, animateCreation = false
} = isFreeTileInRowOptions(options) ? options : {}
self.tiles.set(tileId, { tileId, x, y, width, height, zIndex, isMinimized })
self.tiles.set(tileId, { tileId, x, y, width, height, zIndex, isHidden, isMinimized })
animateCreation && self.animateCreationTiles.add(tileId)
},
removeTile(tileId: string) {
Expand Down
10 changes: 7 additions & 3 deletions v3/src/v2/import-v2-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ export function importV2Document(v2Document: CodapV2Document) {
const {
layout: { left = 0, top = 0, width, height: v2Height, isVisible, zIndex }, savedHeight
} = v2Component
const isMinimized = (!!savedHeight && savedHeight >= v2Height && !isVisible) || undefined
const height = savedHeight && isMinimized ? savedHeight : v2Height
const isHidden = isVisible === false
const v2Minimized = (!!savedHeight && savedHeight >= v2Height) || undefined
const isMinimized = v2Minimized && !isHidden
const height = savedHeight && v2Minimized ? savedHeight : v2Height
// only apply imported width and height to resizable tiles
const _width = !info.isFixedWidth ? { width } : {}
const _height = !info?.isFixedHeight ? { height } : {}
const _zIndex = zIndex != null ? { zIndex } : {}
if (zIndex != null && zIndex > maxZIndex) maxZIndex = zIndex
const layout: IFreeTileInRowOptions = { x: left, y: top, ..._width, ..._height, ..._zIndex, isMinimized }
const layout: IFreeTileInRowOptions = {
x: left, y: top, ..._width, ..._height, ..._zIndex, isHidden, isMinimized
}
newTile = content?.insertTileSnapshotInRow(tile, row, layout)
}
}
Expand Down

0 comments on commit 2eb134d

Please sign in to comment.