Skip to content

Commit

Permalink
fix: import of v2 documents with minimized components (#1622)
Browse files Browse the repository at this point in the history
  • Loading branch information
kswenson authored Nov 15, 2024
1 parent 6162b9a commit 1e998bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions v3/src/models/document/free-tile-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface IFreeTileInRowOptions extends ITileInRowOptions {
width?: number
height?: number
zIndex?: number
isMinimized?: boolean
animateCreation?: boolean
}
export const isFreeTileInRowOptions = (options?: ITileInRowOptions): options is IFreeTileInRowOptions =>
Expand Down Expand Up @@ -141,9 +142,10 @@ export const FreeTileRow = TileRowModel
},
insertTile(tileId: string, options?: ITileInRowOptions) {
const {
x = 50, y = 50, width = undefined, height = undefined, zIndex = this.nextZIndex(), animateCreation = false
x = 50, y = 50, width = undefined, height = undefined, zIndex = this.nextZIndex(),
isMinimized = undefined, animateCreation = false
} = isFreeTileInRowOptions(options) ? options : {}
self.tiles.set(tileId, { tileId, x, y, width, height, zIndex })
self.tiles.set(tileId, { tileId, x, y, width, height, zIndex, isMinimized })
animateCreation && self.animateCreationTiles.add(tileId)
},
removeTile(tileId: string) {
Expand Down
8 changes: 6 additions & 2 deletions v3/src/v2/import-v2-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ export function importV2Document(v2Document: CodapV2Document) {
if (row && tile) {
const info = getTileComponentInfo(tile.content.type)
if (info) {
const { left = 0, top = 0, width, height, zIndex } = v2Component.layout
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
// 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 }
const layout: IFreeTileInRowOptions = { x: left, y: top, ..._width, ..._height, ..._zIndex, isMinimized }
newTile = content?.insertTileSnapshotInRow(tile, row, layout)
}
}
Expand Down

0 comments on commit 1e998bd

Please sign in to comment.